-
-
Notifications
You must be signed in to change notification settings - Fork 34.5k
gh-141770: Annotate anonymous mmap usage if "-X dev" is used #142079
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.
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
Changes from 9 commits
0e3933d
8b7023e
816d962
979ce02
b3d8547
0c5a495
e757dd9
cb9509b
855742b
32cc007
49b4f95
1b88b75
e2eedbc
a680677
8ec4d73
c0e08b6
e66e650
b0ca751
c9138de
8f77e0d
8706fce
8ce8281
d71a744
4dd1ee4
fee757e
a240b3c
805c539
795d31c
be4d550
290864a
b287e0c
1619f95
a1ad592
e4e4835
0429a0a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| Annotate anonymous mmap usage in debug builds only when supported by the | ||
| Linux kernel. Patch by Donghee Na. |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -14,6 +14,7 @@ | |||||
| # endif | ||||||
| #endif | ||||||
| #include "ctypes.h" | ||||||
| #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 | ||||||
|
|
@@ -74,14 +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; | ||||||
| _PyAnnotateMemoryMap(item, mem_size, "cpython:more_core"); | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| #endif | ||||||
|
|
||||||
| #ifdef MALLOC_CLOSURE_DEBUG | ||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -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" // _PyAnnotateMemoryMap() | ||||||
|
corona10 marked this conversation as resolved.
Outdated
|
||||||
| #include "pycore_weakref.h" // FT_CLEAR_WEAKREFS() | ||||||
|
|
||||||
| #include <stddef.h> // offsetof() | ||||||
|
|
@@ -1951,6 +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"); | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
(If we allow users to set an annotation: this could be
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it's better to annotate this as allocated with the Python If the mmap is not anonymous, the annotation fails. Good. |
||||||
| m_obj->access = (access_mode)access; | ||||||
| return (PyObject *)m_obj; | ||||||
| } | ||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -467,6 +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"); | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. obmalloc only uses mmap for arenas
Suggested change
|
||||||
| return ptr; | ||||||
| #else | ||||||
| return malloc(size); | ||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -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) { | ||||||
| _PyAnnotateMemoryMap(memory, size, "cpython:jit_alloc"); | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| } | ||||||
| #endif | ||||||
| if (failed) { | ||||||
| jit_error("unable to allocate memory"); | ||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -61,6 +61,7 @@ | |||||
| #include "pycore_ceval.h" // _PyPerf_Callbacks | ||||||
| #include "pycore_frame.h" | ||||||
| #include "pycore_interp.h" | ||||||
| #include "pycore_obmalloc.h" // _PyAnnotateMemoryMap() | ||||||
| #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 | ||||||
| } | ||||||
| _PyAnnotateMemoryMap(perf_jit_map_state.mapped_buffer, page_size, "cpython:perf_map_jit_init"); | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| #endif | ||||||
|
|
||||||
| perf_jit_map_state.mapped_size = page_size; | ||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -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" // _PyAnnotateMemoryMap() | ||||||
| #include "pycore_runtime.h" // _PyRuntime | ||||||
|
|
||||||
|
|
||||||
|
|
@@ -290,6 +291,7 @@ new_code_arena(void) | |||||
| perf_status = PERF_STATUS_FAILED; | ||||||
| return -1; | ||||||
| } | ||||||
| _PyAnnotateMemoryMap(memory, mem_size, "cpython:new_code_arena"); | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| void *start = &_Py_trampoline_func_start; | ||||||
| void *end = &_Py_trampoline_func_end; | ||||||
| size_t code_size = end - start; | ||||||
|
|
||||||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Uh oh!
There was an error while loading. Please reload this page.