Skip to content

Commit abbdd08

Browse files
Roman GushchinAlexei Starovoitov
authored andcommitted
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
1 parent db54330 commit abbdd08

1 file changed

Lines changed: 4 additions & 20 deletions

File tree

‎kernel/bpf/ringbuf.c‎

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ struct bpf_ringbuf {
4848

4949
struct bpf_ringbuf_map {
5050
struct bpf_map map;
51-
struct bpf_map_memory memory;
5251
struct bpf_ringbuf *rb;
5352
};
5453

@@ -131,7 +130,7 @@ static struct bpf_ringbuf *bpf_ringbuf_alloc(size_t data_sz, int numa_node)
131130

132131
rb = bpf_ringbuf_area_alloc(data_sz, numa_node);
133132
if (!rb)
134-
return ERR_PTR(-ENOMEM);
133+
return NULL;
135134

136135
spin_lock_init(&rb->spinlock);
137136
init_waitqueue_head(&rb->waitq);
@@ -147,8 +146,6 @@ static struct bpf_ringbuf *bpf_ringbuf_alloc(size_t data_sz, int numa_node)
147146
static struct bpf_map *ringbuf_map_alloc(union bpf_attr *attr)
148147
{
149148
struct bpf_ringbuf_map *rb_map;
150-
u64 cost;
151-
int err;
152149

153150
if (attr->map_flags & ~RINGBUF_CREATE_FLAG_MASK)
154151
return ERR_PTR(-EINVAL);
@@ -170,26 +167,13 @@ static struct bpf_map *ringbuf_map_alloc(union bpf_attr *attr)
170167

171168
bpf_map_init_from_attr(&rb_map->map, attr);
172169

173-
cost = sizeof(struct bpf_ringbuf_map) +
174-
sizeof(struct bpf_ringbuf) +
175-
attr->max_entries;
176-
err = bpf_map_charge_init(&rb_map->map.memory, cost);
177-
if (err)
178-
goto err_free_map;
179-
180170
rb_map->rb = bpf_ringbuf_alloc(attr->max_entries, rb_map->map.numa_node);
181-
if (IS_ERR(rb_map->rb)) {
182-
err = PTR_ERR(rb_map->rb);
183-
goto err_uncharge;
171+
if (!rb_map->rb) {
172+
kfree(rb_map);
173+
return ERR_PTR(-ENOMEM);
184174
}
185175

186176
return &rb_map->map;
187-
188-
err_uncharge:
189-
bpf_map_charge_finish(&rb_map->map.memory);
190-
err_free_map:
191-
kfree(rb_map);
192-
return ERR_PTR(err);
193177
}
194178

195179
static void bpf_ringbuf_free(struct bpf_ringbuf *rb)

0 commit comments

Comments
 (0)