From patchwork Wed Aug 2 20:10:30 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Long Li X-Patchwork-Id: 9877485 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 89450602BC for ; Wed, 2 Aug 2017 20:13:03 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7AD2B2874E for ; Wed, 2 Aug 2017 20:13:03 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6FBA12876A; Wed, 2 Aug 2017 20:13:03 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.4 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1EC2B2874E for ; Wed, 2 Aug 2017 20:13:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753104AbdHBUM3 (ORCPT ); Wed, 2 Aug 2017 16:12:29 -0400 Received: from a2nlsmtp01-04.prod.iad2.secureserver.net ([198.71.225.38]:36974 "EHLO a2nlsmtp01-04.prod.iad2.secureserver.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753007AbdHBUMZ (ORCPT ); Wed, 2 Aug 2017 16:12:25 -0400 Received: from linuxonhyperv.com ([107.180.71.197]) by : HOSTING RELAY : with SMTP id czzId52z33vhKczzIdxf1z; Wed, 02 Aug 2017 13:11:24 -0700 x-originating-ip: 107.180.71.197 Received: from longli by linuxonhyperv.com with local (Exim 4.89) (envelope-from ) id 1dczzI-0005HX-Ab; Wed, 02 Aug 2017 13:11:24 -0700 From: Long Li To: Steve French , linux-cifs@vger.kernel.org, samba-technical@lists.samba.org, linux-kernel@vger.kernel.org Cc: Long Li Subject: [[PATCH v1] 19/37] [CIFS] SMBD: Manage credits on SMBD client and server Date: Wed, 2 Aug 2017 13:10:30 -0700 Message-Id: <1501704648-20159-20-git-send-email-longli@exchange.microsoft.com> X-Mailer: git-send-email 1.7.1 In-Reply-To: <1501704648-20159-1-git-send-email-longli@exchange.microsoft.com> References: <1501704648-20159-1-git-send-email-longli@exchange.microsoft.com> X-CMAE-Envelope: MS4wfLp8aWyXiEZEB+XrQLNGMc13SHHAONMn/Mg9o7Xh5e2l46XQQMqGiGiQ2d29zGcPxiQFxZnNhEhdynQsvyPKF38Jcj32z8Yrs+IgoRjtXr81ant5oBqE pMkyBOVwOj+coYZtH3OM985kJvsFz+WuNse7q9FUQnkIrGLtjBLu3AiNComz0zUjG4DyJPgz4sl9Z2K853g123BtLJiFSODcC+L09sOqk+APfQtiB4tYJ6Uv 4UPH3T86GxkeVYO0+sRyFrU2zDs6ghdQGX/WPK9xPPytykMJypEFVSrqqJ7TVLoRKL6hF39B8gR7XFhVgVGRUtLwdxoXScUd2uLDIgId+0g= Sender: linux-cifs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-cifs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Long Li SMB client and server maintain a credit system on the SMBD transport. Credits are used to tell when the client or server can send a packet to the peer, based on current memory or resource usage. Signed-off-by: Long Li --- fs/cifs/cifsrdma.c | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/fs/cifs/cifsrdma.c b/fs/cifs/cifsrdma.c index eb48651..97cde3f 100644 --- a/fs/cifs/cifsrdma.c +++ b/fs/cifs/cifsrdma.c @@ -575,6 +575,46 @@ static int cifs_rdma_post_send_negotiate_req(struct cifs_rdma_info *info) } /* + * Extend the credits to remote peer + * This implements [MS-SMBD] 3.1.5.9 + * The idea is that we should extend credits to remote peer as quickly as + * it's allowed, to maintain data flow. We allocate as much as receive + * buffer as possible, and extend the receive credits to remote peer + * return value: the new credtis being granted. + */ +static int manage_credits_prior_sending(struct cifs_rdma_info *info) +{ + int ret = 0; + struct cifs_rdma_response *response; + int rc; + + if (atomic_read(&info->receive_credit_target) > + atomic_read(&info->receive_credits)) { + while (true) { + response = get_receive_buffer(info); + if (!response) + break; + + response->type = SMBD_TRANSFER_DATA; + response->first_segment = false; + rc = cifs_rdma_post_recv(info, response); + if (rc) { + log_rdma_recv("post_recv failed rc=%d\n", rc); + put_receive_buffer(info, response); + break; + } + + ret++; + } + } + + atomic_add(ret, &info->receive_credits); + log_transport_credit(info); + + return ret; +} + +/* * Send a page * page: the page to send * offset: offset in the page to send @@ -607,6 +647,8 @@ static int cifs_rdma_post_send_page(struct cifs_rdma_info *info, struct page *pa packet = (struct smbd_data_transfer *) request->packet; packet->credits_requested = cpu_to_le16(info->send_credit_target); + packet->credits_granted = + cpu_to_le16(manage_credits_prior_sending(info)); packet->flags = cpu_to_le16(0); packet->reserved = cpu_to_le16(0); @@ -718,6 +760,8 @@ static int cifs_rdma_post_send_empty(struct cifs_rdma_info *info) request->info = info; packet = (struct smbd_data_transfer_no_data *) request->packet; + credits_granted = manage_credits_prior_sending(info); + /* nothing to do? */ if (credits_granted==0 && flags==0) { mempool_free(request, info->request_mempool); @@ -827,6 +871,7 @@ static int cifs_rdma_post_send_data( packet = (struct smbd_data_transfer *) request->packet; packet->credits_requested = cpu_to_le16(info->send_credit_target); + packet->credits_granted = cpu_to_le16(manage_credits_prior_sending(info)); packet->flags = cpu_to_le16(0); packet->reserved = cpu_to_le16(0);