Skip to content

mem.VirtualMemory() returns zero swap stats on MacOS 12.1 Monterey #1206

Open
@rustomax

Description

Swap stats are at zero while sysctl -n vm.swapusage returns non-zero values on Monterey

To Reproduce

package main

import (
	"fmt"
	"github.com/shirou/gopsutil/mem"
)

func main() {
	vmStat, _ := mem.VirtualMemory()
	fmt.Printf("%v\n", vmStat)
}

Output:

{"total":68719476736,"available":54567813120,"used":14151663616,"usedPercent":20.59338092803955,"free":49884401664,"active":6553595904,"inactive":4683411456,"wired":4498362368,"laundry":0,"buffers":0,"cached":0,"writeback":0,"dirty":0,"writebacktmp":0,"shared":0,"slab":0,"sreclaimable":0,"sunreclaim":0,"pagetables":0,"swapcached":0,"commitlimit":0,"committedas":0,"hightotal":0,"highfree":0,"lowtotal":0,"lowfree":0,"swaptotal":0,"swapfree":0,"mapped":0,"vmalloctotal":0,"vmallocused":0,"vmallocchunk":0,"hugepagestotal":0,"hugepagesfree":0,"hugepagesize":0}

Expected behavior:
Match values returned by sysctl

sysctl -n vm.swapusage
total = 2048.00M  used = 676.25M  free = 1371.75M  (encrypted)

Environment:

sw_vers
ProductName:    macOS
ProductVersion: 12.1
BuildVersion:   21C52

uname -a
Darwin 21.2.0 Darwin Kernel Version 21.2.0: Sun Nov 28 20:28:54 PST 2021; root:xnu-8019.61.5~1/RELEASE_X86_64 x86_64

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions