Re: [PATCH bpf-next] bpf: increase supported cgroup storage value size

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 07/23, Martin KaFai Lau wrote:
On Thu, Jul 22, 2021 at 05:27:47PM -0700, Stanislav Fomichev wrote:
> Current max cgroup storage value size is 4k (PAGE_SIZE). The other local
> storages accept up to 64k (BPF_LOCAL_STORAGE_MAX_VALUE_SIZE). Let's align
> max cgroup value size with the other storages.
>
> For percpu, the max is 32k (PCPU_MIN_UNIT_SIZE) because percpu
> allocator is not happy about larger values.
>
> netcnt test is extended to exercise those maximum values
> (non-percpu max size is close to, but not real max).
>
> Signed-off-by: Stanislav Fomichev <sdf@xxxxxxxxxx>
> ---
>  kernel/bpf/local_storage.c                    | 12 +++++-
>  tools/testing/selftests/bpf/netcnt_common.h   | 38 +++++++++++++++----
>  .../testing/selftests/bpf/progs/netcnt_prog.c | 29 +++++++-------
>  tools/testing/selftests/bpf/test_netcnt.c     | 25 +++++++-----
>  4 files changed, 73 insertions(+), 31 deletions(-)
>
> diff --git a/kernel/bpf/local_storage.c b/kernel/bpf/local_storage.c
> index 7ed2a14dc0de..a276da74c20a 100644
> --- a/kernel/bpf/local_storage.c
> +++ b/kernel/bpf/local_storage.c
> @@ -1,6 +1,7 @@
>  //SPDX-License-Identifier: GPL-2.0
>  #include <linux/bpf-cgroup.h>
>  #include <linux/bpf.h>
> +#include <linux/bpf_local_storage.h>
>  #include <linux/btf.h>
>  #include <linux/bug.h>
>  #include <linux/filter.h>
> @@ -284,8 +285,17 @@ static int cgroup_storage_get_next_key(struct bpf_map *_map, void *key,
>  static struct bpf_map *cgroup_storage_map_alloc(union bpf_attr *attr)
>  {
>  	int numa_node = bpf_map_attr_numa_node(attr);
> +	__u32 max_value_size = PCPU_MIN_UNIT_SIZE;
>  	struct bpf_cgroup_storage_map *map;
>
> +	/* percpu is bound by PCPU_MIN_UNIT_SIZE, non-percu
> +	 * is the same as other local storages.
> +	 */
> +	if (attr->map_type == BPF_MAP_TYPE_CGROUP_STORAGE)
> +		max_value_size = BPF_LOCAL_STORAGE_MAX_VALUE_SIZE;
> +
> +	BUILD_BUG_ON(PCPU_MIN_UNIT_SIZE > BPF_LOCAL_STORAGE_MAX_VALUE_SIZE);
If PCPU_MIN_UNIT_SIZE did become larger, I assume it would be bounded by
BPF_LOCAL_STORAGE_MAX_VALUE_SIZE again?

Instead of BUILD_BUG_ON, how about a min_t here:

	if (attr->map_type == BPF_MAP_TYPE_PERCPU_CGROUP_STORAGE)
		max_value_size = min_t(__u32,
					BPF_LOCAL_STORAGE_MAX_VALUE_SIZE,
					PCPU_MIN_UNIT_SIZE);

Sounds like a much better idea, thanks, will incorporate into v2.



[Index of Archives]     [Linux Samsung SoC]     [Linux Rockchip SoC]     [Linux Actions SoC]     [Linux for Synopsys ARC Processors]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]


  Powered by Linux