Skip to contentSkip to conversation

swapoff, but no swapon in initab

Buildroot Carlos Santos 3 participants 13 messages Jun 6, 2018 – Jun 20, 2018

lore
Share & tools
lore
#0 lore raw

Hi,

I'm working on a product that needs a swap partition and noticed that both package/{busybox,sysvinit}/inittab invoke "swapoff -a" in their shutdown sequences but do not invoke "swapon -a". Is this intentional or the swapon call is missing (e.g. right after "mount -a")?

BTW, what about systemd?

Signature · 4 lines
Carlos Santos (Casantos) - DATACOM, P&D
Rua Am?rica, 1000 - Eldorado do Sul, RS, Brasil - 92990-000
casantos at datacom.com.br          +55 51 3933.3000 ext. 3627
http://www.datacom.ind.br
#1 lore raw
Quoted 6 lines · Carlos Santos

Hi,

I'm working on a product that needs a swap partition and noticed that both package/{busybox,sysvinit}/inittab invoke "swapoff -a" in their shutdown sequences but do not invoke "swapon -a". Is this intentional or the swapon call is missing (e.g. right after "mount -a")?

It has been like that since

commit ffde94bd2ca21542ae0b4518348f8e986b9d92e0 (tag: 0_0)

Author: Eric Andersen <[email protected]>
Date:   Sat Dec 22 01:56:11 2001

Initial revision

so whatever reason there was, it is lost in the mists of time.

IMO I think it's pointless (the kernel will freeze swap accesses before
shutdown) and possibly wrong (swap to file should be disabled before the corresponding filesystem is unmounted).

Anyway, the proper way to handle swap is by adding it to fstab, no? I just
checked and busybox seems to support it.

Regards,
Arnout

Quoted 1 line

BTW, what about systemd?

Signature · 6 lines
Arnout Vandecappelle                          arnout at mind be
Senior Embedded Software Architect            +32-16-286500
Essensium/Mind                                http://www.mind.be
G.Geenslaan 9, 3001 Leuven, Belgium           BE 872 984 063 RPR Leuven
LinkedIn profile: http://www.linkedin.com/in/arnoutvandecappelle
GPG fingerprint:  7493 020B C7E3 8618 8DEC 222C 82EB F404 F9AC 0DDF
#2 lore raw
Quoted 23 lines

From: "Arnout Vandecappelle" <[email protected]>
To: "DATACOM" <[email protected]>, "buildroot" <[email protected]>
Sent: Thursday, June 7, 2018 6:12:48 PM
Subject: Re: [Buildroot] swapoff, but no swapon in initab

Quoted 6 lines · Carlos Santos

Hi,

I'm working on a product that needs a swap partition and noticed that both package/{busybox,sysvinit}/inittab invoke "swapoff -a" in their shutdown sequences but do not invoke "swapon -a". Is this intentional or the swapon call is missing (e.g. right after "mount -a")?

It has been like that since

commit ffde94bd2ca21542ae0b4518348f8e986b9d92e0 (tag: 0_0)

Author: Eric Andersen <[email protected]>
Date:   Sat Dec 22 01:56:11 2001

Initial revision

so whatever reason there was, it is lost in the mists of time.

Quoted 7 lines

IMO I think it's pointless (the kernel will freeze swap accesses before shutdown) and possibly wrong (swap to file should be disabled before the corresponding filesystem is unmounted).

Anyway, the proper way to handle swap is by adding it to fstab, no? I just checked and busybox seems to support it.

The point here is that I'd like to avoid adding yet another init script just to call swap{on,off} in its st{art,op} phase. A "swapon -a" in inittab would inspect /etc/fstab, as stated in the man page:

"All devices marked as ``swap'' in /etc/fstab are made available,
except for those with the ``noauto'' option. Devices that are already being used as swap are silently skipped."

So even if the system already has such init script (e.g. from a rootfs ovelay) a second call would be harmless.

