Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 568162 - sys-apps/openrc - swapfiles should be stopped as one of the last services
Summary: sys-apps/openrc - swapfiles should be stopped as one of the last services
Status: RESOLVED FIXED
Alias: None
Product: Gentoo Hosted Projects
Classification: Unclassified
Component: OpenRC (show other bugs)
Hardware: All Linux
: Normal normal (vote)
Assignee: OpenRC Team
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-12-13 13:47 UTC by Thomas Deutschmann (RETIRED)
Modified: 2016-09-06 20:22 UTC (History)
0 users

See Also:
Package list:
Runtime testing required: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Thomas Deutschmann (RETIRED) gentoo-dev 2015-12-13 13:47:54 UTC
Hi,

I noticed that swapfiles service will be stopped as one of the first services on shutdown:

rc shutdown logging started at Sun Dec 13 14:34:07 2015

 * Stopping local ...
 [ ok ]
 * Saving random seed ...
 [ ok ]
 * Deactivating additional swap space ...
 [ ok ]
 * Stopping sshd ...
 [ ok ]
 * Stopping shorewall6 ...
 [ ok ]
 * Stopping shorewall ...
 [ ok ]
 * Stopping Pure-FTPd ...
 [ ok ]
 * Stopping postfix  ...
 [ ok ]
 * Stopping nginx ...
 [ ok ]
 * Stopping PHP FastCGI Process Manager ...
 [ ok ]
 * Unmounting network filesystems ...
 [ ok ]
 * Stopping mysql ...
 [ ok ]
 * Stopping memcached (mysql) ...
 [ ok ]
 * Stopping memcached (www) ...
 [ ok ]
 * Stopping ntpd ...
 [ ok ]
 * Stopping lvmetad ...
 [ ok ]
 * Stopping incrond ...
 [ ok ]
 * Stopping haveged ...
 [ ok ]
 * Stopping fcron ...
 [ ok ]
 * Stopping collectd ...
[...]


If your system is out of memory and using your swapfile this could a problem. If we could make sure that swapfiles service would stop as one of the last services we would avoid such situations.

Seen with =sys-apps/openrc-0.19.1.

Reproducible: Always
Comment 1 William Hubbs gentoo-dev 2015-12-14 17:10:50 UTC
My plan for this is to remove the swapfiles service. That will mean that
you will have to configure the dependencies of swap to be correct, e.g.
in /etc/conf.d/swap:
rc_need="localmount"
or
rc_need="netmount"
if you are using swap files.

Any thoughts about this?

