Skip to content

Commit b08040d

Browse files
rgushchinkernel-patches-bot
authored andcommitted
bpf: eliminate rlimit-based memory accounting infra for bpf maps
Remove rlimit-based accounting infrastructure code, which is not used anymore. Signed-off-by: Roman Gushchin <guro@fb.com> Acked-by: Song Liu <songliubraving@fb.com>
1 parent a5fcf2a commit b08040d

File tree

4 files changed

+3
-82
lines changed

4 files changed

+3
-82
lines changed

include/linux/bpf.h

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -136,11 +136,6 @@ struct bpf_map_ops {
136136
const struct bpf_iter_seq_info *iter_seq_info;
137137
};
138138

139-
struct bpf_map_memory {
140-
u32 pages;
141-
struct user_struct *user;
142-
};
143-
144139
struct bpf_map {
145140
/* The first two cachelines with read-mostly members of which some
146141
* are also accessed in fast-path (e.g. ops, max_entries).
@@ -161,7 +156,6 @@ struct bpf_map {
161156
u32 btf_key_type_id;
162157
u32 btf_value_type_id;
163158
struct btf *btf;
164-
struct bpf_map_memory memory;
165159
#ifdef CONFIG_MEMCG_KMEM
166160
struct mem_cgroup *memcg;
167161
#endif
@@ -1222,12 +1216,6 @@ void bpf_map_inc_with_uref(struct bpf_map *map);
12221216
struct bpf_map * __must_check bpf_map_inc_not_zero(struct bpf_map *map);
12231217
void bpf_map_put_with_uref(struct bpf_map *map);
12241218
void bpf_map_put(struct bpf_map *map);
1225-
int bpf_map_charge_memlock(struct bpf_map *map, u32 pages);
1226-
void bpf_map_uncharge_memlock(struct bpf_map *map, u32 pages);
1227-
int bpf_map_charge_init(struct bpf_map_memory *mem, u64 size);
1228-
void bpf_map_charge_finish(struct bpf_map_memory *mem);
1229-
void bpf_map_charge_move(struct bpf_map_memory *dst,
1230-
struct bpf_map_memory *src);
12311219
void *bpf_map_area_alloc(u64 size, int numa_node);
12321220
void *bpf_map_area_mmapable_alloc(u64 size, int numa_node);
12331221
void bpf_map_area_free(void *base);

kernel/bpf/syscall.c

Lines changed: 2 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -359,60 +359,6 @@ static void bpf_uncharge_memlock(struct user_struct *user, u32 pages)
359359
atomic_long_sub(pages, &user->locked_vm);
360360
}
361361

362-
int bpf_map_charge_init(struct bpf_map_memory *mem, u64 size)
363-
{
364-
u32 pages = round_up(size, PAGE_SIZE) >> PAGE_SHIFT;
365-
struct user_struct *user;
366-
int ret;
367-
368-
if (size >= U32_MAX - PAGE_SIZE)
369-
return -E2BIG;
370-
371-
user = get_current_user();
372-
ret = bpf_charge_memlock(user, pages);
373-
if (ret) {
374-
free_uid(user);
375-
return ret;
376-
}
377-
378-
mem->pages = pages;
379-
mem->user = user;
380-
381-
return 0;
382-
}
383-
384-
void bpf_map_charge_finish(struct bpf_map_memory *mem)
385-
{
386-
bpf_uncharge_memlock(mem->user, mem->pages);
387-
free_uid(mem->user);
388-
}
389-
390-
void bpf_map_charge_move(struct bpf_map_memory *dst,
391-
struct bpf_map_memory *src)
392-
{
393-
*dst = *src;
394-
395-
/* Make sure src will not be used for the redundant uncharging. */
396-
memset(src, 0, sizeof(struct bpf_map_memory));
397-
}
398-
399-
int bpf_map_charge_memlock(struct bpf_map *map, u32 pages)
400-
{
401-
int ret;
402-
403-
ret = bpf_charge_memlock(map->memory.user, pages);
404-
if (ret)
405-
return ret;
406-
map->memory.pages += pages;
407-
return ret;
408-
}
409-
410-
void bpf_map_uncharge_memlock(struct bpf_map *map, u32 pages)
411-
{
412-
bpf_uncharge_memlock(map->memory.user, pages);
413-
map->memory.pages -= pages;
414-
}
415-
416362
static int bpf_map_alloc_id(struct bpf_map *map)
417363
{
418364
int id;
@@ -482,14 +428,11 @@ static void bpf_map_release_memcg(struct bpf_map *map)
482428
static void bpf_map_free_deferred(struct work_struct *work)
483429
{
484430
struct bpf_map *map = container_of(work, struct bpf_map, work);
485-
struct bpf_map_memory mem;
486431

487-
bpf_map_charge_move(&mem, &map->memory);
488432
security_bpf_map_free(map);
489433
bpf_map_release_memcg(map);
490434
/* implementation dependent freeing */
491435
map->ops->map_free(map);
492-
bpf_map_charge_finish(&mem);
493436
}
494437

495438
static void bpf_map_put_uref(struct bpf_map *map)
@@ -568,15 +511,15 @@ static void bpf_map_show_fdinfo(struct seq_file *m, struct file *filp)
568511
"value_size:\t%u\n"
569512
"max_entries:\t%u\n"
570513
"map_flags:\t%#x\n"
571-
"memlock:\t%llu\n"
514+
"memlock:\t%llu\n" /* deprecated */
572515
"map_id:\t%u\n"
573516
"frozen:\t%u\n",
574517
map->map_type,
575518
map->key_size,
576519
map->value_size,
577520
map->max_entries,
578521
map->map_flags,
579-
map->memory.pages * 1ULL << PAGE_SHIFT,
522+
0LLU,
580523
map->id,
581524
READ_ONCE(map->frozen));
582525
if (type) {
@@ -819,7 +762,6 @@ static int map_check_btf(struct bpf_map *map, const struct btf *btf,
819762
static int map_create(union bpf_attr *attr)
820763
{
821764
int numa_node = bpf_map_attr_numa_node(attr);
822-
struct bpf_map_memory mem;
823765
struct bpf_map *map;
824766
int f_flags;
825767
int err;
@@ -918,9 +860,7 @@ static int map_create(union bpf_attr *attr)
918860
security_bpf_map_free(map);
919861
free_map:
920862
btf_put(map->btf);
921-
bpf_map_charge_move(&mem, &map->memory);
922863
map->ops->map_free(map);
923-
bpf_map_charge_finish(&mem);
924864
return err;
925865
}
926866

tools/testing/selftests/bpf/progs/bpf_iter_bpf_map.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,6 @@ int dump_bpf_map(struct bpf_iter__bpf_map *ctx)
2323

2424
BPF_SEQ_PRINTF(seq, "%8u %8ld %8ld %10lu\n", map->id, map->refcnt.counter,
2525
map->usercnt.counter,
26-
map->memory.user->locked_vm.counter);
26+
0LLU);
2727
return 0;
2828
}

