Skip to content

Commit 5f74f82

Browse files
Hans Westgaard Rydavem330
authored andcommitted
net:Add sysctl_max_skb_frags
Devices may have limits on the number of fragments in an skb they support. Current codebase uses a constant as maximum for number of fragments one skb can hold and use. When enabling scatter/gather and running traffic with many small messages the codebase uses the maximum number of fragments and may thereby violate the max for certain devices. The patch introduces a global variable as max number of fragments. Signed-off-by: Hans Westgaard Ry <hans.westgaard.ry@oracle.com> Reviewed-by: Håkon Bugge <haakon.bugge@oracle.com> Acked-by: Eric Dumazet <edumazet@google.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 9cf7490 commit 5f74f82

4 files changed

Lines changed: 15 additions & 2 deletions

File tree

‎include/linux/skbuff.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,7 @@ struct sk_buff;
299299
#else
300300
#define MAX_SKB_FRAGS (65536/PAGE_SIZE + 1)
301301
#endif
302+
extern int sysctl_max_skb_frags;
302303

303304
typedef struct skb_frag_struct skb_frag_t;
304305

‎net/core/skbuff.c‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@
7979

8080
struct kmem_cache *skbuff_head_cache __read_mostly;
8181
static struct kmem_cache *skbuff_fclone_cache __read_mostly;
82+
int sysctl_max_skb_frags __read_mostly = MAX_SKB_FRAGS;
83+
EXPORT_SYMBOL(sysctl_max_skb_frags);
8284

8385
/**
8486
* skb_panic - private function for out-of-line support

‎net/core/sysctl_net_core.c‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ static int zero = 0;
2626
static int one = 1;
2727
static int min_sndbuf = SOCK_MIN_SNDBUF;
2828
static int min_rcvbuf = SOCK_MIN_RCVBUF;
29+
static int max_skb_frags = MAX_SKB_FRAGS;
2930

3031
static int net_msg_warn; /* Unused, but still a sysctl */
3132

@@ -392,6 +393,15 @@ static struct ctl_table net_core_table[] = {
392393
.mode = 0644,
393394
.proc_handler = proc_dointvec
394395
},
396+
{
397+
.procname = "max_skb_frags",
398+
.data = &sysctl_max_skb_frags,
399+
.maxlen = sizeof(int),
400+
.mode = 0644,
401+
.proc_handler = proc_dointvec_minmax,
402+
.extra1 = &one,
403+
.extra2 = &max_skb_frags,
404+
},
395405
{ }
396406
};
397407

‎net/ipv4/tcp.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -940,7 +940,7 @@ static ssize_t do_tcp_sendpages(struct sock *sk, struct page *page, int offset,
940940

941941
i = skb_shinfo(skb)->nr_frags;
942942
can_coalesce = skb_can_coalesce(skb, i, page, offset);
943-
if (!can_coalesce && i >= MAX_SKB_FRAGS) {
943+
if (!can_coalesce && i >= sysctl_max_skb_frags) {
944944
tcp_mark_push(tp, skb);
945945
goto new_segment;
946946
}
@@ -1213,7 +1213,7 @@ int tcp_sendmsg(struct sock *sk, struct msghdr *msg, size_t size)
12131213

12141214
if (!skb_can_coalesce(skb, i, pfrag->page,
12151215
pfrag->offset)) {
1216-
if (i == MAX_SKB_FRAGS || !sg) {
1216+
if (i == sysctl_max_skb_frags || !sg) {
12171217
tcp_mark_push(tp, skb);
12181218
goto new_segment;
12191219
}

0 commit comments

Comments
 (0)