Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 401003 - /etc/init.d/swap executed too early at stop time
Summary: /etc/init.d/swap executed too early at stop time
Status: RESOLVED FIXED
Alias: None
Product: Gentoo Hosted Projects
Classification: Unclassified
Component: OpenRC (show other bugs)
Hardware: All Linux
: Normal major (vote)
Assignee: OpenRC Team
URL:
Whiteboard:
Keywords:
: 407777 (view as bug list)
Depends on:
Blocks: 399185
  Show dependency tree
 
Reported: 2012-01-27 09:20 UTC by Giampaolo Tomassoni
Modified: 2012-03-11 15:53 UTC (History)
1 user (show)

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 Giampaolo Tomassoni 2012-01-27 09:20:17 UTC
At init level 6, the /etc/init.d/swap script is executed when all the system services are still alive.

This causes a very slow shutdown time and possibly even the failure of swap deactivation on system with a moderate to high memory pressure.

This is due to the fact that swap deactivation implies reclaiming all the swapped pages in memory, which:

1) may be a slow process if swap space is moderately used;
2) is useless, because that pages are going to be released anyway (often with very few accesses to them) when the owning service(s) stop;
3) may fail if free-memory < swapped-out-size.

Please note every and each *nix system I put my fingers on was used to deactivate swap space after having stopped most services. The actual openrc approach in this is really unreasonable.

Reproducible: Always

Steps to Reproduce:
1. shutdown -h now
2.
3.
Actual Results:  
(example)

rc shutdown logging started at Fri Jan 27 09:55:02 2012

 * Stopping local
 [ ok ]
 * Saving random seed ...
 [ ok ]
 * Deactivating swap devices ...
 [ ok ]
 * samba -> stop: smbd ...
 [ ok ]
 * samba -> stop: nmbd ...
 [ ok ]
 * Stopping sshd ...
 [ ok ]
 * Unmounting network filesystems ...
 [ ok ]
 * Stopping cupsd ...
 [ ok ]
 * Stopping syslog-ng ...
 [ ok ]
 * Stopping D-BUS system messagebus ...
 [ ok ]
 * Storing ALSA Mixer Levels ...
 [ ok ]
 * Unmounting loop devices
 * Unmounting filesystems
 *   Unmounting /boot ...
 [ ok ]
 * Shutting down the Logical Volume Manager
 * Finished Shutting down the Logical Volume Manager
 * Stopping udevd ...
 [ ok ]


Expected Results:  
(example)

rc shutdown logging started at Fri Jan 27 09:55:02 2012

 * Stopping local
 [ ok ]
 * Saving random seed ...
 [ ok ]
 * samba -> stop: smbd ...
 [ ok ]
 * samba -> stop: nmbd ...
 [ ok ]
 * Stopping sshd ...
 [ ok ]
 * Unmounting network filesystems ...
 [ ok ]
 * Stopping cupsd ...
 [ ok ]
 * Stopping syslog-ng ...
 [ ok ]
 * Stopping D-BUS system messagebus ...
 [ ok ]
 * Storing ALSA Mixer Levels ...
 [ ok ]
 * Deactivating swap devices ...
 [ ok ]
 * Unmounting loop devices
 * Unmounting filesystems
 *   Unmounting /boot ...
 [ ok ]
 * Shutting down the Logical Volume Manager
 * Finished Shutting down the Logical Volume Manager
 * Stopping udevd ...
 [ ok ]
Comment 1 Christian Ruppert (idl0r) gentoo-dev 2012-01-27 17:00:11 UTC
Is "swap" in your boot runlevel?
Comment 2 William Hubbs gentoo-dev 2012-01-27 18:35:56 UTC
It is in my boot runlevel, and  I can definitely confirm this issue:

Below is my shutdown log. Notice how early swap is deactivated.


rc shutdown logging started at Sat Dec 10 10:23:33 2011

 * Stopping local
 [ ok ]
 * Stopping vixie-cron ...
 [ ok ]
 * Saving random seed ...
 [ ok ]
 * Deactivating swap devices ...
 [ ok ]
 * Use of the opts variable is deprecated and will be
 * removed in the future.
 * Please use extra_commands, extra_started_commands or extra_stopped_commands.
 * Stopping syslog-ng ...
 [ ok ]
 * Bringing down interface lo
 *   Caching network module dependencies
 * Stopping D-BUS system messagebus ...
 [ ok ]
 * Use of the opts variable is deprecated and will be
 * removed in the future.
 * Please use extra_commands, extra_started_commands or extra_stopped_commands.
 * Storing ALSA Mixer Levels ...
 [ ok ]
 * Unmounting loop devices
 * Unmounting filesystems
 *   Unmounting /tmp ...
 *   in use but fuser finds nothing
 [ !! ]
 *   Unmounting /srv ...
 [ ok ]
 *   Unmounting /opt ...
 [ ok ]
 *   Unmounting /usr/local ...
 [ ok ]
 *   Unmounting /var ...
 [ ok ]
 *   Unmounting /usr ...
 [ ok ]
 *   Unmounting /home ...
 [ ok ]
 *   Unmounting /boot ...
 [ ok ]
 * Stopping udev ...
 [ ok ]

rc shutdown logging stopped at Sat Dec 10 10:23:37 2011
Comment 3 Giampaolo Tomassoni 2012-01-27 18:54:31 UTC
(In reply to comment #1)
> Is "swap" in your boot runlevel?

Yes, of course.

This is from one of my gentoo box:

xxx ~ # rc-update | grep swap
                 swap | boot
Comment 4 Giampaolo Tomassoni 2012-01-27 19:09:15 UTC
Besides, I would suggest to merge (back?) the swap activation/deactivation stuff in /etc/init.d/localmount, which is the way most other *nixes do.

Please note swap partitions are defined in /etc/fstab, so it seems reasonable to me to have them be handled by localmount.
Comment 5 William Hubbs gentoo-dev 2012-01-27 20:55:02 UTC
For the record, in baselayout-1, swap was part of localmount. I have no
idea why they were split in openrc.

So, unless there is some reason not to, I do plan on merging them back
together.
Comment 6 William Hubbs gentoo-dev 2012-02-13 14:49:29 UTC
This is fixed in commit 79d6f10.

I did not merge swap and localmount as I originally thought. Instead, we
now have two separate swap scripts. Swap runs before localmount and
swapfiles runs after localmount to handle the additional swap. They run
in the opposite order when shutting down so that swapfiles are
deactivated first, then local filesystems are unmounted and the rest of
swap is deactivated.
Comment 7 Toralf Förster gentoo-dev 2012-03-11 15:53:29 UTC
*** Bug 407777 has been marked as a duplicate of this bug. ***