-
-
Notifications
You must be signed in to change notification settings - Fork 33.6k
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
base: main
Are you sure you want to change the base?
Conversation
|
cc @picnixz |
|
FYI, Fedora does not support yet even if the kernel version itself already support it. |
Co-authored-by: Bénédikt Tran <[email protected]>
|
FWIW, it would be useful to have an option to enable this in release builds too. |
|
@SpecLad Thanks for the feedback, I will create a separate PR :) |
|
@SpecLad Just out of curiosity, passing the build flag through |
|
To be clear, by "option" I really mean a runtime option. 🙂 It would be pretty annoying to have to rebuild Python just for this. If you compare with other implementations, none of them require a compile-time option:
TBH, I don't see why Python shouldn't also permanently enable this, but I would settle for "off by default, enabled with environment variable or |
|
It's a bit annoying that this would only be supported on Linux. Do we have an option that isn't supported everywhere? |
Include/internal/pycore_mmap.h
Outdated
| # include <sys/prctl.h> | ||
| #endif | ||
|
|
||
| static inline int |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Surely this isn't worth putting into a macro? As a regular function, it will be fully internal, and PGO can inline the parts of it that are appropriate.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I prefer static inline functions. I don't see the advantage of using a macro. Inlining or not shouldn't make any difference on performance.
|
@zooba I've updated PR. PTAL :) |
Include/internal/pycore_mmap.h
Outdated
| #if defined(HAVE_PR_SET_VMA_ANON_NAME) && defined(__linux__) | ||
| # define _PyAnnotateMemoryMap(addr, size, name) \ | ||
| do { \ | ||
| if (_Py_GetConfig()->dev_mode) { \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I understood that it should always be enabled if Python is built in debug mode (if Py_DEBUG macro is defined).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I prefer consistent behavior
I considered the following options:
- Always enable it for both debug and release builds (as long as the build flag is enabled).
- Enable it only when -X dev is passed. (current choice)
To me, any other combination feels weird (e.g enabling it unconditionally in debug builds but requiring -X dev for release build)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is another code paths which is enabled if the Development Mode is enabled or Python is built in debug mode: checking errors argument in str.encode(encoding, errors), PyUnicode_Decode() and PyUnicode_FromEncodedObject().
In the past, a similar thing was done for errors on closing a file (io_finalize() in Modules/_io/iobase.c). Since Python 3.13, close errors on I/O are now always logged as unraisable exceptions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Accepted the suggestion :)
Include/internal/pycore_mmap.h
Outdated
| #endif | ||
|
|
||
| #if defined(HAVE_PR_SET_VMA_ANON_NAME) && defined(__linux__) && defined(Py_DEBUG) | ||
| # define _PyAnnotateMemoryMap(addr, size, name) \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we really need macros? it is just to avoid the (unsigned long) cast? If so, I would suggest having a static inline function (but you can have a macro for the no-op case to avoid an empty function) and leave the rest to the compiler. Or if you want to keep a macro, please align the \ (see PEP-7).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would also prefer a static inline function for cleaner code.
Include/internal/pycore_mmap.h
Outdated
| #endif | ||
|
|
||
| #if defined(HAVE_PR_SET_VMA_ANON_NAME) && defined(__linux__) && defined(Py_DEBUG) | ||
| # define _PyAnnotateMemoryMap(addr, size, name) \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would also prefer a static inline function for cleaner code.
Co-authored-by: Victor Stinner <[email protected]>
Co-authored-by: Victor Stinner <[email protected]>
corona10
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doc/whatsnew/3.15.rst
Outdated
| 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). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* Annotating anonymous mmap usage is now supported if Linux kernel
supports :manpage:`PR_SET_VMA_ANON_NAME <PR_SET_VMA(2const)>`
(Linux 5.17 or newer).I don't know under which manpage entry it is, but if you locally run Sphinx, you should be able to find the correct one. That way, users would have a link to click on. If there isn't a manpage, nevermind.
Misc/NEWS.d/next/Core_and_Builtins/2025-11-29-18-14-28.gh-issue-141770.JURnvg.rst
Outdated
Show resolved
Hide resolved
| } | ||
| #endif | ||
| assert(strlen(name) < 80); | ||
| prctl(PR_SET_VMA, PR_SET_VMA_ANON_NAME, (unsigned long)(addr), size, name); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you want to restore the previous errno maybe? (I actually don't know whether we're consistent in "ignoring" errnos).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Accepted :)
…e-141770.JURnvg.rst Co-authored-by: Bénédikt Tran <[email protected]>
Misc/NEWS.d/next/Core_and_Builtins/2025-11-29-18-14-28.gh-issue-141770.JURnvg.rst
Outdated
Show resolved
Hide resolved
…e-141770.JURnvg.rst Co-authored-by: Victor Stinner <[email protected]>


mmapin_PyMem_ArenaAllocfor debugging #141770