From f2b222b2c2fb7d5647d4cf9a7e8aac80dbe39e6b Mon Sep 17 00:00:00 2001 From: enkore Date: Wed, 15 Mar 2017 17:08:07 +0100 Subject: [PATCH] Archive: allocate zeros when needed (#2308) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit fixes huge memory usage of mount (8 MiB × number of archives) (cherry picked from commit 883a7eefb2d0301cd0e178ccd2da8480b2e1ac95) --- borg/archive.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/borg/archive.py b/borg/archive.py index 178ad94b8..0c57680f4 100644 --- a/borg/archive.py +++ b/borg/archive.py @@ -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: