Bug 251993 - bsdinstall: Can create swap partition size that generates kern.maxswzone warning
Summary: bsdinstall: Can create swap partition size that generates kern.maxswzone warning
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: bin (show other bugs)
Version: 12.2-RELEASE
Hardware: Any Any
: --- Affects Some People
Assignee: Ed Maste
URL: https://reviews.freebsd.org/D53106
Keywords: needs-patch
Depends on:
Blocks:
 
Reported: 2020-12-20 15:47 UTC by Robert Watson
Modified: 2026-06-11 20:32 UTC (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Robert Watson freebsd_committer freebsd_triage 2020-12-20 15:47:02 UTC
I installed FreeBSD 12.2 in a VMware virtual machine, and get the following console output on every boot:

> warning: total configured swap (262134 pages) exceeds maximum recommended amount (215992 pages).
> warning: increase kern.maxswzone or reduce amount of swap.

I selected only the defaults going through the installer on the disc1 ISO. It seems like the installer would ideally not create more swap than the kernel supports, or might arrange for loader.conf to be suitably tuned if it were to do so.

robert@freebsd-amd64:~/git % gpart list
Geom name: da0
modified: false
state: OK
fwheads: 255
fwsectors: 63
last: 41942999
first: 40
entries: 128
scheme: GPT
Providers:
1. Name: da0p1
   Mediasize: 524288 (512K)
   Sectorsize: 512
   Stripesize: 0
   Stripeoffset: 20480
   Mode: r0w0e0
   efimedia: HD(1,GPT,11392b84-42b5-11eb-a6e4-000c29a7ef2d,0x28,0x400)
   rawuuid: 11392b84-42b5-11eb-a6e4-000c29a7ef2d
   rawtype: 83bd6b9d-7f41-11dc-be0b-001560b84f0f
   label: (null)
   length: 524288
   offset: 20480
   type: freebsd-boot
   index: 1
   end: 1063
   start: 40
2. Name: da0p2
   Mediasize: 20400570368 (19G)
   Sectorsize: 512
   Stripesize: 0
   Stripeoffset: 544768
   Mode: r1w1e1
   efimedia: HD(2,GPT,11397edd-42b5-11eb-a6e4-000c29a7ef2d,0x428,0x25ffc00)
   rawuuid: 11397edd-42b5-11eb-a6e4-000c29a7ef2d
   rawtype: 516e7cb6-6ecf-11d6-8ff8-00022d09712b
   label: (null)
   length: 20400570368
   offset: 544768
   type: freebsd-ufs
   index: 2
   end: 39845927
   start: 1064
3. Name: da0p3
   Mediasize: 1073700864 (1.0G)
   Sectorsize: 512
   Stripesize: 0
   Stripeoffset: 3221245952
   Mode: r1w1e0
   efimedia: HD(3,GPT,1139fcde-42b5-11eb-a6e4-000c29a7ef2d,0x2600028,0x1fffb0)
   rawuuid: 1139fcde-42b5-11eb-a6e4-000c29a7ef2d
   rawtype: 516e7cb5-6ecf-11d6-8ff8-00022d09712b
   label: (null)
   length: 1073700864
   offset: 20401115136
   type: freebsd-swap
   index: 3
   end: 41942999
   start: 39845928
Consumers:
1. Name: da0
   Mediasize: 21474836480 (20G)
   Sectorsize: 512
   Mode: r2w2e3
Comment 1 Robert Watson freebsd_committer freebsd_triage 2020-12-20 15:49:20 UTC
I should have included this further information:

real memory  = 268435456 (256 MB)
avail memory = 218734592 (208 MB)
Comment 2 Vladimir Druzenko freebsd_committer freebsd_triage 2020-12-20 15:59:18 UTC
(In reply to Robert Watson from comment #1)
You can just ignore this warning.
Comment 3 Robert Watson freebsd_committer freebsd_triage 2020-12-20 16:12:28 UTC
There's probably also an argument for always allocating enough state to support 1GB of swap, given that possibly that is what the installer thinks is the minimum?
Comment 4 Robert Watson freebsd_committer freebsd_triage 2020-12-20 19:24:17 UTC
(In reply to VVD from comment #2)

I am happily ignoring the warning. But I guess the point I'm trying to make is: Our installer should not, by default, create configurations that require warnings. This might be fixed by changing the behaviour of the installer (set up less swap if we're going to create a configuration that will trigger a warning), or by changing the kernel (e.g., to to tune for at least 1GB of swap no matter the physical memory size, since we've decided in the installer that 1GB is a good minimum). Or maybe the warning is boring and we should suppress it.
Comment 5 Ed Maste freebsd_committer freebsd_triage 2020-12-21 00:15:03 UTC
Absolutely we should not have warnings that should be ignored or are unactionable after completing a default install. That said, for this specific case I think a warning for the relatively small amount of memory provisioned for the VM might be appropriate.
Comment 6 ota 2020-12-27 00:31:28 UTC
Or we can grab the maximum from sysctl:

% sysctl -d vm.swap_maxpages
vm.swap_maxpages: Maximum amount of swap pages supported
% sysctl vm.swap_maxpages
vm.swap_maxpages: 4019904
Comment 7 Robert Watson freebsd_committer freebsd_triage 2020-12-28 11:01:14 UTC
If bsdinstall warned that the VM might be under provisioned, and we expect that the VM might get resized as a result, we would likely want to the larger swap size. This suggests that the problem is too many warnings from the kernel, and not enough from the installer?
Comment 8 Kubilay Kocak freebsd_committer freebsd_triage 2021-12-05 23:31:41 UTC
What might a suitable patch look like or do?
Comment 9 Ed Maste freebsd_committer freebsd_triage 2023-03-06 20:12:28 UTC
(In reply to Kubilay Kocak from comment #8)

The warning was added in:

commit 3ff863f1aa52963ea55487477573f70caa275a94
Author: Dag-Erling Smørgrav <des@FreeBSD.org>
Date:   Thu Aug 16 08:29:49 2012 +0000

    - When running out of swzone, instead of spewing an error message every
      tick until the situation is resolved (if ever), just print a single
      message when running out and another when space becomes available.
    
    - When adding more swap, warn if the total amount exceeds half the
      theoretical maximum we can handle.

Notes:
    svn path=/head/; revision=239327

I suspect the real issue is:
> real memory  = 268435456 (256 MB)
Typical installations likely involve a minimum of 1GB of RAM, or maybe 512MB.

The installer's swap size default is set by:
#define SWAP_SIZE(available)   MIN(available/20, 4*1024*1024*1024LL)

> What might a suitable patch look like or do?

Could be one or more of:
- add another limit to the SWAP_SIZE MIN(), so that we'd choose less swap for this installation (either "real memory" or the vm.swap_maxpages sysctl)
- have the installer produce a warning when run on a system with less than 512MB of RAM 
- instead of emitting a warning from the kernel, just ignore (do not use) provided swap space that's above what kern.maxswzone permits
Comment 10 Mark Linimon freebsd_committer freebsd_triage 2024-10-04 12:42:46 UTC
^Triage: clear unneeded flags.  Nothing has yet been committed to be merged.
Comment 11 Ed Maste freebsd_committer freebsd_triage 2025-06-19 16:36:38 UTC
I have submitted https://reviews.freebsd.org/D50942 to sync the UFS and ZFS swap defaults as a first step, and will later look at a possible maximum to avoid the maxswzone warning.

We also use the swap partition for kernel dumps though and might want to make sure it is large enough to capture a dump. I'm not sure if the default of MIN(avail/20, 4GB) is suitable today but either way I suspect that a limit based on maxswzone will be too small on high-memory systems.
Comment 12 commit-hook freebsd_committer freebsd_triage 2025-06-20 19:23:29 UTC
A commit in branch main references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=eb5884c564ae0e37df1d8a3fc5704ab6b2fa07d0

commit eb5884c564ae0e37df1d8a3fc5704ab6b2fa07d0
Author:     Ed Maste <emaste@FreeBSD.org>
AuthorDate: 2025-06-19 19:48:14 +0000
Commit:     Ed Maste <emaste@FreeBSD.org>
CommitDate: 2025-06-20 19:22:18 +0000

    bsdinstall: Emit a warning if the system has too little memory

    PR:             251993
    Reviewed by:    adrian
    Event:          Kitchener-Waterloo Hackathon 202506
    Sponsored by:   The FreeBSD Foundation
    Differential Revision: https://reviews.freebsd.org/D50944

 usr.sbin/bsdinstall/scripts/auto | 8 ++++++++
 1 file changed, 8 insertions(+)
Comment 13 commit-hook freebsd_committer freebsd_triage 2025-07-30 18:39:17 UTC
A commit in branch stable/14 references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=525795cde28bbbc0aba3e5f359dfc877b9f248d1

commit 525795cde28bbbc0aba3e5f359dfc877b9f248d1
Author:     Ed Maste <emaste@FreeBSD.org>
AuthorDate: 2025-06-19 19:48:14 +0000
Commit:     Ed Maste <emaste@FreeBSD.org>
CommitDate: 2025-07-30 18:06:38 +0000

    bsdinstall: Emit a warning if the system has too little memory

    PR:             251993
    Reviewed by:    adrian
    Event:          Kitchener-Waterloo Hackathon 202506
    Sponsored by:   The FreeBSD Foundation
    Differential Revision: https://reviews.freebsd.org/D50944

    (cherry picked from commit eb5884c564ae0e37df1d8a3fc5704ab6b2fa07d0)

 usr.sbin/bsdinstall/scripts/auto | 8 ++++++++
 1 file changed, 8 insertions(+)
Comment 14 Ed Maste freebsd_committer freebsd_triage 2025-09-01 20:45:57 UTC
Not yet fixed
Comment 15 commit-hook freebsd_committer freebsd_triage 2025-10-15 17:32:56 UTC
A commit in branch main references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=52f9722e6ffff6fee309e6040b7b5313499a03ef

commit 52f9722e6ffff6fee309e6040b7b5313499a03ef
Author:     Ed Maste <emaste@FreeBSD.org>
AuthorDate: 2023-03-06 20:24:05 +0000
Commit:     Ed Maste <emaste@FreeBSD.org>
CommitDate: 2025-10-15 16:29:56 +0000

    bsdinstall: Limit default swap to maximum supported by kernel

    PR:             251993
    Reviewed by:    cperciva
    Sponsored by:   The FreeBSD Foundation
    Differential Revision: https://reviews.freebsd.org/D53106

 usr.sbin/bsdinstall/partedit/part_wizard.c | 25 +++++++++++++++++++++++--
 1 file changed, 23 insertions(+), 2 deletions(-)
Comment 16 commit-hook freebsd_committer freebsd_triage 2025-12-16 15:41:43 UTC
A commit in branch stable/15 references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=8f84fdda4c788d63cf0bb0bb19962a0ebcf2e6a4

commit 8f84fdda4c788d63cf0bb0bb19962a0ebcf2e6a4
Author:     Ed Maste <emaste@FreeBSD.org>
AuthorDate: 2023-03-06 20:24:05 +0000
Commit:     Ed Maste <emaste@FreeBSD.org>
CommitDate: 2025-12-16 15:40:40 +0000

    bsdinstall: Limit default swap to maximum supported by kernel

    PR:             251993
    Reviewed by:    cperciva
    Sponsored by:   The FreeBSD Foundation
    Differential Revision: https://reviews.freebsd.org/D53106

    (cherry picked from commit 52f9722e6ffff6fee309e6040b7b5313499a03ef)

 usr.sbin/bsdinstall/partedit/part_wizard.c | 25 +++++++++++++++++++++++--
 1 file changed, 23 insertions(+), 2 deletions(-)