Skip to content

Commit d35c99f

Browse files
edumazetdavem330
authored andcommitted
netlink: do not enter direct reclaim from netlink_dump()
Since linux-3.15, netlink_dump() can use up to 16384 bytes skb allocations. Due to struct skb_shared_info ~320 bytes overhead, we end up using order-3 (on x86) page allocations, that might trigger direct reclaim and add stress. The intent was really to attempt a large allocation but immediately fallback to a smaller one (order-1 on x86) in case of memory stress. On recent kernels (linux-4.4), we can remove __GFP_DIRECT_RECLAIM to meet the goal. Old kernels would need to remove __GFP_WAIT While we are at it, since we do an order-3 allocation, allow to use all the allocated bytes instead of 16384 to reduce syscalls during large dumps. iproute2 already uses 32KB recvmsg() buffer sizes. Alexei provided an initial patch downsizing to SKB_WITH_OVERHEAD(16384) Fixes: 9063e21 ("netlink: autosize skb lengthes") Signed-off-by: Eric Dumazet <[email protected]> Reported-by: Alexei Starovoitov <[email protected]> Cc: Greg Thelen <[email protected]> Reviewed-by: Greg Rose <[email protected]> Acked-by: Alexei Starovoitov <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 6664498 commit d35c99f

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

net/netlink/af_netlink.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1832,7 +1832,7 @@ static int netlink_recvmsg(struct socket *sock, struct msghdr *msg, size_t len,
18321832
/* Record the max length of recvmsg() calls for future allocations */
18331833
nlk->max_recvmsg_len = max(nlk->max_recvmsg_len, len);
18341834
nlk->max_recvmsg_len = min_t(size_t, nlk->max_recvmsg_len,
1835-
16384);
1835+
SKB_WITH_OVERHEAD(32768));
18361836

18371837
copied = data_skb->len;
18381838
if (len < copied) {
@@ -2083,8 +2083,9 @@ static int netlink_dump(struct sock *sk)
20832083

20842084
if (alloc_min_size < nlk->max_recvmsg_len) {
20852085
alloc_size = nlk->max_recvmsg_len;
2086-
skb = alloc_skb(alloc_size, GFP_KERNEL |
2087-
__GFP_NOWARN | __GFP_NORETRY);
2086+
skb = alloc_skb(alloc_size,
2087+
(GFP_KERNEL & ~__GFP_DIRECT_RECLAIM) |
2088+
__GFP_NOWARN | __GFP_NORETRY);
20882089
}
20892090
if (!skb) {
20902091
alloc_size = alloc_min_size;

0 commit comments

Comments
 (0)