gopsutil icon indicating copy to clipboard operation
gopsutil copied to clipboard

[disk] Modify stat free, from bavail to bfree

Open secake opened this issue 4 years ago • 3 comments
trafficstars

From:
Free:        (uint64(stat.Bavail) * uint64(bsize)), 
To:
Free:        (uint64(stat.Bfree) * uint64(bsize)),

https://pkg.go.dev/golang.org/x/sys/unix#Statfs_t

type Statfs_t
type Statfs_t struct {
	Type    int64
	Bsize   int64
	Blocks  uint64
	Bfree   uint64   /* free blocks in fs */
	Bavail  uint64   /* free blocks avail to non-superuser */
	Files   uint64
	Ffree   uint64
	Fsid    Fsid
	Namelen int64
	Frsize  int64
	Flags   int64
	Spare   [4]int64
}

In some cases, the old implementation may have Total-Free!=Used。

secake avatar Nov 04 '21 04:11 secake

According to the psutil implementation, Free is a "avail_to_user", not a "avail_to_root". Could you tell us what Linux kernel version think Total-Free! = Used?

shirou avatar Nov 07 '21 13:11 shirou

According to the psutil implementation, Free is a "avail_to_user", not a "avail_to_root". Could you tell us what Linux kernel version think Total-Free! = Used?

Thanks for your replay! I encountered this problem in ‘CentOS Linux release 7.7.1908 (Core)’. I think Total-Free! = Used may be caused by the following reasons :total is only available to root, free is avail_to_user, not avail_to_root, used is (total-avail_to_root), so total - free != uesd
But I don't know if it is intentional to do so. Because the github.com/giampaolo/psutil readme example is also Total-Free! = Used.

secake avatar Nov 08 '21 02:11 secake

According to the psutil implementation line 190, psutil implementation line 194, Free is a "avail_to_root", not a "avail_to_user". the purpose of "avail_to_user" is to calculate "usage_percent_user".

secake avatar Sep 09 '22 07:09 secake