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.