Archive: allocate zeros when needed (#2308)

fixes huge memory usage of mount (8 MiB × number of archives)
(cherry picked from commit 883a7eefb2)
This commit is contained in:
enkore 2017-03-15 17:08:07 +01:00 committed by Thomas Waldmann
parent 50b4c9f2f9
commit f2b222b2c2
1 changed files with 4 additions and 1 deletions

View File

@ -204,6 +204,7 @@ class Archive:
if start is None:
start = datetime.utcnow()
start_monotonic = time.monotonic()
self.chunker_params = chunker_params
self.start = start
self.start_monotonic = start_monotonic
if end is None:
@ -227,7 +228,7 @@ class Archive:
raise self.DoesNotExist(name)
info = self.manifest.archives[name]
self.load(info[b'id'])
self.zeros = b'\0' * (1 << chunker_params[1])
self.zeros = None
def _load_meta(self, id):
data = self.key.decrypt(id, self.repository.get(id))
@ -405,6 +406,8 @@ Number of files: {0.stats.nfiles}'''.format(
with backup_io():
os.link(source, path)
else:
if sparse and self.zeros is None:
self.zeros = b'\0' * (1 << self.chunker_params[1])
with backup_io():
fd = open(path, 'wb')
with fd: