Bug description:
With the help of newly added trackfd=False option in mmap.mmap constructor, we can create far more mmap.mmap objects beyond the open file limit. But creating a lot of mmap.mmap instances seems to cause memory errors (“OSError: [Errno 12] Cannot allocate memory”).
Example:
import mmap, os
fn = "/tmp/some_file"
fd = os.open(fn, os.O_CREAT | os.O_RDWR | os.O_TRUNC, 0o600)
os.ftruncate(fd, 1)
mmap_objects = []
try:
for i in range(1_000_000):
mmap_object = mmap.mmap(fd, 1, trackfd=False)
mmap_objects.append(mmap_object)
except:
print(i)
raise
I ran the snippet above on a CentOS8 server with 48GB RAM, and it stopped at the 65479th iterations with the mentioned error.
By contrast, creation of 1M builtins.object instances can be easily done and a C program that creates 1M mmap pointers can also finish with no error.
This issue were also reproduced on RHEL7.2.
CPython versions tested on:
3.13
Operating systems tested on:
Linux (CentOS 8, RHEL 7)
EDIT
I made a horrible mistake in my C program that it does not check if the pointer returned by mmap is valid. In fact, the max number of valid mmap pointers it can create is 65515. Sorry for the false and misleading statement.
Bug description:
With the help of newly added
trackfd=Falseoption inmmap.mmapconstructor, we can create far moremmap.mmapobjects beyond the open file limit. But creating a lot ofmmap.mmapinstances seems to cause memory errors (“OSError: [Errno 12] Cannot allocate memory”).Example:
I ran the snippet above on a CentOS8 server with 48GB RAM, and it stopped at the 65479th iterations with the mentioned error.
By contrast, creation of 1M
builtins.objectinstances can be easily doneand a C program that creates 1M.mmappointers can also finish with no errorThis issue were also reproduced on RHEL7.2.
CPython versions tested on:
3.13
Operating systems tested on:
Linux (CentOS 8, RHEL 7)
EDIT
I made a horrible mistake in my C program that it does not check if the pointer returned by
mmapis valid. In fact, the max number of validmmappointers it can create is 65515. Sorry for the false and misleading statement.