Bug 987136

Summary: RFE: add 'discard' swap option support for /etc/fstab
Product: [Fedora] Fedora Reporter: Carl Roth <roth>
Component: systemdAssignee: Jan Synacek <jsynacek>
Status: CLOSED RAWHIDE QA Contact: Fedora Extras Quality Assurance <extras-qa>
Severity: medium Docs Contact:
Priority: unspecified    
Version: rawhideCC: johannbg, jsynacek, lnykryn, msekleta, plautrba, roth, rvokal, systemd-maint, vpavlin, zbyszek
Target Milestone: ---   
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: systemd-216-4.fc21 Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2014-10-17 17:10:58 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description Carl Roth 2013-07-22 19:11:00 UTC
Description of problem:

systemd-fstab-generator ignores the 'discard' mount option in /etc/fstab for swap partitions.  Additionally, there is no syntax in the systemd.swap unit files to specify this feature.

Version-Release number of selected component (if applicable):

systemd-201-2.fc18.7.x86_64

How reproducible:

always

Steps to Reproduce:
1. 
2. 
3.

Actual results:


Expected results:


Additional info:

It's an open question how to actually tell if a swap partition is using 'discard' (not systemd-specific).  It's definitely the case that the option is not reflected in the unit file.

Comment 1 Carl Roth 2013-07-22 20:37:22 UTC
If the dmesg results are to be believed, I think this is the difference between 'discard' and 'no discard' (see the 'D' flag):

# swapon /dev/disk/by-uuid/d8e4b4bf-9f1e-446a-a5b0-0325c4ef7d73
# dmesg | grep swap | tail -1
[773331.002898] Adding 8388604k swap on /dev/mapper/M4_CT256_AF15-scruffy_f18_swap.  Priority:-1 extents:1 across:8388604k SS

# swapon --discard /dev/disk/by-uuid/d8e4b4bf-9f1e-446a-a5b0-0325c4ef7d73
# dmesg | grep swap | tail -1
[773346.691092] Adding 8388604k swap on /dev/mapper/M4_CT256_AF15-scruffy_f18_swap.  Priority:-1 extents:1 across:8388604k SSD

More importantly, my /etc/fstab lists that partition with the 'discard' option, and at boot time the option is ignored (presumably because of systemd):
# dmesg | grep swap | head -1
[    2.527089] Adding 8388604k swap on /dev/mapper/M4_CT256_AF15-scruffy_f18_swap.  Priority:-1 extents:1 across:8388604k SS

So this is more of a general systemd/bootup problem.

Comment 2 Carl Roth 2013-07-22 20:39:04 UTC
As per

http://cgit.freedesktop.org/systemd/systemd/tree/src/core/swap.c

this is not currently a supported feature in systemd.

Comment 3 Carl Roth 2013-07-22 20:46:47 UTC
(In reply to Carl Roth from comment #1)
> If the dmesg results are to be believed, I think this is the difference
> between 'discard' and 'no discard' (see the 'D' flag):

Found it at

http://lxr.free-electrons.com/source/mm/swapfile.c?v=3.9#L2136

Comment 4 Lennart Poettering 2014-06-19 18:56:08 UTC
Does "swapon -a" read this from fstab? We should probably support the same syntax.

Comment 5 Carl Roth 2014-06-19 19:43:46 UTC
(In reply to Lennart Poettering from comment #4)
> Does "swapon -a" read this from fstab? We should probably support the same
> syntax.

Yes, see

https://git.kernel.org/cgit/utils/util-linux/util-linux.git/tree/sys-utils/swapon.c#n640