mirror of
https://github.com/vlang/v.git
synced 2025-09-14 06:52:36 +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
|
module runtime
|
||||||
|
|
||||||
|
#include <sys/sysctl.h>
|
||||||
|
#include <uvm/uvmexp.h>
|
||||||
|
|
||||||
|
struct C.uvmexp {
|
||||||
|
pagesize int
|
||||||
|
free int
|
||||||
|
}
|
||||||
|
|
||||||
fn free_memory_impl() usize {
|
fn free_memory_impl() usize {
|
||||||
$if cross ? {
|
$if cross ? {
|
||||||
return 1
|
return 1
|
||||||
}
|
}
|
||||||
$if !cross ? {
|
$if !cross ? {
|
||||||
$if openbsd {
|
$if openbsd {
|
||||||
page_size := usize(C.sysconf(C._SC_PAGESIZE))
|
mib := [C.CTL_VM, C.VM_UVMEXP]!
|
||||||
av_phys_pages := usize(C.sysconf(C._SC_AVPHYS_PAGES))
|
mut uvm := C.uvmexp{0, 0}
|
||||||
return page_size * av_phys_pages
|
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
|
return 1
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue