Bug 238670 - [libkvm][patch] kvm_getswapinfo() returns swap device sizes too small incorrectly
Summary: [libkvm][patch] kvm_getswapinfo() returns swap device sizes too small incorre...
Status: New
Alias: None
Product: Base System
Classification: Unclassified
Component: bin (show other bugs)
Version: 12.0-RELEASE
Hardware: Any Any
: --- Affects Only Me
Assignee: freebsd-bugs (Nobody)
URL:
Keywords: patch
Depends on:
Blocks:
 
Reported: 2019-06-17 17:33 UTC by ota
Modified: 2022-10-17 12:39 UTC (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
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
md0
# 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
md0          888   1016 XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
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.

https://svnweb.freebsd.org/base/stable/11/lib/libkvm/kvm_getswapinfo.c?revision=331722&view=markup#l135

Is this a candidate for 11.3 release patch, too?
Comment 4 Graham Perrin freebsd_committer freebsd_triage 2022-10-17 12:39:56 UTC
Keyword: 

    patch
or  patch-ready

– in lieu of summary line prefix: 

    [patch]

* bulk change for the keyword
* summary lines may be edited manually (not in bulk). 

Keyword descriptions and search interface: 

    <https://bugs.freebsd.org/bugzilla/describekeywords.cgi>