mirror of
https://github.com/torvalds/linux
synced 2024-09-06 18:01:05 +00:00
bpf: Eliminate rlimit-based memory accounting for bpf ringbuffer
Do not use rlimit-based memory accounting for bpf ringbuffer. It has been replaced with the memcg-based memory accounting. bpf_ringbuf_alloc() can't return anything except ERR_PTR(-ENOMEM) and a valid pointer, so to simplify the code make it return NULL in the first case. This allows to drop a couple of lines in ringbuf_map_alloc() and also makes it look similar to other memory allocating function like kmalloc(). Signed-off-by: Roman Gushchin <guro@fb.com> Signed-off-by: Alexei Starovoitov <ast@kernel.org> Acked-by: Song Liu <songliubraving@fb.com> Acked-by: Andrii Nakryiko <andriin@fb.com> Link: https://lore.kernel.org/bpf/20201201215900.3569844-28-guro@fb.com
This commit is contained in:
parent
db54330d3e
commit
abbdd0813f
|
@ -48,7 +48,6 @@ struct bpf_ringbuf {
|
|||
|
||||
struct bpf_ringbuf_map {
|
||||
struct bpf_map map;
|
||||
struct bpf_map_memory memory;
|
||||
struct bpf_ringbuf *rb;
|
||||
};
|
||||
|
||||
|
@ -131,7 +130,7 @@ static struct bpf_ringbuf *bpf_ringbuf_alloc(size_t data_sz, int numa_node)
|
|||
|
||||
rb = bpf_ringbuf_area_alloc(data_sz, numa_node);
|
||||
if (!rb)
|
||||
return ERR_PTR(-ENOMEM);
|
||||
return NULL;
|
||||
|
||||
spin_lock_init(&rb->spinlock);
|
||||
init_waitqueue_head(&rb->waitq);
|
||||
|
@ -147,8 +146,6 @@ static struct bpf_ringbuf *bpf_ringbuf_alloc(size_t data_sz, int numa_node)
|
|||
static struct bpf_map *ringbuf_map_alloc(union bpf_attr *attr)
|
||||
{
|
||||
struct bpf_ringbuf_map *rb_map;
|
||||
u64 cost;
|
||||
int err;
|
||||
|
||||
if (attr->map_flags & ~RINGBUF_CREATE_FLAG_MASK)
|
||||
return ERR_PTR(-EINVAL);
|
||||
|
@ -170,26 +167,13 @@ static struct bpf_map *ringbuf_map_alloc(union bpf_attr *attr)
|
|||
|
||||
bpf_map_init_from_attr(&rb_map->map, attr);
|
||||
|
||||
cost = sizeof(struct bpf_ringbuf_map) +
|
||||
sizeof(struct bpf_ringbuf) +
|
||||
attr->max_entries;
|
||||
err = bpf_map_charge_init(&rb_map->map.memory, cost);
|
||||
if (err)
|
||||
goto err_free_map;
|
||||
|
||||
rb_map->rb = bpf_ringbuf_alloc(attr->max_entries, rb_map->map.numa_node);
|
||||
if (IS_ERR(rb_map->rb)) {
|
||||
err = PTR_ERR(rb_map->rb);
|
||||
goto err_uncharge;
|
||||
if (!rb_map->rb) {
|
||||
kfree(rb_map);
|
||||
return ERR_PTR(-ENOMEM);
|
||||
}
|
||||
|
||||
return &rb_map->map;
|
||||
|
||||
err_uncharge:
|
||||
bpf_map_charge_finish(&rb_map->map.memory);
|
||||
err_free_map:
|
||||
kfree(rb_map);
|
||||
return ERR_PTR(err);
|
||||
}
|
||||
|
||||
static void bpf_ringbuf_free(struct bpf_ringbuf *rb)
|
||||
|
|
Loading…
Reference in a new issue