bpf: Add bpf_local_storage_free()
This patch refactors local_storage freeing logic into bpf_local_storage_free(). It is a preparation work for a later patch that uses bpf_mem_cache_alloc/free. The other kfree(local_storage) cases are also changed to bpf_local_storage_free(..., reuse_now = true). Signed-off-by: Martin KaFai Lau <martin.lau@kernel.org> Link: https://lore.kernel.org/r/20230308065936.1550103-12-martin.lau@linux.dev Signed-off-by: Alexei Starovoitov <ast@kernel.org>
This commit is contained in:
parent
1288aaa278
commit
7e30a8477b
@ -114,6 +114,16 @@ static void bpf_local_storage_free_trace_rcu(struct rcu_head *rcu)
|
|||||||
call_rcu(rcu, bpf_local_storage_free_rcu);
|
call_rcu(rcu, bpf_local_storage_free_rcu);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void bpf_local_storage_free(struct bpf_local_storage *local_storage,
|
||||||
|
bool reuse_now)
|
||||||
|
{
|
||||||
|
if (!reuse_now)
|
||||||
|
call_rcu_tasks_trace(&local_storage->rcu,
|
||||||
|
bpf_local_storage_free_trace_rcu);
|
||||||
|
else
|
||||||
|
call_rcu(&local_storage->rcu, bpf_local_storage_free_rcu);
|
||||||
|
}
|
||||||
|
|
||||||
static void bpf_selem_free_rcu(struct rcu_head *rcu)
|
static void bpf_selem_free_rcu(struct rcu_head *rcu)
|
||||||
{
|
{
|
||||||
struct bpf_local_storage_elem *selem;
|
struct bpf_local_storage_elem *selem;
|
||||||
@ -218,13 +228,8 @@ static void bpf_selem_unlink_storage(struct bpf_local_storage_elem *selem,
|
|||||||
local_storage, selem, true, reuse_now);
|
local_storage, selem, true, reuse_now);
|
||||||
raw_spin_unlock_irqrestore(&local_storage->lock, flags);
|
raw_spin_unlock_irqrestore(&local_storage->lock, flags);
|
||||||
|
|
||||||
if (free_local_storage) {
|
if (free_local_storage)
|
||||||
if (!reuse_now)
|
bpf_local_storage_free(local_storage, reuse_now);
|
||||||
call_rcu_tasks_trace(&local_storage->rcu,
|
|
||||||
bpf_local_storage_free_trace_rcu);
|
|
||||||
else
|
|
||||||
call_rcu(&local_storage->rcu, bpf_local_storage_free_rcu);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void bpf_selem_link_storage_nolock(struct bpf_local_storage *local_storage,
|
void bpf_selem_link_storage_nolock(struct bpf_local_storage *local_storage,
|
||||||
@ -391,7 +396,7 @@ int bpf_local_storage_alloc(void *owner,
|
|||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
uncharge:
|
uncharge:
|
||||||
kfree(storage);
|
bpf_local_storage_free(storage, true);
|
||||||
mem_uncharge(smap, owner, sizeof(*storage));
|
mem_uncharge(smap, owner, sizeof(*storage));
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
@ -636,7 +641,7 @@ void bpf_local_storage_destroy(struct bpf_local_storage *local_storage)
|
|||||||
raw_spin_unlock_irqrestore(&local_storage->lock, flags);
|
raw_spin_unlock_irqrestore(&local_storage->lock, flags);
|
||||||
|
|
||||||
if (free_storage)
|
if (free_storage)
|
||||||
call_rcu(&local_storage->rcu, bpf_local_storage_free_rcu);
|
bpf_local_storage_free(local_storage, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
u64 bpf_local_storage_map_mem_usage(const struct bpf_map *map)
|
u64 bpf_local_storage_map_mem_usage(const struct bpf_map *map)
|
||||||
|
Loading…
Reference in New Issue
Block a user