Skip to content
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

detect large page size on freebsd. #531

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion src/os.c
Original file line number Diff line number Diff line change
Expand Up @@ -261,14 +261,32 @@ static void os_detect_overcommit(void) {
#endif
}

static void os_detect_large_page_size() {
#if defined(__FreeBSD__)
size_t ptr[4] = {0};
size_t len = sizeof(ptr) / sizeof(ptr[0]);
getpagesizes(ptr, len);

// large page size starts from the second offset at least
for (size_t i = 1; i < len; i++) {
if (!(ptr[i] % MI_MiB)) {
large_os_page_size = ptr[i];
break;
}
}
#else
large_os_page_size = 2*MI_MiB;
#endif
}

void _mi_os_init() {
// get the page size
long result = sysconf(_SC_PAGESIZE);
if (result > 0) {
os_page_size = (size_t)result;
os_alloc_granularity = os_page_size;
}
large_os_page_size = 2*MI_MiB; // TODO: can we query the OS for this?
os_detect_large_page_size();
os_detect_overcommit();
}
#endif
Expand Down