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

runtime: add freebsd free_memory() support #23594

Merged
merged 3 commits into from
Jan 29, 2025
Merged
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
22 changes: 22 additions & 0 deletions vlib/runtime/free_memory_impl_freebsd.c.v
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
module runtime

fn C.sysctlnametomib(name charptr, mib &int, len &usize) int

fn free_memory_impl() usize {
$if cross ? {
return 1
}
$if !cross ? {
$if freebsd {
page_size := usize(C.sysconf(C._SC_PAGESIZE))
mut mib := [4]int{}
mut len := usize(4)
unsafe { C.sysctlnametomib(c'vm.stats.vm.v_free_count', &mib[0], &len) }
mut free_pages := int(0)
bufsize := usize(4)
unsafe { C.sysctl(&mib[0], mib.len, &free_pages, &bufsize, 0, 0) }
return page_size * usize(free_pages)
}
}
return 1
}
Loading