BPF Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH] bpf: Avoid allocing memory on memoryless numa node
@ 2020-10-10  8:44 Xianting Tian
  2020-10-12  1:21 ` Alexei Starovoitov
  0 siblings, 1 reply; 3+ messages in thread
From: Xianting Tian @ 2020-10-10  8:44 UTC (permalink / raw)
  To: ast, daniel, davem, kuba, hawk, john.fastabend, kafai,
	songliubraving, yhs, andriin, kpsingh
  Cc: netdev, bpf, linux-kernel, Xianting Tian

In architecture like powerpc, we can have cpus without any local memory
attached to it. In such cases the node does not have real memory.

Use local_memory_node(), which is guaranteed to have memory.
local_memory_node is a noop in other architectures that does not support
memoryless nodes.

Signed-off-by: Xianting Tian <tian.xianting@h3c.com>
---
 kernel/bpf/cpumap.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/kernel/bpf/cpumap.c b/kernel/bpf/cpumap.c
index 6386b7bb9..2c885c00a 100644
--- a/kernel/bpf/cpumap.c
+++ b/kernel/bpf/cpumap.c
@@ -423,7 +423,7 @@ __cpu_map_entry_alloc(struct bpf_cpumap_val *value, u32 cpu, int map_id)
 	struct xdp_bulk_queue *bq;
 
 	/* Have map->numa_node, but choose node of redirect target CPU */
-	numa = cpu_to_node(cpu);
+	numa = local_memory_node(cpu_to_node(cpu));
 
 	rcpu = kzalloc_node(sizeof(*rcpu), gfp, numa);
 	if (!rcpu)
-- 
2.17.1


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] bpf: Avoid allocing memory on memoryless numa node
  2020-10-10  8:44 [PATCH] bpf: Avoid allocing memory on memoryless numa node Xianting Tian
@ 2020-10-12  1:21 ` Alexei Starovoitov
  2020-10-12  1:26   ` Tianxianting
  0 siblings, 1 reply; 3+ messages in thread
From: Alexei Starovoitov @ 2020-10-12  1:21 UTC (permalink / raw)
  To: Xianting Tian
  Cc: Alexei Starovoitov, Daniel Borkmann, David S. Miller,
	Jakub Kicinski, Jesper Dangaard Brouer, John Fastabend,
	Martin KaFai Lau, Song Liu, Yonghong Song, Andrii Nakryiko,
	KP Singh, Network Development, bpf, LKML

On Sat, Oct 10, 2020 at 1:55 AM Xianting Tian <tian.xianting@h3c.com> wrote:
>
> In architecture like powerpc, we can have cpus without any local memory
> attached to it. In such cases the node does not have real memory.
>
> Use local_memory_node(), which is guaranteed to have memory.
> local_memory_node is a noop in other architectures that does not support
> memoryless nodes.
...
>         /* Have map->numa_node, but choose node of redirect target CPU */
> -       numa = cpu_to_node(cpu);
> +       numa = local_memory_node(cpu_to_node(cpu));

There are so many calls to cpu_to_node() throughout the kernel.
Are you going to convert all of them one patch at a time to the above sequence?
Why not do this CONFIG_HAVE_MEMORYLESS_NODES
in cpu_to_node() instead?
and save the churn.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* RE: [PATCH] bpf: Avoid allocing memory on memoryless numa node
  2020-10-12  1:21 ` Alexei Starovoitov
@ 2020-10-12  1:26   ` Tianxianting
  0 siblings, 0 replies; 3+ messages in thread
From: Tianxianting @ 2020-10-12  1:26 UTC (permalink / raw)
  To: Alexei Starovoitov
  Cc: Alexei Starovoitov, Daniel Borkmann, David S. Miller,
	Jakub Kicinski, Jesper Dangaard Brouer, John Fastabend,
	Martin KaFai Lau, Song Liu, Yonghong Song, Andrii Nakryiko,
	KP Singh, Network Development, bpf, LKML

Thanks Alexei for your suggestion,
I will try to do it.

-----Original Message-----
From: Alexei Starovoitov [mailto:alexei.starovoitov@gmail.com] 
Sent: Monday, October 12, 2020 9:21 AM
To: tianxianting (RD) <tian.xianting@h3c.com>
Cc: Alexei Starovoitov <ast@kernel.org>; Daniel Borkmann <daniel@iogearbox.net>; David S. Miller <davem@davemloft.net>; Jakub Kicinski <kuba@kernel.org>; Jesper Dangaard Brouer <hawk@kernel.org>; John Fastabend <john.fastabend@gmail.com>; Martin KaFai Lau <kafai@fb.com>; Song Liu <songliubraving@fb.com>; Yonghong Song <yhs@fb.com>; Andrii Nakryiko <andriin@fb.com>; KP Singh <kpsingh@chromium.org>; Network Development <netdev@vger.kernel.org>; bpf <bpf@vger.kernel.org>; LKML <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] bpf: Avoid allocing memory on memoryless numa node

On Sat, Oct 10, 2020 at 1:55 AM Xianting Tian <tian.xianting@h3c.com> wrote:
>
> In architecture like powerpc, we can have cpus without any local 
> memory attached to it. In such cases the node does not have real memory.
>
> Use local_memory_node(), which is guaranteed to have memory.
> local_memory_node is a noop in other architectures that does not 
> support memoryless nodes.
...
>         /* Have map->numa_node, but choose node of redirect target CPU */
> -       numa = cpu_to_node(cpu);
> +       numa = local_memory_node(cpu_to_node(cpu));

There are so many calls to cpu_to_node() throughout the kernel.
Are you going to convert all of them one patch at a time to the above sequence?
Why not do this CONFIG_HAVE_MEMORYLESS_NODES in cpu_to_node() instead?
and save the churn.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, back to index

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-10  8:44 [PATCH] bpf: Avoid allocing memory on memoryless numa node Xianting Tian
2020-10-12  1:21 ` Alexei Starovoitov
2020-10-12  1:26   ` Tianxianting

BPF Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/bpf/0 bpf/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 bpf bpf/ https://lore.kernel.org/bpf \
		bpf@vger.kernel.org
	public-inbox-index bpf

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.bpf


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git