On Thu, Nov 26, 2026 at 03:02:02PM +0200, Mike Rapoport wrote:
> (added Christian)
>
> On Mon, Nov 23, 2026 at 08:15:49PM +0000, Amir Hosseini via B4 Relay wrote:
> > From: Amir Hosseini <m…@amir.fyi>
> >
> > When an allocation fails, alloc_large_system_hash() halves the table and
> > retries until it is down to a single page. It does not stop at
> > low_limit, although commit 31fe62b95866 ("mm: add a low limit to
> > alloc_large_system_hash") added low_limit precisely so that callers need
> > not check the size they get back.
> >
> > The TCP source port perturbation table depends on that. It passes
> > low_limit == high_limit == INET_TABLE_PERTURB_SIZE and neither
> > _hash_shift nor _hash_mask, so it cannot learn the real size, and
> > __inet_hash_connect() fills and indexes INET_TABLE_PERTURB_SIZE entries.
> > On a single node system hashdist is off and the table needs one order-6
> > GFP_ATOMIC allocation. If that fails, e.g. because most memory was
> > reserved for HugeTLB at boot, the situation commit e67b72b90b7e ("tcp:
> > use alloc_large_system_hash() to allocate table_perturb") was meant to
> > handle, the table is silently halved and the first connect() writes up
> > to 240 KiB of random bytes past its end, typically into the TCP
> > established hash table:
>
> This is hard to read :/
>
> > Table-perturb hash table entries: 32768 (order: 5, 131072 bytes, linear)
> > ...
> > Oops: general protection fault, probably for non-canonical address 0xe480dbf6b420b3d9: 0000 [#1] SMP KASAN
> > RIP: 0010:__inet_lookup_established+0x168/0x5d0
> > Call Trace:
> > <IRQ>
> > tcp_v4_rcv
> > ip_protocol_deliver_rcu
> > ip_local_deliver
> >
> > Stop halving at low_limit. If the linear allocation still fails, retry
> > the same size with vmalloc_huge(), which this function already uses for
> > tables that are too large for the page allocator or when hashdist is
> > set, and which does not need physically contiguous memory. If that
> > fails too, panic as before.
>
> So, AFAIU the gist is here is that page allocator fails, let's fallback to
> vmalloc_huge().
>
> 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.
>
> But there is another question: do we really need physically contiguous
> memory for the hashes we get from alloc_large_system_hash()?
>
> AFAIU, we can just drop the alloc_pages_exact() case and keep memblock for
> HASH_EARLY and vmalloc_huge() for the rest.
>
> Eric, Christian, what do you think?
I think the dentry and inode cache are unchanged by what you suggest.
Tables under 2 mb would get mapped with 4 k pages instead of direct-map
huge pages. That would affect mnt_init() and move it to vmalloc_huge().
Would probably mean a few tlb misses in lookup_mnt()? That needs to be
really really fast on mount crossings. So if this doesn't degrade lookup
performance I don't care that much.