Skip to content

Commit

Permalink
pythongh-128679: Redesign tracemalloc locking
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
vstinner committed Jan 15, 2025
1 parent 40a4d88 commit 853a1df
Show file tree
Hide file tree
Showing 3 changed files with 203 additions and 228 deletions.
6 changes: 0 additions & 6 deletions Include/internal/pycore_object.h
Original file line number Diff line number Diff line change
Expand Up @@ -299,12 +299,6 @@ Py_ssize_t _Py_ExplicitMergeRefcount(PyObject *op, Py_ssize_t extra);
extern int _PyType_CheckConsistency(PyTypeObject *type);
extern int _PyDict_CheckConsistency(PyObject *mp, int check_content);

/* Update the Python traceback of an object. This function must be called
when a memory block is reused from a free list.
Internal function called by _Py_NewReference(). */
extern int _PyTraceMalloc_TraceRef(PyObject *op, PyRefTracerEvent event, void*);

// Fast inlined version of PyType_HasFeature()
static inline int
_PyType_HasFeature(PyTypeObject *type, unsigned long feature) {
Expand Down
8 changes: 4 additions & 4 deletions Include/internal/pycore_tracemalloc.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ struct _PyTraceMalloc_Config {
} initialized;

/* Is tracemalloc tracing memory allocations?
Variable protected by the GIL */
Variable protected by the TABLES_LOCK(). */
int tracing;

/* limit of the number of frames in a traceback, 1 by default.
Expand Down Expand Up @@ -85,14 +85,14 @@ struct _tracemalloc_runtime_state {
size_t peak_traced_memory;
/* Hash table used as a set to intern filenames:
PyObject* => PyObject*.
Protected by the GIL */
Protected by the TABLES_LOCK(). */
_Py_hashtable_t *filenames;
/* Buffer to store a new traceback in traceback_new().
Protected by the GIL. */
Protected by the TABLES_LOCK(). */
struct tracemalloc_traceback *traceback;
/* Hash table used as a set to intern tracebacks:
traceback_t* => traceback_t*
Protected by the GIL */
Protected by the TABLES_LOCK(). */
_Py_hashtable_t *tracebacks;
/* pointer (void*) => trace (trace_t*).
Protected by TABLES_LOCK(). */
Expand Down
Loading

0 comments on commit 853a1df

Please sign in to comment.