On Thu, Nov 30, 2023 at 10:01:18PM +0800, Hou Tao wrote: > From: Hou Tao <houtao1@xxxxxxxxxx> > > When removing the inner map from the outer map, the inner map will be > freed after one RCU grace period and one RCU tasks trace grace > period, so it is certain that the bpf program, which may access the > inner map, has exited before the inner map is freed. > > However there is no need to wait for one RCU tasks trace grace period if > the outer map is only accessed by non-sleepable program. So adding > sleepable_refcnt in bpf_map and increasing sleepable_refcnt when adding > the outer map into env->used_maps for sleepable program. Considering the > max number of bpf program is INT_MAX - 1, atomic_t instead of atomic64_t > is used for sleepable_refcnt. When removing the inner map from the outer > map, using sleepable_refcnt to decide whether or not a RCU tasks trace > grace period is needed before freeing the inner map. Optimizing too soon as usual? I bet you saw that we use: atomic64_t refcnt for bpf_map, but you probably didn't dig into git history and missed commit 92117d8443bc ("bpf: fix refcnt overflow") ?