* [PATCH net-next] tun: use netdev_alloc_frag() in tun_napi_alloc_frags()
@ 2018-11-18 15:37 Eric Dumazet
2018-11-19 3:01 ` David Miller
0 siblings, 1 reply; 2+ messages in thread
From: Eric Dumazet @ 2018-11-18 15:37 UTC (permalink / raw)
To: David S . Miller
Cc: netdev, Eric Dumazet, Eric Dumazet, Petar Penkov, Mahesh Bandewar,
Willem de Bruijn
In order to cook skbs in the same way than Ethernet drivers,
it is probably better to not use GFP_KERNEL, but rather
use the GFP_ATOMIC and PFMEMALLOC mechanisms provided by
netdev_alloc_frag().
This would allow to use tun driver even in memory stress
situations, especially if swap is used over this tun channel.
Fixes: 90e33d459407 ("tun: enable napi_gro_frags() for TUN/TAP driver")
Signed-off-by: Eric Dumazet <edumazet@google.com>
Cc: Petar Penkov <peterpenkov96@gmail.com>
Cc: Mahesh Bandewar <maheshb@google.com>
Cc: Willem de Bruijn <willemb@google.com>
---
drivers/net/tun.c | 15 +++++++--------
1 file changed, 7 insertions(+), 8 deletions(-)
diff --git a/drivers/net/tun.c b/drivers/net/tun.c
index 36163a147d3950a5d7451abed96809c2af7c322f..1e9da697081d10e086a26deb1ab38e62f77436b5 100644
--- a/drivers/net/tun.c
+++ b/drivers/net/tun.c
@@ -1478,23 +1478,22 @@ static struct sk_buff *tun_napi_alloc_frags(struct tun_file *tfile,
skb->truesize += skb->data_len;
for (i = 1; i < it->nr_segs; i++) {
- struct page_frag *pfrag = ¤t->task_frag;
size_t fragsz = it->iov[i].iov_len;
+ struct page *page;
+ void *frag;
if (fragsz == 0 || fragsz > PAGE_SIZE) {
err = -EINVAL;
goto free;
}
-
- if (!skb_page_frag_refill(fragsz, pfrag, GFP_KERNEL)) {
+ frag = netdev_alloc_frag(fragsz);
+ if (!frag) {
err = -ENOMEM;
goto free;
}
-
- skb_fill_page_desc(skb, i - 1, pfrag->page,
- pfrag->offset, fragsz);
- page_ref_inc(pfrag->page);
- pfrag->offset += fragsz;
+ page = virt_to_head_page(frag);
+ skb_fill_page_desc(skb, i - 1, page,
+ frag - page_address(page), fragsz);
}
return skb;
--
2.19.1.1215.g8438c0b245-goog
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH net-next] tun: use netdev_alloc_frag() in tun_napi_alloc_frags()
2018-11-18 15:37 [PATCH net-next] tun: use netdev_alloc_frag() in tun_napi_alloc_frags() Eric Dumazet
@ 2018-11-19 3:01 ` David Miller
0 siblings, 0 replies; 2+ messages in thread
From: David Miller @ 2018-11-19 3:01 UTC (permalink / raw)
To: edumazet; +Cc: netdev, eric.dumazet, peterpenkov96, maheshb, willemb
From: Eric Dumazet <edumazet@google.com>
Date: Sun, 18 Nov 2018 07:37:33 -0800
> In order to cook skbs in the same way than Ethernet drivers,
> it is probably better to not use GFP_KERNEL, but rather
> use the GFP_ATOMIC and PFMEMALLOC mechanisms provided by
> netdev_alloc_frag().
>
> This would allow to use tun driver even in memory stress
> situations, especially if swap is used over this tun channel.
>
> Fixes: 90e33d459407 ("tun: enable napi_gro_frags() for TUN/TAP driver")
> Signed-off-by: Eric Dumazet <edumazet@google.com>
Applied.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2018-11-19 13:23 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-11-18 15:37 [PATCH net-next] tun: use netdev_alloc_frag() in tun_napi_alloc_frags() Eric Dumazet
2018-11-19 3:01 ` David Miller
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).