Skip to content

Commit c7a0abd

Browse files
committed
pythongh-128679: Redesign tracemalloc locking
* tracemalloc_realloc_gil() and tracemalloc_raw_realloc() no longer remove the trace on reentrant call. * _PyTraceMalloc_Stop() unregisters _PyTraceMalloc_TraceRef(). * _PyTraceMalloc_GetTraces() sets the reentrant flag. * tracemalloc_clear_traces_unlocked() sets the reentrant flag.
1 parent 40a4d88 commit c7a0abd

File tree

3 files changed

+203
-223
lines changed

3 files changed

+203
-223
lines changed

Include/internal/pycore_object.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -299,12 +299,6 @@ Py_ssize_t _Py_ExplicitMergeRefcount(PyObject *op, Py_ssize_t extra);
299299
extern int _PyType_CheckConsistency(PyTypeObject *type);
300300
extern int _PyDict_CheckConsistency(PyObject *mp, int check_content);
301301

302-
/* Update the Python traceback of an object. This function must be called
303-
when a memory block is reused from a free list.
304-
305-
Internal function called by _Py_NewReference(). */
306-
extern int _PyTraceMalloc_TraceRef(PyObject *op, PyRefTracerEvent event, void*);
307-
308302
// Fast inlined version of PyType_HasFeature()
309303
static inline int
310304
_PyType_HasFeature(PyTypeObject *type, unsigned long feature) {

Include/internal/pycore_tracemalloc.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ struct _PyTraceMalloc_Config {
2525
} initialized;
2626

2727
/* Is tracemalloc tracing memory allocations?
28-
Variable protected by the GIL */
28+
Variable protected by the TABLES_LOCK(). */
2929
int tracing;
3030

3131
/* limit of the number of frames in a traceback, 1 by default.
@@ -85,14 +85,14 @@ struct _tracemalloc_runtime_state {
8585
size_t peak_traced_memory;
8686
/* Hash table used as a set to intern filenames:
8787
PyObject* => PyObject*.
88-
Protected by the GIL */
88+
Protected by the TABLES_LOCK(). */
8989
_Py_hashtable_t *filenames;
9090
/* Buffer to store a new traceback in traceback_new().
91-
Protected by the GIL. */
91+
Protected by the TABLES_LOCK(). */
9292
struct tracemalloc_traceback *traceback;
9393
/* Hash table used as a set to intern tracebacks:
9494
traceback_t* => traceback_t*
95-
Protected by the GIL */
95+
Protected by the TABLES_LOCK(). */
9696
_Py_hashtable_t *tracebacks;
9797
/* pointer (void*) => trace (trace_t*).
9898
Protected by TABLES_LOCK(). */

0 commit comments

Comments
 (0)