Signature · 3 lines
Carlos Santos (Casantos) - DATACOM, P&D
?Marched towards the enemy, spear upright, armed with the certainty
that only the ignorant can have.? ? Epitaph of a volunteer
#3 lore raw
Quoted 28 lines · Carlos Santos
Quoted 28 lines

From: "Arnout Vandecappelle" <[email protected]>
To: "DATACOM" <[email protected]>, "buildroot" <[email protected]>
Sent: Thursday, June 7, 2018 6:12:48 PM
Subject: Re: [Buildroot] swapoff, but no swapon in initab

Quoted 6 lines · Carlos Santos

Hi,

I'm working on a product that needs a swap partition and noticed that both package/{busybox,sysvinit}/inittab invoke "swapoff -a" in their shutdown sequences but do not invoke "swapon -a". Is this intentional or the swapon call is missing (e.g. right after "mount -a")?

It has been like that since

commit ffde94bd2ca21542ae0b4518348f8e986b9d92e0 (tag: 0_0)

Author: Eric Andersen <[email protected]>
Date:   Sat Dec 22 01:56:11 2001

Initial revision

so whatever reason there was, it is lost in the mists of time.

IMO I think it's pointless (the kernel will freeze swap accesses before shutdown) and possibly wrong (swap to file should be disabled before the corresponding filesystem is unmounted).

Quoted 6 lines
Quoted 2 lines

Anyway, the proper way to handle swap is by adding it to fstab, no? I just checked and busybox seems to support it.

The point here is that I'd like to avoid adding yet another init script just to call swap{on,off} in its st{art,op} phase. A "swapon -a" in inittab would inspect /etc/fstab, as stated in the man page:

Ah, yes, I thought mount -a would do that.

Quoted 4 lines

"All devices marked as ``swap'' in /etc/fstab are made available,
except for those with the ``noauto'' option. Devices that are already being used as swap are silently skipped."

So bottom line: it would make sense to add a swapon -a to the default inittabs
(both busybox and sysv).

For system, BTW, I would expect it would already do the right thing based on
fstab, no?

Regards,
Arnout

Quoted 4 lines

So even if the system already has such init script (e.g. from a rootfs ovelay) a second call would be harmless.

Signature · 6 lines
Arnout Vandecappelle                          arnout at mind be
Senior Embedded Software Architect            +32-16-286500
Essensium/Mind                                http://www.mind.be
G.Geenslaan 9, 3001 Leuven, Belgium           BE 872 984 063 RPR Leuven
LinkedIn profile: http://www.linkedin.com/in/arnoutvandecappelle
GPG fingerprint:  7493 020B C7E3 8618 8DEC 222C 82EB F404 F9AC 0DDF
#4 lore raw
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

"Arnout" == Arnout Vandecappelle <[email protected]> writes:

Hi,

Quoted 6 lines
Quoted 3 lines

"All devices marked as ``swap'' in /etc/fstab are made available, except for those with the ``noauto'' option. Devices that are already being used as swap are silently skipped."

So bottom line: it would make sense to add a swapon -a to the default inittabs
(both busybox and sysv).

Don't we then end up with an ugly error message / somewhat needlessly bloat everyones busybox config for the (very common) situation where swap is not used and disabled in the kernel?

Signature · 1 line
Bye, Peter Korsgaard
#5 lore raw
Quoted 14 lines

From: "Peter Korsgaard" <[email protected]>
To: "Arnout Vandecappelle" <[email protected]>
Cc: "DATACOM" <[email protected]>, "buildroot" <[email protected]>
Sent: Tuesday, June 12, 2018 6:06:13 AM
Subject: Re: swapoff, but no swapon in initab

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

"Arnout" == Arnout Vandecappelle <[email protected]> writes:

Hi,

Quoted 3 lines
Quoted 3 lines

