Skip to content

Commit ce27ec6

Browse files
edumazetdavem330
authored andcommitted
net: add high_order_alloc_disable sysctl/static key
>From linux-3.7, (commit 5640f76 "net: use a per task frag allocator") TCP sendmsg() has preferred using order-3 allocations. While it gives good results for most cases, we had reports that heavy uses of TCP over loopback were hitting a spinlock contention in page allocations/freeing. This commits adds a sysctl so that admins can opt-in for order-0 allocations. Hopefully mm layer might optimize order-3 allocations in the future since it could give us a nice boost (see 8 lines of following benchmark) The following benchmark shows a win when more than 8 TCP_STREAM threads are running (56 x86 cores server in my tests) for thr in {1..30} do sysctl -wq net.core.high_order_alloc_disable=0 T0=`./super_netperf $thr -H 127.0.0.1 -l 15` sysctl -wq net.core.high_order_alloc_disable=1 T1=`./super_netperf $thr -H 127.0.0.1 -l 15` echo $thr:$T0:$T1 done 1: 49979: 37267 2: 98745: 76286 3: 141088: 110051 4: 177414: 144772 5: 197587: 173563 6: 215377: 208448 7: 241061: 234087 8: 267155: 263373 9: 295069: 297402 10: 312393: 335213 11: 340462: 368778 12: 371366: 403954 13: 412344: 443713 14: 426617: 473580 15: 474418: 507861 16: 503261: 538539 17: 522331: 563096 18: 532409: 567084 19: 550824: 605240 20: 525493: 641988 21: 564574: 665843 22: 567349: 690868 23: 583846: 710917 24: 588715: 736306 25: 603212: 763494 26: 604083: 792654 27: 602241: 796450 28: 604291: 797993 29: 611610: 833249 30: 577356: 841062 Signed-off-by: Eric Dumazet <edumazet@google.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 0b7d7f6 commit ce27ec6

3 files changed

Lines changed: 12 additions & 1 deletion

File tree

‎include/net/sock.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2534,6 +2534,8 @@ extern int sysctl_optmem_max;
25342534
extern __u32 sysctl_wmem_default;
25352535
extern __u32 sysctl_rmem_default;
25362536

2537+
DECLARE_STATIC_KEY_FALSE(net_high_order_alloc_disable_key);
2538+
25372539
static inline int sk_get_wmem0(const struct sock *sk, const struct proto *proto)
25382540
{
25392541
/* Does this proto have per netns sysctl_wmem ? */

‎net/core/sock.c‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2320,6 +2320,7 @@ static void sk_leave_memory_pressure(struct sock *sk)
23202320

23212321
/* On 32bit arches, an skb frag is limited to 2^15 */
23222322
#define SKB_FRAG_PAGE_ORDER get_order(32768)
2323+
DEFINE_STATIC_KEY_FALSE(net_high_order_alloc_disable_key);
23232324

23242325
/**
23252326
* skb_page_frag_refill - check that a page_frag contains enough room
@@ -2344,7 +2345,8 @@ bool skb_page_frag_refill(unsigned int sz, struct page_frag *pfrag, gfp_t gfp)
23442345
}
23452346

23462347
pfrag->offset = 0;
2347-
if (SKB_FRAG_PAGE_ORDER) {
2348+
if (SKB_FRAG_PAGE_ORDER &&
2349+
!static_branch_unlikely(&net_high_order_alloc_disable_key)) {
23482350
/* Avoid direct reclaim but allow kswapd to wake */
23492351
pfrag->page = alloc_pages((gfp & ~__GFP_DIRECT_RECLAIM) |
23502352
__GFP_COMP | __GFP_NOWARN |

‎net/core/sysctl_net_core.c‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -562,6 +562,13 @@ static struct ctl_table net_core_table[] = {
562562
.extra1 = &zero,
563563
.extra2 = &two,
564564
},
565+
{
566+
.procname = "high_order_alloc_disable",
567+
.data = &net_high_order_alloc_disable_key.key,
568+
.maxlen = sizeof(net_high_order_alloc_disable_key),
569+
.mode = 0644,
570+
.proc_handler = proc_do_static_key,
571+
},
565572
{ }
566573
};
567574

0 commit comments

Comments
 (0)