Hi Amir,
On Tue, Dec 01, 2026 at 07:31:32PM +0000, Amir Hosseini wrote:
>
> From: Amir Hosseini <m…@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.