From nobody Thu May 15 15:11:19 2025 X-Original-To: dev-commits-src-main@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4Zytw230MSz5wTc1; Thu, 15 May 2025 15:11:30 +0000 (UTC) (envelope-from kostikbel@gmail.com) Received: from kib.kiev.ua (kib.kiev.ua [IPv6:2001:470:d5e7:1::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 4Zytw2040bz41B3; Thu, 15 May 2025 15:11:29 +0000 (UTC) (envelope-from kostikbel@gmail.com) Authentication-Results: mx1.freebsd.org; none Received: from tom.home (kib@localhost [127.0.0.1] (may be forged)) by kib.kiev.ua (8.18.1/8.18.1) with ESMTP id 54FFBJlP057115; Thu, 15 May 2025 18:11:22 +0300 (EEST) (envelope-from kostikbel@gmail.com) DKIM-Filter: OpenDKIM Filter v2.10.3 kib.kiev.ua 54FFBJlP057115 Received: (from kostik@localhost) by tom.home (8.18.1/8.18.1/Submit) id 54FFBJm0057113; Thu, 15 May 2025 18:11:19 +0300 (EEST) (envelope-from kostikbel@gmail.com) X-Authentication-Warning: tom.home: kostik set sender to kostikbel@gmail.com using -f Date: Thu, 15 May 2025 18:11:19 +0300 From: Konstantin Belousov To: Olivier Certner Cc: src-committers@freebsd.org, dev-commits-src-all@freebsd.org, dev-commits-src-main@freebsd.org Subject: Re: git: 73f9251c0b52 - main - Compute 'maxproc'/'maxfiles' from memory amount; Expand/fix comments Message-ID: References: <202505151423.54FENTXl057685@gitrepo.freebsd.org> List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-main@freebsd.org Sender: owner-dev-commits-src-main@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <202505151423.54FENTXl057685@gitrepo.freebsd.org> X-Spam-Status: No, score=-1.0 required=5.0 tests=ALL_TRUSTED,BAYES_00, DKIM_ADSP_CUSTOM_MED,FORGED_GMAIL_RCVD,FREEMAIL_FROM, NML_ADSP_CUSTOM_MED autolearn=no autolearn_force=no version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on tom.home X-Rspamd-Queue-Id: 4Zytw2040bz41B3 X-Rspamd-Pre-Result: action=no action; module=replies; Message is reply to one we originated X-Spamd-Result: default: False [-4.00 / 15.00]; REPLY(-4.00)[]; ASN(0.00)[asn:6939, ipnet:2001:470::/32, country:US] X-Spamd-Bar: ---- On Thu, May 15, 2025 at 02:23:29PM +0000, Olivier Certner wrote: > The branch main has been updated by olce: > > URL: https://cgit.FreeBSD.org/src/commit/?id=73f9251c0b52ac0bfb2f2baff27493d6bae216f6 > > commit 73f9251c0b52ac0bfb2f2baff27493d6bae216f6 > Author: Olivier Certner > AuthorDate: 2025-05-02 12:47:32 +0000 > Commit: Olivier Certner > CommitDate: 2025-05-15 14:22:53 +0000 > > Compute 'maxproc'/'maxfiles' from memory amount; Expand/fix comments > > Change the formulae so that 'maxproc' and 'maxfiles' are computed based > on the physical memory amount, and not the corresponding number of > pages. Make sure that the practical results are unchanged for all > architectures (which is possible since all have 4096 as their > PAGE_SIZE). Despite this, we do this change to make it clearer how many > units of these values are computed per MB, which is easier on readers. Not all architectures have PAGE_SIZE of 4K. Not going back to the historic arches, and out of tree patches for x86, I believe that arm64 has in-tree support for 16K pages. VM system is fine with the page sizes from 4K to 32K. > > Change the comments accordingly and expand them to indicate which parts > of the computations are actually not used by default. In passing, fix the > comments about default values and limits for 'maxfiles' (they were off). > > No functional change (intended). > > MFC after: 3 days > Sponsored by: The FreeBSD Foundation > Differential Revision: https://reviews.freebsd.org/D50124 > --- > sys/kern/subr_param.c | 44 +++++++++++++++++++++++++++----------------- > 1 file changed, 27 insertions(+), 17 deletions(-) > > diff --git a/sys/kern/subr_param.c b/sys/kern/subr_param.c > index f4359efec466..471640c290a7 100644 > --- a/sys/kern/subr_param.c > +++ b/sys/kern/subr_param.c > @@ -69,13 +69,14 @@ > # define HZ_VM HZ > # endif > #endif > +/* See the comments in init_param2() for these. */ > #define NPROC (20 + 16 * maxusers) > -#ifndef NBUF > -#define NBUF 0 > -#endif > #ifndef MAXFILES > #define MAXFILES (40 + 32 * maxusers) > #endif > +#ifndef NBUF > +#define NBUF 0 > +#endif > > static int sysctl_kern_vm_guest(SYSCTL_HANDLER_ARGS); > > @@ -275,13 +276,14 @@ init_param1(void) > void > init_param2(long physpages) > { > + long maxproc_clamp, maxfiles_clamp; > > TSENTER(); > /* Base parameters */ > maxusers = MAXUSERS; > TUNABLE_INT_FETCH("kern.maxusers", &maxusers); > if (maxusers == 0) { > - maxusers = physpages / (2 * 1024 * 1024 / PAGE_SIZE); > + maxusers = pgtok(physpages) / (2 * 1024); > if (maxusers < 32) > maxusers = 32; > #ifdef VM_MAX_AUTOTUNE_MAXUSERS > @@ -290,35 +292,43 @@ init_param2(long physpages) > #endif > /* > * Scales down the function in which maxusers grows once > - * we hit 384. > + * we hit 384 (16MB to get a new "user"). > */ > if (maxusers > 384) > maxusers = 384 + ((maxusers - 384) / 8); > } > > /* > - * The following can be overridden after boot via sysctl. Note: > - * unless overridden, these macros are ultimately based on maxusers. > - * Limit maxproc so that kmap entries cannot be exhausted by > - * processes. > + * The following can be overridden after boot via sysctl. Note: unless > + * overridden, these macros are ultimately based on 'maxusers'. Limit > + * maxproc so that kmap entries cannot be exhausted by processes. The > + * default for 'maxproc' linearly scales as 16 times 'maxusers' (so, > + * linearly with 8 processes per MB up to 768MB, then 1 process per MB; > + * overridable by a tunable), and is then clamped at 21 + 1/3 processes > + * per MB (which never happens by default as long as physical memory is > + * > ~1.5MB). > */ > maxproc = NPROC; > TUNABLE_INT_FETCH("kern.maxproc", &maxproc); > - if (maxproc > (physpages / 12)) > - maxproc = physpages / 12; > + maxproc_clamp = pgtok(physpages) / (3 * 1024 / 64); > + if (maxproc > maxproc_clamp) > + maxproc = maxproc_clamp; > if (maxproc > pid_max) > maxproc = pid_max; > maxprocperuid = (maxproc * 9) / 10; > > /* > - * The default limit for maxfiles is 1/12 of the number of > - * physical page but not less than 16 times maxusers. > - * At most it can be 1/6 the number of physical pages. > + * 'maxfiles' by default is set to 32 files per MB (overridable by > + * a tunable), and is then clamped at 64 files per MB (which thus never > + * happens by default). (The default MAXFILES is for all practical > + * purposes not used, as it gives a lower value than 32 files per MB as > + * soon as there is more than ~2.5MB of memory.) > */ > - maxfiles = imax(MAXFILES, physpages / 8); > + maxfiles = imax(MAXFILES, pgtok(physpages) / (1024 / 32)); > TUNABLE_INT_FETCH("kern.maxfiles", &maxfiles); > - if (maxfiles > (physpages / 4)) > - maxfiles = physpages / 4; > + maxfiles_clamp = pgtok(physpages) / (1024 / 64); > + if (maxfiles > maxfiles_clamp) > + maxfiles = maxfiles_clamp; > maxfilesperproc = (maxfiles / 10) * 9; > TUNABLE_INT_FETCH("kern.maxfilesperproc", &maxfilesperproc); >