mirror of
https://github.com/torvalds/linux.git
synced 2024-11-10 22:21:40 +00:00
bpf: Eliminate rlimit-based memory accounting for hashtab maps
Do not use rlimit-based memory accounting for hashtab 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-24-guro@fb.com
This commit is contained in:
parent
844f157f6c
commit
755e5d5536
@ -443,7 +443,6 @@ static struct bpf_map *htab_map_alloc(union bpf_attr *attr)
|
|||||||
bool prealloc = !(attr->map_flags & BPF_F_NO_PREALLOC);
|
bool prealloc = !(attr->map_flags & BPF_F_NO_PREALLOC);
|
||||||
struct bpf_htab *htab;
|
struct bpf_htab *htab;
|
||||||
int err, i;
|
int err, i;
|
||||||
u64 cost;
|
|
||||||
|
|
||||||
htab = kzalloc(sizeof(*htab), GFP_USER | __GFP_ACCOUNT);
|
htab = kzalloc(sizeof(*htab), GFP_USER | __GFP_ACCOUNT);
|
||||||
if (!htab)
|
if (!htab)
|
||||||
@ -481,26 +480,12 @@ static struct bpf_map *htab_map_alloc(union bpf_attr *attr)
|
|||||||
htab->n_buckets > U32_MAX / sizeof(struct bucket))
|
htab->n_buckets > U32_MAX / sizeof(struct bucket))
|
||||||
goto free_htab;
|
goto free_htab;
|
||||||
|
|
||||||
cost = (u64) htab->n_buckets * sizeof(struct bucket) +
|
|
||||||
(u64) htab->elem_size * htab->map.max_entries;
|
|
||||||
|
|
||||||
if (percpu)
|
|
||||||
cost += (u64) round_up(htab->map.value_size, 8) *
|
|
||||||
num_possible_cpus() * htab->map.max_entries;
|
|
||||||
else
|
|
||||||
cost += (u64) htab->elem_size * num_possible_cpus();
|
|
||||||
|
|
||||||
/* if map size is larger than memlock limit, reject it */
|
|
||||||
err = bpf_map_charge_init(&htab->map.memory, cost);
|
|
||||||
if (err)
|
|
||||||
goto free_htab;
|
|
||||||
|
|
||||||
err = -ENOMEM;
|
err = -ENOMEM;
|
||||||
htab->buckets = bpf_map_area_alloc(htab->n_buckets *
|
htab->buckets = bpf_map_area_alloc(htab->n_buckets *
|
||||||
sizeof(struct bucket),
|
sizeof(struct bucket),
|
||||||
htab->map.numa_node);
|
htab->map.numa_node);
|
||||||
if (!htab->buckets)
|
if (!htab->buckets)
|
||||||
goto free_charge;
|
goto free_htab;
|
||||||
|
|
||||||
for (i = 0; i < HASHTAB_MAP_LOCK_COUNT; i++) {
|
for (i = 0; i < HASHTAB_MAP_LOCK_COUNT; i++) {
|
||||||
htab->map_locked[i] = bpf_map_alloc_percpu(&htab->map,
|
htab->map_locked[i] = bpf_map_alloc_percpu(&htab->map,
|
||||||
@ -541,8 +526,6 @@ free_map_locked:
|
|||||||
for (i = 0; i < HASHTAB_MAP_LOCK_COUNT; i++)
|
for (i = 0; i < HASHTAB_MAP_LOCK_COUNT; i++)
|
||||||
free_percpu(htab->map_locked[i]);
|
free_percpu(htab->map_locked[i]);
|
||||||
bpf_map_area_free(htab->buckets);
|
bpf_map_area_free(htab->buckets);
|
||||||
free_charge:
|
|
||||||
bpf_map_charge_finish(&htab->map.memory);
|
|
||||||
free_htab:
|
free_htab:
|
||||||
lockdep_unregister_key(&htab->lockdep_key);
|
lockdep_unregister_key(&htab->lockdep_key);
|
||||||
kfree(htab);
|
kfree(htab);
|
||||||
|
Loading…
Reference in New Issue
Block a user