From nobody Sun Aug 18 09:08:17 2024 X-Original-To: freebsd-hackers@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4WmqtJ4KPWz5SlCQ for ; Sun, 18 Aug 2024 09:19:20 +0000 (UTC) (envelope-from yuri@FreeBSD.org) Received: from shell1.rawbw.com (shell1.rawbw.com [198.144.192.42]) by mx1.freebsd.org (Postfix) with ESMTP id 4WmqtH69ZBz4941 for ; Sun, 18 Aug 2024 09:19:19 +0000 (UTC) (envelope-from yuri@FreeBSD.org) Authentication-Results: mx1.freebsd.org; dkim=none; dmarc=fail reason="No valid SPF, No valid DKIM" header.from=freebsd.org (policy=none); spf=softfail (mx1.freebsd.org: 198.144.192.42 is neither permitted nor denied by domain of yuri@FreeBSD.org) smtp.mailfrom=yuri@FreeBSD.org Received: from [192.168.5.3] (c-98-42-44-116.hsd1.ca.comcast.net [98.42.44.116]) (authenticated bits=0) by shell1.rawbw.com (8.15.1/8.15.1) with ESMTPSA id 47I98ILv032903 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NO) for ; Sun, 18 Aug 2024 02:08:18 -0700 (PDT) (envelope-from yuri@FreeBSD.org) X-Authentication-Warning: shell1.rawbw.com: Host c-98-42-44-116.hsd1.ca.comcast.net [98.42.44.116] claimed to be [192.168.5.3] Content-Type: multipart/alternative; boundary="------------pFgYWDsaAK7Ml0hRG2c3H04P" Message-ID: <6076fe34-eb23-47cc-8bd2-6000ddf0a091@FreeBSD.org> Date: Sun, 18 Aug 2024 02:08:17 -0700 List-Id: Technical discussions relating to FreeBSD List-Archive: https://lists.freebsd.org/archives/freebsd-hackers List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-freebsd-hackers@FreeBSD.org MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Content-Language: en-US To: Freebsd hackers list From: Yuri Subject: Can free swap size be determined from the sysctl information ? X-Spamd-Bar: + X-Spamd-Result: default: False [1.84 / 15.00]; VIOLATED_DIRECT_SPF(3.50)[]; SUBJECT_ENDS_QUESTION(1.00)[]; NEURAL_HAM_MEDIUM(-1.00)[-1.000]; NEURAL_HAM_LONG(-1.00)[-1.000]; NEURAL_HAM_SHORT(-0.87)[-0.874]; MIME_GOOD(-0.10)[multipart/alternative,text/plain]; ONCE_RECEIVED(0.10)[]; DMARC_POLICY_SOFTFAIL(0.10)[freebsd.org : No valid SPF, No valid DKIM,none]; RCVD_NO_TLS_LAST(0.10)[]; XM_UA_NO_VERSION(0.01)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; RCVD_COUNT_ONE(0.00)[1]; TO_DN_ALL(0.00)[]; RCPT_COUNT_ONE(0.00)[1]; GREYLIST(0.00)[pass,body]; ARC_NA(0.00)[]; FREEFALL_USER(0.00)[yuri]; RCVD_VIA_SMTP_AUTH(0.00)[]; MIME_TRACE(0.00)[0:+,1:+,2:~]; R_SPF_SOFTFAIL(0.00)[~all:c]; FROM_EQ_ENVFROM(0.00)[]; FROM_HAS_DN(0.00)[]; ASN(0.00)[asn:7961, ipnet:198.144.192.0/23, country:US]; PREVIOUSLY_DELIVERED(0.00)[freebsd-hackers@freebsd.org]; R_DKIM_NA(0.00)[]; MLMMJ_DEST(0.00)[freebsd-hackers@FreeBSD.org]; TO_DOM_EQ_FROM_DOM(0.00)[]; MID_RHS_MATCH_FROM(0.00)[]; HAS_XAW(0.00)[] X-Rspamd-Queue-Id: 4WmqtH69ZBz4941 This is a multi-part message in MIME format. --------------pFgYWDsaAK7Ml0hRG2c3H04P Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit 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"];      swap            /disk-large1/swap-64GB 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. Thanks, Yuri --------------pFgYWDsaAK7Ml0hRG2c3H04P Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: 8bit 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.



Thanks,

Yuri


--------------pFgYWDsaAK7Ml0hRG2c3H04P--