tools/testing/selftests/bpf/progs/map_ptr_kern.c

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,12 @@ __u32 g_line = 0;
2626
return 0; \
2727
})
2828

29-
struct bpf_map_memory {
30-
__u32 pages;
31-
} __attribute__((preserve_access_index));
32-
3329
struct bpf_map {
3430
enum bpf_map_type map_type;
3531
__u32 key_size;
3632
__u32 value_size;
3733
__u32 max_entries;
3834
__u32 id;
39-
struct bpf_map_memory memory;
4035
} __attribute__((preserve_access_index));
4136

4237
static inline int check_bpf_map_fields(struct bpf_map *map, __u32 key_size,
@@ -47,7 +42,6 @@ static inline int check_bpf_map_fields(struct bpf_map *map, __u32 key_size,
4742
VERIFY(map->value_size == value_size);
4843
VERIFY(map->max_entries == max_entries);
4944
VERIFY(map->id > 0);
50-
VERIFY(map->memory.pages > 0);
5145

5246
return 1;
5347
}
@@ -60,7 +54,6 @@ static inline int check_bpf_map_ptr(struct bpf_map *indirect,
6054
VERIFY(indirect->value_size == direct->value_size);
6155
VERIFY(indirect->max_entries == direct->max_entries);
6256
VERIFY(indirect->id == direct->id);
63-
VERIFY(indirect->memory.pages == direct->memory.pages);
6457

6558
return 1;
6659
}

0 commit comments

Comments
 (0)