netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Eric Dumazet <eric.dumazet@gmail.com>
To: Li RongQing <lirongqing@baidu.com>,
	netdev@vger.kernel.org, pablo@netfilter.org,
	kadlec@blackhole.kfki.hu, fw@strlen.de,
	netfilter-devel@vger.kernel.org, coreteam@netfilter.org,
	edumazet@google.com
Subject: Re: [PATCH][v2] netfilter: use kvzalloc to allocate memory for hashtable
Date: Tue, 24 Jul 2018 22:44:37 -0700	[thread overview]
Message-ID: <c86c7a1d-863d-229c-0383-c2e50aa6c5a2@gmail.com> (raw)
In-Reply-To: <1532496894-17200-1-git-send-email-lirongqing@baidu.com>



On 07/24/2018 10:34 PM, Li RongQing wrote:
> nf_ct_alloc_hashtable is used to allocate memory for conntrack,
> NAT bysrc and expectation hashtable. Assuming 64k bucket size,
> which means 7th order page allocation, __get_free_pages, called
> by nf_ct_alloc_hashtable, will trigger the direct memory reclaim
> and stall for a long time, when system has lots of memory stress

...

>  	sz = nr_slots * sizeof(struct hlist_nulls_head);
> -	hash = (void *)__get_free_pages(GFP_KERNEL | __GFP_NOWARN | __GFP_ZERO,
> -					get_order(sz));
> -	if (!hash)
> -		hash = vzalloc(sz);
> +	hash = kvzalloc(sz, GFP_KERNEL);


You could remove the @sz computation and call 

hash = kvcalloc(nr_slots, sizeof(struct hlist_nulls_head), GFP_KERNEL);

Thanks to kvmalloc_array() check, you also could remove the :

if (nr_slots > (UINT_MAX / sizeof(struct hlist_nulls_head)))
    return NULL;

That would remove a lot of stuff now we have proper helpers.

  reply	other threads:[~2018-07-25  6:54 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-07-25  5:34 [PATCH][v2] netfilter: use kvzalloc to allocate memory for hashtable Li RongQing
2018-07-25  5:44 ` Eric Dumazet [this message]
2018-07-25  5:49   ` 答复: " Li,Rongqing

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=c86c7a1d-863d-229c-0383-c2e50aa6c5a2@gmail.com \
    --to=eric.dumazet@gmail.com \
    --cc=coreteam@netfilter.org \
    --cc=edumazet@google.com \
    --cc=fw@strlen.de \
    --cc=kadlec@blackhole.kfki.hu \
    --cc=lirongqing@baidu.com \
    --cc=netdev@vger.kernel.org \
    --cc=netfilter-devel@vger.kernel.org \
    --cc=pablo@netfilter.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).