From nobody Thu Feb 09 20:52:25 2023 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 4PCTZd3y31z3ngSZ; Thu, 9 Feb 2023 20:52:25 +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 "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4PCTZd3T9dz4285; Thu, 9 Feb 2023 20:52:25 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1675975945; 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=kjBTmjjiruu4104DT3Gw+cU/bb2iSNB0Vp8mVdEHhiU=; b=sJmng2obBtbvd9O6gO2DqgqD0bPayjW4G5uaO5/0Cjm8MbTo4QCLZZu53KeeOiGCBWEOqe jvjx6pI7m2DWW0LVsiT+02cLa9eG2vW3eI52US9F/vydeu4TvDFoYm/kLKi4HhRcsB62+V u+tXZwug0lckYke2OVUgOp5eEBxe74X5hZZ5jKTBQIN5j49bcIrvUo+CS68b7daWDUF6kT cR7A0SGvuSFR0PR8ZABwOuKjDyfnpxdeU3FFk13bsXDVmzddTROiDeyDjrDmpnqTuCxUDN vCce37nxo6JdPAMyIwKzZWeQaN4ZNJ3RiRdnxZkS0Ri3SGPQxp+Yl6CJno7vcQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1675975945; 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=kjBTmjjiruu4104DT3Gw+cU/bb2iSNB0Vp8mVdEHhiU=; b=IgZ5iJyo/43QoE/Iy4ydrAcF8t3xb4i/QM+dGQcgC+JkdoVpddHcxJYggs/UaDfev+bPsC zvKlwO22tbynbCCwPIYIbuc8J8Udkot7dcQuLI8z+23FBeg/Mv6K6jl7SexLDWTyZkV/DJ DZ6SW8/+Yh79V89DRgf2jcZbT+TJKADleBOO246WYqPC6PEuRI5EXHNmlmlOZY8VKtKaGj 9R4AteTKSzqi9SP8mowtMBHjaKn7QFq6YR6pOFIlgDjvsMmuZynduk4EjSIcyc7lyz87V0 apbYaBfhYWyQE4ynDTzLFNukA8fd7Zogw7tErSwt91Q6AzDg3B2dadgQw6qa2w== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1675975945; a=rsa-sha256; cv=none; b=RMTWOQEoTZyJJcbusJE/FWFVUIyuBFS3Ci0QnXeKWC0KK1iSkb7s4EuseLefvDPtM18BxI OIKM23GBAV0b/UP0KHTpQWqiiY9qmw/qO21i5kH3B3K5MuPKZBzGZiq1ACysJZQMvHhfnH 6gjQV8LbAAXO1IMBCFIgzUM37HlaIwJD8LbCVKvP/h8gQ/v9QrEDbw1hQGyWVUwsxxD6cF hcak/vxJQ0VcS+tXRq9vy+ZCOcl//baa50cWaABQfNSSktNiSV/+5uTGEw+WrPVAHRy+Kb miguA+l5TTSNpS+23uPA6ZAxuIRh202xRTT3LJ5Kt9sIYwQH2jh3o0vHeQPXZQ== 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 4PCTZd2Z1Vzs9L; Thu, 9 Feb 2023 20:52:25 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 319KqPl1013464; Thu, 9 Feb 2023 20:52:25 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 319KqPkW013463; Thu, 9 Feb 2023 20:52:25 GMT (envelope-from git) Date: Thu, 9 Feb 2023 20:52:25 GMT Message-Id: <202302092052.319KqPkW013463@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: "Alexander V. Chernikov" Subject: git: 2631a2599b8b - stable/13 - sockbufs: add sbreserve_locked_limit() with custom maxsockbuf limit. 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: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: melifaro X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: 2631a2599b8b3b4c6f651a9bbe54454167b13bcf Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by melifaro: URL: https://cgit.FreeBSD.org/src/commit/?id=2631a2599b8b3b4c6f651a9bbe54454167b13bcf commit 2631a2599b8b3b4c6f651a9bbe54454167b13bcf Author: Alexander V. Chernikov AuthorDate: 2022-09-27 13:52:11 +0000 Commit: Alexander V. Chernikov CommitDate: 2023-02-09 20:40:58 +0000 sockbufs: add sbreserve_locked_limit() with custom maxsockbuf limit. Protocols such as netlink may need a large socket receive buffer, measured in tens of megabytes. This change allows netlink to set larger socket buffers (given the privs are in place), without requiring user to manuall bump maxsockbuf. Reviewed by: glebius Differential Revision: https://reviews.freebsd.org/D36747 (cherry picked from commit 7b660faa9e30c15d3be9b2c44c3ca046a33331f4) --- sys/kern/uipc_sockbuf.c | 22 +++++++++++++++------- sys/sys/sockbuf.h | 2 ++ 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/sys/kern/uipc_sockbuf.c b/sys/kern/uipc_sockbuf.c index 80505dd4dbd2..cbfcc0e5fe95 100644 --- a/sys/kern/uipc_sockbuf.c +++ b/sys/kern/uipc_sockbuf.c @@ -64,9 +64,10 @@ void (*aio_swake)(struct socket *, struct sockbuf *); * Primitive routines for operating on socket buffers */ +#define BUF_MAX_ADJ(_sz) (((u_quad_t)(_sz)) * MCLBYTES / (MSIZE + MCLBYTES)) + u_long sb_max = SB_MAX; -u_long sb_max_adj = - (quad_t)SB_MAX * MCLBYTES / (MSIZE + MCLBYTES); /* adjusted sb_max */ +u_long sb_max_adj = BUF_MAX_ADJ(SB_MAX); static u_long sb_efficiency = 8; /* parameter for sbreserve() */ @@ -592,7 +593,7 @@ sysctl_handle_sb_max(SYSCTL_HANDLER_ARGS) if (tmp_sb_max < MSIZE + MCLBYTES) return (EINVAL); sb_max = tmp_sb_max; - sb_max_adj = (u_quad_t)sb_max * MCLBYTES / (MSIZE + MCLBYTES); + sb_max_adj = BUF_MAX_ADJ(sb_max); return (0); } @@ -601,8 +602,8 @@ sysctl_handle_sb_max(SYSCTL_HANDLER_ARGS) * become limiting if buffering efficiency is near the normal case. */ int -sbreserve_locked(struct sockbuf *sb, u_long cc, struct socket *so, - struct thread *td) +sbreserve_locked_limit(struct sockbuf *sb, u_long cc, struct socket *so, + u_long buf_max, struct thread *td) { rlim_t sbsize_limit; @@ -615,7 +616,7 @@ sbreserve_locked(struct sockbuf *sb, u_long cc, struct socket *so, * appropriate thread resource limits are available. In that case, * we don't apply a process limit. */ - if (cc > sb_max_adj) + if (cc > BUF_MAX_ADJ(buf_max)) return (0); if (td != NULL) { sbsize_limit = lim_cur(td, RLIMIT_SBSIZE); @@ -624,12 +625,19 @@ sbreserve_locked(struct sockbuf *sb, u_long cc, struct socket *so, if (!chgsbsize(so->so_cred->cr_uidinfo, &sb->sb_hiwat, cc, sbsize_limit)) return (0); - sb->sb_mbmax = min(cc * sb_efficiency, sb_max); + sb->sb_mbmax = min(cc * sb_efficiency, buf_max); if (sb->sb_lowat > sb->sb_hiwat) sb->sb_lowat = sb->sb_hiwat; return (1); } +int +sbreserve_locked(struct sockbuf *sb, u_long cc, struct socket *so, + struct thread *td) +{ + return (sbreserve_locked_limit(sb, cc, so, sb_max, td)); +} + int sbsetopt(struct socket *so, int cmd, u_long cc) { diff --git a/sys/sys/sockbuf.h b/sys/sys/sockbuf.h index a263555b3a21..57f080615bdc 100644 --- a/sys/sys/sockbuf.h +++ b/sys/sys/sockbuf.h @@ -176,6 +176,8 @@ void sbrelease_locked(struct sockbuf *sb, struct socket *so); int sbsetopt(struct socket *so, int cmd, u_long cc); int sbreserve_locked(struct sockbuf *sb, u_long cc, struct socket *so, struct thread *td); +int sbreserve_locked_limit(struct sockbuf *sb, u_long cc, struct socket *so, + u_long buf_max, struct thread *td); void sbsndptr_adv(struct sockbuf *sb, struct mbuf *mb, u_int len); struct mbuf * sbsndptr_noadv(struct sockbuf *sb, u_int off, u_int *moff);