From: Vincent Pelletier <plr.vincent@gmail.com>
To: Pablo Neira Ayuso <pablo@netfilter.org>
Cc: netfilter-devel@vger.kernel.org, davem@davemloft.net,
netdev@vger.kernel.org, kuba@kernel.org,
Florian Westphal <fw@strlen.de>
Subject: Re: [PATCH net 2/5] netfilter: conntrack: sanitize table size default settings
Date: Thu, 31 Mar 2022 14:59:09 +0000 [thread overview]
Message-ID: <20220331145909.085a0f30@gmail.com> (raw)
In-Reply-To: <20210903163020.13741-3-pablo@netfilter.org>
Hello,
On Fri, 3 Sep 2021 18:30:17 +0200, Pablo Neira Ayuso <pablo@netfilter.org> wrote:
> From: Florian Westphal <fw@strlen.de>
>
> conntrack has two distinct table size settings:
> nf_conntrack_max and nf_conntrack_buckets.
>
> The former limits how many conntrack objects are allowed to exist
> in each namespace.
>
> The second sets the size of the hashtable.
>
> As all entries are inserted twice (once for original direction, once for
> reply), there should be at least twice as many buckets in the table than
> the maximum number of conntrack objects that can exist at the same time.
>
> Change the default multiplier to 1 and increase the chosen bucket sizes.
> This results in the same nf_conntrack_max settings as before but reduces
> the average bucket list length.
[...]
> nf_conntrack_htable_size
> = (((nr_pages << PAGE_SHIFT) / 16384)
> / sizeof(struct hlist_head));
> - if (nr_pages > (4 * (1024 * 1024 * 1024 / PAGE_SIZE)))
> - nf_conntrack_htable_size = 65536;
> + if (BITS_PER_LONG >= 64 &&
> + nr_pages > (4 * (1024 * 1024 * 1024 / PAGE_SIZE)))
> + nf_conntrack_htable_size = 262144;
> else if (nr_pages > (1024 * 1024 * 1024 / PAGE_SIZE))
> - nf_conntrack_htable_size = 16384;
[...]
> + nf_conntrack_htable_size = 65536;
With this formula, there seems to be a discontinuity between the
proportional and fixed regimes:
64bits: 4GB/16k/8 = 32k, which gets bumped to 256k
32bits: 1GB/16k/4 = 16k, which gets bumped to 64k
Is this intentional ?
The background for my interest in this formula comes from OpenWRT:
low-RAM devices intended to handle a lot of connections, which led
OpenWRT to use sysctl to increase the maximum number of entries in this
hash table compared to what this formula produces.
Unfortunately, the result is that not-so-low-RAM devices running
OpenWRT get the same limit as low-RAM devices, so I am trying to tweak
the divisor in the first expression and getting rid of the sysctl call.
But then I am failing to see how I should adapt the expressions in
these "if"s blocks.
If they were maximum sizes (say, something like
nf_conntrack_htable_size = max(nf_conntrack_htable_size, 256k)), I
would understand, but I find this discontinuity surprising.
Am I missing something ?
For reference, this change is
commit d532bcd0b2699d84d71a0c71d37157ac6eb3be25
in Linus' tree.
Regards,
--
Vincent Pelletier
GPG fingerprint 983A E8B7 3B91 1598 7A92 3845 CAC9 3691 4257 B0C1
next prev parent reply other threads:[~2022-03-31 14:59 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-09-03 16:30 [PATCH net 0/5] Netfilter fixes for net Pablo Neira Ayuso
2021-09-03 16:30 ` [PATCH net 1/5] netfilter: nft_ct: protect nft_ct_pcpu_template_refcnt with mutex Pablo Neira Ayuso
2021-09-04 1:30 ` patchwork-bot+netdevbpf
2021-09-03 16:30 ` [PATCH net 2/5] netfilter: conntrack: sanitize table size default settings Pablo Neira Ayuso
2022-03-31 14:59 ` Vincent Pelletier [this message]
2022-03-31 15:21 ` Florian Westphal
2021-09-03 16:30 ` [PATCH net 3/5] netfilter: conntrack: switch to siphash Pablo Neira Ayuso
2021-09-03 16:30 ` [PATCH net 4/5] netfilter: refuse insertion if chain has grown too large Pablo Neira Ayuso
2021-09-03 16:30 ` [PATCH net 5/5] netfilter: socket: icmp6: fix use-after-scope Pablo Neira Ayuso
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220331145909.085a0f30@gmail.com \
--to=plr.vincent@gmail.com \
--cc=davem@davemloft.net \
--cc=fw@strlen.de \
--cc=kuba@kernel.org \
--cc=netdev@vger.kernel.org \
--cc=netfilter-devel@vger.kernel.org \
--cc=pablo@netfilter.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).