Hi, On 12/4/2023 2:54 AM, Alexei Starovoitov wrote: > 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") ? Yes. I didn't think it thoroughly. Although the max number of bpf program INT_MAX - 1, but the allocation of id happens after the increase of sleepable_refcnt, so the overflow is still possible. Will fix it in v5.