All of lore.kernel.org
 help / color / mirror / Atom feed
From: Mike Rapoport <rppt@kernel.org>
To: Amir Hosseini <me@amir.fyi>
Cc: akpm@linux-foundation.org, edumazet@kernel.org,
	davem@davemloft.net, brauner@kernel.org, muchun.song@linux.dev,
	linux-mm@kvack.org, netdev@vger.kernel.org
Subject: Re: [PATCH] mm/mm_init: don't shrink large system hash tables below low_limit
Date: Tue, 1 Dec 2026 16:55:03 +0200	[thread overview]
Message-ID: <aw7fxwCeHX5jFYW1@kernel.org> (raw)
In-Reply-To: <20261129231312.1442788-1-me@amir.fyi>

On Sun, Nov 29, 2026 at 11:13:12PM +0000, Amir Hosseini wrote:
> On Thu, Nov 26, 2026 at 03:02:02PM +0200, Mike Rapoport wrote:
> > This is hard to read :/
> 
> Sorry about that, I will rewrite it in v2.
> 
> > So, AFAIU the gist is here is that page allocator fails, let's fallback to
> > vmalloc_huge().
> 
> The main problem is what happens after the failure. The loop keeps
> halving the table below low_limit, but table_perturb passes no shift or
> mask, so TCP still uses all 65536 entries. The first connect() then
> writes random data past the end of the table. In my test it hit the TCP
> established hash and the kernel crashed.

I looked more closely at the table_perturb case, and it seems it is really
set on using 65536 entries.

Since that table is allocated in an initcall why not simply replace it with
kvmalloc_array()?

If there is enough free contiguous memory, the kmalloc() branch will
allocate it. If not, vmalloc_huge() for 265k buffer anyway falls back to
small pages.

> > The large hashes are normally allocated at boot time when memory is not yet
> > fragmented, so it's very unlikely that page allocator would fail.
> 
> It is rare, but it does happen. hugetlb_init() takes the boot time 2M
> pages from the buddy allocator before inet_init() runs, so with a large
> hugepages= there may be no order-6 block left. Muchun hit this failure
> on a real server, which is why e67b72b90b7e moved table_perturb to
> alloc_large_system_hash(). That works on NUMA because hashdist uses
> vmalloc, but on a single node system the table is halved instead. On
> mainline I could only trigger it with fail_page_alloc. I first saw it
> with the out-of-tree ASI patches, where it happened in 3 of 4 boots
> with 2 vCPUs.
> 
> > AFAIU, we can just drop the alloc_pages_exact() case and keep memblock for
> > HASH_EARLY and vmalloc_huge() for the rest.
> 
> That would fix this case too, and 64-bit NUMA machines already work this
> way. My only concerns are that on x86 tables smaller than 2M would be
> mapped with 4K pages instead of the direct map's large pages, and that
> 32-bit has little vmalloc space, as the comment above HASHDIST_DEFAULT
> says.
> 
> Either way, I think the loop should not go below low_limit, so that a
> failure panics instead of corrupting memory. I can send v2 with that and
> whichever vmalloc_huge() change you and Eric prefer.

You are right that the loop should respect the low_limit, but the entire
alloc_large_system_hash() is quite convoluted and I believe it requires
more drastic refactoring.
 
> Thanks,
> Amir

-- 
Sincerely yours,
Mike.


  reply	other threads:[~2026-12-01 14:55 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-23 20:15 [PATCH] mm/mm_init: don't shrink large system hash tables below low_limit Amir Hosseini via B4 Relay
2026-11-23 20:15 ` Amir Hosseini
2026-11-26 13:02 ` Mike Rapoport
2026-11-29 23:13   ` Amir Hosseini
2026-12-01 14:55     ` Mike Rapoport [this message]
2026-12-01 18:24       ` Amir Hosseini
2026-11-30 16:14   ` Christian Brauner

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=aw7fxwCeHX5jFYW1@kernel.org \
    --to=rppt@kernel.org \
    --cc=akpm@linux-foundation.org \
    --cc=brauner@kernel.org \
    --cc=davem@davemloft.net \
    --cc=edumazet@kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=me@amir.fyi \
    --cc=muchun.song@linux.dev \
    --cc=netdev@vger.kernel.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.