-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Get Windows percent swap usage from performance counters #2160
Conversation
Calculations are incorrect in some cases. For example, in my case, i have 32 GB physical ram and 4.75 swap. When i run cext.virtual_mem(), I get following result.
|
That depends on your definition of "used". That swap is "committed".
That "Commit total" is memory reserved for open programs. It is reserved instantly because Windows guarantees it will be available when asked for. Your used physical memory is 34200948736 - 18837475328 = 15363473408 (14.3 GB) Physical memory used does not increment until the reserved pages are accessed. So you have 22.0 GB - 14.3 GB = 7.73 GB of pages reserved (committed) but not yet accessed. This exceeds the size of your swap file, therefore you have "used" all your swap. |
379abfd
to
78861c2
Compare
f069638
to
00724f0
Compare
Sorry for all the pushes. I think I'm done now... but see the linked issue for further discussion on virtual memory API. |
It seems to me that Windows doesn't use swap until committed memory exceeds total physical memory, that would be weird... |
I would think Windows might put rarely-accessed pages on disk in order to keep faster RAM available for new programs to start up. Right now in my Windows VM I have 12% swap file usage with only 40% "physical" memory usage. But I do get the point that "reserved" shouldn't mean "used". I'm flipping this back to draft to just ignore the Commit Total and use |
@giampaolo I could really use some help here. I'm trying to return a (double) float from the method and use it in a calculation to multiply by an integer and then round back to an integer. My total python experience is self-taught for about 2-3 weeks of hacking around. I'm confident in the approach here but not the coding details with the casting, rounding, etc. |
Mmm I'm not sure I understand. To round in python you do: >>> round(1.423, 1)
1.4 As for the C types: https://docs.python.org/3/c-api/arg.html#numbers FYI I will be on vacation for the next 7 days (with no laptop) so I won't be able to code for a while. =) |
Can't build on Windows. Error
|
Yeah, I know. I can see the same in appveyor and am fumbling around here.... |
Unsuccessfully 🙂 |
I have no idea why there are compile errors in |
Oh, duh, a missing semicolon in wmi.h..... 🙄 |
Good night, I will continue participation tomorrow 😩 |
Yeah I deleted that while troubleshooting the missing semicolon 🙄 |
05ec114
to
366b4e1
Compare
Signed-off-by: Daniel Widdis <[email protected]>
Signed-off-by: Daniel Widdis <[email protected]>
Signed-off-by: Daniel Widdis <[email protected]>
Signed-off-by: Daniel Widdis <[email protected]>
Signed-off-by: Daniel Widdis <[email protected]>
Signed-off-by: Daniel Widdis <[email protected]>
Signed-off-by: Daniel Widdis <[email protected]>
Signed-off-by: Daniel Widdis <[email protected]>
Signed-off-by: Daniel Widdis <[email protected]>
Signed-off-by: Daniel Widdis <[email protected]>
Signed-off-by: Daniel Widdis <[email protected]>
Signed-off-by: Daniel Widdis <[email protected]>
Signed-off-by: Daniel Widdis <[email protected]>
Signed-off-by: Daniel Widdis <[email protected]>
Signed-off-by: Daniel Widdis <[email protected]>
FYI, I was looking at #2161 and you have a test case (with exact match) from the WMI tables backing the performance counters. So this somewhat "proves" the equivalence in terms of data source.
This seems reasonable. As mentioned before, the only lack of precision is taking an integer division. I could avoid the float, however, by fetching integer values. The "Formatted" counter values give the double, but if I fetch the "Raw" counter values they would give exactly the same integers as in that WMI query we are both using as a test case, which I think are in units of page size (4096 I think). That would still give us the benefits of the PDH API lookup and avoid losing any precision with floating points.
I think I've addressed all your requests. There's some transient failure on macos unassociated with my changes. |
Signed-off-by: Daniel Widdis <[email protected]>
fail if PdhGetFormattedCounterValue fails
Thanks a lot Daniel. I made a small edit to your changes: if |
Thanks! Yeah, I agree this is the right approach. Also thanks for fixing up formatting. I don't normally write code in c or python so don't have the usual set of IDE / linter tools. Glad the substance of the code change is useful! |
Finally merged. Thanks and see you around! |
Signed-off-by: Daniel Widdis [email protected]
Summary
Description
Commit Total (physical + swap used) is incremented earlier than physical memory used, which leads to overestimating physical memory available, and results in negative "available" values when subtracting physical available from the available system (commit limit - commit total) value determining swap available.
This PR ignores Commit Total and instead calculates swap usage using the performance counter for Paging File % Usage.