From fe8e14cb2ce030a22f3a982db156a38770706b0c Mon Sep 17 00:00:00 2001 From: Thomas Waldmann Date: Tue, 14 Feb 2017 20:54:25 +0100 Subject: [PATCH] fuse: get rid of chunk accounting the chunk accounting code tried to reflect repo space usage via the st_blocks of the files. so, a specific chunk that was shared between multiple files [inodes] was only accounted for one specific file. thus, the overall "du" of everything in the fuse mounted repo was maybe correctly reflecting the repo space usage, but the decision which file has the chunk (the space) was kind of arbitrary and not really useful. otoh, a simple fuse getattr() was rather expensive due to this as it needed to iterate over the chunks list to compute the st_blocks value. also it needed quite some memory for the accounting. thus, st_blocks is now just ceil(size / blocksize). also: fixed bug that st_blocks was a floating point value previously. also: preparing for further optimization of size computation (see next cs) --- src/borg/fuse.py | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/src/borg/fuse.py b/src/borg/fuse.py index 53f60462f..db84fcdeb 100644 --- a/src/borg/fuse.py +++ b/src/borg/fuse.py @@ -72,7 +72,6 @@ class FuseOperations(llfuse.Operations): self.contents = defaultdict(dict) self.default_dir = Item(mode=0o40755, mtime=int(time.time() * 1e9), uid=os.getuid(), gid=os.getgid()) self.pending_archives = {} - self.accounted_chunks = {} self.cache = ItemCache() data_cache_capacity = int(os.environ.get('BORG_MOUNT_DATA_CACHE_ENTRIES', os.cpu_count() or 1)) logger.debug('mount data cache capacity: %d chunks', data_cache_capacity) @@ -258,14 +257,9 @@ class FuseOperations(llfuse.Operations): def getattr(self, inode, ctx=None): item = self.get_item(inode) size = 0 - dsize = 0 if 'chunks' in item: - # if we would not need to compute dsize, we could get size quickly from item.size, if present. for key, chunksize, _ in item.chunks: size += chunksize - if self.accounted_chunks.get(key, inode) == inode: - self.accounted_chunks[key] = inode - dsize += chunksize entry = llfuse.EntryAttributes() entry.st_ino = inode entry.generation = 0 @@ -278,7 +272,7 @@ class FuseOperations(llfuse.Operations): entry.st_rdev = item.get('rdev', 0) entry.st_size = size entry.st_blksize = 512 - entry.st_blocks = dsize / 512 + entry.st_blocks = (size + entry.st_blksize - 1) // entry.st_blksize # note: older archives only have mtime (not atime nor ctime) mtime_ns = item.mtime if have_fuse_xtime_ns: