Re: [PATCH 1/3] netfilter/x_tables: go back to using vmalloc for xt_table_info
From: Daniil Tatianin
Date: Tue Sep 23 2025 - 08:04:55 EST
On 9/23/25 2:36 PM, Florian Westphal wrote:
Daniil Tatianin <d-tatianin@xxxxxxxxxxxxxx> wrote:
I agree with Eric. There is nothing special in xtables compared toOn Mon, Sep 22, 2025 at 12:48 PM Daniil Tatianin
<d-tatianin@xxxxxxxxxxxxxx> wrote:
This code previously always used vmalloc for anything aboveThis would hint at an issue with kvmalloc(), why not fixing it, instead
PAGE_ALLOC_COSTLY_ORDER, but this logic was changed in
commit eacd86ca3b036 ("net/netfilter/x_tables.c: use kvmalloc() in xt_alloc_table_info()").
The commit that changed it did so because "xt_alloc_table_info()
basically opencodes kvmalloc()", which is not actually what it was
doing. kvmalloc() does not attempt to go directly to vmalloc if the
order the caller is trying to allocate is "expensive", instead it only
uses vmalloc as a fallback in case the buddy allocator is not able to
fullfill the request.
The difference between the two is actually huge in case the system is
under memory pressure and has no free pages of a large order. Before the
change to kvmalloc we wouldn't even try going to the buddy allocator for
large orders, but now we would force it to try to find a page of the
required order by waking up kswapd/kcompactd and dropping reclaimable memory
for no reason at all to satisfy our huge order allocation that could easily
exist within vmalloc'ed memory instead.
of trying to fix all its users ?
kvmalloc usage elsewhere in the stack. Why "fix" xtables and not e.g.
rhashtable?
Please work with mm hackers to improve the situation for your use case.
Maybe its enough to raise __GFP_NORETRY in kmalloc_gfp_adjust() if size
results in >= PAGE_ALLOC_COSTLY_ORDER allocation.
Thanks for your reply! Perhaps this is the way to go, although this might have
much broader implications since there are tons of other callers to take into account.
I'm not sure whether rhashtable's size also directly depends on user input, I was only
aware of x_table since this is the case we ran into specifically.
Thanks for the quick reply! From my understanding, there is a lot ofHow can that work? kvmalloc won't make vmalloc backed memory
callers of kvmalloc
who do indeed benefit from the physical memory being contiguous, because
it is then
used for hardware DMA etc., so I'm not sure that would be feasible.
physically contiguous.
The allocated physical memory won't be contiguous only for fallback cases (which should be rare),
I assume in that case the hardware operation may end up being more expensive with larger scatter-gather
lists etc. So most of the time such code can take optimized paths for fully contiguous memory. This is not
the case for x_tables etc.