Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

gh-132917: Use RSS + swap for estimate of process memory usage#133464

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
nascheme merged 3 commits intopython:mainfromnascheme:gc_check_mem_usage
May 5, 2025

Conversation

nascheme
Copy link
Member

@naschemenascheme commentedMay 5, 2025
edited by github-actionsbot
Loading

This is a small refinement ofGH-133399. Including the swap usage as well as the RSS is a good idea in case some pages of the process got swapped out. Doing this in a cross-platform way is a bit challenging but this PR should on Linux, MacOS, and Windows at least. For OpenBSD and FreeBSD, we just use RSS.


📚 Documentation preview 📚:https://cpython-previews--133464.org.readthedocs.build/

@naschemenascheme marked this pull request as ready for reviewMay 5, 2025 20:46
@pablogsal
Copy link
Member

Exquisite

nascheme reacted with laugh emoji

@naschemenascheme merged commit893034c intopython:mainMay 5, 2025
45 checks passed
@Yhg1s
Copy link
Member

Yikes, reading a file in /proc to determine whether the GC should run? That feels... ugh. Also, we primarily care about allocations offrom Python, right? Doesn't mimalloc already have enough information to tell us the total heap size or something?

@pablogsal
Copy link
Member

Yikes, reading a file in /proc to determine whether the GC should run? That feels... ugh.

Well that's technically the official Linux interface to get this info so as long as you like the approach of making GC runs depend on memory watermark this is the correct way.

Also, we primarily care about allocations offrom Python, right? Doesn't mimalloc already have enough information to tell us the total heap size or something?

Yep, See also my comment in#133399 (review)

On the other hand we don't necessarily want to count Python only memory. If an object holds a big buffer allocated by malloc you also want to delete that object anyway. Is a less clear cut that the GC actually will do anything but is also not correct to say that's independent.

@nascheme
Copy link
MemberAuthor

Yikes, reading a file in /proc to determine whether the GC should run? That feels... ugh. Also, we primarily care about allocations offrom Python, right? Doesn't mimalloc already have enough information to tell us the total heap size or something?

It only happens whengc_should_collect() would have previously run a full collection. If it ran on every call, that would be bad. On Linux, it seems the only API to get that info. Using mimalloc info, while presumably fast, doesn't account to memory used by other allocators or from mmap, etc. I think this approach is better.

@Yhg1s
Copy link
Member

Hrm. Okay, different observation then: aren't we now running the risk ofevery thread reading the file (and doing all the work of checking the limits) in order to schedule the GC,even if it's already scheduled? I mean, we did that before as well, but that was when "all the work" was just checking a couple of oft-used memory locations. Now it actually consumes system resources (open files), which feels more fraught. Should we skip doing the check if the GC is already scheduled (or even "already being checked")?

@pablogsal
Copy link
Member

I still think a hybrid approach is best where we can weight the mimalloc side independently in the general resident size.

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@pablogsalpablogsalpablogsal approved these changes

Assignees
No one assigned
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

3 participants
@nascheme@pablogsal@Yhg1s

[8]ページ先頭

©2009-2025 Movatter.jp