"All devices marked as ``swap'' in /etc/fstab are made available, except for those with the ``noauto'' option. Devices that are already being used as swap are silently skipped."

Quoted 6 lines
Quoted 2 lines

So bottom line: it would make sense to add a swapon -a to the default inittabs
(both busybox and sysv).

Don't we then end up with an ugly error message / somewhat needlessly bloat everyones busybox config for the (very common) situation where swap is not used and disabled in the kernel?

A "swapon -a" does nothing if a swap entry is not found in /etc/fstab, so there is no error message. Conversely, a "swapoff -a" does nothing if a mounted swap is not found but I did not test if it issues some error message due to a failing system call when swap is disabled in the kernel. I will run some tests and submit an additional patch, if necessary.

Signature · 3 lines
Carlos Santos (Casantos) - DATACOM, P&D
?Marched towards the enemy, spear upright, armed with the certainty
that only the ignorant can have.? ? Epitaph of a volunteer
#6 lore raw
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

"Carlos" == Carlos Santos <[email protected]> writes:

Hi,

Quoted 7 lines
Quoted 6 lines
Quoted 2 lines

So bottom line: it would make sense to add a swapon -a to the default inittabs
(both busybox and sysv).

Don't we then end up with an ugly error message / somewhat needlessly bloat everyones busybox config for the (very common) situation where swap is not used and disabled in the kernel?

Quoted 6 lines

A "swapon -a" does nothing if a swap entry is not found in /etc/fstab, so there is no error message. Conversely, a "swapoff -a" does nothing if a mounted swap is not found but I did not test if it issues some error message due to a failing system call when swap is disabled in the kernel. I will run some tests and submit an additional patch, if necessary.

It does not:

grep CONFIG_SWAP .config
# CONFIG_SWAP is not set

# swapon -a ; echo $?
0

But it does require people to add swapon/swapoff to their busybox config even if they aren't using swap, otherwise they would get error messages at bootup/shutdown (I know they already get it at shutdown, but an orderly shutdown is a lot more rare than bootup).

But ok, the swapon/swapoff applet is very small, so I guess that is OK.

size util-linux/swaponoff.o

   text    data     bss     dec     hex filename
    597       0       0     597     255 util-linux/swaponoff.o
Signature · 1 line
Bye, Peter Korsgaard
#7 lore raw
Quoted 20 lines · Peter Korsgaard
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

"Carlos" == Carlos Santos <[email protected]> writes:

Hi,

Quoted 7 lines
Quoted 6 lines
Quoted 2 lines

So bottom line: it would make sense to add a swapon -a to the default inittabs
(both busybox and sysv).

Don't we then end up with an ugly error message / somewhat needlessly bloat everyones busybox config for the (very common) situation where swap is not used and disabled in the kernel?

Quoted 6 lines

A "swapon -a" does nothing if a swap entry is not found in /etc/fstab, so there is no error message. Conversely, a "swapoff -a" does nothing if a mounted swap is not found but I did not test if it issues some error message due to a failing system call when swap is disabled in the kernel. I will run some tests and submit an additional patch, if necessary.

It does not:

Quoted 8 lines

grep CONFIG_SWAP .config
# CONFIG_SWAP is not set

# swapon -a ; echo $?
0

But it does require people to add swapon/swapoff to their busybox config even if they aren't using swap, otherwise they would get error messages

I think if people start customizing the busybox config and remove stuff from
it, then it's only reasonable that they also modify the default inittab. Swapon and swapoff are both enabled in our busybox.config and busybox-minimal.config.

Regards,
Arnout

Quoted 9 lines

at bootup/shutdown (I know they already get it at shutdown, but an orderly shutdown is a lot more rare than bootup).

But ok, the swapon/swapoff applet is very small, so I guess that is OK.

size util-linux/swaponoff.o

   text    data     bss     dec     hex filename
    597       0       0     597     255 util-linux/swaponoff.o
