GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — gh-129185: Remove internal TRACE_RAW_MALLOC macro by vstinner · Pull Request #129218 · python/cpython

gh-129185: Remove internal TRACE_RAW_MALLOC macro #129218

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Sign up for GitHub

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
vstinner merged 1 commit into python:main from vstinner:tracemalloc_raw
Jan 23, 2025

Uh oh!

There was an error while loading. Please reload this page.

Merged

gh-129185: Remove internal TRACE_RAW_MALLOC macro #129218

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
1 commit
Select commit
f2957f1
gh-129185: Remove internal TRACE_RAW_MALLOC macro
vstinner Jan 23, 2025
File filter
Filter by extension

Clear filters
Conversations
Failed to load comments.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Jump to
Jump to file
Failed to load files.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Diff view
Diff view
gh-129185: Remove internal TRACE_RAW_MALLOC macro
Always build tracemalloc with PyMem_RawMalloc() hooks.
  • Loading branch information

Uh oh!

There was an error while loading. Please reload this page.

@vstinner
vstinner committed Jan 23, 2025
commit f2957f1c2ac196e50d13e43e10adea12ce0abddc

There are no files selected for viewing

6 changes: 0 additions & 6 deletions 6 Include/internal/pycore_tracemalloc.h
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,6 @@ extern "C" {
#include "pycore_hashtable.h" // _Py_hashtable_t


/* Trace memory blocks allocated by PyMem_RawMalloc() */
#define TRACE_RAW_MALLOC


struct _PyTraceMalloc_Config {
/* Module initialized?
Variable protected by the GIL */
Expand Down Expand Up @@ -74,9 +70,7 @@ struct _tracemalloc_runtime_state {
PyMemAllocatorEx obj;
} allocators;

#if defined(TRACE_RAW_MALLOC)
PyThread_type_lock tables_lock;
#endif
/* Size in bytes of currently traced memory.
Protected by TABLES_LOCK(). */
size_t traced_memory;
Expand Down
48 changes: 3 additions & 45 deletions 48 Python/tracemalloc.c
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,12 @@ static int _PyTraceMalloc_TraceRef(PyObject *op, PyRefTracerEvent event,
#define allocators _PyRuntime.tracemalloc.allocators


#if defined(TRACE_RAW_MALLOC)
/* This lock is needed because tracemalloc_free() is called without
the GIL held from PyMem_RawFree(). It cannot acquire the lock because it
would introduce a deadlock in _PyThreadState_DeleteCurrent(). */
# define tables_lock _PyRuntime.tracemalloc.tables_lock
# define TABLES_LOCK() PyThread_acquire_lock(tables_lock, 1)
# define TABLES_UNLOCK() PyThread_release_lock(tables_lock)
#else
/* variables are protected by the GIL */
# define TABLES_LOCK()
# define TABLES_UNLOCK()
#endif
#define tables_lock _PyRuntime.tracemalloc.tables_lock
#define TABLES_LOCK() PyThread_acquire_lock(tables_lock, 1)
#define TABLES_UNLOCK() PyThread_release_lock(tables_lock)


#define DEFAULT_DOMAIN 0
Expand Down Expand Up @@ -98,9 +92,6 @@ tracemalloc_error(const char *format, ...)
#endif


#if defined(TRACE_RAW_MALLOC)
#define REENTRANT_THREADLOCAL

#define tracemalloc_reentrant_key _PyRuntime.tracemalloc.reentrant_key

/* Any non-NULL pointer can be used */
Expand Down Expand Up @@ -137,25 +128,6 @@ set_reentrant(int reentrant)
}
}

#else

/* TRACE_RAW_MALLOC not defined: variable protected by the GIL */
static int tracemalloc_reentrant = 0;

static int
get_reentrant(void)
{
return tracemalloc_reentrant;
}

static void
set_reentrant(int reentrant)
{
assert(reentrant != tracemalloc_reentrant);
tracemalloc_reentrant = reentrant;
}
#endif


static Py_uhash_t
hashtable_hash_pyobject(const void *key)
Expand Down Expand Up @@ -709,7 +681,6 @@ tracemalloc_realloc_gil(void *ctx, void *ptr, size_t new_size)
}


#ifdef TRACE_RAW_MALLOC
static void*
tracemalloc_raw_malloc(void *ctx, size_t size)
{
Expand All @@ -729,7 +700,6 @@ tracemalloc_raw_realloc(void *ctx, void *ptr, size_t new_size)
{
return tracemalloc_realloc(1, ctx, ptr, new_size);
}
#endif /* TRACE_RAW_MALLOC */


static void
Expand Down Expand Up @@ -767,20 +737,16 @@ _PyTraceMalloc_Init(void)

PyMem_GetAllocator(PYMEM_DOMAIN_RAW, &allocators.raw);

#ifdef REENTRANT_THREADLOCAL
if (PyThread_tss_create(&tracemalloc_reentrant_key) != 0) {
return _PyStatus_NO_MEMORY();
}
#endif

#if defined(TRACE_RAW_MALLOC)
if (tables_lock == NULL) {
tables_lock = PyThread_allocate_lock();
if (tables_lock == NULL) {
return _PyStatus_NO_MEMORY();
}
}
#endif

tracemalloc_filenames = hashtable_new(hashtable_hash_pyobject,
hashtable_compare_unicode,
Expand Down Expand Up @@ -826,16 +792,12 @@ tracemalloc_deinit(void)
_Py_hashtable_destroy(tracemalloc_tracebacks);
_Py_hashtable_destroy(tracemalloc_filenames);

#if defined(TRACE_RAW_MALLOC)
if (tables_lock != NULL) {
PyThread_free_lock(tables_lock);
tables_lock = NULL;
}
#endif

#ifdef REENTRANT_THREADLOCAL
PyThread_tss_delete(&tracemalloc_reentrant_key);
#endif
}


Expand Down Expand Up @@ -866,7 +828,6 @@ _PyTraceMalloc_Start(int max_nframe)
}

PyMemAllocatorEx alloc;
#ifdef TRACE_RAW_MALLOC
alloc.malloc = tracemalloc_raw_malloc;
alloc.calloc = tracemalloc_raw_calloc;
alloc.realloc = tracemalloc_raw_realloc;
Expand All @@ -875,7 +836,6 @@ _PyTraceMalloc_Start(int max_nframe)
alloc.ctx = &allocators.raw;
PyMem_GetAllocator(PYMEM_DOMAIN_RAW, &allocators.raw);
PyMem_SetAllocator(PYMEM_DOMAIN_RAW, &alloc);
#endif

alloc.malloc = tracemalloc_malloc_gil;
alloc.calloc = tracemalloc_calloc_gil;
Expand Down Expand Up @@ -916,9 +876,7 @@ _PyTraceMalloc_Stop(void)
tracemalloc_config.tracing = 0;

/* unregister the hook on memory allocators */
#ifdef TRACE_RAW_MALLOC
PyMem_SetAllocator(PYMEM_DOMAIN_RAW, &allocators.raw);
#endif
PyMem_SetAllocator(PYMEM_DOMAIN_MEM, &allocators.mem);
PyMem_SetAllocator(PYMEM_DOMAIN_OBJ, &allocators.obj);

Expand Down
Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.