[Devel] [PATCH RH8] memcg: enable accounting for nft objects
Vasily Averin
vvs at virtuozzo.com
Wed Apr 21 13:34:28 MSK 2021
Patch enables memcg accounting for nft objects.
https://jira.sw.ru/browse/PSBM-128719
Signed-off-by: Vasily Averin <vvs at virtuozzo.com>
---
net/netfilter/nf_tables_api.c | 44 +++++++++++++++++++----------------
1 file changed, 24 insertions(+), 20 deletions(-)
diff --git a/net/netfilter/nf_tables_api.c b/net/netfilter/nf_tables_api.c
index 935790a08b1d..7bdc9e39ded6 100644
--- a/net/netfilter/nf_tables_api.c
+++ b/net/netfilter/nf_tables_api.c
@@ -113,7 +113,7 @@ static struct nft_trans *nft_trans_alloc_gfp(const struct nft_ctx *ctx,
{
struct nft_trans *trans;
- trans = kzalloc(sizeof(struct nft_trans) + size, gfp);
+ trans = kzalloc(sizeof(struct nft_trans) + size, gfp | __GFP_ACCOUNT);
if (trans == NULL)
return NULL;
@@ -964,6 +964,7 @@ static int nf_tables_newtable(struct net *net, struct sock *nlsk,
struct nft_table *table;
u32 flags = 0;
struct nft_ctx ctx;
+ gfp_t gfp = GFP_KERNEL_ACCOUNT;
int err;
lockdep_assert_held(&net->nft_commit_mutex);
@@ -991,11 +992,11 @@ static int nf_tables_newtable(struct net *net, struct sock *nlsk,
}
err = -ENOMEM;
- table = kzalloc(sizeof(*table), GFP_KERNEL);
+ table = kzalloc(sizeof(*table), gfp);
if (table == NULL)
goto err_kzalloc;
- table->name = nla_strdup(attr, GFP_KERNEL);
+ table->name = nla_strdup(attr, gfp);
if (table->name == NULL)
goto err_strdup;
@@ -1646,7 +1647,7 @@ static struct nft_hook *nft_netdev_hook_alloc(struct net *net,
struct nft_hook *hook;
int err;
- hook = kmalloc(sizeof(struct nft_hook), GFP_KERNEL);
+ hook = kmalloc(sizeof(struct nft_hook), GFP_KERNEL_ACCOUNT);
if (!hook) {
err = -ENOMEM;
goto err_hook_alloc;
@@ -1849,7 +1850,7 @@ static struct nft_rule **nf_tables_chain_alloc_rules(const struct nft_chain *cha
alloc *= sizeof(struct nft_rule *);
alloc += sizeof(struct nft_rules_old);
- return kvmalloc(alloc, GFP_KERNEL);
+ return kvmalloc(alloc, GFP_KERNEL_ACCOUNT);
}
static void nft_basechain_hook_init(struct nf_hook_ops *ops, u8 family,
@@ -1906,6 +1907,7 @@ static int nf_tables_addchain(struct nft_ctx *ctx, u8 family, u8 genmask,
struct nft_trans *trans;
struct nft_chain *chain;
struct nft_rule **rules;
+ gfp_t gfp = GFP_KERNEL_ACCOUNT;
int err;
if (table->use == UINT_MAX)
@@ -1918,7 +1920,7 @@ static int nf_tables_addchain(struct nft_ctx *ctx, u8 family, u8 genmask,
if (err < 0)
return err;
- basechain = kzalloc(sizeof(*basechain), GFP_KERNEL);
+ basechain = kzalloc(sizeof(*basechain), gfp);
if (basechain == NULL) {
nft_chain_release_hook(&hook);
return -ENOMEM;
@@ -1943,7 +1945,7 @@ static int nf_tables_addchain(struct nft_ctx *ctx, u8 family, u8 genmask,
return err;
}
} else {
- chain = kzalloc(sizeof(*chain), GFP_KERNEL);
+ chain = kzalloc(sizeof(*chain), gfp);
if (chain == NULL)
return -ENOMEM;
}
@@ -1952,7 +1954,7 @@ static int nf_tables_addchain(struct nft_ctx *ctx, u8 family, u8 genmask,
INIT_LIST_HEAD(&chain->rules);
chain->handle = nf_tables_alloc_handle(table);
chain->table = table;
- chain->name = nla_strdup(nla[NFTA_CHAIN_NAME], GFP_KERNEL);
+ chain->name = nla_strdup(nla[NFTA_CHAIN_NAME], gfp);
if (!chain->name) {
err = -ENOMEM;
goto err1;
@@ -2107,7 +2109,7 @@ static int nf_tables_updchain(struct nft_ctx *ctx, u8 genmask, u8 policy,
char *name;
err = -ENOMEM;
- name = nla_strdup(nla[NFTA_CHAIN_NAME], GFP_KERNEL);
+ name = nla_strdup(nla[NFTA_CHAIN_NAME], GFP_KERNEL_ACCOUNT);
if (!name)
goto err;
@@ -2524,7 +2526,7 @@ struct nft_expr *nft_expr_init(const struct nft_ctx *ctx,
goto err1;
err = -ENOMEM;
- expr = kzalloc(info.ops->size, GFP_KERNEL);
+ expr = kzalloc(info.ops->size, GFP_KERNEL_ACCOUNT);
if (expr == NULL)
goto err2;
@@ -3080,7 +3082,7 @@ static int nf_tables_newrule(struct net *net, struct sock *nlsk,
}
err = -ENOMEM;
- rule = kzalloc(sizeof(*rule) + size + usize, GFP_KERNEL);
+ rule = kzalloc(sizeof(*rule) + size + usize, GFP_KERNEL_ACCOUNT);
if (rule == NULL)
goto err1;
@@ -3517,7 +3519,7 @@ static int nf_tables_set_alloc_name(struct nft_ctx *ctx, struct nft_set *set,
free_page((unsigned long)inuse);
}
- set->name = kasprintf(GFP_KERNEL, name, min + n);
+ set->name = kasprintf(GFP_KERNEL_ACCOUNT, name, min + n);
if (!set->name)
return -ENOMEM;
@@ -3911,6 +3913,7 @@ static int nf_tables_newset(struct net *net, struct sock *nlsk,
struct nft_set_desc desc;
unsigned char *udata;
u16 udlen;
+ gfp_t gfp = GFP_KERNEL_ACCOUNT;
int err;
int i;
@@ -4050,13 +4053,13 @@ static int nf_tables_newset(struct net *net, struct sock *nlsk,
if (ops->privsize != NULL)
size = ops->privsize(nla, &desc);
- set = kvzalloc(sizeof(*set) + size + udlen, GFP_KERNEL);
+ set = kvzalloc(sizeof(*set) + size + udlen, gfp);
if (!set) {
err = -ENOMEM;
goto err1;
}
- name = nla_strdup(nla[NFTA_SET_NAME], GFP_KERNEL);
+ name = nla_strdup(nla[NFTA_SET_NAME], gfp);
if (!name) {
err = -ENOMEM;
goto err2;
@@ -4991,7 +4994,7 @@ static int nft_add_set_elem(struct nft_ctx *ctx, struct nft_set *set,
err = -ENOMEM;
elem.priv = nft_set_elem_init(set, &tmpl, elem.key.val.data,
elem.key_end.val.data, data.data,
- timeout, GFP_KERNEL);
+ timeout, GFP_KERNEL_ACCOUNT);
if (elem.priv == NULL)
goto err_parse_data;
@@ -5199,7 +5202,7 @@ static int nft_del_setelem(struct nft_ctx *ctx, struct nft_set *set,
err = -ENOMEM;
elem.priv = nft_set_elem_init(set, &tmpl, elem.key.val.data,
elem.key_end.val.data, NULL, 0,
- GFP_KERNEL);
+ GFP_KERNEL_ACCOUNT);
if (elem.priv == NULL)
goto fail_elem;
@@ -5460,7 +5463,7 @@ static struct nft_object *nft_obj_init(const struct nft_ctx *ctx,
}
err = -ENOMEM;
- obj = kzalloc(sizeof(*obj) + ops->size, GFP_KERNEL);
+ obj = kzalloc(sizeof(*obj) + ops->size, GFP_KERNEL_ACCOUNT);
if (!obj)
goto err2;
@@ -5583,7 +5586,7 @@ static int nf_tables_newobj(struct net *net, struct sock *nlsk,
obj->key.table = table;
obj->handle = nf_tables_alloc_handle(table);
- obj->key.name = nla_strdup(nla[NFTA_OBJ_NAME], GFP_KERNEL);
+ obj->key.name = nla_strdup(nla[NFTA_OBJ_NAME], GFP_KERNEL_ACCOUNT);
if (!obj->key.name) {
err = -ENOMEM;
goto err2;
@@ -6130,6 +6133,7 @@ static int nf_tables_newflowtable(struct net *net, struct sock *nlsk,
struct nft_hook *hook, *next;
struct nft_table *table;
struct nft_ctx ctx;
+ gfp_t gfp = GFP_KERNEL_ACCOUNT;
int err;
if (!nla[NFTA_FLOWTABLE_TABLE] ||
@@ -6163,7 +6167,7 @@ static int nf_tables_newflowtable(struct net *net, struct sock *nlsk,
nft_ctx_init(&ctx, net, skb, nlh, family, table, NULL, nla);
- flowtable = kzalloc(sizeof(*flowtable), GFP_KERNEL);
+ flowtable = kzalloc(sizeof(*flowtable), gfp);
if (!flowtable)
return -ENOMEM;
@@ -6171,7 +6175,7 @@ static int nf_tables_newflowtable(struct net *net, struct sock *nlsk,
flowtable->handle = nf_tables_alloc_handle(table);
INIT_LIST_HEAD(&flowtable->hook_list);
- flowtable->name = nla_strdup(nla[NFTA_FLOWTABLE_NAME], GFP_KERNEL);
+ flowtable->name = nla_strdup(nla[NFTA_FLOWTABLE_NAME], gfp);
if (!flowtable->name) {
err = -ENOMEM;
goto err1;
--
2.25.1
More information about the Devel
mailing list