Signature · 6 lines
Arnout Vandecappelle                          arnout at mind be
Senior Embedded Software Architect            +32-16-286500
Essensium/Mind                                http://www.mind.be
G.Geenslaan 9, 3001 Leuven, Belgium           BE 872 984 063 RPR Leuven
LinkedIn profile: http://www.linkedin.com/in/arnoutvandecappelle
GPG fingerprint:  7493 020B C7E3 8618 8DEC 222C 82EB F404 F9AC 0DDF
#8 lore raw
Quoted 8 lines
Quoted 4 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line

"Arnout" == Arnout Vandecappelle <[email protected]> writes:

But it does require people to add swapon/swapoff to their busybox config even if they aren't using swap, otherwise they would get error messages

I think if people start customizing the busybox config and remove stuff from
it, then it's only reasonable that they also modify the default inittab.

Correct.

Quoted 1 line

Swaponand swapoff are both enabled in our busybox.config and busybox-minimal.config.

Hmm, does swap work on nommu? I would guess not. Looking at the kernel option:

git grep -A3 'config SWAP' init/Kconfig
init/Kconfig:config SWAP

init/Kconfig-   bool "Support for paging of anonymous memory (swap)"
init/Kconfig-   depends on MMU && BLOCK
init/Kconfig-   default y
Signature · 1 line
Bye, Peter Korsgaard
#9 lore raw
Quoted 9 lines · Peter Korsgaard
Quoted 8 lines
Quoted 4 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line

"Arnout" == Arnout Vandecappelle <[email protected]> writes:

But it does require people to add swapon/swapoff to their busybox config even if they aren't using swap, otherwise they would get error messages

I think if people start customizing the busybox config and remove stuff from
it, then it's only reasonable that they also modify the default inittab.

Quoted 6 lines

Correct.

Quoted 1 line

Swaponand swapoff are both enabled in our busybox.config and busybox-minimal.config.

Hmm, does swap work on nommu? I would guess not. Looking at the kernel option:

