From owner-dev-commits-src-main@freebsd.org Fri Sep 10 18:32:54 2021 Return-Path: Delivered-To: dev-commits-src-main@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 2546E661034; Fri, 10 Sep 2021 18:32:54 +0000 (UTC) (envelope-from glebius@freebsd.org) Received: from cell.glebi.us (glebi.us [162.251.186.162]) (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 (2048 bits) client-digest SHA256) (Client CN "cell.glebi.us", Issuer "cell.glebi.us" (not verified)) by mx1.freebsd.org (Postfix) with ESMTPS id 4H5kyF3yptz4mW9; Fri, 10 Sep 2021 18:32:53 +0000 (UTC) (envelope-from glebius@freebsd.org) Received: from cell.glebi.us (localhost [127.0.0.1]) by cell.glebi.us (8.16.1/8.16.1) with ESMTPS id 18AIWpPr001637 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NO); Fri, 10 Sep 2021 11:32:51 -0700 (PDT) (envelope-from glebius@freebsd.org) Received: (from glebius@localhost) by cell.glebi.us (8.16.1/8.16.1/Submit) id 18AIWpDS001636; Fri, 10 Sep 2021 11:32:51 -0700 (PDT) (envelope-from glebius@freebsd.org) X-Authentication-Warning: cell.glebi.us: glebius set sender to glebius@freebsd.org using -f Date: Fri, 10 Sep 2021 11:32:51 -0700 From: Gleb Smirnoff To: Mateusz Guzik Cc: kp@freebsd.org, src-committers@freebsd.org, dev-commits-src-all@freebsd.org, dev-commits-src-main@freebsd.org Subject: Re: git: 5091ca26507b - main - pf: save on branching in the common case in pf_test Message-ID: References: <202108171959.17HJx2lL069856@gitrepo.freebsd.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Rspamd-Queue-Id: 4H5kyF3yptz4mW9 X-Spamd-Bar: ---- Authentication-Results: mx1.freebsd.org; none X-Spamd-Result: default: False [-4.00 / 15.00]; REPLY(-4.00)[] X-BeenThere: dev-commits-src-main@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commit messages for the main branch of the src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 10 Sep 2021 18:32:54 -0000 Mateusz, On Fri, Sep 10, 2021 at 09:43:06AM +0200, Mateusz Guzik wrote: M> > M> diff --git a/sys/netpfil/pf/pf.c b/sys/netpfil/pf/pf.c M> > M> index e2dd3eb7c0de..add76c7b98d4 100644 M> > M> --- a/sys/netpfil/pf/pf.c M> > M> +++ b/sys/netpfil/pf/pf.c M> > M> @@ -6151,7 +6151,7 @@ pf_test(int dir, int pflags, struct ifnet *ifp, M> > struct mbuf **m0, struct inpcb * M> > M> M> > M> PF_RULES_RLOCK(); M> > M> M> > M> - if (ip_divert_ptr != NULL && M> > M> + if (__predict_false(ip_divert_ptr != NULL) && M> > M> > This is an optimization for a setup without divert(4) at cost of M> > pessimization M> > for a setup with divert(4). IMHO, __predict_false() predicate should guard M> > against error paths and other unusual events, not favor one setup over M> > other. M> > M> M> divert is non-standard and comes with tons of overhead, so I think M> this is justified. pf is also non-standard and comes with tons of overhead, so what about such change to ip_input(), and similar to ip_output(): diff --git a/sys/netinet/ip_input.c b/sys/netinet/ip_input.c index 465c00e4dac..e6feb837114 100644 --- a/sys/netinet/ip_input.c +++ b/sys/netinet/ip_input.c @@ -605,7 +605,7 @@ ip_input(struct mbuf *m) */ /* Jump over all PFIL processing if hooks are not active. */ - if (!PFIL_HOOKED_IN(V_inet_pfil_head)) + if (__predict_true(!PFIL_HOOKED_IN(V_inet_pfil_head))) goto passin; odst = ip->ip_dst; I hope that brings my point. M> The real fix would be to either implement hot patchable branches or M> otherwise generate pf_test always (or never) doing divert without M> having to check for it, but that's far in the future. That would be great, but before we have such tools, I believe optimization for one particular setup at cost of pessimization of other setups is not a way to go. -- Gleb Smirnoff