From nobody Wed May 21 10:08:30 2025 X-Original-To: dev-commits-src-all@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 4b2Rvf2scfz5x8kM; Wed, 21 May 2025 10:08:30 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (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-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R11" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4b2Rvf17m9z3DTk; Wed, 21 May 2025 10:08:30 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1747822110; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=AI0FRyVn83XWZDlW/O2BrG67fMCg+xpqoB91syUtV6s=; b=fOj2P9GYotf6Pbtv3bDWrK0kL9AyCO2I1ji24SEkj1428amnpYZLsKA304/0vLDMIKHVlB iiwbJbAwlFGUQYCVwA+LL1wNuOsJwuxQVgkX8IPd1ku9/OjVAqfauY320Kelp3GxjXqVU/ B1QbSePMvdkrXMY4NTuCySGlb65MlsdWSsPd/48v+wjrEVLHLjZHW+wlXzKC3h7DoVqD6z PWLPwx6e4mmkohFTOZj9k6+dqQmO//7nldFbFaSKlj8Mi9oKjmwDv79zACc8hHnkAmsk8u VzntbanCvS2kIwNnZahodPceXbN5VU3U6mUPvLwVAY6m6+vk0oI9zR59oZhrOQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1747822110; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=AI0FRyVn83XWZDlW/O2BrG67fMCg+xpqoB91syUtV6s=; b=SEL+tSGDVVFoK7/0LCJk71kGhMRLPIdDNBjLjHAfDIzk+gTgtEgXNDWypDJFOxO/+gfVfb i7+JeUV4FBjGt0p0g78u/jKyOq7xVLOafw/gllfPWO+rfD76IYtvH1l2LZTnvIRqRxICDX 3dBwb2duAWB/rHU82OSgD5QgLY0YAue8DN5gE3GWz7tIX4kVAG6Y0GbzS+b9ealJR3/6aU 4plXpJgWfB+gy4QW67fmHwoyq8lNFWQTud513nVbKgK2EOMYhzqxvGwXxkc8aQ+r/6jZHI g25jApnFtB0As0qwdmTQMm+pRSBXbg4Xx0SYr7/+j0gCEUv/G0sSaKnf3oxvSg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1747822110; a=rsa-sha256; cv=none; b=xuCQvoqb1TBEJgdtU5l7lPDTItTdoxTN6hvksCYp5UonftflFW3moaJv0r7OuUhZ5QeIaD edFXR3R6b/8RyFK5NWOW99Ba2RSeswKUSPRaXeUfnyXL+FeRFrqk2Lqlq3ZdGG+jJ+o3ng VuY6jU1O7Y3uc35RVfKiZWKaI1DCSbZZ08tNRAQsb+eSpGaN3hTKwgvrZikCT4CyC0UWa2 FRwcbDWfbgPVO5IEVEBAvG09z6OCphWAFa+Qh6qSvSJMrTiDbFB2ysVPlHb8H7luDDuyxv Lh1nSCUqlwNx4RQbey2A+GloHfuKcorB27HWxpHTbQcYXNoGwRUcBWY6x1usFg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (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 mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4b2Rvf0kvGzVXp; Wed, 21 May 2025 10:08:30 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 54LA8UHD011797; Wed, 21 May 2025 10:08:30 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 54LA8U1v011794; Wed, 21 May 2025 10:08:30 GMT (envelope-from git) Date: Wed, 21 May 2025 10:08:30 GMT Message-Id: <202505211008.54LA8U1v011794@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Olivier Certner Subject: git: fbc73f17ba17 - releng/14.3 - Compute 'maxproc'/'maxfiles' from memory amount; Expand/fix comments List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: olce X-Git-Repository: src X-Git-Refname: refs/heads/releng/14.3 X-Git-Reftype: branch X-Git-Commit: fbc73f17ba172e74c5b5a1b0d85a53fbc61b2402 Auto-Submitted: auto-generated The branch releng/14.3 has been updated by olce: URL: https://cgit.FreeBSD.org/src/commit/?id=fbc73f17ba172e74c5b5a1b0d85a53fbc61b2402 commit fbc73f17ba172e74c5b5a1b0d85a53fbc61b2402 Author: Olivier Certner AuthorDate: 2025-05-02 12:47:32 +0000 Commit: Olivier Certner CommitDate: 2025-05-21 10:07:36 +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. 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 (cherry picked from commit 73f9251c0b52ac0bfb2f2baff27493d6bae216f6) (cherry picked from commit e7d4e52eafb016707ef3dd3b778d76db280c06a4) Approved by: re (cperciva) --- 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 67dc10213a70..36009a5c1be1 100644 --- a/sys/kern/subr_param.c +++ b/sys/kern/subr_param.c @@ -70,13 +70,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); @@ -276,13 +277,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 @@ -291,35 +293,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);