Skip to content

Commit 0d2c4f9

Browse files
Roman GushchinAlexei Starovoitov
authored andcommitted
bpf: Eliminate rlimit-based memory accounting for sockmap and sockhash maps
Do not use rlimit-based memory accounting for sockmap and sockhash maps. It has been replaced with the memcg-based memory accounting. Signed-off-by: Roman Gushchin <guro@fb.com> Signed-off-by: Alexei Starovoitov <ast@kernel.org> Acked-by: Song Liu <songliubraving@fb.com> Link: https://lore.kernel.org/bpf/20201201215900.3569844-29-guro@fb.com
1 parent abbdd08 commit 0d2c4f9

1 file changed

Lines changed: 6 additions & 27 deletions

File tree

‎net/core/sock_map.c‎

Lines changed: 6 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@ struct bpf_stab {
2727
static struct bpf_map *sock_map_alloc(union bpf_attr *attr)
2828
{
2929
struct bpf_stab *stab;
30-
u64 cost;
31-
int err;
3230

3331
if (!capable(CAP_NET_ADMIN))
3432
return ERR_PTR(-EPERM);
@@ -46,22 +44,15 @@ static struct bpf_map *sock_map_alloc(union bpf_attr *attr)
4644
bpf_map_init_from_attr(&stab->map, attr);
4745
raw_spin_lock_init(&stab->lock);
4846

49-
/* Make sure page count doesn't overflow. */
50-
cost = (u64) stab->map.max_entries * sizeof(struct sock *);
51-
err = bpf_map_charge_init(&stab->map.memory, cost);
52-
if (err)
53-
goto free_stab;
54-
5547
stab->sks = bpf_map_area_alloc(stab->map.max_entries *
5648
sizeof(struct sock *),
5749
stab->map.numa_node);
58-
if (stab->sks)
59-
return &stab->map;
60-
err = -ENOMEM;
61-
bpf_map_charge_finish(&stab->map.memory);
62-
free_stab:
63-
kfree(stab);
64-
return ERR_PTR(err);
50+
if (!stab->sks) {
51+
kfree(stab);
52+
return ERR_PTR(-ENOMEM);
53+
}
54+
55+
return &stab->map;
6556
}
6657

6758
int sock_map_get_from_fd(const union bpf_attr *attr, struct bpf_prog *prog)
@@ -1104,7 +1095,6 @@ static struct bpf_map *sock_hash_alloc(union bpf_attr *attr)
11041095
{
11051096
struct bpf_shtab *htab;
11061097
int i, err;
1107-
u64 cost;
11081098

11091099
if (!capable(CAP_NET_ADMIN))
11101100
return ERR_PTR(-EPERM);
@@ -1132,21 +1122,10 @@ static struct bpf_map *sock_hash_alloc(union bpf_attr *attr)
11321122
goto free_htab;
11331123
}
11341124

1135-
cost = (u64) htab->buckets_num * sizeof(struct bpf_shtab_bucket) +
1136-
(u64) htab->elem_size * htab->map.max_entries;
1137-
if (cost >= U32_MAX - PAGE_SIZE) {
1138-
err = -EINVAL;
1139-
goto free_htab;
1140-
}
1141-
err = bpf_map_charge_init(&htab->map.memory, cost);
1142-
if (err)
1143-
goto free_htab;
1144-
11451125
htab->buckets = bpf_map_area_alloc(htab->buckets_num *
11461126
sizeof(struct bpf_shtab_bucket),
11471127
htab->map.numa_node);
11481128
if (!htab->buckets) {
1149-
bpf_map_charge_finish(&htab->map.memory);
11501129
err = -ENOMEM;
11511130
goto free_htab;
11521131
}

0 commit comments

Comments
 (0)