Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp3875963pxb; Sat, 13 Feb 2021 12:26:56 -0800 (PST) X-Google-Smtp-Source: ABdhPJwZY+LBRWvT0gpWGckSnzWGokYpJtz9HMZP1zETX+SAsUYCsKQEJRwKGmGRy1HhiaQhFrqc X-Received: by 2002:a17:906:b106:: with SMTP id u6mr8599973ejy.313.1613248016716; Sat, 13 Feb 2021 12:26:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1613248016; cv=none; d=google.com; s=arc-20160816; b=B6TUae1dsN7Gn2ocBNHfNC7qk+t1hOjjxuGDqhJ7idNYuI0+QkC72YSdteDzs6beCW EjLnWREREwGcMIJxvHXQ9x5pvAoUbGqIRlHzcagN5qhmujaYb5b5B2G47InBtcFlrT6w Fm/JQyomO0601PO6LfXJZ32TeNu0rMC6QiYqVN2Ei8V1xJ0bdRb1fkHsGQBROJ68Ihbf a9mXhQJu4AjyqnF9tp/hffAq6ZEw3Pn1y/xspErMcyiceVonvpGCCH7ym+jCeOj1FdEr UFmcVC7BXvCEZgmh+i51cNTDZkmlyEHUHwrfGu8Ythmsp6yu+nntGSa44kIczFHSIYjs Evlw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=8MAINtt+a9i0PBZvktf84WsV++WsOOcZTg6x72Yp+XI=; b=tM/sjzTlMYpjKzfGjodpKeI8Y2rq/5NusjnkMApRov1z++pP7ZCsxyp+rQkXeh6q6o ua75hsHF++HbbOJTVt0LGjvWDKHBIuO72xy9qwT37vX3PNwsbleXZL+HxnOc9+N1ZZkc Jxzh9v27BFQwxgGNgGaIPAmDwz/KorOoMCpRmo7OonF9q+5ry/UgK17oJzUB9UOxfssm GUBqGdycNp/vKotWhu7gQpQQ0tA01rU/99waeigo81H/VWbLLFnn6A3pFVxydr3rcOEI vTLjIgULEIzA9KPMD/U6mcmYJ2otfxHwXvfHQqd0Rg1wq5bsLDo8QxuWu1w9hK8fpcx5 QNHw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=mpcOCsWc; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id br5si8630284ejb.608.2021.02.13.12.26.19; Sat, 13 Feb 2021 12:26:56 -0800 (PST) Received-SPF: pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=mpcOCsWc; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229649AbhBMU0S (ORCPT + 99 others); Sat, 13 Feb 2021 15:26:18 -0500 Received: from mail.kernel.org ([198.145.29.99]:58602 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229647AbhBMU0R (ORCPT ); Sat, 13 Feb 2021 15:26:17 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 35B8164DC3; Sat, 13 Feb 2021 20:25:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1613247936; bh=B6tCooq2ymPux9vQhoH/1JULKQzCFAKDIEdLLkIgbFQ=; h=From:To:Cc:Subject:Date:From; b=mpcOCsWcO/3WJJXCgr6rU9xKg6nsD5a8W0JH8VJVwj5Nz5+4r4QKnQ3WHqGEtZXau dCdpM3r81mDxX8uyJUWssllSIP1TuwKGmEdmHtkypNoZ4FOSRClocgkAnDwoNZVw74 k05Zi6eiV+1SMrXfcyqTCTfbf8Gdp/QNC1vSRxcbJ0Hy9JxAJ6/AZYigi8oYRgEsxv ZV04JfrDGNE43lcuc+bTNNkCmStkbhIq7yQkn3fNkwq08CAFPGyA/353B0kpnkbuXT EipBYw9jMl92KqG3h2LRZ3peNSrn9LfZI6qEShDMEVCKALlIB8AItbmrz+9lpYzJEC MBGZNApTFDbXQ== From: trondmy@kernel.org To: "J. Bruce Fields" , Chuck Lever Cc: linux-nfs@vger.kernel.org Subject: [PATCH] SUNRPC: Use TCP_CORK to optimise send performance on the server Date: Sat, 13 Feb 2021 15:25:32 -0500 Message-Id: <20210213202532.23146-1-trondmy@kernel.org> X-Mailer: git-send-email 2.29.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org From: Trond Myklebust Use a counter to keep track of how many requests are queued behind the xprt->xpt_mutex, and keep TCP_CORK set until the queue is empty. Signed-off-by: Trond Myklebust --- include/linux/sunrpc/svcsock.h | 2 ++ net/sunrpc/svcsock.c | 8 +++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/include/linux/sunrpc/svcsock.h b/include/linux/sunrpc/svcsock.h index b7ac7fe68306..bcc555c7ae9c 100644 --- a/include/linux/sunrpc/svcsock.h +++ b/include/linux/sunrpc/svcsock.h @@ -35,6 +35,8 @@ struct svc_sock { /* Total length of the data (not including fragment headers) * received so far in the fragments making up this rpc: */ u32 sk_datalen; + /* Number of queued send requests */ + atomic_t sk_sendqlen; struct page * sk_pages[RPCSVC_MAXPAGES]; /* received data */ }; diff --git a/net/sunrpc/svcsock.c b/net/sunrpc/svcsock.c index 5a809c64dc7b..231f510a4830 100644 --- a/net/sunrpc/svcsock.c +++ b/net/sunrpc/svcsock.c @@ -1171,18 +1171,23 @@ static int svc_tcp_sendto(struct svc_rqst *rqstp) svc_tcp_release_rqst(rqstp); + atomic_inc(&svsk->sk_sendqlen); mutex_lock(&xprt->xpt_mutex); if (svc_xprt_is_dead(xprt)) goto out_notconn; + tcp_sock_set_cork(svsk->sk_sk, true); err = svc_tcp_sendmsg(svsk->sk_sock, &msg, xdr, marker, &sent); xdr_free_bvec(xdr); trace_svcsock_tcp_send(xprt, err < 0 ? err : sent); if (err < 0 || sent != (xdr->len + sizeof(marker))) goto out_close; + if (atomic_dec_and_test(&svsk->sk_sendqlen)) + tcp_sock_set_cork(svsk->sk_sk, false); mutex_unlock(&xprt->xpt_mutex); return sent; out_notconn: + atomic_dec(&svsk->sk_sendqlen); mutex_unlock(&xprt->xpt_mutex); return -ENOTCONN; out_close: @@ -1192,6 +1197,7 @@ static int svc_tcp_sendto(struct svc_rqst *rqstp) (err < 0) ? err : sent, xdr->len); set_bit(XPT_CLOSE, &xprt->xpt_flags); svc_xprt_enqueue(xprt); + atomic_dec(&svsk->sk_sendqlen); mutex_unlock(&xprt->xpt_mutex); return -EAGAIN; } @@ -1261,7 +1267,7 @@ static void svc_tcp_init(struct svc_sock *svsk, struct svc_serv *serv) svsk->sk_datalen = 0; memset(&svsk->sk_pages[0], 0, sizeof(svsk->sk_pages)); - tcp_sk(sk)->nonagle |= TCP_NAGLE_OFF; + tcp_sock_set_nodelay(sk); set_bit(XPT_DATA, &svsk->sk_xprt.xpt_flags); switch (sk->sk_state) { -- 2.29.2