Message388743
I'm not sure that it's needed to have a "per interpreter" allocator. The needed feature is to be able to call PyMem_Malloc() in parallel in different threads. If I understood correctly, the glibc malloc has a per-thread fast allocator (no locking) and then falls back to a slow allocator (locking) if the fast allocator failed. Maybe pymalloc could have per-thread memory arenas.
When I implemented the PEP 587, I spend a significant amount of time to avoid using pymalloc before Py_Initialize() is called: only use PyMem_RawMalloc() before Py_Initialize().
But I'm not 100% sure that pymalloc is not used before Py_Initialize() nor *after* Py_Finalize(). For example, we should check if a daemon thread can call PyMem_Malloc() after Py_Finalize(), even if they are supposed to exit as soon as they try to acquire the GIL, even the GIL must be held to use pymalloc (to use PyMem_Malloc and PyObject_Malloc):
https://docs.python.org/dev/c-api/memory.html#memory-interface
See also bpo-37448:
"Add radix tree implementation for obmalloc address_in_range()"
https://github.com/python/cpython/pull/14474 |
|
Date |
User |
Action |
Args |
2021-03-15 14:37:55 | vstinner | set | recipients:
+ vstinner, JunyiXie |
2021-03-15 14:37:54 | vstinner | set | messageid: <1615819075.0.0.624798167433.issue43313@roundup.psfhosted.org> |
2021-03-15 14:37:54 | vstinner | link | issue43313 messages |
2021-03-15 14:37:54 | vstinner | create | |
|