git: 5091ca26507b - main - pf: save on branching in the common case in pf_test

Mateusz Guzik mjguzik at gmail.com
Fri Sep 10 07:43:09 UTC 2021


On 9/10/21, Gleb Smirnoff <glebius at freebsd.org> wrote:
>   Mateusz,
>
> On Tue, Aug 17, 2021 at 07:59:02PM +0000, Mateusz Guzik wrote:
> M> The branch main has been updated by mjg:
> M>
> M> URL:
> https://cgit.FreeBSD.org/src/commit/?id=5091ca26507b83ebd5ce677dd26bd10e4bad4153
> M>
> M> commit 5091ca26507b83ebd5ce677dd26bd10e4bad4153
> M> Author:     Mateusz Guzik <mjg at FreeBSD.org>
> M> AuthorDate: 2021-08-17 18:04:31 +0000
> M> Commit:     Mateusz Guzik <mjg at FreeBSD.org>
> M> CommitDate: 2021-08-17 19:56:33 +0000
> M>
> M>     pf: save on branching in the common case in pf_test
> M>
> M>     Reviewed by:    kp
> M>     Sponsored by:   Rubicon Communications, LLC ("Netgate")
> M> ---
> M>  sys/netpfil/pf/pf.c | 6 +++---
> M>  1 file changed, 3 insertions(+), 3 deletions(-)
> M>
> M> diff --git a/sys/netpfil/pf/pf.c b/sys/netpfil/pf/pf.c
> M> index e2dd3eb7c0de..add76c7b98d4 100644
> M> --- a/sys/netpfil/pf/pf.c
> M> +++ b/sys/netpfil/pf/pf.c
> M> @@ -6151,7 +6151,7 @@ pf_test(int dir, int pflags, struct ifnet *ifp,
> struct mbuf **m0, struct inpcb *
> M>
> M>  	PF_RULES_RLOCK();
> M>
> M> -	if (ip_divert_ptr != NULL &&
> M> +	if (__predict_false(ip_divert_ptr != NULL) &&
>
> This is an optimization for a setup without divert(4) at cost of
> pessimization
> for a setup with divert(4). IMHO, __predict_false() predicate should guard
> against error paths and other unusual events, not favor one setup over
> other.
>

divert is non-standard and comes with tons of overhead, so I think
this is justified.

The real fix would be to either implement hot patchable branches or
otherwise generate pf_test always (or never) doing divert without
having to check for it, but that's far in the future.

-- 
Mateusz Guzik <mjguzik gmail.com>


More information about the dev-commits-src-main mailing list