William
Comment 2 Robin Johnson archtester Gentoo Infrastructure gentoo-dev Security 2015-12-14 21:21:47 UTC
@williamh:
If you're going to remove swapfiles as a separate service, please make it detect if a given path is a filename, and auto-depend on localmount or netmount (based on fstab).
Comment 3 Thomas Deutschmann (RETIRED) gentoo-dev 2015-12-14 21:46:26 UTC
(In reply to William Hubbs from comment #1)
> My plan for this is to remove the swapfiles service.

OK.


> That will mean that you will have to configure the dependencies
> of swap to be correct, e.g.
> in /etc/conf.d/swap:
> rc_need="localmount"
> or
> rc_need="netmount"
> if you are using swap files.

But please use a default which works for most users (I think this should be rc_need="localmount").


While reading /etc/init.d/swap I noticed that this service will also unmount any mounted tmpfs. That should be changed. Should I open an own bug for this?
Comment 4 William Hubbs gentoo-dev 2015-12-22 17:16:33 UTC
(In reply to Robin Johnson from comment #2)
> @williamh:
> If you're going to remove swapfiles as a separate service, please make it
> detect if a given path is a filename, and auto-depend on localmount or
> netmount (based on fstab).

All swap entries in fstab have the file system type "swap", and the first part of the entry does not have to be a path name at all. I don't see a clean way to tell whether a swap entry is a file or partition, or whether it is local or remote.

(In reply to Thomas D. from comment #3)
> (In reply to William Hubbs from comment #1)
> > My plan for this is to remove the swapfiles service.
> 
> OK.
> 
> 
> > That will mean that you will have to configure the dependencies
> > of swap to be correct, e.g.
> > in /etc/conf.d/swap:
> > rc_need="localmount"
> > or
> > rc_need="netmount"
> > if you are using swap files.
> 
> But please use a default which works for most users (I think this should be
> rc_need="localmount").

I think most users use swap partitions, and you don't need anything mounted for those. The goal is to activate swap as early as possible.

> 
> 
> While reading /etc/init.d/swap I noticed that this service will also unmount
> any mounted tmpfs. That should be changed. Should I open an own bug for this?

Any separate issue goes to a separate bug. There may be a reason we do this though, but I don't remember what it is right now.
Comment 5 Robin Johnson archtester Gentoo Infrastructure gentoo-dev Security 2016-01-29 01:06:02 UTC
(In reply to William Hubbs from comment #4)
> (In reply to Robin Johnson from comment #2)
> > @williamh:
> > If you're going to remove swapfiles as a separate service, please make it
> > detect if a given path is a filename, and auto-depend on localmount or
> > netmount (based on fstab).
> 
> All swap entries in fstab have the file system type "swap", and the first
> part of the entry does not have to be a path name at all. I don't see a
> clean way to tell whether a swap entry is a file or partition, or whether it
> is local or remote.
Take the first part of the entry, and resolve it (symlinks, UUID, LABEL etc) and look at the type of the result.
file -> swapfile
device -> partition etc (in fact, all key=value entries will be devices)

> I think most users use swap partitions, and you don't need anything mounted
> for those. The goal is to activate swap as early as possible.
Does anybody still use swap on network block devices (NBD, iSCSI, ATA-over-ethernet, other things)? It used to be a big thing for clusters.

> > While reading /etc/init.d/swap I noticed that this service will also unmount
> > any mounted tmpfs. That should be changed. Should I open an own bug for this?
> Any separate issue goes to a separate bug. There may be a reason we do this
> though, but I don't remember what it is right now.
Remind me to file after we have the new version of this service.
Comment 6 William Hubbs gentoo-dev 2016-05-16 17:15:01 UTC
(In reply to Robin Johnson from comment #5)
> (In reply to William Hubbs from comment #4)
> > (In reply to Robin Johnson from comment #2)
> > > @williamh:
> > > If you're going to remove swapfiles as a separate service, please make it
> > > detect if a given path is a filename, and auto-depend on localmount or
> > > netmount (based on fstab).
> > 
> > All swap entries in fstab have the file system type "swap", and the first
> > part of the entry does not have to be a path name at all. I don't see a
> > clean way to tell whether a swap entry is a file or partition, or whether it
> > is local or remote.
> Take the first part of the entry, and resolve it (symlinks, UUID, LABEL etc)
> and look at the type of the result.
> file -> swapfile
> device -> partition etc (in fact, all key=value entries will be devices)
> 
> > I think most users use swap partitions, and you don't need anything mounted
> > for those. The goal is to activate swap as early as possible.
> Does anybody still use swap on network block devices (NBD, iSCSI,
> ATA-over-ethernet, other things)? It used to be a big thing for clusters.

I think the most common case for swap, by far, will be local partitions. I think it is reasonable to document the other possibilities in /etc/conf.d/swap and assume that if someone is using swap files, swap partitions on nbd, or swap files on network file systems, they know what they are doing and can configure the order of the swap service appropriately.

> > > While reading /etc/init.d/swap I noticed that this service will also unmount
> > > any mounted tmpfs. That should be changed. Should I open an own bug for this?
> > Any separate issue goes to a separate bug. There may be a reason we do this
> > though, but I don't remember what it is right now.
> Remind me to file after we have the new version of this service.
I looked at this just now, and the comments imply that there could be a deadlock if we don't unmount all unused tmpfs file systems, but they do not elaborate.

# Try to unmount all tmpfs filesystems not in use, else a deadlock may
# occur. As $RC_SVCDIR may also be tmpfs we cd to it to lock it

If I remove this, there could be a regression, but again I don't know that there would be, because the comments are not specific.

On the other hand, if there is no regression, I don't have a problem removing it.
Comment 7 dwfreed 2016-09-06 17:35:16 UTC
The issue I see is that if you have a lot of stuff in tmpfs on your system to the point that a lot of it is sitting in swap, and you then proceed to unmount all your swap, things are going to get really unhappy.  The kernel will probably OOM kill something, and it won't be your tmpfs.  If you have significantly large swap, to the point that your tmpfs commitment is more than your RAM, in the old days, the kernel would deadlock (see bug 13599; this is the reason for that comment in the initscript); these days, swapoff will just fail with "Cannot allocate memory."  However, if your tmpfs commitment low enough that swapoff succeeds, but high enough to use pretty much all of your RAM, the kernel will trigger the OOM killer, which will happily do things like keep killing bash, so you can't stay logged into your system long enough to fix it, or decide to kill OpenRC, while it's in the process of shutting down your system.  So the only change that would make any sense there would be moving the tmpfs unmount into its own initscript, and making it happen before swap.
Comment 8 William Hubbs gentoo-dev 2016-09-06 20:22:12 UTC
https://github.com/openrc/openrc/commit/d06db93

removes the swapfiles service and adds instructions to the NEWS file as
well as a conf.d/swap file.

https://github.com/openrc/openrc/commit/d5db548

removes the section of code that unmounts all tmpfs file systems from
the swap service.

These will be included in OpenRC-0.22.