BPF Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH bpf-next] xsk: support allocations of large umems
@ 2020-01-14  9:49 Magnus Karlsson
  2020-01-15 19:10 ` Jonathan Lemon
  0 siblings, 1 reply; 3+ messages in thread
From: Magnus Karlsson @ 2020-01-14  9:49 UTC (permalink / raw)
  To: magnus.karlsson, bjorn.topel, ast, daniel, netdev, jonathan.lemon
  Cc: rgoodfel, bpf

When registering a umem area that is sufficiently large (>1G on an
x86), kmalloc cannot be used to allocate one of the internal data
structures, as the size requested gets too large. Use kvmalloc instead
that falls back on vmalloc if the allocation is too large for kmalloc.

Also add accounting for this structure as it is triggered by a user
space action (the XDP_UMEM_REG setsockopt) and it is by far the
largest structure of kernel allocated memory in xsk.

Signed-off-by: Magnus Karlsson <magnus.karlsson@intel.com>
Reported-by: Ryan Goodfellow <rgoodfel@isi.edu>
---
 net/xdp/xdp_umem.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/net/xdp/xdp_umem.c b/net/xdp/xdp_umem.c
index 3049af2..f93e917 100644
--- a/net/xdp/xdp_umem.c
+++ b/net/xdp/xdp_umem.c
@@ -249,7 +249,7 @@ static void xdp_umem_release(struct xdp_umem *umem)
 	xdp_umem_unmap_pages(umem);
 	xdp_umem_unpin_pages(umem);
 
-	kfree(umem->pages);
+	kvfree(umem->pages);
 	umem->pages = NULL;
 
 	xdp_umem_unaccount_pages(umem);
@@ -409,7 +409,8 @@ static int xdp_umem_reg(struct xdp_umem *umem, struct xdp_umem_reg *mr)
 	if (err)
 		goto out_account;
 
-	umem->pages = kcalloc(umem->npgs, sizeof(*umem->pages), GFP_KERNEL);
+	umem->pages = kvcalloc(umem->npgs, sizeof(*umem->pages),
+			       GFP_KERNEL_ACCOUNT);
 	if (!umem->pages) {
 		err = -ENOMEM;
 		goto out_pin;
@@ -419,7 +420,7 @@ static int xdp_umem_reg(struct xdp_umem *umem, struct xdp_umem_reg *mr)
 	if (!err)
 		return 0;
 
-	kfree(umem->pages);
+	kvfree(umem->pages);
 
 out_pin:
 	xdp_umem_unpin_pages(umem);
-- 
2.7.4


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

* Re: [PATCH bpf-next] xsk: support allocations of large umems
  2020-01-14  9:49 [PATCH bpf-next] xsk: support allocations of large umems Magnus Karlsson
@ 2020-01-15 19:10 ` Jonathan Lemon
  2020-01-15 19:43   ` Alexei Starovoitov
  0 siblings, 1 reply; 3+ messages in thread
From: Jonathan Lemon @ 2020-01-15 19:10 UTC (permalink / raw)
  To: Magnus Karlsson; +Cc: bjorn.topel, ast, daniel, netdev, rgoodfel, bpf



On 14 Jan 2020, at 1:49, Magnus Karlsson wrote:

> When registering a umem area that is sufficiently large (>1G on an
> x86), kmalloc cannot be used to allocate one of the internal data
> structures, as the size requested gets too large. Use kvmalloc instead
> that falls back on vmalloc if the allocation is too large for kmalloc.
>
> Also add accounting for this structure as it is triggered by a user
> space action (the XDP_UMEM_REG setsockopt) and it is by far the
> largest structure of kernel allocated memory in xsk.
>
> Signed-off-by: Magnus Karlsson <magnus.karlsson@intel.com>
> Reported-by: Ryan Goodfellow <rgoodfel@isi.edu>

Acked-by: Jonathan Lemon <jonathan.lemon@gmail.com>

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

* Re: [PATCH bpf-next] xsk: support allocations of large umems
  2020-01-15 19:10 ` Jonathan Lemon
@ 2020-01-15 19:43   ` Alexei Starovoitov
  0 siblings, 0 replies; 3+ messages in thread
From: Alexei Starovoitov @ 2020-01-15 19:43 UTC (permalink / raw)
  To: Jonathan Lemon
  Cc: Magnus Karlsson, Björn Töpel, Alexei Starovoitov,
	Daniel Borkmann, Network Development, rgoodfel, bpf

On Wed, Jan 15, 2020 at 11:10 AM Jonathan Lemon
<jonathan.lemon@gmail.com> wrote:
>
>
>
> On 14 Jan 2020, at 1:49, Magnus Karlsson wrote:
>
> > When registering a umem area that is sufficiently large (>1G on an
> > x86), kmalloc cannot be used to allocate one of the internal data
> > structures, as the size requested gets too large. Use kvmalloc instead
> > that falls back on vmalloc if the allocation is too large for kmalloc.
> >
> > Also add accounting for this structure as it is triggered by a user
> > space action (the XDP_UMEM_REG setsockopt) and it is by far the
> > largest structure of kernel allocated memory in xsk.
> >
> > Signed-off-by: Magnus Karlsson <magnus.karlsson@intel.com>
> > Reported-by: Ryan Goodfellow <rgoodfel@isi.edu>
>
> Acked-by: Jonathan Lemon <jonathan.lemon@gmail.com>

Applied. Thanks

^ 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-01-14  9:49 [PATCH bpf-next] xsk: support allocations of large umems Magnus Karlsson
2020-01-15 19:10 ` Jonathan Lemon
2020-01-15 19:43   ` Alexei Starovoitov

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