From 0e3933d562f7a8eaefe1b80d02070f9b830d13dd Mon Sep 17 00:00:00 2001 From: Donghee Na Date: Sat, 29 Nov 2025 01:14:21 +0900 Subject: [PATCH 01/34] gh-141770: Annotate anonymous mmap only for debug build --- Include/internal/pycore_pymem.h | 14 ++++++++++++++ configure | 18 ++++++++++++++++++ configure.ac | 6 ++++++ pyconfig.h.in | 7 +++++++ 4 files changed, 45 insertions(+) diff --git a/Include/internal/pycore_pymem.h b/Include/internal/pycore_pymem.h index 05484e847f1195..52c93afc6e7389 100644 --- a/Include/internal/pycore_pymem.h +++ b/Include/internal/pycore_pymem.h @@ -11,6 +11,10 @@ extern "C" { # error "this header requires Py_BUILD_CORE define" #endif +#if defined(Py_DEBUG) && defined(HAVE_PR_SET_VMA_ANON_NAME) +#include +#endif + // Try to get the allocators name set by _PyMem_SetupAllocators(). // Return NULL if unknown. // Export for '_testinternalcapi' shared extension. @@ -91,6 +95,16 @@ static inline int _PyMem_IsULongFreed(unsigned long value) #endif } +static inline int _PyMem_Annotate_Mmap(void *addr, size_t size, const char *name) +{ +#if defined(Py_DEBUG) && defined(HAVE_PR_SET_VMA_ANON_NAME) + prctl(PR_SET_VMA, PR_SET_VMA_ANON_NAME, (unsigned long)addr, size, name); + return 0; +#else + return 0; +#endif +} + extern int _PyMem_GetAllocatorName( const char *name, PyMemAllocatorName *allocator); diff --git a/configure b/configure index 4bcb639d781dd7..68d5a9ffe9dec2 100755 --- a/configure +++ b/configure @@ -23932,6 +23932,24 @@ printf "%s\n" "#define HAVE_UT_NAMESIZE 1" >>confdefs.h fi +ac_fn_check_decl "$LINENO" "PR_SET_VMA_ANON_NAME" "ac_cv_have_decl_PR_SET_VMA_ANON_NAME" "#include +" "$ac_c_undeclared_builtin_options" "CFLAGS" +if test "x$ac_cv_have_decl_PR_SET_VMA_ANON_NAME" = xyes +then : + ac_have_decl=1 +else case e in #( + e) ac_have_decl=0 ;; +esac +fi +printf "%s\n" "#define HAVE_DECL_PR_SET_VMA_ANON_NAME $ac_have_decl" >>confdefs.h +if test $ac_have_decl = 1 +then : + +printf "%s\n" "#define HAVE_PR_SET_VMA_ANON_NAME 1" >>confdefs.h + +fi + + # check for openpty, login_tty, and forkpty diff --git a/configure.ac b/configure.ac index a1f1cf207c5f34..862c3ba5c45a89 100644 --- a/configure.ac +++ b/configure.ac @@ -5578,6 +5578,12 @@ AC_CHECK_DECLS([UT_NAMESIZE], [], [@%:@include ]) +AC_CHECK_DECLS([PR_SET_VMA_ANON_NAME], + [AC_DEFINE([HAVE_PR_SET_VMA_ANON_NAME], [1], + [Define if you have the 'PR_SET_VMA_ANON_NAME' constant.])], + [], + [@%:@include ]) + # check for openpty, login_tty, and forkpty AC_CHECK_FUNCS([openpty], [], diff --git a/pyconfig.h.in b/pyconfig.h.in index 8a9f5ca8ec826d..aabf9f0be8da55 100644 --- a/pyconfig.h.in +++ b/pyconfig.h.in @@ -228,6 +228,10 @@ /* Define to 1 if you have the header file. */ #undef HAVE_DB_H +/* Define to 1 if you have the declaration of 'PR_SET_VMA_ANON_NAME', and to 0 + if you don't. */ +#undef HAVE_DECL_PR_SET_VMA_ANON_NAME + /* Define to 1 if you have the declaration of 'RTLD_DEEPBIND', and to 0 if you don't. */ #undef HAVE_DECL_RTLD_DEEPBIND @@ -996,6 +1000,9 @@ /* Define if your compiler supports function prototype */ #undef HAVE_PROTOTYPES +/* Define if you have the 'PR_SET_VMA_ANON_NAME' constant. */ +#undef HAVE_PR_SET_VMA_ANON_NAME + /* Define to 1 if you have the 'pthread_condattr_setclock' function. */ #undef HAVE_PTHREAD_CONDATTR_SETCLOCK From 8b7023eed267ac7d40dc931b2804e1462aecc113 Mon Sep 17 00:00:00 2001 From: Donghee Na Date: Sat, 29 Nov 2025 10:35:23 +0900 Subject: [PATCH 02/34] Apply annotation feature to modules --- Modules/_ctypes/malloc_closure.c | 2 ++ Modules/mmapmodule.c | 2 ++ Objects/obmalloc.c | 1 + Python/jit.c | 3 +++ Python/perf_jit_trampoline.c | 2 ++ Python/perf_trampoline.c | 2 ++ 6 files changed, 12 insertions(+) diff --git a/Modules/_ctypes/malloc_closure.c b/Modules/_ctypes/malloc_closure.c index db405acf8727b5..a63680f5af08f1 100644 --- a/Modules/_ctypes/malloc_closure.c +++ b/Modules/_ctypes/malloc_closure.c @@ -14,6 +14,7 @@ # endif #endif #include "ctypes.h" +#include "pycore_obmalloc.h" // _PyMem_Annotate_Mmap() /* BLOCKSIZE can be adjusted. Larger blocksize will take a larger memory overhead, but allocate less blocks from the system. It may be that some @@ -82,6 +83,7 @@ static void more_core(void) 0); if (item == (void *)MAP_FAILED) return; + _PyMem_Annotate_Mmap(item, count * sizeof(ITEM), "Python:more_core"); #endif #ifdef MALLOC_CLOSURE_DEBUG diff --git a/Modules/mmapmodule.c b/Modules/mmapmodule.c index ac8521f8aa9b6e..00e2ec70587aaa 100644 --- a/Modules/mmapmodule.c +++ b/Modules/mmapmodule.c @@ -26,6 +26,7 @@ #include "pycore_abstract.h" // _Py_convert_optional_to_ssize_t() #include "pycore_bytesobject.h" // _PyBytes_Find() #include "pycore_fileutils.h" // _Py_stat_struct +#include "pycore_obmalloc.h" // _PyMem_Annotate_Mmap() #include "pycore_weakref.h" // FT_CLEAR_WEAKREFS() #include // offsetof() @@ -1951,6 +1952,7 @@ new_mmap_object(PyTypeObject *type, PyObject *args, PyObject *kwdict) PyErr_SetFromErrno(PyExc_OSError); return NULL; } + _PyMem_Annotate_Mmap(m_obj->data, map_size, "Python:new_mmap_object"); m_obj->access = (access_mode)access; return (PyObject *)m_obj; } diff --git a/Objects/obmalloc.c b/Objects/obmalloc.c index 2b95ebbf8e5ac0..5d38c53cad434b 100644 --- a/Objects/obmalloc.c +++ b/Objects/obmalloc.c @@ -467,6 +467,7 @@ _PyMem_ArenaAlloc(void *Py_UNUSED(ctx), size_t size) if (ptr == MAP_FAILED) return NULL; assert(ptr != NULL); + _PyMem_Annotate_Mmap(ptr, size, "Python:PyMem_ArenaAlloc"); return ptr; #else return malloc(size); diff --git a/Python/jit.c b/Python/jit.c index 7ab0f8ddd430dd..10c1f93ba0ee4c 100644 --- a/Python/jit.c +++ b/Python/jit.c @@ -71,6 +71,9 @@ jit_alloc(size_t size) int prot = PROT_READ | PROT_WRITE; unsigned char *memory = mmap(NULL, size, prot, flags, -1, 0); int failed = memory == MAP_FAILED; + if (!failed) { + _PyMem_Annotate_Mmap(memory, size, "Python:jit_alloc"); + } #endif if (failed) { jit_error("unable to allocate memory"); diff --git a/Python/perf_jit_trampoline.c b/Python/perf_jit_trampoline.c index 8732be973616d4..f241fce6ae2a90 100644 --- a/Python/perf_jit_trampoline.c +++ b/Python/perf_jit_trampoline.c @@ -61,6 +61,7 @@ #include "pycore_ceval.h" // _PyPerf_Callbacks #include "pycore_frame.h" #include "pycore_interp.h" +#include "pycore_obmalloc.h" // _PyMem_Annotate_Mmap() #include "pycore_runtime.h" // _PyRuntime #ifdef PY_HAVE_PERF_TRAMPOLINE @@ -1085,6 +1086,7 @@ static void* perf_map_jit_init(void) { close(fd); return NULL; // Memory mapping failed } + _PyMem_Annotate_Mmap(perf_jit_map_state.mapped_buffer, page_size, "Python:perf_map_jit_init"); #endif perf_jit_map_state.mapped_size = page_size; diff --git a/Python/perf_trampoline.c b/Python/perf_trampoline.c index 987e8d2a11a659..efd71c71be3ea9 100644 --- a/Python/perf_trampoline.c +++ b/Python/perf_trampoline.c @@ -132,6 +132,7 @@ any DWARF information available for them). #include "Python.h" #include "pycore_ceval.h" // _PyPerf_Callbacks #include "pycore_interpframe.h" // _PyFrame_GetCode() +#include "pycore_obmalloc.h" // _PyMem_Annotate_Mmap() #include "pycore_runtime.h" // _PyRuntime @@ -290,6 +291,7 @@ new_code_arena(void) perf_status = PERF_STATUS_FAILED; return -1; } + _PyMem_Annotate_Mmap(memory, mem_size, "Python:new_code_arena"); void *start = &_Py_trampoline_func_start; void *end = &_Py_trampoline_func_end; size_t code_size = end - start; From 816d962d906fb2a4760b7200be57815416d48ca8 Mon Sep 17 00:00:00 2001 From: Donghee Na Date: Sat, 29 Nov 2025 18:14:31 +0900 Subject: [PATCH 03/34] Add NEWS.d --- .../2025-11-29-18-14-28.gh-issue-141770.JURnvg.rst | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 Misc/NEWS.d/next/Core_and_Builtins/2025-11-29-18-14-28.gh-issue-141770.JURnvg.rst diff --git a/Misc/NEWS.d/next/Core_and_Builtins/2025-11-29-18-14-28.gh-issue-141770.JURnvg.rst b/Misc/NEWS.d/next/Core_and_Builtins/2025-11-29-18-14-28.gh-issue-141770.JURnvg.rst new file mode 100644 index 00000000000000..13ddc19e2dcd7c --- /dev/null +++ b/Misc/NEWS.d/next/Core_and_Builtins/2025-11-29-18-14-28.gh-issue-141770.JURnvg.rst @@ -0,0 +1,2 @@ +Annotate anonymous mmap usage in debug builds only when supported by the +Linux kernel. Patch by Donghee Na. From 979ce02ed5c065eb98955f8c600ae82106758a9e Mon Sep 17 00:00:00 2001 From: Donghee Na Date: Sat, 29 Nov 2025 09:30:30 +0000 Subject: [PATCH 04/34] nit --- Include/internal/pycore_pymem.h | 3 +++ Modules/_ctypes/malloc_closure.c | 5 +++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/Include/internal/pycore_pymem.h b/Include/internal/pycore_pymem.h index 52c93afc6e7389..ce376829c16a98 100644 --- a/Include/internal/pycore_pymem.h +++ b/Include/internal/pycore_pymem.h @@ -99,6 +99,9 @@ static inline int _PyMem_Annotate_Mmap(void *addr, size_t size, const char *name { #if defined(Py_DEBUG) && defined(HAVE_PR_SET_VMA_ANON_NAME) prctl(PR_SET_VMA, PR_SET_VMA_ANON_NAME, (unsigned long)addr, size, name); + // Ignore errno from prctl + // See: https://bugzilla.redhat.com/show_bug.cgi?id=2302746 + errno = 0; return 0; #else return 0; diff --git a/Modules/_ctypes/malloc_closure.c b/Modules/_ctypes/malloc_closure.c index a63680f5af08f1..64a1bfcf4888de 100644 --- a/Modules/_ctypes/malloc_closure.c +++ b/Modules/_ctypes/malloc_closure.c @@ -75,15 +75,16 @@ static void more_core(void) if (item == NULL) return; #else + size_t mem_size = count * sizeof(ITEM); item = (ITEM *)mmap(NULL, - count * sizeof(ITEM), + mem_size, PROT_READ | PROT_WRITE | PROT_EXEC, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); if (item == (void *)MAP_FAILED) return; - _PyMem_Annotate_Mmap(item, count * sizeof(ITEM), "Python:more_core"); + _PyMem_Annotate_Mmap(item, mem_size, "Python:more_core"); #endif #ifdef MALLOC_CLOSURE_DEBUG From b3d854777d02616dd9bcee208c7c06f7b7f20b17 Mon Sep 17 00:00:00 2001 From: Donghee Na Date: Sat, 29 Nov 2025 18:31:32 +0900 Subject: [PATCH 05/34] Update Include/internal/pycore_pymem.h MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com> --- Include/internal/pycore_pymem.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Include/internal/pycore_pymem.h b/Include/internal/pycore_pymem.h index ce376829c16a98..d28644154c5e95 100644 --- a/Include/internal/pycore_pymem.h +++ b/Include/internal/pycore_pymem.h @@ -95,7 +95,8 @@ static inline int _PyMem_IsULongFreed(unsigned long value) #endif } -static inline int _PyMem_Annotate_Mmap(void *addr, size_t size, const char *name) +static inline int +_PyMem_Annotate_Mmap(void *addr, size_t size, const char *name) { #if defined(Py_DEBUG) && defined(HAVE_PR_SET_VMA_ANON_NAME) prctl(PR_SET_VMA, PR_SET_VMA_ANON_NAME, (unsigned long)addr, size, name); From 0c5a49535b7d4d5545718d8855a2d12fb322e643 Mon Sep 17 00:00:00 2001 From: Donghee Na Date: Sat, 29 Nov 2025 09:33:35 +0000 Subject: [PATCH 06/34] Address code review --- Include/internal/pycore_pymem.h | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/Include/internal/pycore_pymem.h b/Include/internal/pycore_pymem.h index d28644154c5e95..5bb1975841f40c 100644 --- a/Include/internal/pycore_pymem.h +++ b/Include/internal/pycore_pymem.h @@ -103,10 +103,8 @@ _PyMem_Annotate_Mmap(void *addr, size_t size, const char *name) // Ignore errno from prctl // See: https://bugzilla.redhat.com/show_bug.cgi?id=2302746 errno = 0; - return 0; -#else - return 0; #endif + return 0; } extern int _PyMem_GetAllocatorName( From e757dd9cf75d7ead222ab634aa54378605c3a1ce Mon Sep 17 00:00:00 2001 From: Donghee Na Date: Sat, 29 Nov 2025 19:56:37 +0900 Subject: [PATCH 07/34] Address code review --- Include/internal/pycore_pymem.h | 7 ++++--- Modules/_ctypes/malloc_closure.c | 4 ++-- Modules/mmapmodule.c | 4 ++-- Objects/obmalloc.c | 2 +- Python/jit.c | 2 +- Python/perf_jit_trampoline.c | 4 ++-- Python/perf_trampoline.c | 4 ++-- 7 files changed, 14 insertions(+), 13 deletions(-) diff --git a/Include/internal/pycore_pymem.h b/Include/internal/pycore_pymem.h index 5bb1975841f40c..8ad3d705492c76 100644 --- a/Include/internal/pycore_pymem.h +++ b/Include/internal/pycore_pymem.h @@ -11,7 +11,8 @@ extern "C" { # error "this header requires Py_BUILD_CORE define" #endif -#if defined(Py_DEBUG) && defined(HAVE_PR_SET_VMA_ANON_NAME) +#if defined(Py_DEBUG) && defined(HAVE_PR_SET_VMA_ANON_NAME) && defined(__linux__) +#include #include #endif @@ -96,9 +97,9 @@ static inline int _PyMem_IsULongFreed(unsigned long value) } static inline int -_PyMem_Annotate_Mmap(void *addr, size_t size, const char *name) +_PyAnnotateMemoryMap(void *addr, size_t size, const char *name) { -#if defined(Py_DEBUG) && defined(HAVE_PR_SET_VMA_ANON_NAME) +#if defined(Py_DEBUG) && defined(HAVE_PR_SET_VMA_ANON_NAME) && defined(__linux__) prctl(PR_SET_VMA, PR_SET_VMA_ANON_NAME, (unsigned long)addr, size, name); // Ignore errno from prctl // See: https://bugzilla.redhat.com/show_bug.cgi?id=2302746 diff --git a/Modules/_ctypes/malloc_closure.c b/Modules/_ctypes/malloc_closure.c index 64a1bfcf4888de..c73f2125bcf514 100644 --- a/Modules/_ctypes/malloc_closure.c +++ b/Modules/_ctypes/malloc_closure.c @@ -14,7 +14,7 @@ # endif #endif #include "ctypes.h" -#include "pycore_obmalloc.h" // _PyMem_Annotate_Mmap() +#include "pycore_obmalloc.h" // _PyAnnotateMemoryMap() /* BLOCKSIZE can be adjusted. Larger blocksize will take a larger memory overhead, but allocate less blocks from the system. It may be that some @@ -84,7 +84,7 @@ static void more_core(void) 0); if (item == (void *)MAP_FAILED) return; - _PyMem_Annotate_Mmap(item, mem_size, "Python:more_core"); + _PyAnnotateMemoryMap(item, mem_size, "Python:more_core"); #endif #ifdef MALLOC_CLOSURE_DEBUG diff --git a/Modules/mmapmodule.c b/Modules/mmapmodule.c index 00e2ec70587aaa..face61524d3c8d 100644 --- a/Modules/mmapmodule.c +++ b/Modules/mmapmodule.c @@ -26,7 +26,7 @@ #include "pycore_abstract.h" // _Py_convert_optional_to_ssize_t() #include "pycore_bytesobject.h" // _PyBytes_Find() #include "pycore_fileutils.h" // _Py_stat_struct -#include "pycore_obmalloc.h" // _PyMem_Annotate_Mmap() +#include "pycore_obmalloc.h" // _PyAnnotateMemoryMap() #include "pycore_weakref.h" // FT_CLEAR_WEAKREFS() #include // offsetof() @@ -1952,7 +1952,7 @@ new_mmap_object(PyTypeObject *type, PyObject *args, PyObject *kwdict) PyErr_SetFromErrno(PyExc_OSError); return NULL; } - _PyMem_Annotate_Mmap(m_obj->data, map_size, "Python:new_mmap_object"); + _PyAnnotateMemoryMap(m_obj->data, map_size, "Python:new_mmap_object"); m_obj->access = (access_mode)access; return (PyObject *)m_obj; } diff --git a/Objects/obmalloc.c b/Objects/obmalloc.c index 5d38c53cad434b..5c2a07b474de17 100644 --- a/Objects/obmalloc.c +++ b/Objects/obmalloc.c @@ -467,7 +467,7 @@ _PyMem_ArenaAlloc(void *Py_UNUSED(ctx), size_t size) if (ptr == MAP_FAILED) return NULL; assert(ptr != NULL); - _PyMem_Annotate_Mmap(ptr, size, "Python:PyMem_ArenaAlloc"); + _PyAnnotateMemoryMap(ptr, size, "Python:PyMem_ArenaAlloc"); return ptr; #else return malloc(size); diff --git a/Python/jit.c b/Python/jit.c index 10c1f93ba0ee4c..86b20a81d0120d 100644 --- a/Python/jit.c +++ b/Python/jit.c @@ -72,7 +72,7 @@ jit_alloc(size_t size) unsigned char *memory = mmap(NULL, size, prot, flags, -1, 0); int failed = memory == MAP_FAILED; if (!failed) { - _PyMem_Annotate_Mmap(memory, size, "Python:jit_alloc"); + _PyAnnotateMemoryMap(memory, size, "Python:jit_alloc"); } #endif if (failed) { diff --git a/Python/perf_jit_trampoline.c b/Python/perf_jit_trampoline.c index f241fce6ae2a90..e2bb4d98870388 100644 --- a/Python/perf_jit_trampoline.c +++ b/Python/perf_jit_trampoline.c @@ -61,7 +61,7 @@ #include "pycore_ceval.h" // _PyPerf_Callbacks #include "pycore_frame.h" #include "pycore_interp.h" -#include "pycore_obmalloc.h" // _PyMem_Annotate_Mmap() +#include "pycore_obmalloc.h" // _PyAnnotateMemoryMap() #include "pycore_runtime.h" // _PyRuntime #ifdef PY_HAVE_PERF_TRAMPOLINE @@ -1086,7 +1086,7 @@ static void* perf_map_jit_init(void) { close(fd); return NULL; // Memory mapping failed } - _PyMem_Annotate_Mmap(perf_jit_map_state.mapped_buffer, page_size, "Python:perf_map_jit_init"); + _PyAnnotateMemoryMap(perf_jit_map_state.mapped_buffer, page_size, "Python:perf_map_jit_init"); #endif perf_jit_map_state.mapped_size = page_size; diff --git a/Python/perf_trampoline.c b/Python/perf_trampoline.c index efd71c71be3ea9..aa1d5fc6fa26bd 100644 --- a/Python/perf_trampoline.c +++ b/Python/perf_trampoline.c @@ -132,7 +132,7 @@ any DWARF information available for them). #include "Python.h" #include "pycore_ceval.h" // _PyPerf_Callbacks #include "pycore_interpframe.h" // _PyFrame_GetCode() -#include "pycore_obmalloc.h" // _PyMem_Annotate_Mmap() +#include "pycore_obmalloc.h" // _PyAnnotateMemoryMap() #include "pycore_runtime.h" // _PyRuntime @@ -291,7 +291,7 @@ new_code_arena(void) perf_status = PERF_STATUS_FAILED; return -1; } - _PyMem_Annotate_Mmap(memory, mem_size, "Python:new_code_arena"); + _PyAnnotateMemoryMap(memory, mem_size, "Python:new_code_arena"); void *start = &_Py_trampoline_func_start; void *end = &_Py_trampoline_func_end; size_t code_size = end - start; From cb9509bc7ad01c79928c0f23ab3b5f820034bf18 Mon Sep 17 00:00:00 2001 From: Donghee Na Date: Sun, 30 Nov 2025 10:28:30 +0900 Subject: [PATCH 08/34] Change annotation prefix --- Modules/_ctypes/malloc_closure.c | 2 +- Modules/mmapmodule.c | 2 +- Objects/obmalloc.c | 2 +- Python/jit.c | 2 +- Python/perf_jit_trampoline.c | 2 +- Python/perf_trampoline.c | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Modules/_ctypes/malloc_closure.c b/Modules/_ctypes/malloc_closure.c index c73f2125bcf514..2a0f1c215b5e64 100644 --- a/Modules/_ctypes/malloc_closure.c +++ b/Modules/_ctypes/malloc_closure.c @@ -84,7 +84,7 @@ static void more_core(void) 0); if (item == (void *)MAP_FAILED) return; - _PyAnnotateMemoryMap(item, mem_size, "Python:more_core"); + _PyAnnotateMemoryMap(item, mem_size, "cpython:more_core"); #endif #ifdef MALLOC_CLOSURE_DEBUG diff --git a/Modules/mmapmodule.c b/Modules/mmapmodule.c index face61524d3c8d..a9d9582e29f260 100644 --- a/Modules/mmapmodule.c +++ b/Modules/mmapmodule.c @@ -1952,7 +1952,7 @@ new_mmap_object(PyTypeObject *type, PyObject *args, PyObject *kwdict) PyErr_SetFromErrno(PyExc_OSError); return NULL; } - _PyAnnotateMemoryMap(m_obj->data, map_size, "Python:new_mmap_object"); + _PyAnnotateMemoryMap(m_obj->data, map_size, "cpython:new_mmap_object"); m_obj->access = (access_mode)access; return (PyObject *)m_obj; } diff --git a/Objects/obmalloc.c b/Objects/obmalloc.c index 5c2a07b474de17..80ee0c6aab56b0 100644 --- a/Objects/obmalloc.c +++ b/Objects/obmalloc.c @@ -467,7 +467,7 @@ _PyMem_ArenaAlloc(void *Py_UNUSED(ctx), size_t size) if (ptr == MAP_FAILED) return NULL; assert(ptr != NULL); - _PyAnnotateMemoryMap(ptr, size, "Python:PyMem_ArenaAlloc"); + _PyAnnotateMemoryMap(ptr, size, "cpython:PyMem_ArenaAlloc"); return ptr; #else return malloc(size); diff --git a/Python/jit.c b/Python/jit.c index 86b20a81d0120d..26bfcf0cd693eb 100644 --- a/Python/jit.c +++ b/Python/jit.c @@ -72,7 +72,7 @@ jit_alloc(size_t size) unsigned char *memory = mmap(NULL, size, prot, flags, -1, 0); int failed = memory == MAP_FAILED; if (!failed) { - _PyAnnotateMemoryMap(memory, size, "Python:jit_alloc"); + _PyAnnotateMemoryMap(memory, size, "cpython:jit_alloc"); } #endif if (failed) { diff --git a/Python/perf_jit_trampoline.c b/Python/perf_jit_trampoline.c index e2bb4d98870388..0e1023aa8218b7 100644 --- a/Python/perf_jit_trampoline.c +++ b/Python/perf_jit_trampoline.c @@ -1086,7 +1086,7 @@ static void* perf_map_jit_init(void) { close(fd); return NULL; // Memory mapping failed } - _PyAnnotateMemoryMap(perf_jit_map_state.mapped_buffer, page_size, "Python:perf_map_jit_init"); + _PyAnnotateMemoryMap(perf_jit_map_state.mapped_buffer, page_size, "cpython:perf_map_jit_init"); #endif perf_jit_map_state.mapped_size = page_size; diff --git a/Python/perf_trampoline.c b/Python/perf_trampoline.c index aa1d5fc6fa26bd..9af9ae17f1b322 100644 --- a/Python/perf_trampoline.c +++ b/Python/perf_trampoline.c @@ -291,7 +291,7 @@ new_code_arena(void) perf_status = PERF_STATUS_FAILED; return -1; } - _PyAnnotateMemoryMap(memory, mem_size, "Python:new_code_arena"); + _PyAnnotateMemoryMap(memory, mem_size, "cpython:new_code_arena"); void *start = &_Py_trampoline_func_start; void *end = &_Py_trampoline_func_end; size_t code_size = end - start; From 855742bca5bd7379f71f0abcb0e1a7eb5d6a7c75 Mon Sep 17 00:00:00 2001 From: Donghee Na Date: Sun, 30 Nov 2025 10:42:48 +0900 Subject: [PATCH 09/34] nit --- configure | 1 + configure.ac | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/configure b/configure index 68d5a9ffe9dec2..53789d72dd62cb 100755 --- a/configure +++ b/configure @@ -23933,6 +23933,7 @@ fi ac_fn_check_decl "$LINENO" "PR_SET_VMA_ANON_NAME" "ac_cv_have_decl_PR_SET_VMA_ANON_NAME" "#include + #include " "$ac_c_undeclared_builtin_options" "CFLAGS" if test "x$ac_cv_have_decl_PR_SET_VMA_ANON_NAME" = xyes then : diff --git a/configure.ac b/configure.ac index 862c3ba5c45a89..a84940aa9f1554 100644 --- a/configure.ac +++ b/configure.ac @@ -5582,7 +5582,8 @@ AC_CHECK_DECLS([PR_SET_VMA_ANON_NAME], [AC_DEFINE([HAVE_PR_SET_VMA_ANON_NAME], [1], [Define if you have the 'PR_SET_VMA_ANON_NAME' constant.])], [], - [@%:@include ]) + [@%:@include + @%:@include ]) # check for openpty, login_tty, and forkpty From 32cc00780d096bd2acc64acd03441d54b5c5fd97 Mon Sep 17 00:00:00 2001 From: Donghee Na Date: Tue, 2 Dec 2025 01:43:11 +0900 Subject: [PATCH 10/34] Address code review --- Include/internal/pycore_pymem.h | 11 ++++++----- Modules/_ctypes/malloc_closure.c | 2 +- Modules/mmapmodule.c | 2 +- Objects/obmalloc.c | 2 +- Python/jit.c | 2 +- Python/perf_jit_trampoline.c | 2 +- Python/perf_trampoline.c | 2 +- 7 files changed, 12 insertions(+), 11 deletions(-) diff --git a/Include/internal/pycore_pymem.h b/Include/internal/pycore_pymem.h index 8ad3d705492c76..3d4f1559a95376 100644 --- a/Include/internal/pycore_pymem.h +++ b/Include/internal/pycore_pymem.h @@ -100,12 +100,13 @@ static inline int _PyAnnotateMemoryMap(void *addr, size_t size, const char *name) { #if defined(Py_DEBUG) && defined(HAVE_PR_SET_VMA_ANON_NAME) && defined(__linux__) - prctl(PR_SET_VMA, PR_SET_VMA_ANON_NAME, (unsigned long)addr, size, name); - // Ignore errno from prctl - // See: https://bugzilla.redhat.com/show_bug.cgi?id=2302746 - errno = 0; + assert(strlen(name) < 80); + prctl(PR_SET_VMA, PR_SET_VMA_ANON_NAME, (unsigned long)addr, size, name); + // Ignore errno from prctl + // See: https://bugzilla.redhat.com/show_bug.cgi?id=2302746 + errno = 0; #endif - return 0; + return 0; } extern int _PyMem_GetAllocatorName( diff --git a/Modules/_ctypes/malloc_closure.c b/Modules/_ctypes/malloc_closure.c index 2a0f1c215b5e64..175054dae3b86e 100644 --- a/Modules/_ctypes/malloc_closure.c +++ b/Modules/_ctypes/malloc_closure.c @@ -84,7 +84,7 @@ static void more_core(void) 0); if (item == (void *)MAP_FAILED) return; - _PyAnnotateMemoryMap(item, mem_size, "cpython:more_core"); + _PyAnnotateMemoryMap(item, mem_size, "cpython:malloc_closure:more_core"); #endif #ifdef MALLOC_CLOSURE_DEBUG diff --git a/Modules/mmapmodule.c b/Modules/mmapmodule.c index a9d9582e29f260..c43d195292ddea 100644 --- a/Modules/mmapmodule.c +++ b/Modules/mmapmodule.c @@ -1952,7 +1952,7 @@ new_mmap_object(PyTypeObject *type, PyObject *args, PyObject *kwdict) PyErr_SetFromErrno(PyExc_OSError); return NULL; } - _PyAnnotateMemoryMap(m_obj->data, map_size, "cpython:new_mmap_object"); + _PyAnnotateMemoryMap(m_obj->data, map_size, "cpython:mmap:new_mmap_object"); m_obj->access = (access_mode)access; return (PyObject *)m_obj; } diff --git a/Objects/obmalloc.c b/Objects/obmalloc.c index 80ee0c6aab56b0..f57ada4b68b7ce 100644 --- a/Objects/obmalloc.c +++ b/Objects/obmalloc.c @@ -467,7 +467,7 @@ _PyMem_ArenaAlloc(void *Py_UNUSED(ctx), size_t size) if (ptr == MAP_FAILED) return NULL; assert(ptr != NULL); - _PyAnnotateMemoryMap(ptr, size, "cpython:PyMem_ArenaAlloc"); + _PyAnnotateMemoryMap(ptr, size, "cpython:obmalloc:PyMem_ArenaAlloc"); return ptr; #else return malloc(size); diff --git a/Python/jit.c b/Python/jit.c index 26bfcf0cd693eb..e8ed44c3e9aba0 100644 --- a/Python/jit.c +++ b/Python/jit.c @@ -72,7 +72,7 @@ jit_alloc(size_t size) unsigned char *memory = mmap(NULL, size, prot, flags, -1, 0); int failed = memory == MAP_FAILED; if (!failed) { - _PyAnnotateMemoryMap(memory, size, "cpython:jit_alloc"); + _PyAnnotateMemoryMap(memory, size, "cpython:jit:jit_alloc"); } #endif if (failed) { diff --git a/Python/perf_jit_trampoline.c b/Python/perf_jit_trampoline.c index 0e1023aa8218b7..8d0a48649cfc81 100644 --- a/Python/perf_jit_trampoline.c +++ b/Python/perf_jit_trampoline.c @@ -1086,7 +1086,7 @@ static void* perf_map_jit_init(void) { close(fd); return NULL; // Memory mapping failed } - _PyAnnotateMemoryMap(perf_jit_map_state.mapped_buffer, page_size, "cpython:perf_map_jit_init"); + _PyAnnotateMemoryMap(perf_jit_map_state.mapped_buffer, page_size, "cpython:perf_jit_trampoline:perf_map_jit_init"); #endif perf_jit_map_state.mapped_size = page_size; diff --git a/Python/perf_trampoline.c b/Python/perf_trampoline.c index 9af9ae17f1b322..11e5886538a31f 100644 --- a/Python/perf_trampoline.c +++ b/Python/perf_trampoline.c @@ -291,7 +291,7 @@ new_code_arena(void) perf_status = PERF_STATUS_FAILED; return -1; } - _PyAnnotateMemoryMap(memory, mem_size, "cpython:new_code_arena"); + _PyAnnotateMemoryMap(memory, mem_size, "cpython:perf_trampoline:new_code_arena"); void *start = &_Py_trampoline_func_start; void *end = &_Py_trampoline_func_end; size_t code_size = end - start; From 49b4f95336b8daade9945902f814b1173e09c9ba Mon Sep 17 00:00:00 2001 From: Donghee Na Date: Wed, 3 Dec 2025 02:00:59 +0900 Subject: [PATCH 11/34] Apply suggestions from code review Co-authored-by: Victor Stinner --- Include/internal/pycore_pymem.h | 4 ++-- Modules/mmapmodule.c | 2 +- Python/jit.c | 2 +- Python/perf_jit_trampoline.c | 2 +- Python/perf_trampoline.c | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Include/internal/pycore_pymem.h b/Include/internal/pycore_pymem.h index 3d4f1559a95376..a6837c339be7bf 100644 --- a/Include/internal/pycore_pymem.h +++ b/Include/internal/pycore_pymem.h @@ -12,8 +12,8 @@ extern "C" { #endif #if defined(Py_DEBUG) && defined(HAVE_PR_SET_VMA_ANON_NAME) && defined(__linux__) -#include -#include +# include +# include #endif // Try to get the allocators name set by _PyMem_SetupAllocators(). diff --git a/Modules/mmapmodule.c b/Modules/mmapmodule.c index c43d195292ddea..4795a23a858f02 100644 --- a/Modules/mmapmodule.c +++ b/Modules/mmapmodule.c @@ -1952,7 +1952,7 @@ new_mmap_object(PyTypeObject *type, PyObject *args, PyObject *kwdict) PyErr_SetFromErrno(PyExc_OSError); return NULL; } - _PyAnnotateMemoryMap(m_obj->data, map_size, "cpython:mmap:new_mmap_object"); + _PyAnnotateMemoryMap(m_obj->data, map_size, "cpython:mmap"); m_obj->access = (access_mode)access; return (PyObject *)m_obj; } diff --git a/Python/jit.c b/Python/jit.c index e8ed44c3e9aba0..dbb8e58dd2a739 100644 --- a/Python/jit.c +++ b/Python/jit.c @@ -72,7 +72,7 @@ jit_alloc(size_t size) unsigned char *memory = mmap(NULL, size, prot, flags, -1, 0); int failed = memory == MAP_FAILED; if (!failed) { - _PyAnnotateMemoryMap(memory, size, "cpython:jit:jit_alloc"); + _PyAnnotateMemoryMap(memory, size, "cpython:jit"); } #endif if (failed) { diff --git a/Python/perf_jit_trampoline.c b/Python/perf_jit_trampoline.c index 8d0a48649cfc81..9704250195974b 100644 --- a/Python/perf_jit_trampoline.c +++ b/Python/perf_jit_trampoline.c @@ -1086,7 +1086,7 @@ static void* perf_map_jit_init(void) { close(fd); return NULL; // Memory mapping failed } - _PyAnnotateMemoryMap(perf_jit_map_state.mapped_buffer, page_size, "cpython:perf_jit_trampoline:perf_map_jit_init"); + _PyAnnotateMemoryMap(perf_jit_map_state.mapped_buffer, page_size, "cpython:perf_jit_trampoline"); #endif perf_jit_map_state.mapped_size = page_size; diff --git a/Python/perf_trampoline.c b/Python/perf_trampoline.c index 11e5886538a31f..54bf752145b0e0 100644 --- a/Python/perf_trampoline.c +++ b/Python/perf_trampoline.c @@ -291,7 +291,7 @@ new_code_arena(void) perf_status = PERF_STATUS_FAILED; return -1; } - _PyAnnotateMemoryMap(memory, mem_size, "cpython:perf_trampoline:new_code_arena"); + _PyAnnotateMemoryMap(memory, mem_size, "cpython:perf_trampoline"); void *start = &_Py_trampoline_func_start; void *end = &_Py_trampoline_func_end; size_t code_size = end - start; From 1b88b75271d9ffb39fb25bc8399adf64ff1a0de0 Mon Sep 17 00:00:00 2001 From: Donghee Na Date: Wed, 3 Dec 2025 02:02:14 +0900 Subject: [PATCH 12/34] Address code review --- Objects/obmalloc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Objects/obmalloc.c b/Objects/obmalloc.c index f57ada4b68b7ce..a6746b2ad4f47d 100644 --- a/Objects/obmalloc.c +++ b/Objects/obmalloc.c @@ -467,7 +467,7 @@ _PyMem_ArenaAlloc(void *Py_UNUSED(ctx), size_t size) if (ptr == MAP_FAILED) return NULL; assert(ptr != NULL); - _PyAnnotateMemoryMap(ptr, size, "cpython:obmalloc:PyMem_ArenaAlloc"); + _PyAnnotateMemoryMap(ptr, size, "cpython:obmalloc"); return ptr; #else return malloc(size); From e2eedbc99875391a7dcd4b67af07fcc2de7283ab Mon Sep 17 00:00:00 2001 From: Donghee Na Date: Wed, 3 Dec 2025 02:05:02 +0900 Subject: [PATCH 13/34] Address code review --- Modules/mmapmodule.c | 2 +- Python/perf_jit_trampoline.c | 2 +- Python/perf_trampoline.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Modules/mmapmodule.c b/Modules/mmapmodule.c index 4795a23a858f02..1a466db2fcec45 100644 --- a/Modules/mmapmodule.c +++ b/Modules/mmapmodule.c @@ -26,7 +26,7 @@ #include "pycore_abstract.h" // _Py_convert_optional_to_ssize_t() #include "pycore_bytesobject.h" // _PyBytes_Find() #include "pycore_fileutils.h" // _Py_stat_struct -#include "pycore_obmalloc.h" // _PyAnnotateMemoryMap() +#include "pycore_pymem.h" // _PyAnnotateMemoryMap() #include "pycore_weakref.h" // FT_CLEAR_WEAKREFS() #include // offsetof() diff --git a/Python/perf_jit_trampoline.c b/Python/perf_jit_trampoline.c index 9704250195974b..d8c2949b522940 100644 --- a/Python/perf_jit_trampoline.c +++ b/Python/perf_jit_trampoline.c @@ -61,7 +61,7 @@ #include "pycore_ceval.h" // _PyPerf_Callbacks #include "pycore_frame.h" #include "pycore_interp.h" -#include "pycore_obmalloc.h" // _PyAnnotateMemoryMap() +#include "pycore_pymem.h" // _PyAnnotateMemoryMap() #include "pycore_runtime.h" // _PyRuntime #ifdef PY_HAVE_PERF_TRAMPOLINE diff --git a/Python/perf_trampoline.c b/Python/perf_trampoline.c index 54bf752145b0e0..baa83814c6a5a1 100644 --- a/Python/perf_trampoline.c +++ b/Python/perf_trampoline.c @@ -132,7 +132,7 @@ any DWARF information available for them). #include "Python.h" #include "pycore_ceval.h" // _PyPerf_Callbacks #include "pycore_interpframe.h" // _PyFrame_GetCode() -#include "pycore_obmalloc.h" // _PyAnnotateMemoryMap() +#include "pycore_pymem.h" // _PyAnnotateMemoryMap() #include "pycore_runtime.h" // _PyRuntime From a680677f756b390f52534ebec77a5332a1dbc216 Mon Sep 17 00:00:00 2001 From: Donghee Na Date: Thu, 4 Dec 2025 03:14:51 +0900 Subject: [PATCH 14/34] test --- Include/internal/pycore_pymem.h | 18 ------------------ Makefile.pre.in | 1 + Modules/_ctypes/malloc_closure.c | 2 +- Modules/mmapmodule.c | 2 +- Objects/obmalloc.c | 1 + Python/jit.c | 1 + Python/perf_jit_trampoline.c | 2 +- Python/perf_trampoline.c | 2 +- 8 files changed, 7 insertions(+), 22 deletions(-) diff --git a/Include/internal/pycore_pymem.h b/Include/internal/pycore_pymem.h index a6837c339be7bf..05484e847f1195 100644 --- a/Include/internal/pycore_pymem.h +++ b/Include/internal/pycore_pymem.h @@ -11,11 +11,6 @@ extern "C" { # error "this header requires Py_BUILD_CORE define" #endif -#if defined(Py_DEBUG) && defined(HAVE_PR_SET_VMA_ANON_NAME) && defined(__linux__) -# include -# include -#endif - // Try to get the allocators name set by _PyMem_SetupAllocators(). // Return NULL if unknown. // Export for '_testinternalcapi' shared extension. @@ -96,19 +91,6 @@ static inline int _PyMem_IsULongFreed(unsigned long value) #endif } -static inline int -_PyAnnotateMemoryMap(void *addr, size_t size, const char *name) -{ -#if defined(Py_DEBUG) && defined(HAVE_PR_SET_VMA_ANON_NAME) && defined(__linux__) - assert(strlen(name) < 80); - prctl(PR_SET_VMA, PR_SET_VMA_ANON_NAME, (unsigned long)addr, size, name); - // Ignore errno from prctl - // See: https://bugzilla.redhat.com/show_bug.cgi?id=2302746 - errno = 0; -#endif - return 0; -} - extern int _PyMem_GetAllocatorName( const char *name, PyMemAllocatorName *allocator); diff --git a/Makefile.pre.in b/Makefile.pre.in index 7b8e7ec0965180..c098cf8e1d4e4b 100644 --- a/Makefile.pre.in +++ b/Makefile.pre.in @@ -1378,6 +1378,7 @@ PYTHON_HEADERS= \ $(srcdir)/Include/internal/pycore_long.h \ $(srcdir)/Include/internal/pycore_memoryobject.h \ $(srcdir)/Include/internal/pycore_mimalloc.h \ + $(srcdir)/Include/internal/pycore_mmap.h \ $(srcdir)/Include/internal/pycore_modsupport.h \ $(srcdir)/Include/internal/pycore_moduleobject.h \ $(srcdir)/Include/internal/pycore_namespace.h \ diff --git a/Modules/_ctypes/malloc_closure.c b/Modules/_ctypes/malloc_closure.c index 175054dae3b86e..d81360db5f8d0d 100644 --- a/Modules/_ctypes/malloc_closure.c +++ b/Modules/_ctypes/malloc_closure.c @@ -14,7 +14,7 @@ # endif #endif #include "ctypes.h" -#include "pycore_obmalloc.h" // _PyAnnotateMemoryMap() +#include "pycore_mmap.h" // _PyAnnotateMemoryMap() /* BLOCKSIZE can be adjusted. Larger blocksize will take a larger memory overhead, but allocate less blocks from the system. It may be that some diff --git a/Modules/mmapmodule.c b/Modules/mmapmodule.c index 1a466db2fcec45..37003020de2688 100644 --- a/Modules/mmapmodule.c +++ b/Modules/mmapmodule.c @@ -26,7 +26,7 @@ #include "pycore_abstract.h" // _Py_convert_optional_to_ssize_t() #include "pycore_bytesobject.h" // _PyBytes_Find() #include "pycore_fileutils.h" // _Py_stat_struct -#include "pycore_pymem.h" // _PyAnnotateMemoryMap() +#include "pycore_mmap.h" // _PyAnnotateMemoryMap() #include "pycore_weakref.h" // FT_CLEAR_WEAKREFS() #include // offsetof() diff --git a/Objects/obmalloc.c b/Objects/obmalloc.c index a6746b2ad4f47d..1b67217db31ece 100644 --- a/Objects/obmalloc.c +++ b/Objects/obmalloc.c @@ -2,6 +2,7 @@ #include "Python.h" #include "pycore_interp.h" // _PyInterpreterState_HasFeature +#include "pycore_mmap.h" // _PyAnnotateMemoryMap() #include "pycore_object.h" // _PyDebugAllocatorStats() definition #include "pycore_obmalloc.h" #include "pycore_obmalloc_init.h" diff --git a/Python/jit.c b/Python/jit.c index dbb8e58dd2a739..2a1acc38703c49 100644 --- a/Python/jit.c +++ b/Python/jit.c @@ -16,6 +16,7 @@ #include "pycore_intrinsics.h" #include "pycore_list.h" #include "pycore_long.h" +#include "pycore_mmap.h" #include "pycore_opcode_metadata.h" #include "pycore_opcode_utils.h" #include "pycore_optimizer.h" diff --git a/Python/perf_jit_trampoline.c b/Python/perf_jit_trampoline.c index d8c2949b522940..af7d8f9f1ec0ae 100644 --- a/Python/perf_jit_trampoline.c +++ b/Python/perf_jit_trampoline.c @@ -61,7 +61,7 @@ #include "pycore_ceval.h" // _PyPerf_Callbacks #include "pycore_frame.h" #include "pycore_interp.h" -#include "pycore_pymem.h" // _PyAnnotateMemoryMap() +#include "pycore_mmap.h" // _PyAnnotateMemoryMap() #include "pycore_runtime.h" // _PyRuntime #ifdef PY_HAVE_PERF_TRAMPOLINE diff --git a/Python/perf_trampoline.c b/Python/perf_trampoline.c index baa83814c6a5a1..669a47ae17377a 100644 --- a/Python/perf_trampoline.c +++ b/Python/perf_trampoline.c @@ -132,7 +132,7 @@ any DWARF information available for them). #include "Python.h" #include "pycore_ceval.h" // _PyPerf_Callbacks #include "pycore_interpframe.h" // _PyFrame_GetCode() -#include "pycore_pymem.h" // _PyAnnotateMemoryMap() +#include "pycore_mmap.h" // _PyAnnotateMemoryMap() #include "pycore_runtime.h" // _PyRuntime From 8ec4d73676dbda3f9e28befc3ae1e1c4990efc44 Mon Sep 17 00:00:00 2001 From: Donghee Na Date: Thu, 4 Dec 2025 03:17:06 +0900 Subject: [PATCH 15/34] Add Include/internal/pycore_mmap.h --- Include/internal/pycore_mmap.h | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 Include/internal/pycore_mmap.h diff --git a/Include/internal/pycore_mmap.h b/Include/internal/pycore_mmap.h new file mode 100644 index 00000000000000..2f282ac9f0248a --- /dev/null +++ b/Include/internal/pycore_mmap.h @@ -0,0 +1,33 @@ +#ifndef Py_INTERNAL_MMAP_H +#define Py_INTERNAL_MMAP_H + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef Py_BUILD_CORE +# error "this header requires Py_BUILD_CORE define" +#endif + +#if defined(Py_DEBUG) && defined(HAVE_PR_SET_VMA_ANON_NAME) && defined(__linux__) +# include +# include +#endif + +static inline int +_PyAnnotateMemoryMap(void *addr, size_t size, const char *name) +{ +#if defined(Py_DEBUG) && defined(HAVE_PR_SET_VMA_ANON_NAME) && defined(__linux__) + assert(strlen(name) < 80); + prctl(PR_SET_VMA, PR_SET_VMA_ANON_NAME, (unsigned long)addr, size, name); + // Ignore errno from prctl + // See: https://bugzilla.redhat.com/show_bug.cgi?id=2302746 + errno = 0; +#endif + return 0; +} + +#ifdef __cplusplus +} +#endif +#endif // !Py_INTERNAL_MMAP_H From c0e08b66ffe1da9c49e3ca4af5bf27feb6e14176 Mon Sep 17 00:00:00 2001 From: Donghee Na Date: Wed, 3 Dec 2025 18:24:56 +0000 Subject: [PATCH 16/34] fix --- Include/internal/pycore_mmap.h | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/Include/internal/pycore_mmap.h b/Include/internal/pycore_mmap.h index 2f282ac9f0248a..830d882c8a437c 100644 --- a/Include/internal/pycore_mmap.h +++ b/Include/internal/pycore_mmap.h @@ -9,7 +9,9 @@ extern "C" { # error "this header requires Py_BUILD_CORE define" #endif -#if defined(Py_DEBUG) && defined(HAVE_PR_SET_VMA_ANON_NAME) && defined(__linux__) +#include "pycore_pystate.h" + +#if defined(HAVE_PR_SET_VMA_ANON_NAME) && defined(__linux__) # include # include #endif @@ -17,12 +19,14 @@ extern "C" { static inline int _PyAnnotateMemoryMap(void *addr, size_t size, const char *name) { -#if defined(Py_DEBUG) && defined(HAVE_PR_SET_VMA_ANON_NAME) && defined(__linux__) - assert(strlen(name) < 80); - prctl(PR_SET_VMA, PR_SET_VMA_ANON_NAME, (unsigned long)addr, size, name); - // Ignore errno from prctl - // See: https://bugzilla.redhat.com/show_bug.cgi?id=2302746 - errno = 0; +#if defined(HAVE_PR_SET_VMA_ANON_NAME) && defined(__linux__) + if (_Py_GetConfig()->dev_mode) { + assert(strlen(name) < 80); + prctl(PR_SET_VMA, PR_SET_VMA_ANON_NAME, (unsigned long)addr, size, name); + // Ignore errno from prctl + // See: https://bugzilla.redhat.com/show_bug.cgi?id=2302746 + errno = 0; + } #endif return 0; } From e66e6507db44f097736b40e6a678bdb50fd11dd5 Mon Sep 17 00:00:00 2001 From: Donghee Na Date: Thu, 4 Dec 2025 03:29:28 +0900 Subject: [PATCH 17/34] Update PC --- PCbuild/pythoncore.vcxproj | 1 + PCbuild/pythoncore.vcxproj.filters | 3 +++ 2 files changed, 4 insertions(+) diff --git a/PCbuild/pythoncore.vcxproj b/PCbuild/pythoncore.vcxproj index 85363949c2344f..dcfb75ce162b2f 100644 --- a/PCbuild/pythoncore.vcxproj +++ b/PCbuild/pythoncore.vcxproj @@ -277,6 +277,7 @@ + diff --git a/PCbuild/pythoncore.vcxproj.filters b/PCbuild/pythoncore.vcxproj.filters index 17999690990fb9..247f4b5a784f9c 100644 --- a/PCbuild/pythoncore.vcxproj.filters +++ b/PCbuild/pythoncore.vcxproj.filters @@ -735,6 +735,9 @@ Include\internal + + Include\internal + Include\internal From b0ca751cf63b9c7db2f20832533aa0419103dd4c Mon Sep 17 00:00:00 2001 From: Donghee Na Date: Thu, 4 Dec 2025 03:31:35 +0900 Subject: [PATCH 18/34] Update --- .../2025-11-29-18-14-28.gh-issue-141770.JURnvg.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Misc/NEWS.d/next/Core_and_Builtins/2025-11-29-18-14-28.gh-issue-141770.JURnvg.rst b/Misc/NEWS.d/next/Core_and_Builtins/2025-11-29-18-14-28.gh-issue-141770.JURnvg.rst index 13ddc19e2dcd7c..a9f12aaa3ee588 100644 --- a/Misc/NEWS.d/next/Core_and_Builtins/2025-11-29-18-14-28.gh-issue-141770.JURnvg.rst +++ b/Misc/NEWS.d/next/Core_and_Builtins/2025-11-29-18-14-28.gh-issue-141770.JURnvg.rst @@ -1,2 +1,2 @@ -Annotate anonymous mmap usage in debug builds only when supported by the -Linux kernel. Patch by Donghee Na. +Annotate anonymous mmap usage only when supported by the +Linux kernel and if "-X dev" is used. Patch by Donghee Na. From c9138deab589f20226570595a65205f07aa54d01 Mon Sep 17 00:00:00 2001 From: Donghee Na Date: Thu, 4 Dec 2025 03:38:28 +0900 Subject: [PATCH 19/34] Update Whats News --- Doc/whatsnew/3.15.rst | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Doc/whatsnew/3.15.rst b/Doc/whatsnew/3.15.rst index 4882ddb4310fc2..33e4f46e0fceda 100644 --- a/Doc/whatsnew/3.15.rst +++ b/Doc/whatsnew/3.15.rst @@ -1247,6 +1247,10 @@ Build changes set to ``no`` or with :option:`!--without-system-libmpdec`. (Contributed by Sergey B Kirpichev in :gh:`115119`.) +* Annotating anonymous mmap usage is now supported if Linux kernel supports `PR_SET_VMA_ANON_NAME`. + Annotations are visible in `/proc//maps` if the kernel supports the feature + and `-X dev` is passed to the interpreter. + (Contributed by Donghee Na in :gh:`141770`) Porting to Python 3.15 ====================== From 8706fce4d1a62922a0054a5d94c5cad4ae999528 Mon Sep 17 00:00:00 2001 From: Donghee Na Date: Thu, 4 Dec 2025 21:08:29 +0900 Subject: [PATCH 20/34] Address code review --- Include/internal/pycore_mmap.h | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/Include/internal/pycore_mmap.h b/Include/internal/pycore_mmap.h index 830d882c8a437c..132c8e155842bd 100644 --- a/Include/internal/pycore_mmap.h +++ b/Include/internal/pycore_mmap.h @@ -16,20 +16,20 @@ extern "C" { # include #endif -static inline int -_PyAnnotateMemoryMap(void *addr, size_t size, const char *name) -{ #if defined(HAVE_PR_SET_VMA_ANON_NAME) && defined(__linux__) - if (_Py_GetConfig()->dev_mode) { - assert(strlen(name) < 80); - prctl(PR_SET_VMA, PR_SET_VMA_ANON_NAME, (unsigned long)addr, size, name); - // Ignore errno from prctl - // See: https://bugzilla.redhat.com/show_bug.cgi?id=2302746 - errno = 0; - } +# define _PyAnnotateMemoryMap(addr, size, name) \ + do { \ + if (_Py_GetConfig()->dev_mode) { \ + assert(strlen(name) < 80); \ + prctl(PR_SET_VMA, PR_SET_VMA_ANON_NAME, (unsigned long)(addr), (size), (name)); \ + /* Ignore errno from prctl */ \ + /* See: https://bugzilla.redhat.com/show_bug.cgi?id=2302746 */ \ + errno = 0; \ + } \ + } while (0) +#else +# define _PyAnnotateMemoryMap(addr, size, name) ((void)0) #endif - return 0; -} #ifdef __cplusplus } From 8ce82817375269e3cb6136f1248c7b8dd269bf01 Mon Sep 17 00:00:00 2001 From: Donghee Na Date: Thu, 4 Dec 2025 21:11:03 +0900 Subject: [PATCH 21/34] lint --- Doc/whatsnew/3.15.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/whatsnew/3.15.rst b/Doc/whatsnew/3.15.rst index 81ef70ad32ac17..2f09b5ee3ccbb0 100644 --- a/Doc/whatsnew/3.15.rst +++ b/Doc/whatsnew/3.15.rst @@ -1254,7 +1254,7 @@ Build changes (Contributed by Stan Ulbrych and Petr Viktorin in :gh:`139707`.) * Annotating anonymous mmap usage is now supported if Linux kernel supports `PR_SET_VMA_ANON_NAME`. - Annotations are visible in `/proc//maps` if the kernel supports the feature + Annotations are visible in `/proc//maps` if the kernel supports the feature and `-X dev` is passed to the interpreter. (Contributed by Donghee Na in :gh:`141770`) From d71a74487775b9b6a97a9e04c27d35e8a8ac398e Mon Sep 17 00:00:00 2001 From: Donghee Na Date: Thu, 4 Dec 2025 21:21:25 +0900 Subject: [PATCH 22/34] Update --- Doc/whatsnew/3.15.rst | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Doc/whatsnew/3.15.rst b/Doc/whatsnew/3.15.rst index 2f09b5ee3ccbb0..d8e8fc3b8857fc 100644 --- a/Doc/whatsnew/3.15.rst +++ b/Doc/whatsnew/3.15.rst @@ -1253,11 +1253,12 @@ Build changes modules that are missing or packaged separately. (Contributed by Stan Ulbrych and Petr Viktorin in :gh:`139707`.) -* Annotating anonymous mmap usage is now supported if Linux kernel supports `PR_SET_VMA_ANON_NAME`. - Annotations are visible in `/proc//maps` if the kernel supports the feature - and `-X dev` is passed to the interpreter. +* Annotating anonymous mmap usage is now supported if Linux kernel supports ``PR_SET_VMA_ANON_NAME``. + Annotations are visible in ``/proc//maps`` if the kernel supports the feature + and ``-X dev`` is passed to the interpreter. (Contributed by Donghee Na in :gh:`141770`) + Porting to Python 3.15 ====================== From 4dd1ee469927ab1418c3f894159d69091c630d1d Mon Sep 17 00:00:00 2001 From: Donghee Na Date: Fri, 5 Dec 2025 03:42:59 +0900 Subject: [PATCH 23/34] Address code review --- Doc/whatsnew/3.15.rst | 2 +- Include/internal/pycore_mmap.h | 11 ++++++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/Doc/whatsnew/3.15.rst b/Doc/whatsnew/3.15.rst index d8e8fc3b8857fc..ce29b555399da9 100644 --- a/Doc/whatsnew/3.15.rst +++ b/Doc/whatsnew/3.15.rst @@ -1255,7 +1255,7 @@ Build changes * Annotating anonymous mmap usage is now supported if Linux kernel supports ``PR_SET_VMA_ANON_NAME``. Annotations are visible in ``/proc//maps`` if the kernel supports the feature - and ``-X dev`` is passed to the interpreter. + and ``-X dev`` is passed to the Python or Python is built in debug mode. (Contributed by Donghee Na in :gh:`141770`) diff --git a/Include/internal/pycore_mmap.h b/Include/internal/pycore_mmap.h index 132c8e155842bd..7bf7b4797c9b4a 100644 --- a/Include/internal/pycore_mmap.h +++ b/Include/internal/pycore_mmap.h @@ -16,7 +16,16 @@ extern "C" { # include #endif -#if defined(HAVE_PR_SET_VMA_ANON_NAME) && defined(__linux__) +#if defined(HAVE_PR_SET_VMA_ANON_NAME) && defined(__linux__) && defined(Py_DEBUG) +# define _PyAnnotateMemoryMap(addr, size, name) \ + do { \ + assert(strlen(name) < 80); \ + prctl(PR_SET_VMA, PR_SET_VMA_ANON_NAME, (unsigned long)(addr), (size), (name)); \ + /* Ignore errno from prctl */ \ + /* See: https://bugzilla.redhat.com/show_bug.cgi?id=2302746 */ \ + errno = 0; \ + } while (0) +#elif defined(HAVE_PR_SET_VMA_ANON_NAME) && defined(__linux__) # define _PyAnnotateMemoryMap(addr, size, name) \ do { \ if (_Py_GetConfig()->dev_mode) { \ From fee757e3de64af2bcf24e45b37f76b05edfc8767 Mon Sep 17 00:00:00 2001 From: Donghee Na Date: Fri, 5 Dec 2025 23:03:09 +0900 Subject: [PATCH 24/34] Apply suggestions from code review Co-authored-by: Victor Stinner --- Doc/whatsnew/3.15.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Doc/whatsnew/3.15.rst b/Doc/whatsnew/3.15.rst index ce29b555399da9..927eeef263804c 100644 --- a/Doc/whatsnew/3.15.rst +++ b/Doc/whatsnew/3.15.rst @@ -1253,9 +1253,9 @@ Build changes modules that are missing or packaged separately. (Contributed by Stan Ulbrych and Petr Viktorin in :gh:`139707`.) -* Annotating anonymous mmap usage is now supported if Linux kernel supports ``PR_SET_VMA_ANON_NAME``. +* Annotating anonymous mmap usage is now supported if Linux kernel supports ``PR_SET_VMA_ANON_NAME`` (Linux 5.17 or newer). Annotations are visible in ``/proc//maps`` if the kernel supports the feature - and ``-X dev`` is passed to the Python or Python is built in debug mode. + and :option:`-X dev <-X>` is passed to the Python or Python is built in :ref:`debug mode `. (Contributed by Donghee Na in :gh:`141770`) From a240b3c3ba64456b745a8b0779cdc12b6269b7e8 Mon Sep 17 00:00:00 2001 From: Donghee Na Date: Fri, 5 Dec 2025 23:04:54 +0900 Subject: [PATCH 25/34] Update Objects/obmalloc.c Co-authored-by: Victor Stinner --- Objects/obmalloc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Objects/obmalloc.c b/Objects/obmalloc.c index 1b67217db31ece..b1f9fa2e692265 100644 --- a/Objects/obmalloc.c +++ b/Objects/obmalloc.c @@ -468,7 +468,7 @@ _PyMem_ArenaAlloc(void *Py_UNUSED(ctx), size_t size) if (ptr == MAP_FAILED) return NULL; assert(ptr != NULL); - _PyAnnotateMemoryMap(ptr, size, "cpython:obmalloc"); + _PyAnnotateMemoryMap(ptr, size, "cpython:pymalloc"); return ptr; #else return malloc(size); From 805c539e40776fac45c7b4d4075113aeaaac1b22 Mon Sep 17 00:00:00 2001 From: Donghee Na Date: Fri, 5 Dec 2025 23:08:09 +0900 Subject: [PATCH 26/34] Address code review --- Include/internal/pycore_mmap.h | 43 +++++++++++++++++----------------- 1 file changed, 22 insertions(+), 21 deletions(-) diff --git a/Include/internal/pycore_mmap.h b/Include/internal/pycore_mmap.h index 7bf7b4797c9b4a..8d88ca6699afcf 100644 --- a/Include/internal/pycore_mmap.h +++ b/Include/internal/pycore_mmap.h @@ -16,28 +16,29 @@ extern "C" { # include #endif -#if defined(HAVE_PR_SET_VMA_ANON_NAME) && defined(__linux__) && defined(Py_DEBUG) -# define _PyAnnotateMemoryMap(addr, size, name) \ - do { \ - assert(strlen(name) < 80); \ - prctl(PR_SET_VMA, PR_SET_VMA_ANON_NAME, (unsigned long)(addr), (size), (name)); \ - /* Ignore errno from prctl */ \ - /* See: https://bugzilla.redhat.com/show_bug.cgi?id=2302746 */ \ - errno = 0; \ - } while (0) -#elif defined(HAVE_PR_SET_VMA_ANON_NAME) && defined(__linux__) -# define _PyAnnotateMemoryMap(addr, size, name) \ - do { \ - if (_Py_GetConfig()->dev_mode) { \ - assert(strlen(name) < 80); \ - prctl(PR_SET_VMA, PR_SET_VMA_ANON_NAME, (unsigned long)(addr), (size), (name)); \ - /* Ignore errno from prctl */ \ - /* See: https://bugzilla.redhat.com/show_bug.cgi?id=2302746 */ \ - errno = 0; \ - } \ - } while (0) +#if defined(HAVE_PR_SET_VMA_ANON_NAME) && defined(__linux__) +static inline void +_PyAnnotateMemoryMap(void *addr, size_t size, const char *name) +{ +#ifndef Py_DEBUG + if (!_Py_GetConfig()->dev_mode) { + return; + } +#endif + assert(strlen(name) < 80); + prctl(PR_SET_VMA, PR_SET_VMA_ANON_NAME, (unsigned long)(addr), size, name); + /* Ignore errno from prctl */ + /* See: https://bugzilla.redhat.com/show_bug.cgi?id=2302746 */ + errno = 0; +} #else -# define _PyAnnotateMemoryMap(addr, size, name) ((void)0) +static inline void +_PyAnnotateMemoryMap(void *addr, size_t size, const char *name) +{ + (void)addr; + (void)size; + (void)name; +} #endif #ifdef __cplusplus From 795d31c636abb8cce22afb78c72c03fc96a631bf Mon Sep 17 00:00:00 2001 From: Donghee Na Date: Sat, 6 Dec 2025 00:42:00 +0900 Subject: [PATCH 27/34] Update Misc/NEWS.d/next/Core_and_Builtins/2025-11-29-18-14-28.gh-issue-141770.JURnvg.rst MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com> --- .../2025-11-29-18-14-28.gh-issue-141770.JURnvg.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Misc/NEWS.d/next/Core_and_Builtins/2025-11-29-18-14-28.gh-issue-141770.JURnvg.rst b/Misc/NEWS.d/next/Core_and_Builtins/2025-11-29-18-14-28.gh-issue-141770.JURnvg.rst index a9f12aaa3ee588..75cd0985d66e8f 100644 --- a/Misc/NEWS.d/next/Core_and_Builtins/2025-11-29-18-14-28.gh-issue-141770.JURnvg.rst +++ b/Misc/NEWS.d/next/Core_and_Builtins/2025-11-29-18-14-28.gh-issue-141770.JURnvg.rst @@ -1,2 +1,2 @@ Annotate anonymous mmap usage only when supported by the -Linux kernel and if "-X dev" is used. Patch by Donghee Na. +Linux kernel and if ``-X dev`` is used. Patch by Donghee Na. From be4d55020bbdf92af8dd422c583ba90e1aa4fccd Mon Sep 17 00:00:00 2001 From: Donghee Na Date: Sat, 6 Dec 2025 07:58:50 +0900 Subject: [PATCH 28/34] Address code review --- Doc/whatsnew/3.15.rst | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Doc/whatsnew/3.15.rst b/Doc/whatsnew/3.15.rst index 927eeef263804c..4425e49ae4a54a 100644 --- a/Doc/whatsnew/3.15.rst +++ b/Doc/whatsnew/3.15.rst @@ -1253,7 +1253,8 @@ Build changes modules that are missing or packaged separately. (Contributed by Stan Ulbrych and Petr Viktorin in :gh:`139707`.) -* Annotating anonymous mmap usage is now supported if Linux kernel supports ``PR_SET_VMA_ANON_NAME`` (Linux 5.17 or newer). +* Annotating anonymous mmap usage is now supported if Linux kernel supports + :manpage:`PR_SET_VMA_ANON_NAME ` (Linux 5.17 or newer). Annotations are visible in ``/proc//maps`` if the kernel supports the feature and :option:`-X dev <-X>` is passed to the Python or Python is built in :ref:`debug mode `. (Contributed by Donghee Na in :gh:`141770`) From 290864a38afed46575e6fd4fd56947f41702178f Mon Sep 17 00:00:00 2001 From: Donghee Na Date: Sat, 6 Dec 2025 08:01:35 +0900 Subject: [PATCH 29/34] Address code review --- Include/internal/pycore_mmap.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Include/internal/pycore_mmap.h b/Include/internal/pycore_mmap.h index 8d88ca6699afcf..e7074da658b184 100644 --- a/Include/internal/pycore_mmap.h +++ b/Include/internal/pycore_mmap.h @@ -26,10 +26,11 @@ _PyAnnotateMemoryMap(void *addr, size_t size, const char *name) } #endif assert(strlen(name) < 80); + int old_errno = errno; prctl(PR_SET_VMA, PR_SET_VMA_ANON_NAME, (unsigned long)(addr), size, name); /* Ignore errno from prctl */ /* See: https://bugzilla.redhat.com/show_bug.cgi?id=2302746 */ - errno = 0; + errno = old_errno; } #else static inline void From b287e0cb423c6bb95aad9458c67a27b47c8c0418 Mon Sep 17 00:00:00 2001 From: Donghee Na Date: Sat, 6 Dec 2025 08:03:16 +0900 Subject: [PATCH 30/34] nit --- Doc/whatsnew/3.15.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/whatsnew/3.15.rst b/Doc/whatsnew/3.15.rst index 4425e49ae4a54a..e6435835046906 100644 --- a/Doc/whatsnew/3.15.rst +++ b/Doc/whatsnew/3.15.rst @@ -1253,7 +1253,7 @@ Build changes modules that are missing or packaged separately. (Contributed by Stan Ulbrych and Petr Viktorin in :gh:`139707`.) -* Annotating anonymous mmap usage is now supported if Linux kernel supports +* Annotating anonymous mmap usage is now supported if Linux kernel supports :manpage:`PR_SET_VMA_ANON_NAME ` (Linux 5.17 or newer). Annotations are visible in ``/proc//maps`` if the kernel supports the feature and :option:`-X dev <-X>` is passed to the Python or Python is built in :ref:`debug mode `. From 1619f9594ccc147987989d95d413bd2cd2d9775d Mon Sep 17 00:00:00 2001 From: Donghee Na Date: Sat, 6 Dec 2025 20:42:56 +0900 Subject: [PATCH 31/34] Update Misc/NEWS.d/next/Core_and_Builtins/2025-11-29-18-14-28.gh-issue-141770.JURnvg.rst Co-authored-by: Victor Stinner --- .../2025-11-29-18-14-28.gh-issue-141770.JURnvg.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Misc/NEWS.d/next/Core_and_Builtins/2025-11-29-18-14-28.gh-issue-141770.JURnvg.rst b/Misc/NEWS.d/next/Core_and_Builtins/2025-11-29-18-14-28.gh-issue-141770.JURnvg.rst index 75cd0985d66e8f..3a5c0fd70edb1e 100644 --- a/Misc/NEWS.d/next/Core_and_Builtins/2025-11-29-18-14-28.gh-issue-141770.JURnvg.rst +++ b/Misc/NEWS.d/next/Core_and_Builtins/2025-11-29-18-14-28.gh-issue-141770.JURnvg.rst @@ -1,2 +1,2 @@ Annotate anonymous mmap usage only when supported by the -Linux kernel and if ``-X dev`` is used. Patch by Donghee Na. +Linux kernel and if ``-X dev`` is used or Python is built in debug mode. Patch by Donghee Na. From a1ad59294ff50d934ec535c11f5666257b75fba9 Mon Sep 17 00:00:00 2001 From: Donghee Na Date: Mon, 8 Dec 2025 23:09:40 +0900 Subject: [PATCH 32/34] Update Include/internal/pycore_mmap.h Co-authored-by: Victor Stinner --- Include/internal/pycore_mmap.h | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/Include/internal/pycore_mmap.h b/Include/internal/pycore_mmap.h index e7074da658b184..28de7df287a4e2 100644 --- a/Include/internal/pycore_mmap.h +++ b/Include/internal/pycore_mmap.h @@ -34,11 +34,8 @@ _PyAnnotateMemoryMap(void *addr, size_t size, const char *name) } #else static inline void -_PyAnnotateMemoryMap(void *addr, size_t size, const char *name) +_PyAnnotateMemoryMap(void *Py_UNUSED(addr), size_t Py_UNUSED(size), const char *Py_UNUSED(name)) { - (void)addr; - (void)size; - (void)name; } #endif From e4e4835ed1305255522d8a43f4c35f10cdaf3701 Mon Sep 17 00:00:00 2001 From: Donghee Na Date: Mon, 8 Dec 2025 23:10:53 +0900 Subject: [PATCH 33/34] Update Modules/_ctypes/malloc_closure.c Co-authored-by: Petr Viktorin --- Modules/_ctypes/malloc_closure.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Modules/_ctypes/malloc_closure.c b/Modules/_ctypes/malloc_closure.c index d81360db5f8d0d..62c7aa5d6affbf 100644 --- a/Modules/_ctypes/malloc_closure.c +++ b/Modules/_ctypes/malloc_closure.c @@ -84,7 +84,7 @@ static void more_core(void) 0); if (item == (void *)MAP_FAILED) return; - _PyAnnotateMemoryMap(item, mem_size, "cpython:malloc_closure:more_core"); + _PyAnnotateMemoryMap(item, mem_size, "cpython:ctypes"); #endif #ifdef MALLOC_CLOSURE_DEBUG From 0429a0a1819b1b8334338c743eb1d5930bd89637 Mon Sep 17 00:00:00 2001 From: Donghee Na Date: Mon, 8 Dec 2025 23:20:14 +0900 Subject: [PATCH 34/34] Update Include/internal/pycore_mmap.h Co-authored-by: Victor Stinner --- Include/internal/pycore_mmap.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Include/internal/pycore_mmap.h b/Include/internal/pycore_mmap.h index 28de7df287a4e2..214fd4362a55fe 100644 --- a/Include/internal/pycore_mmap.h +++ b/Include/internal/pycore_mmap.h @@ -27,7 +27,7 @@ _PyAnnotateMemoryMap(void *addr, size_t size, const char *name) #endif assert(strlen(name) < 80); int old_errno = errno; - prctl(PR_SET_VMA, PR_SET_VMA_ANON_NAME, (unsigned long)(addr), size, name); + prctl(PR_SET_VMA, PR_SET_VMA_ANON_NAME, (unsigned long)addr, size, name); /* Ignore errno from prctl */ /* See: https://bugzilla.redhat.com/show_bug.cgi?id=2302746 */ errno = old_errno;