Skip to content

Support discard in "block" and "swapon"#13

Open
mstorchak wants to merge 4 commits intoopenwrt:masterfrom
mstorchak:master
Open

Support discard in "block" and "swapon"#13
mstorchak wants to merge 4 commits intoopenwrt:masterfrom
mstorchak:master

Conversation

@mstorchak
Copy link
Copy Markdown

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 block by extending the swap entries of fstab config with the discard parameter that provides full control over the discard feature.
swapon is another entry point for swap activation, so it gets an extra flag -d. The implementation is inspired by busybox.

@mstorchak
Copy link
Copy Markdown
Author

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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant