mirror of
https://github.com/vlang/v.git
synced 2025-09-14 15:02:33 +03:00
runtime: improve free_memory implementation for OpenBSD, by getting the stats from its UVM system (#24431)
This commit is contained in:
parent
bbee42f15e
commit
656afa9d13
1 changed files with 13 additions and 3 deletions
|
@ -1,14 +1,24 @@
|
|||
module runtime
|
||||
|
||||
#include <sys/sysctl.h>
|
||||
#include <uvm/uvmexp.h>
|
||||
|
||||
struct C.uvmexp {
|
||||
pagesize int
|
||||
free int
|
||||
}
|
||||
|
||||
fn free_memory_impl() usize {
|
||||
$if cross ? {
|
||||
return 1
|
||||
}
|
||||
$if !cross ? {
|
||||
$if openbsd {
|
||||
page_size := usize(C.sysconf(C._SC_PAGESIZE))
|
||||
av_phys_pages := usize(C.sysconf(C._SC_AVPHYS_PAGES))
|
||||
return page_size * av_phys_pages
|
||||
mib := [C.CTL_VM, C.VM_UVMEXP]!
|
||||
mut uvm := C.uvmexp{0, 0}
|
||||
mut len := sizeof(C.uvmexp)
|
||||
unsafe { C.sysctl(&mib[0], mib.len, &uvm, &len, C.NULL, 0) }
|
||||
return usize(uvm.pagesize * uvm.free)
|
||||
}
|
||||
}
|
||||
return 1
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue