forked from python/cpython
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
pythongh-111968: Introduce _PyFreeListState and _PyFreeListState_GET …
…API (pythongh-113584)
- Loading branch information
Showing
17 changed files
with
171 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#ifndef Py_INTERNAL_FREELIST_H | ||
#define Py_INTERNAL_FREELIST_H | ||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
#ifndef Py_BUILD_CORE | ||
# error "this header requires Py_BUILD_CORE define" | ||
#endif | ||
|
||
#ifndef WITH_FREELISTS | ||
// without freelists | ||
# define PyList_MAXFREELIST 0 | ||
#endif | ||
|
||
/* Empty list reuse scheme to save calls to malloc and free */ | ||
#ifndef PyList_MAXFREELIST | ||
# define PyList_MAXFREELIST 80 | ||
#endif | ||
|
||
struct _Py_list_state { | ||
#if PyList_MAXFREELIST > 0 | ||
PyListObject *free_list[PyList_MAXFREELIST]; | ||
int numfree; | ||
#endif | ||
}; | ||
|
||
typedef struct _Py_freelist_state { | ||
struct _Py_list_state list; | ||
} _PyFreeListState; | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif | ||
#endif /* !Py_INTERNAL_FREELIST_H */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#include "Python.h" | ||
#include "pycore_pystate.h" // _PyFreeListState_GET() | ||
#include "pycore_tstate.h" // _PyThreadStateImpl | ||
|
||
#ifdef Py_GIL_DISABLED | ||
|
||
/* Clear all free lists | ||
* All free lists are cleared during the collection of the highest generation. | ||
* Allocated items in the free list may keep a pymalloc arena occupied. | ||
* Clearing the free lists may give back memory to the OS earlier. | ||
* Free-threading version: Since freelists are managed per thread, | ||
* GC should clear all freelists by traversing all threads. | ||
*/ | ||
void | ||
_PyGC_ClearAllFreeLists(PyInterpreterState *interp) | ||
{ | ||
_PyTuple_ClearFreeList(interp); | ||
_PyFloat_ClearFreeList(interp); | ||
_PyDict_ClearFreeList(interp); | ||
_PyAsyncGen_ClearFreeLists(interp); | ||
_PyContext_ClearFreeList(interp); | ||
|
||
HEAD_LOCK(&_PyRuntime); | ||
_PyThreadStateImpl *tstate = (_PyThreadStateImpl *)interp->threads.head; | ||
while (tstate != NULL) { | ||
_Py_ClearFreeLists(&tstate->freelist_state, 0); | ||
tstate = (_PyThreadStateImpl *)tstate->base.next; | ||
} | ||
HEAD_UNLOCK(&_PyRuntime); | ||
} | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#include "Python.h" | ||
#include "pycore_pystate.h" // _Py_ClearFreeLists() | ||
|
||
#ifndef Py_GIL_DISABLED | ||
|
||
/* Clear all free lists | ||
* All free lists are cleared during the collection of the highest generation. | ||
* Allocated items in the free list may keep a pymalloc arena occupied. | ||
* Clearing the free lists may give back memory to the OS earlier. | ||
*/ | ||
void | ||
_PyGC_ClearAllFreeLists(PyInterpreterState *interp) | ||
{ | ||
_PyTuple_ClearFreeList(interp); | ||
_PyFloat_ClearFreeList(interp); | ||
_PyDict_ClearFreeList(interp); | ||
_PyAsyncGen_ClearFreeLists(interp); | ||
_PyContext_ClearFreeList(interp); | ||
|
||
_Py_ClearFreeLists(&interp->freelist_state, 0); | ||
} | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.