Support discard in "block" and "swapon"#13
Conversation
Define swap flags according to the kernel definitions: musl and glibc provide SWAP_FLAG_DISCARD, but not discard policies. Based on busybox's swaponoff.c Signed-off-by: Maxim Storchak <m.storchak@gmail.com>
Intorduce a new fstab.@swap[] attribute, "discard" that can take values - on, 1, yes -- to enable the default discard mode - once, pages -- to enable the corresponding discard policy - anythinge else -- to disable discard Discard is enabled by default. Signed-off-by: Maxim Storchak <m.storchak@gmail.com>
Add a new option, -d, with an optional argument "once" or "pages". -d with no arguments uses the default kernel discarding policy which enables both the initial discard (once) and discards the released swap pages. By default discard is disabled. Inspired by busybox's swaponoff.c Signed-off-by: Maxim Storchak <m.storchak@gmail.com>
It's safe to enable discard on the devices that don't support it. In such case kernel ignores the discard flags. Signed-off-by: Maxim Storchak <m.storchak@gmail.com>
|
Thank you for your work on this feature, and sorry for the delay in dealing with your contribution. As the kernel gracefully handles devices which do support |
|
@dangowrt , thank you for getting back to me! If you still think it should be opt-out, I can update the PR. the following doesn't apply to swaps
|
SSD drives are quite common, so following their rules (discarding the unused blocks) can extend their life time. In addition, even if the device doesn't support discard, kernel can always "downgrade" the flags.
This PR adds discard options to
blockby extending theswapentries offstabconfig with thediscardparameter that provides full control over the discard feature.swaponis another entry point for swap activation, so it gets an extra flag-d. The implementation is inspired by busybox.