Bug 238670

Summary: [libkvm][patch] kvm_getswapinfo() returns swap device sizes too small incorrectly
Product: Base System Reporter: ota
Component: binAssignee: freebsd-bugs (Nobody) <bugs>
Status: New ---    
Severity: Affects Only Me CC: emaste, linimon
Priority: ---    
Version: 12.0-RELEASE   
Hardware: Any   
OS: Any   

Description ota 2019-06-17 17:33:13 UTC
kvm_getswapinfo() function returns smaller device sizes than the actual swap device sizes configured available.  "systat -swap" uses this API and shows problem.  "sysctl -c" uses a different API and displays correct sizes.

While "usesd" swap device sizes are reported correctly, when a swap device is used fully, it looks like system haven overwritten next partition.

The root of problem is libkvm subtracts vm.dmmax, maximum VOP I/O allowed, form size of device erroneously.

The following shows that 1 MB swap device is prepared, attached, and then fully used.  Given FreeBSD swap skips 2 4k blocks, 1016 is the correct size available for swapping. 

# dd if=/dev/zero of=1MB bs=1M count=1
1+0 records in
1+0 records out
1048576 bytes transferred in 0.035823 secs (29271150 bytes/sec)
# mdconfig -a -t vnode -f 1MB
# swapon /dev/md0
# swapctl -l
Device:       1024-blocks     Used:
/dev/ada0s1b    2097144         0
/dev/md0           1016         0
# mount -t tmpfs tmpfs /mnt/tmp
# dd if=/dev/zero of=/mnt/tmp/fill bs=1M count=2000
2000+0 records in
2000+0 records out
2097152000 bytes transferred in 36.267636 secs (57824337 bytes/sec)
# swapctl -l
Device:       1024-blocks     Used:
/dev/ada0s1b    2097144     144220
/dev/md0           1016      1016
# systat -swap
Disk   1K-blocks   Used /0%  /10  /20  /30  /40  /50  /60  /70  /80  /90  /100
ada0s1b  2097016 144216 XXXX
XX       2097904 145232 XXXX
Comment 1 Mark Linimon freebsd_committer freebsd_triage 2019-06-18 10:20:26 UTC
No patch seems attached?
Comment 2 ota 2019-06-18 18:56:53 UTC
(In reply to Mark Linimon from comment #1)

Bugzilla was unstable, I got lots of database error, and couldn't get this page.

https://reviews.freebsd.org/D20674 is my proposal.
Comment 3 ota 2019-06-18 19:24:09 UTC
By the way, this problem goes back to 11 releases, too.


Is this a candidate for 11.3 release patch, too?