From: Pablo Neira Ayuso <pablo@netfilter.org>
To: Liping Zhang <zlpnobody@gmail.com>
Cc: Netfilter Developer Mailing List <netfilter-devel@vger.kernel.org>
Subject: Re: [PATCH nf-next 7/9] netfilter: nf_tables: allow large allocations for new sets
Date: Fri, 26 May 2017 12:18:29 +0200 [thread overview]
Message-ID: <20170526101829.GA2274@salvia> (raw)
In-Reply-To: <CAML_gOcajZUmbsFb56BFwAFe-hje-jT3nvF3A99JOg9khTMMdA@mail.gmail.com>
[-- Attachment #1: Type: text/plain, Size: 701 bytes --]
On Fri, May 26, 2017 at 06:02:34PM +0800, Liping Zhang wrote:
> Hi Pablo,
>
> 2017-05-24 17:50 GMT+08:00 Pablo Neira Ayuso <pablo@netfilter.org>:
> [...]
> > - err = -ENOMEM;
> > - set = kzalloc(sizeof(*set) + size + udlen, GFP_KERNEL);
> > + alloc_size = sizeof(*set) + size + udlen;
> > + if (alloc_size <= (PAGE_SIZE << PAGE_ALLOC_COSTLY_ORDER))
> > + set = kzalloc(alloc_size, GFP_KERNEL | __GFP_NOWARN |
> > + __GFP_NORETRY);
> > if (set == NULL)
> > + set = vzalloc(alloc_size);
>
> I think maybe we can use "set = kvzalloc(alloc_size, GFP_KERNEL);" to simplify
> the above codes.
Like this?
[-- Attachment #2: x.patch --]
[-- Type: text/x-diff, Size: 1240 bytes --]
diff --git a/net/netfilter/nf_tables_api.c b/net/netfilter/nf_tables_api.c
index 0e54090caa8a..bd4fc8b2cd77 100644
--- a/net/netfilter/nf_tables_api.c
+++ b/net/netfilter/nf_tables_api.c
@@ -2910,7 +2910,6 @@ static int nf_tables_newset(struct net *net, struct sock *nlsk,
{
const struct nfgenmsg *nfmsg = nlmsg_data(nlh);
u8 genmask = nft_genmask_next(net);
- unsigned int size, alloc_size;
const struct nft_set_ops *ops;
struct nft_af_info *afi;
struct nft_table *table;
@@ -2922,6 +2921,7 @@ static int nf_tables_newset(struct net *net, struct sock *nlsk,
u32 ktype, dtype, flags, policy, gc_int, objtype;
struct nft_set_desc desc;
unsigned char *udata;
+ unsigned int size;
u16 udlen;
int err;
@@ -3057,13 +3057,8 @@ static int nf_tables_newset(struct net *net, struct sock *nlsk,
if (ops->privsize != NULL)
size = ops->privsize(nla, &desc);
- alloc_size = sizeof(*set) + size + udlen;
- if (alloc_size <= (PAGE_SIZE << PAGE_ALLOC_COSTLY_ORDER))
- set = kzalloc(alloc_size, GFP_KERNEL | __GFP_NOWARN |
- __GFP_NORETRY);
- if (set == NULL)
- set = vzalloc(alloc_size);
- if (set == NULL) {
+ set = kvzalloc(sizeof(*set) + size + udlen, GFP_KERNEL);
+ if (!set) {
err = -ENOMEM;
goto err1;
}
next prev parent reply other threads:[~2017-05-26 10:18 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-05-24 9:50 [PATCH nf-next 0/9] nf_tables set updates Pablo Neira Ayuso
2017-05-24 9:50 ` [PATCH nf-next 1/9] netfilter: nft_set_hash: unnecessary forward declaration Pablo Neira Ayuso
2017-05-24 9:50 ` [PATCH nf-next 2/9] netfilter: nf_tables: no size estimation if number of set elements is unknown Pablo Neira Ayuso
2017-05-24 9:50 ` [PATCH nf-next 3/9] netfilter: nft_set_hash: use nft_rhash prefix for resizable set backend Pablo Neira Ayuso
2017-05-24 9:50 ` [PATCH nf-next 4/9] netfilter: nf_tables: select set backend flavour depending on description Pablo Neira Ayuso
2017-05-24 9:50 ` [PATCH nf-next 5/9] netfilter: nf_tables: pass set description to ->privsize Pablo Neira Ayuso
2017-05-24 9:50 ` [PATCH nf-next 6/9] netfilter: nft_set_hash: add nft_hash_buckets() Pablo Neira Ayuso
2017-05-24 9:50 ` [PATCH nf-next 7/9] netfilter: nf_tables: allow large allocations for new sets Pablo Neira Ayuso
2017-05-26 10:02 ` Liping Zhang
2017-05-26 10:18 ` Pablo Neira Ayuso [this message]
2017-05-26 10:33 ` Liping Zhang
2017-05-24 9:50 ` [PATCH nf-next 8/9] netfilter: nft_set_hash: add non-resizable hashtable implementation Pablo Neira Ayuso
2017-05-24 10:14 ` Pablo Neira Ayuso
2017-05-24 9:50 ` [PATCH nf-next 9/9] netfilter: nft_set_hash: add lookup variant for fixed size hashtable Pablo Neira Ayuso
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=20170526101829.GA2274@salvia \
--to=pablo@netfilter.org \
--cc=netfilter-devel@vger.kernel.org \
--cc=zlpnobody@gmail.com \
/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).