Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp4769392imm; Tue, 9 Oct 2018 05:07:43 -0700 (PDT) X-Google-Smtp-Source: ACcGV604FYikrc2OscZWCwjYKGxfFWzrdqHR+zASxpDe52rtQ2SfAkf3fGzH4cZdRXfSi8KjX6LX X-Received: by 2002:a63:4952:: with SMTP id y18-v6mr25258526pgk.32.1539086863376; Tue, 09 Oct 2018 05:07:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539086863; cv=none; d=google.com; s=arc-20160816; b=uWUgwLySQs4lOF6FtoRyk37JVD+zJkGVq6u/OYk5rYKnUICeRzVTuecj5Ehbv83+Nj iboPQ20ErCsIbWalySYir9yKCVq0CRU8Ee9nrliltj/c+s1vgKwKywArMBo29eRl2/VI JqIhOvm3zsSSr86j0MUIIiOOEep+s1YBCK4D9nEodOmi82GlCJYg6wjvoAClvR6RwPZu rZnGeB0NunbFB5+4nX+b0yKuOTgceL7p91JXqBp/0i+ZUpfopEpNagOPfQDIfLrIjWQP wmSS/FKQYb8JLXvxaLsAvaiRn9RJv1u1TKzJtWo51VwTQpiNHfVN50phxaz6tY13gfkY S5Ng== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=j728AhKyvqO+SkkudrX1Dpm06WwxmvVoUZ/LAx1+0YE=; b=I63JCMmyaEchpl3Okif4UQAFgpGwwMKnR87ue/BnSaWFMw4OrkkpkMgVCRWTmScCNS 5Lfpe9L6mwt0vSyRNNfMghiyXtyR3a5seCjIsdTkyi5R9lMIPDfsTpvpoFZQRcGU2Yaw apTS13TRWMYya4dnXcGfc1N9qDEgTBvHZ4zK0MXfh+syMjgXcpQVgK55I69Ok19S19uQ CleVPP9juelbcj8rgn+ciOaweDNdCsuFS9mf9KuaelaPK3+ez3mPfv11/wlyc5gj+cF+ 3hEpQfHPLQF8ZUYEASwQq0am9aeH4tor2KgZBwTkuFGiktIIo6epV9TxkqiQpkDvrTwT ah7Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=lWWjryxg; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j16-v6si19315472pgm.501.2018.10.09.05.07.28; Tue, 09 Oct 2018 05:07:43 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=lWWjryxg; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726954AbeJITWa (ORCPT + 99 others); Tue, 9 Oct 2018 15:22:30 -0400 Received: from mail-pg1-f193.google.com ([209.85.215.193]:36027 "EHLO mail-pg1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726415AbeJITWa (ORCPT ); Tue, 9 Oct 2018 15:22:30 -0400 Received: by mail-pg1-f193.google.com with SMTP id f18-v6so720109pgv.3; Tue, 09 Oct 2018 05:05:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=j728AhKyvqO+SkkudrX1Dpm06WwxmvVoUZ/LAx1+0YE=; b=lWWjryxgOPOPzlcjqTF2RwZzMMngrQDr8sfpxf3azWuxF5FPTap01LtmqHEEpa2l0Z 9vzMjstfyWE4G1DgrgaBCgGLjfPqjjnjmcJMbiv+kfjZoVgO4gPfg2JmpF+zlMymeuVc 7FP0fsCN4gxQN7tT0bYlFRzpwaHQCDObu831DxJiGuBOTCVOPHC8r6W1gp0EmVlQksX/ NH06UtDk9SSV8luGZwVWtCul1rAshQJ1ujiQ7x8gYifYr9x/zvdDEgmPt4+yNAPbqIIY 6cR68E+Seh/LesLFnJT3xram2Hwn1De6x5+BjFaK5GUNcSC5Y+Q5GRihJoBSTM9Wu6Co sGyw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=j728AhKyvqO+SkkudrX1Dpm06WwxmvVoUZ/LAx1+0YE=; b=c5PVptBG4Q/zkEsJrQqIftK00CZwu6z8u5DZcEZcKMiwu8irEOYYYFi9Uwh3jWUTWv pzKULI7ZLmuPLyE8lIX0oFlgD1IaF+QP8U2mZRQYnQ2Zcc31kPzb6S5+hcE/CmsuyKgb tLeeKzC3Kc7qXBTAD+7PuHJBuEKBAqDp1P/ZCjU2E8DKJvpat14zV+G2nKv+7GOoRwp3 lFTHG/yNOynz4VMfRl9zo4NOV4fVRB1JV40YSmhoS7w55yJ8n99oiSh5PqWJpBDhihJD t/QzOGWbYBljQ7i+qK+gTUhbXgAxqnZRqhzRFh8j4SCRXbUXsItGgvNfWiUR9+eyYHK4 wGUQ== X-Gm-Message-State: ABuFfoid2XYdN1HA9giXQ99VeU4Y9VhQ6YjOGpl4Br4q4DabK5dJ56Hg ODrvn5m3kjWA9qbg0VQogTM= X-Received: by 2002:a63:ef0b:: with SMTP id u11-v6mr25339879pgh.283.1539086751203; Tue, 09 Oct 2018 05:05:51 -0700 (PDT) Received: from localhost.localdomain ([203.100.54.194]) by smtp.gmail.com with ESMTPSA id m11-v6sm23517239pgn.39.2018.10.09.05.05.49 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 09 Oct 2018 05:05:50 -0700 (PDT) From: Yafang Shao To: edumazet@google.com, davem@davemloft.net Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Yafang Shao Subject: [PATCH net-next] tcp: forbid direct reclaim if MSG_DONTWAIT is set in send path Date: Tue, 9 Oct 2018 20:05:18 +0800 Message-Id: <1539086718-4119-2-git-send-email-laoar.shao@gmail.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1539086718-4119-1-git-send-email-laoar.shao@gmail.com> References: <1539086718-4119-1-git-send-email-laoar.shao@gmail.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org By default, the sk->sk_allocation is GFP_KERNEL, that means if there's no enough memory it will do both direct reclaim and background reclaim. If the size of system memory is great, the direct reclaim may cause great latency spike. When we set MSG_DONTWAIT in send syscalls, we really don't want it to be blocked, so we'd better clear __GFP_DIRECT_RECLAIM when allocate skb in the send path. Then, it will return immediately if there's no enough memory to be allocated, and then the appliation has a chance to do some other stuffs instead of being blocked here. Signed-off-by: Yafang Shao --- net/ipv4/tcp.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c index 43ef83b..fe4f5ce 100644 --- a/net/ipv4/tcp.c +++ b/net/ipv4/tcp.c @@ -1182,6 +1182,7 @@ int tcp_sendmsg_locked(struct sock *sk, struct msghdr *msg, size_t size) bool process_backlog = false; bool zc = false; long timeo; + gfp_t gfp; flags = msg->msg_flags; @@ -1255,6 +1256,9 @@ int tcp_sendmsg_locked(struct sock *sk, struct msghdr *msg, size_t size) /* Ok commence sending. */ copied = 0; + gfp = flags & MSG_DONTWAIT ? sk->sk_allocation & ~__GFP_DIRECT_RECLAIM : + sk->sk_allocation; + restart: mss_now = tcp_send_mss(sk, &size_goal, flags); @@ -1283,8 +1287,7 @@ int tcp_sendmsg_locked(struct sock *sk, struct msghdr *msg, size_t size) } first_skb = tcp_rtx_and_write_queues_empty(sk); linear = select_size(first_skb, zc); - skb = sk_stream_alloc_skb(sk, linear, sk->sk_allocation, - first_skb); + skb = sk_stream_alloc_skb(sk, linear, gfp, first_skb); if (!skb) goto wait_for_memory; -- 1.8.3.1