Netdev List
 help / color / mirror / Atom feed
From: Mike Rapoport <rppt@kernel.org>
To: me@amir.fyi
Cc: Eric Dumazet <edumazet@kernel.org>,
	Neal Cardwell <ncardwell@google.com>,
	Kuniyuki Iwashima <kuniyu@google.com>,
	"David S. Miller" <davem@davemloft.net>,
	Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
	Willem de Bruijn <willemb@google.com>,
	Simon Horman <horms@kernel.org>,
	Muchun Song <muchun.song@linux.dev>,
	netdev@vger.kernel.org, linux-mm@kvack.org
Subject: Re: [PATCH net] tcp: avoid table_perturb overflow on single node hosts
Date: Wed, 2 Dec 2026 11:51:33 +0200	[thread overview]
Message-ID: <aw_qJSpnJCmOAUgz@kernel.org> (raw)
In-Reply-To: <20261201-tcp-perturb-kvmalloc-v1-1-deee7c745fa3@amir.fyi>

Hi Amir,

On Tue, Dec 01, 2026 at 07:31:32PM +0000, Amir Hosseini wrote:
>
> From: Amir Hosseini <me@amir.fyi>
> 
> Since commit e67b72b90b7e ("tcp: use alloc_large_system_hash() to
> allocate table_perturb"), table_perturb is allocated with
> alloc_large_system_hash(). On NUMA hosts it uses vmalloc(), but on
> single node hosts it needs one contiguous 256KB block.

It's vmalloc_huge() and it's used when hashdist is set, i.e. on 64-bit
with more than one node with memory.

> When there is no such block, for example after many HugeTLB pages were
> reserved at boot, the table is made smaller without telling the caller.

It's worth mentioning that alloc_large_system_hash() ignores low_limit
when it retries with smaller sizes.

...

> -	table_perturb = alloc_large_system_hash("Table-perturb",
> -						sizeof(*table_perturb),
> -						INET_TABLE_PERTURB_SIZE,
> -						0, 0, NULL, NULL,
> -						INET_TABLE_PERTURB_SIZE,
> -						INET_TABLE_PERTURB_SIZE);
> +	if (num_online_nodes() > 1) {
> +		/* Use vmalloc() to allow NUMA policy to spread pages
> +		 * on all available nodes if desired.
> +		 */
> +		table_perturb = vmalloc_array(INET_TABLE_PERTURB_SIZE,
> +					      sizeof(*table_perturb));
> +	}

I don't think the special case for NUMA makes sense.

Since commit a061578043993 ("mm/vmalloc: request large order pages from
buddy allocator") vmalloc takes large order blocks from the buddy
allocator, so vmalloc_array() gets the whole table as one block from one
node when it's available.

With the existing code, if there's a free order-6 block, it comes from
alloc_pages() with hashdist=0 and with hashdist=1 it's a single block
from vmalloc mapped with 4k pages.

If there's no such block, with hashdist=0 alloc_large_system_hash()
continues the loop and returns the largest block alloc_pages() can get,
and with hashdist=1 vmalloc is likely to succeed with several blocks
spread across the nodes and mapped with 4k pages.

With kvmalloc_array() a free order-6 block comes from kmalloc() ->
alloc_pages() and if there is no such block, several smaller blocks
come from vmalloc(), spread across the nodes and mapped with 4k pages.

So kvmalloc_array() never shrinks the table, prefers the linear map
when there's a contiguous block and spreads the table across the nodes
exactly in the case where hashdist=1 actually spreads it now.

Please drop the NUMA branch and just use kvmalloc_array().

> +	if (!table_perturb)
> +		table_perturb = kvmalloc_array(INET_TABLE_PERTURB_SIZE,
> +					       sizeof(*table_perturb),
> +					       GFP_KERNEL);
> +	if (!table_perturb)
> +		panic("TCP: failed to alloc table_perturb");
>  }

-- 
Sincerely yours,
Mike.

      reply	other threads:[~2026-12-02  9:51 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-01 19:31 [PATCH net] tcp: avoid table_perturb overflow on single node hosts Amir Hosseini via B4 Relay
2026-12-02  9:51 ` Mike Rapoport [this message]

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=aw_qJSpnJCmOAUgz@kernel.org \
    --to=rppt@kernel.org \
    --cc=davem@davemloft.net \
    --cc=edumazet@kernel.org \
    --cc=horms@kernel.org \
    --cc=kuba@kernel.org \
    --cc=kuniyu@google.com \
    --cc=linux-mm@kvack.org \
    --cc=me@amir.fyi \
    --cc=muchun.song@linux.dev \
    --cc=ncardwell@google.com \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=willemb@google.com \
    /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