Re: adding swap when expanding root filesystem

From: Mike Karels <mike_at_karels.net>
Date: Tue, 08 Nov 2022 17:26:51 UTC
On 8 Nov 2022, at 5:56, Ronald Klop wrote:

> Van: Mike Karels <mike@karels.net>
> Datum: maandag, 7 november 2022 17:10
> Aan: freebsd-arm@freebsd.org
> CC: jmg@freebsd.org
> Onderwerp: adding swap when expanding root filesystem
>>
>> This question is not really arm-specific, but I couldn't think of a better
>> mailing list for it.
>>
>> There are peridic issues reported on small systems like Raspberry Pi
>> where people are running buildworld or poudriere and running out of
>> memory.  As the user gets no control over the disk layout when installing,
>> there is no option to add swap space on the install image.  I have added
>> swap space on a USB disk, but this is often not an option.  It occurred
>> to me that it might be reasonable to add swap space before expanding
>> the root filesystem if there is sufficient space.  I have a prototype,
>> and wondered if this is a good thing to do.  Granted, this will often
>> create swap on microSD, which is not optimal, but probably better than
>> nothing.
>>
>> The current prototype creates a swap partition which is 1/10 of the disk
>> if the disk is at least 15 GB and the initial root partition is no more
>> than 1/3 of the disk, but only up to 1.5x of physical memory.  I would
>> probably enable this by default, but provide a way to disable it via a
>> kenv variable and/or a variable in /etc/rc.conf.
>>
>> Thoughts?
>>
>>         Mike
>>
>
>
> Hi,
>
> Would you mind sharing your prototype?

I’ll send you a pointer.  If anyone else wants to check it out, let
me know.  It is full of debug prints still, and missing some required
changes.  It is somewhat tested with MBR, not with GPT.  If anyone
has a setup to test with GPT, I’d be grateful.  I haven’t tested
with ZFS either, although that part shouldn’t require changes.

Responding to some earlier comments:

- The current limit on swap partition size is 1.5x physmem, as mentioned.
I am considering raising it, but I don’t think I want to go beyond 2x.

- I am considering whether to allow the size to be overridden from kenv
and maybe /etc/rc.conf, including a value to disable.  Right now it is
possible to disable via kenv (untested).

- I agree that not everyone needs swap space; that’s true of “normal”
installs too, which pick a default but allow override with manual
partitioning.  My hope is that it’s a small enough amount that the
default size isn’t too large a drop in root capacity.

		Mike

> Regards,
> Ronald.