瀏覽代碼

Archive: allocate zeros when needed (#2308)

fixes huge memory usage of mount (8 MiB × number of archives)
(cherry picked from commit 883a7eefb2d0301cd0e178ccd2da8480b2e1ac95)
enkore 8 年之前
父節點
當前提交
f2b222b2c2
共有 1 個文件被更改,包括 4 次插入1 次删除
  1. 4 1
      borg/archive.py

+ 4 - 1
borg/archive.py

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