Date: Sun, 18 Aug 2024 12:41:09 +0300 From: Konstantin Belousov <kostikbel@gmail.com> To: Yuri <yuri@freebsd.org> Cc: Freebsd hackers list <freebsd-hackers@freebsd.org> Subject: Re: Can free swap size be determined from the sysctl information ? Message-ID: <ZsHBtW9Xfc4OmbcH@kib.kiev.ua> In-Reply-To: <6076fe34-eb23-47cc-8bd2-6000ddf0a091@FreeBSD.org> References: <6076fe34-eb23-47cc-8bd2-6000ddf0a091@FreeBSD.org>
next in thread | previous in thread | raw e-mail | index | archive | help
On Sun, Aug 18, 2024 at 02:08:17AM -0700, Yuri wrote: > It seems that it should be possible to find free swap size from the sysctl > information, but it isn't obvious how to do this. > > > Here are all *swap* entries in the sysctl information: > $ sysctl -a | grep swap > 0 MD md98 68719441408 512 u 98 s 512 f 0 fs 0 l 68719441408 t vnode file > /disk-large1/swap-64GB label > z0xfffff8004d862400 [shape=box,label="SWAP\nswap\nr#2"]; > <name>swap</name> > <file>/disk-large1/swap-64GB</file> > vm.swap_enabled: 1 > vm.domain.0.stats.unswappable: 0 > vm.swap_idle_threshold2: 10 > vm.swap_idle_threshold1: 2 > vm.swap_idle_enabled: 0 > vm.disable_swapspace_pageouts: 0 > vm.stats.vm.v_swappgsout: 433264 > vm.stats.vm.v_swappgsin: 94457 > vm.stats.vm.v_swapout: 65078 > vm.stats.vm.v_swapin: 11121 > vm.stats.swap.free_completed: 65205 > vm.stats.swap.free_deferred: 86103 > vm.nswapdev: 1 > vm.swap_fragmentation: > vm.swap_async_max: 4 > vm.swap_maxpages: 48890752 > vm.swap_total: 68719439872 > vm.swap_reserved: 16267402461184 > > > top(1) shows 775M of free swap out of 64G total. > top(1) gets swap information from kvm_getswapinfo(3). > > > Motivation: one Golang-based port needs free swap size information, and I am > trying to figure out how to get this information in Golang. > > Golang has the "sysctl" module. Look at kvm_getswapinfo(3). A good example of its use is usr.bin/top/machine.c:swapmode()
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?ZsHBtW9Xfc4OmbcH>
