-
-
Notifications
You must be signed in to change notification settings - Fork 14
Use a more clever formula for available_mem #34
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: julia-uv2-1.44.2
Are you sure you want to change the base?
Changes from all commits
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 |
---|---|---|
|
@@ -31,6 +31,7 @@ | |
#include <mach-o/dyld.h> /* _NSGetExecutablePath */ | ||
#include <sys/resource.h> | ||
#include <sys/sysctl.h> | ||
#include <sys/types.h> | ||
#include <unistd.h> /* sysconf */ | ||
|
||
static uv_once_t once = UV_ONCE_INIT; | ||
|
@@ -130,9 +131,19 @@ uint64_t uv_get_constrained_memory(void) { | |
return 0; /* Memory constraints are unknown. */ | ||
} | ||
|
||
|
||
uint64_t uv_get_available_memory(void) { | ||
return uv_get_free_memory(); | ||
vm_statistics64_data_t info; | ||
mach_msg_type_number_t count = sizeof(info) / sizeof(integer_t); | ||
|
||
if (host_statistics64(mach_host_self(), HOST_VM_INFO64, | ||
(host_info64_t)&info, &count) != KERN_SUCCESS) { | ||
return UV_EINVAL; /* FIXME(bnoordhuis) Translate error. */ | ||
} | ||
// Based on https://github.com/exelban/stats/blob/6c991de101957065f579a550ac2ae358d733d0c0/Modules/RAM/readers.swift#L47-L57 | ||
uint64_t used = info.active_count + info.inactive_count + info.compressor_page_count +info.speculative_count + info.wire_count; | ||
uint64_t not_used = info.purgeable_count + info.external_page_count; | ||
uint64_t available = uv_get_total_memory() - (used - not_used) * sysconf(_SC_PAGESIZE); | ||
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 I think there's an easier way to figure out "available" memory:
You could arguably include 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'm not sure if external is swapped pages, or pages that are on disk by default, but the os is caching on RAM. 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. But your code seems to give very similar results while looking cleaner. |
||
return available; | ||
} | ||
|
||
|
||
|
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.
What is
bnoordhuis
?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.
Ben Noordhuis, the libuv maintainer