]> granicus.if.org Git - python/commitdiff
Issue #21116: Avoid blowing memory when allocating a multiprocessing shared
authorAntoine Pitrou <solipsis@pitrou.net>
Mon, 13 Apr 2015 18:53:43 +0000 (20:53 +0200)
committerAntoine Pitrou <solipsis@pitrou.net>
Mon, 13 Apr 2015 18:53:43 +0000 (20:53 +0200)
array that's larger than 50% of the available RAM.

Patch by Médéric Boquien.

Lib/multiprocessing/heap.py
Misc/ACKS
Misc/NEWS

index 333b3baf20f43b5d88b4c9b67a790dd2c5a4ff2c..44d9638ff6ec4d9d4595d085ab14b7a4065d1c41 100644 (file)
@@ -71,7 +71,14 @@ else:
                 os.unlink(name)
                 util.Finalize(self, os.close, (self.fd,))
                 with open(self.fd, 'wb', closefd=False) as f:
-                    f.write(b'\0'*size)
+                    bs = 1024 * 1024
+                    if size >= bs:
+                        zeros = b'\0' * bs
+                        for _ in range(size // bs):
+                            f.write(zeros)
+                        del zeros
+                    f.write(b'\0' * (size % bs))
+                    assert f.tell() == size
             self.buffer = mmap.mmap(self.fd, self.size)
 
     def reduce_arena(a):
index 9a3de4e8333d042061713d8580ac4bdd27b30f4d..d1074bda05601202b7fc8b1df92ae7c7015c4ef1 100644 (file)
--- a/Misc/ACKS
+++ b/Misc/ACKS
@@ -154,6 +154,7 @@ Wouter Bolsterlee
 Gawain Bolton
 Forest Bond
 Gregory Bond
+Médéric Boquien
 Matias Bordese
 Jonas Borgström
 Jurjen Bos
index 78db876367bc9d1ea631e89d90c26d41c80c09b1..e4574a11c35db43505a2471c3ae8a19601cd89d8 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -29,6 +29,9 @@ Core and Builtins
 Library
 -------
 
+- Issue #21116: Avoid blowing memory when allocating a multiprocessing shared
+  array that's larger than 50% of the available RAM.  Patch by Médéric Boquien.
+
 - Issue #22982: Improve BOM handling when seeking to multiple positions of
   a writable text file.