Doesn't matter if it works or not; if the swapon executable exists, then the
swapon in inittab will pass without error (if you don't have swap configured in fstab). Clearly, the swapon will fail if you indeed have swap enabled in fstab on a NOMMU system, but I don't think we have to protect against that situation, right? It will anyway also fail if you don't have swap enabled in the kernel. Just like mounting the ext2 rootfs will fail if you don't have ext2/3/4 enabled in your kernel...

Regards,
Arnout

Quoted 7 lines

git grep -A3 'config SWAP' init/Kconfig
init/Kconfig:config SWAP

init/Kconfig-   bool "Support for paging of anonymous memory (swap)"
init/Kconfig-   depends on MMU && BLOCK
init/Kconfig-   default y
Signature · 6 lines
Arnout Vandecappelle                          arnout at mind be
Senior Embedded Software Architect            +32-16-286500
Essensium/Mind                                http://www.mind.be
G.Geenslaan 9, 3001 Leuven, Belgium           BE 872 984 063 RPR Leuven
LinkedIn profile: http://www.linkedin.com/in/arnoutvandecappelle
GPG fingerprint:  7493 020B C7E3 8618 8DEC 222C 82EB F404 F9AC 0DDF
#10 lore raw
Quoted 19 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

"Arnout" == Arnout Vandecappelle <[email protected]> writes:

Quoted 9 lines · Peter Korsgaard
Quoted 8 lines
Quoted 4 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line

"Arnout" == Arnout Vandecappelle <[email protected]> writes:

But it does require people to add swapon/swapoff to their busybox config even if they aren't using swap, otherwise they would get error messages

I think if people start customizing the busybox config and remove stuff from
it, then it's only reasonable that they also modify the default inittab.

Quoted 6 lines

Correct.

Quoted 1 line

Swaponand swapoff are both enabled in our busybox.config and busybox-minimal.config.

Hmm, does swap work on nommu? I would guess not. Looking at the kernel option:

Quoted 7 lines

Doesn't matter if it works or not; if the swapon executable exists, then the
swapon in inittab will pass without error (if you don't have swap configured in fstab). Clearly, the swapon will fail if you indeed have swap enabled in fstab on a NOMMU system, but I don't think we have to protect against that situation, right? It will anyway also fail if you don't have swap enabled in the kernel. Just like mounting the ext2 rootfs will fail if you don't have ext2/3/4 enabled in your kernel...

Yes, so the only minor issue is that we need to have swapon/swapoff enabled in busybox-minimal.config even though it isn't useful just to not get an error message during bootup/shutdown.

Signature · 1 line
Bye, Peter Korsgaard
#11 lore raw
Quoted 27 lines · Peter Korsgaard
Quoted 19 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

"Arnout" == Arnout Vandecappelle <[email protected]> writes:

Quoted 9 lines · Peter Korsgaard
Quoted 8 lines
Quoted 4 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line

"Arnout" == Arnout Vandecappelle <[email protected]> writes:

But it does require people to add swapon/swapoff to their busybox config even if they aren't using swap, otherwise they would get error messages

I think if people start customizing the busybox config and remove stuff from
it, then it's only reasonable that they also modify the default inittab.

Quoted 6 lines

Correct.

Quoted 1 line

Swaponand swapoff are both enabled in our busybox.config and busybox-minimal.config.

Hmm, does swap work on nommu? I would guess not. Looking at the kernel option:

Quoted 7 lines

Doesn't matter if it works or not; if the swapon executable exists, then the
swapon in inittab will pass without error (if you don't have swap configured in fstab). Clearly, the swapon will fail if you indeed have swap enabled in fstab on a NOMMU system, but I don't think we have to protect against that situation, right? It will anyway also fail if you don't have swap enabled in the kernel. Just like mounting the ext2 rootfs will fail if you don't have ext2/3/4 enabled in your kernel...

Quoted 3 lines

Yes, so the only minor issue is that we need to have swapon/swapoff enabled in busybox-minimal.config even though it isn't useful just to not get an error message during bootup/shutdown.

Well, it currently _is_ enabled in busybox-minimal.config... Admittedly, this
adds almost 1KB to the busybox size so perhaps it should be removed from -minimal. But the we probably should also remove swapoff from inittab. Hell, perhaps we should do that anyway, since doing swapoff for reboot is utterly useless IMO.

Regards,
Arnout

Signature · 6 lines
Arnout Vandecappelle                          arnout at mind be
Senior Embedded Software Architect            +32-16-286500
Essensium/Mind                                http://www.mind.be
G.Geenslaan 9, 3001 Leuven, Belgium           BE 872 984 063 RPR Leuven
LinkedIn profile: http://www.linkedin.com/in/arnoutvandecappelle
GPG fingerprint:  7493 020B C7E3 8618 8DEC 222C 82EB F404 F9AC 0DDF
#12 lore raw
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

"Arnout" == Arnout Vandecappelle <[email protected]> writes:

Hi,

Quoted 9 lines
Quoted 3 lines

Yes, so the only minor issue is that we need to have swapon/swapoff enabled in busybox-minimal.config even though it isn't useful just to not get an error message during bootup/shutdown.

Well, it currently _is_ enabled in busybox-minimal.config... Admittedly, this
adds almost 1KB to the busybox size so perhaps it should be removed from -minimal. But the we probably should also remove swapoff from inittab. Hell, perhaps we should do that anyway, since doing swapoff for reboot is utterly useless IMO.

Yes, I'm not sure what good swapoff would do just before rebooting, except if you are using a swapfile and keeping it mounted would cause umounting that filesystem to fail - But I've never used swap in a Buildroot based project.

Notice that we will still get the error message from the swapon call during startup if we drop the swapon applet.

Maybe we should just leave it as is.

Signature · 1 line
Bye, Peter Korsgaard