From patchwork Sat Jul 28 15:15:35 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chengguang Xu X-Patchwork-Id: 10547995 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 1EE1D139A for ; Sat, 28 Jul 2018 15:16:38 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0F2782B20D for ; Sat, 28 Jul 2018 15:16:38 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 01F6D2B555; Sat, 28 Jul 2018 15:16:37 +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=-7.9 required=2.0 tests=BAYES_00,FREEMAIL_FROM, MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham 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 A58632B20D for ; Sat, 28 Jul 2018 15:16:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729033AbeG1Qn0 (ORCPT ); Sat, 28 Jul 2018 12:43:26 -0400 Received: from mout.gmx.net ([212.227.15.15]:50689 "EHLO mout.gmx.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728951AbeG1Qn0 (ORCPT ); Sat, 28 Jul 2018 12:43:26 -0400 Received: from localhost.localdomain ([113.87.89.132]) by mail.gmx.com (mrgmx003 [212.227.17.184]) with ESMTPSA (Nemesis) id 0Lvkwm-1g26uQ1aYu-017XxI; Sat, 28 Jul 2018 17:16:31 +0200 From: Chengguang Xu To: ceph-devel@vger.kernel.org Cc: zyan@redhat.com, idryomov@gmail.com, Chengguang Xu Subject: [PATCH 1/6] ceph: introduce a helper for reducing duplicated code Date: Sat, 28 Jul 2018 23:15:35 +0800 Message-Id: <20180728151540.11253-2-cgxu519@gmx.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180728151540.11253-1-cgxu519@gmx.com> References: <20180728151540.11253-1-cgxu519@gmx.com> X-Provags-ID: V03:K1:TbycYZy4KDTvKgqxyjrLxgbqIWmqxVDLj/al5H138ojWXTHZQtu OaNSPjRkxhJcr7t41KFfpMLn+Nr1M3+FjMg62xb5PDSPObxZaaJaSM/GcHMrHqX5aZYCC27 w8ulmolPx4kk0ToGasAGsDZLlFklLj9Dhk+ke56sx6QGJ+Kf6uVj1nJXRlKDchttmB2NxuG +X3iNx07fZmxiumMJ5WVg== X-UI-Out-Filterresults: notjunk:1;V01:K0:ZFGPziWRZic=:cqunsuwf/E0USJpAMO4/+n xBXIoXYhmOg8UbeMnACnrJhUTm3AgCASJ3QZACQ0PiAJ79NAr8JuGVbTkv0l3Ice23U28FdeI EkJtoj0+wQ9ehykfFRgbeCQQszIwneYgLCXTGObR7w0LKL5eaZe8OW7KZb62bslWqPC6d6esV 82UpQ7dk720QtcCLTHnLdsyTjV3FhD59lHWpPO5XlE5RQPVMIfN2gMQ0XH1cq38lVpvjhf2UU NZtZMQ/TtD6K93DqJccx98z0+RkrqgXSmTNeY2B6IwiJjkCVLPjWAvvhghKCdV8EEhr8zk95B KsnMyvYOJki0G74mjeGrq7jJG5T6Vc1w0wQbXKBd5e+L4b7fFkPtBhpdfomC+705y3URG5H6A YGW9lF31A/iPOh05BYSf0VTHSiO7ggWhEc6ZajZEaciaboeWzhaeZB6gpYObSlmy1i1Z14csN wgpo5fYI1aTL270erXl1nv7Mq3Gmhr6D5kSJACNLlyeS185oIOMU4VYC7FW8M0oe385M4lueI m0NO4wv6uW2RKPU1ykwnuW2bOv1dx5d1oRyXC5qch7WGIgWuAqTC7D5kEnhx787H0HdchZRrj 6RyytnplYPMxY1oWJCvev62zaid6tiwMJjPLAkfolQidPqi6LzMyIBM0WuJ3z77exeskp9dhd KGueXWbddF2JY0cir3l3CSflHU+WpVLzEx5SMraJ6Ng6Zfh6/lX2zVPqiCsVVFcHGnlFvhvpG GeCY/7DS4eHgKtwf6tPoxX8juPigxMTsktWXxmAa5kkU/Sm0cVfG9rSUFxs= Sender: ceph-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: ceph-devel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The code of ceph_unreserve_caps() and error handling in ceph_reserve_caps() are duplicated, so introduce a helper __ceph_unreserve_caps() to reduce duplicated code. Signed-off-by: Chengguang Xu --- fs/ceph/caps.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/fs/ceph/caps.c b/fs/ceph/caps.c index f50cc008632a..a3c0dbfac6b2 100644 --- a/fs/ceph/caps.c +++ b/fs/ceph/caps.c @@ -156,6 +156,37 @@ void ceph_adjust_min_caps(struct ceph_mds_client *mdsc, int delta) spin_unlock(&mdsc->caps_list_lock); } +void __ceph_unreserve_caps(struct ceph_mds_client *mdsc, int nr_caps) +{ + struct ceph_cap *cap; + int i; + + if (nr_caps) { + BUG_ON(mdsc->caps_reserve_count < nr_caps); + mdsc->caps_reserve_count -= nr_caps; + if (mdsc->caps_avail_count >= + mdsc->caps_reserve_count + mdsc->caps_min_count) { + mdsc->caps_total_count -= nr_caps; + for (i = 0; i < nr_caps; i++) { + cap = list_first_entry(&mdsc->caps_list, + struct ceph_cap, caps_item); + list_del(&cap->caps_item); + kmem_cache_free(ceph_cap_cachep, cap); + } + } else { + mdsc->caps_avail_count += nr_caps; + } + + dout("%s: caps %d = %d used + %d resv + %d avail\n", + __func__, + mdsc->caps_total_count, mdsc->caps_use_count, + mdsc->caps_reserve_count, mdsc->caps_avail_count); + BUG_ON(mdsc->caps_total_count != mdsc->caps_use_count + + mdsc->caps_reserve_count + + mdsc->caps_avail_count); + } +} + /* * Called under mdsc->mutex. */ From patchwork Sat Jul 28 15:15:36 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chengguang Xu X-Patchwork-Id: 10547997 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 719EE139A for ; Sat, 28 Jul 2018 15:16:45 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5FB692B20D for ; Sat, 28 Jul 2018 15:16:45 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 521872B555; Sat, 28 Jul 2018 15:16:45 +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=-7.9 required=2.0 tests=BAYES_00,FREEMAIL_FROM, MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham 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 E8D962B20D for ; Sat, 28 Jul 2018 15:16:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729040AbeG1Qne (ORCPT ); Sat, 28 Jul 2018 12:43:34 -0400 Received: from mout.gmx.net ([212.227.15.19]:58393 "EHLO mout.gmx.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728951AbeG1Qne (ORCPT ); Sat, 28 Jul 2018 12:43:34 -0400 Received: from localhost.localdomain ([113.87.89.132]) by mail.gmx.com (mrgmx003 [212.227.17.184]) with ESMTPSA (Nemesis) id 0MTSrf-1faTC63JDD-00SRZT; Sat, 28 Jul 2018 17:16:38 +0200 From: Chengguang Xu To: ceph-devel@vger.kernel.org Cc: zyan@redhat.com, idryomov@gmail.com, Chengguang Xu Subject: [PATCH 2/6] ceph: refactor ceph_unreserve_caps() Date: Sat, 28 Jul 2018 23:15:36 +0800 Message-Id: <20180728151540.11253-3-cgxu519@gmx.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180728151540.11253-1-cgxu519@gmx.com> References: <20180728151540.11253-1-cgxu519@gmx.com> X-Provags-ID: V03:K1:f2iemuq9w1y0kuX9qqMhxQ7cntU1ZqGPwNXGTHYc1/Ag1iDITbA hRAXil5YaFKY9sizKhFEgaJ3cyoKkiVMzG4AyXnTINV/roDVYP4X7zVH7A5wMZPKBca16aN LinlDyiPZXjy2IZYIyvEBpkzo2FOLuXksl+x6GhZuHwPMTHZSBFn+qZjYYwlPiOtSMfxjqJ uRJSi346uKsY7DnyWKNtA== X-UI-Out-Filterresults: notjunk:1;V01:K0:Er7IIk2so4w=:TFJC5kfg6/SCq1m4Drin3A hzxdURxGOXB7Zzq0ZrMmevsct3tUwSr3jzQkLAxPX6ouFqSp1jN1XZ1GH+TheBCcYx6CgC3sb jZZg6GIuIv5bNUSLcgsKQysF2PPZ87zzxhFK9BbBwSzDNwZUlMgwDfQkpW/vjrqaT855Q2894 N0RYS/14PEovlfXIE5dE1+jHkNf9ICv3Oi5hlNukjnx68CqQ+pbzAHuvE8IXt8prz9KhqpGDy bVQpxWNM9Jjx/V2mLSW7rTmKlu0NAhtdOe4+uKqq7ATg8WiOagIS1pJ/3684rdfrZ3YmilrHI /idEAArlKbP6GLxBnvztW3evZGCKuqyXp8yMqrwdJczae3awKl/oTM+sa58u6Hqyb7sYAwKzW 3uN2BjOhQgacdWeqlC3eCVL/BK8tDA7FKE7ijGngAf8wzMfTToYO2Ko/CGYc0n/qhrplpRMyy jnKQR0lElVUaUynxp7vcYCkXe2s23a1JcoUsND+Im/VvuL708TyP/5tbbYeowaTuGhVFjzqDu ZlAv4bhNUAtK29pYgfva2zn0hxjKriNatTvDSIfCMY0SUev7yQ4vTuZDKkkV8U3GWrphCjmpf 3Jzbn70L/nECnuPrSZlEA7ONxyV1uTzECewHHhgvHZRubD+GorGUqU2BkFaaNGBpJ2alT9Cco mrZXJgfkB5YQPknmfeRXo5u1Adq/mUxRqDBnhyy0M3kqtE4NlS9QWEqtZAVpw4Us4m49Biwz8 jqXHwToqO/aXlIywyF8f0uAn3mMqxtOU1RRBfOOSblVmuNdAivKbsidC0tI= Sender: ceph-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: ceph-devel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Call new helper __ceph_unreserve_caps() to reduce duplicated code. Signed-off-by: Chengguang Xu --- fs/ceph/caps.c | 32 ++++---------------------------- 1 file changed, 4 insertions(+), 28 deletions(-) diff --git a/fs/ceph/caps.c b/fs/ceph/caps.c index a3c0dbfac6b2..8129f6b39147 100644 --- a/fs/ceph/caps.c +++ b/fs/ceph/caps.c @@ -317,35 +317,11 @@ int ceph_reserve_caps(struct ceph_mds_client *mdsc, int ceph_unreserve_caps(struct ceph_mds_client *mdsc, struct ceph_cap_reservation *ctx) { - int i; - struct ceph_cap *cap; - dout("unreserve caps ctx=%p count=%d\n", ctx, ctx->count); - if (ctx->count) { - spin_lock(&mdsc->caps_list_lock); - BUG_ON(mdsc->caps_reserve_count < ctx->count); - mdsc->caps_reserve_count -= ctx->count; - if (mdsc->caps_avail_count >= - mdsc->caps_reserve_count + mdsc->caps_min_count) { - mdsc->caps_total_count -= ctx->count; - for (i = 0; i < ctx->count; i++) { - cap = list_first_entry(&mdsc->caps_list, - struct ceph_cap, caps_item); - list_del(&cap->caps_item); - kmem_cache_free(ceph_cap_cachep, cap); - } - } else { - mdsc->caps_avail_count += ctx->count; - } - ctx->count = 0; - dout("unreserve caps %d = %d used + %d resv + %d avail\n", - mdsc->caps_total_count, mdsc->caps_use_count, - mdsc->caps_reserve_count, mdsc->caps_avail_count); - BUG_ON(mdsc->caps_total_count != mdsc->caps_use_count + - mdsc->caps_reserve_count + - mdsc->caps_avail_count); - spin_unlock(&mdsc->caps_list_lock); - } + spin_lock(&mdsc->caps_list_lock); + __ceph_unreserve_caps(mdsc, ctx->count); + ctx->count = 0; + spin_unlock(&mdsc->caps_list_lock); return 0; } From patchwork Sat Jul 28 15:15:37 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chengguang Xu X-Patchwork-Id: 10547999 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A99BB112E for ; Sat, 28 Jul 2018 15:16:49 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9A4B62B20D for ; Sat, 28 Jul 2018 15:16:49 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8ED892B555; Sat, 28 Jul 2018 15:16:49 +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=-7.9 required=2.0 tests=BAYES_00,FREEMAIL_FROM, MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham 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 36CE82B20D for ; Sat, 28 Jul 2018 15:16:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729049AbeG1Qni (ORCPT ); Sat, 28 Jul 2018 12:43:38 -0400 Received: from mout.gmx.net ([212.227.15.15]:48023 "EHLO mout.gmx.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728951AbeG1Qni (ORCPT ); Sat, 28 Jul 2018 12:43:38 -0400 Received: from localhost.localdomain ([113.87.89.132]) by mail.gmx.com (mrgmx003 [212.227.17.184]) with ESMTPSA (Nemesis) id 0MIdTM-1fhE2632L2-002EPM; Sat, 28 Jul 2018 17:16:43 +0200 From: Chengguang Xu To: ceph-devel@vger.kernel.org Cc: zyan@redhat.com, idryomov@gmail.com, Chengguang Xu Subject: [PATCH 3/6] ceph: refactor error handling code in ceph_reserve_caps() Date: Sat, 28 Jul 2018 23:15:37 +0800 Message-Id: <20180728151540.11253-4-cgxu519@gmx.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180728151540.11253-1-cgxu519@gmx.com> References: <20180728151540.11253-1-cgxu519@gmx.com> X-Provags-ID: V03:K1:vRt3F8Tz9uNCrLjpxzgR6YR6ZQRWwNEJ/46lGp50cJbYDDcdDRg y9AzTSwSnmo08tFZXjkJderqFqZpN1Sba8+XMDqmCst8y6ooM95EIBZmLZF6doa2lXOHVFy LBEbtN41UzWLbDkmB61E5wM4i9/cQcaSZAxr5D905XmJMUyn7i3USTGvBo6Z3Zs1CVagBlm kvZll234ViGEKPY8fJ+NA== X-UI-Out-Filterresults: notjunk:1;V01:K0:zxDO/AxETwU=:7eBQJciG98kP/jIO4IEwMT D4QkSsNao6uG1RGi52inYXxYp3oJ5umbQxNg8tuZL6lL/pZ53QRcvHw7MYahoy2cGW0PYXMwM OanthsC2/fXglJAyEB3FxfBND5xA2yi1uZCQoQmyIEHJv9PAe5Z063lnfTfUjqxl9yTBnWFgN TO1GlyXCUrHTXOysTyM7V6GRETmOSivuljb/cgS1O5u/DZsLJ39o79voW+x2qRRU3DGuBmGFy 3kZNuo0Pcs4Or2MLs1u+sEv0Ipjx0KdtpWH3CPvS5cJK0r0DMthZ8X98FD4H+Xg/OqWm8xnUp PB3LkXk39+PrZR29zdzcTzhbwd10Dh2Ly402lHxFA5IPI2c9FSeUt5OGne6w/XRNdQSi3joIK XUsIYvmcjjj26IPyZrEc8fyxRVGkS6VOI9Kxb1iseE8misCgTYelk7BaD2aJ6xweO3SNPqQWj RxxC8Pcu71c+TSL91ENoAjhBjzPiVE2vG8HD/J9bwwykkU21P10efxxnV/sBCnlSwBRxIXAsK +DF7FuRLglRjvhQxMbMIUazGqCkKqIPDW8iotbs5FM4MjIGFIxcQSiyQpRUIWPFZtydbPWC5U S56qfPV7pgppuMcsoCK1BofkCXvNZRBlcJC/c3uH+pPybauEkW+GslM0HLulatshO65E7xztk ZXX1bZ1R+9ZifSr+w+prxDz9VtMdN7RsZY830C3/W67oYBuflS2nGGdSdKKKeS6GvhwyJMatD BPVMId2VRHGJSz1CzXmhI4LnEkbkmCgHTV/JxtQBwFGX1B/NKuwW3FTT9C8= Sender: ceph-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: ceph-devel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Call new helper __ceph_unreserve_caps() to reduce duplicated code. Signed-off-by: Chengguang Xu --- fs/ceph/caps.c | 40 +++++++++------------------------------- 1 file changed, 9 insertions(+), 31 deletions(-) diff --git a/fs/ceph/caps.c b/fs/ceph/caps.c index 8129f6b39147..22eb70742c0b 100644 --- a/fs/ceph/caps.c +++ b/fs/ceph/caps.c @@ -198,6 +198,7 @@ int ceph_reserve_caps(struct ceph_mds_client *mdsc, int have; int alloc = 0; int max_caps; + int err = 0; bool trimmed = false; struct ceph_mds_session *s; LIST_HEAD(newcaps); @@ -264,10 +265,12 @@ int ceph_reserve_caps(struct ceph_mds_client *mdsc, pr_warn("reserve caps ctx=%p ENOMEM need=%d got=%d\n", ctx, need, have + alloc); + err = -ENOMEM; goto out_nomem; } BUG_ON(have + alloc != need); +out_nomem: spin_lock(&mdsc->caps_list_lock); mdsc->caps_total_count += alloc; mdsc->caps_reserve_count += alloc; @@ -276,42 +279,17 @@ int ceph_reserve_caps(struct ceph_mds_client *mdsc, BUG_ON(mdsc->caps_total_count != mdsc->caps_use_count + mdsc->caps_reserve_count + mdsc->caps_avail_count); + + if (err) + __ceph_unreserve_caps(mdsc, have + alloc); + else + ctx->count = need; spin_unlock(&mdsc->caps_list_lock); - ctx->count = need; dout("reserve caps ctx=%p %d = %d used + %d resv + %d avail\n", ctx, mdsc->caps_total_count, mdsc->caps_use_count, mdsc->caps_reserve_count, mdsc->caps_avail_count); - return 0; - -out_nomem: - - spin_lock(&mdsc->caps_list_lock); - mdsc->caps_avail_count += have; - mdsc->caps_reserve_count -= have; - - while (!list_empty(&newcaps)) { - cap = list_first_entry(&newcaps, - struct ceph_cap, caps_item); - list_del(&cap->caps_item); - - /* Keep some preallocated caps around (ceph_min_count), to - * avoid lots of free/alloc churn. */ - if (mdsc->caps_avail_count >= - mdsc->caps_reserve_count + mdsc->caps_min_count) { - kmem_cache_free(ceph_cap_cachep, cap); - } else { - mdsc->caps_avail_count++; - mdsc->caps_total_count++; - list_add(&cap->caps_item, &mdsc->caps_list); - } - } - - BUG_ON(mdsc->caps_total_count != mdsc->caps_use_count + - mdsc->caps_reserve_count + - mdsc->caps_avail_count); - spin_unlock(&mdsc->caps_list_lock); - return -ENOMEM; + return err; } int ceph_unreserve_caps(struct ceph_mds_client *mdsc, From patchwork Sat Jul 28 15:15:38 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chengguang Xu X-Patchwork-Id: 10548001 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id D8A60139A for ; Sat, 28 Jul 2018 15:16:55 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C8D9A2B20D for ; Sat, 28 Jul 2018 15:16:55 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BD3572B555; Sat, 28 Jul 2018 15:16:55 +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=-7.9 required=2.0 tests=BAYES_00,FREEMAIL_FROM, MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham 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 5952C2B20D for ; Sat, 28 Jul 2018 15:16:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729064AbeG1Qno (ORCPT ); Sat, 28 Jul 2018 12:43:44 -0400 Received: from mout.gmx.net ([212.227.15.19]:52955 "EHLO mout.gmx.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728951AbeG1Qno (ORCPT ); Sat, 28 Jul 2018 12:43:44 -0400 Received: from localhost.localdomain ([113.87.89.132]) by mail.gmx.com (mrgmx003 [212.227.17.184]) with ESMTPSA (Nemesis) id 0LgZRV-1gM7pF3Qcn-00nwll; Sat, 28 Jul 2018 17:16:49 +0200 From: Chengguang Xu To: ceph-devel@vger.kernel.org Cc: zyan@redhat.com, idryomov@gmail.com, Chengguang Xu Subject: [PATCH 4/6] ceph: change return type of ceph_unreserve_caps() to void Date: Sat, 28 Jul 2018 23:15:38 +0800 Message-Id: <20180728151540.11253-5-cgxu519@gmx.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180728151540.11253-1-cgxu519@gmx.com> References: <20180728151540.11253-1-cgxu519@gmx.com> X-Provags-ID: V03:K1:QcZ2RJQPoM3j7olGw1Lmdb5H0RJ7THBCfyGjYBL4sf4v7Yi8HDg y8LnK2cgNJ2Oh9m4c7RCCHGxlyGvn/+LuMjmex4ygkgefbOSS9x8+lGoccsh2tFyLA1/nnd jH/jokOjLegf0KX7/HhjdSmRTYIwqE41UOod/vWnYo/S5ypmKakqF7k6jzYaKA0UgZvxJBH e1GM5vyur/pm7yhdx207A== X-UI-Out-Filterresults: notjunk:1;V01:K0:BasoGjGXMog=:QoqT77jWQtkIZciF+QxI/a j7hVlLk4pRgubnBCUiCv6CJcg8Fq1NU5BxqGHr0uHnaUczKaaKW1I2a8Skq8gcnQ4n1qczyLn WSZHq+b9sIJ/Q8d1CQFi4WUFqcJ+9rwXsIoDyyrce+Qye5P6fkhOQRmeztsRajGzYd9+q3QHU yglUMH/GrlyduakaKLJgTbRM/+8hM6I6XXIjrZmHkUgCzHHkr75Yh2jP5ZjhjdQSiAoV2DKtg DfJNIuzE1aPdVbMVQfthtym32/sTNNcrHMxUzxwGmWvcGhxIrz4m+zjl9vLoF9OovGzYmrn/s z0U2/Ey1GlW5Uk0U2v/oLCqjgbG3ryRT7nsMQ+XvUxKv00z+05G/7kOzh2HVvh6M6A0ChtJk0 BZhR3P+QpM30yFUzIdniu6XxSPFphLFaEHjQVYe4o2+JdUKapMaKcgrcH0H1iygOs3hHyD8nD AFjKVnphabaE2iMmcajTRifM7ZJfHguxdhVz0JVbEm5qFrb1HMS8YeJE3IPYbulWZHz9JFKc0 oTs1cnalmYCeaPw7PVIsvZrEmak88xGHy7lgO2bvL1ENUB40JDp1YVs2/eEtXv516y3x9U+9F bfwF41iAfUhhNUDG24MPqsByT20nBdMuV4H8lUuQuvzb86eZxL7DrBeVK0c7vsYwtd6pj2Zv9 n52fA8jCxSRsRwyKcJpCOFqhGAdkTVLynQVHfNO6IqA5w5Bkbu5R4dSnpz+QIeh+6B0gKLAze AnyAI7KY/CHlFVlm4r5TW98zfsD8KWhjJkDlOGrkb29KzjtS00ckzNCyjwY= Sender: ceph-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: ceph-devel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP ceph_unreserve_caps() always returns 0 and also callers do not check return code. Signed-off-by: Chengguang Xu --- fs/ceph/caps.c | 3 +-- fs/ceph/super.h | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/fs/ceph/caps.c b/fs/ceph/caps.c index 22eb70742c0b..976d283a6a4e 100644 --- a/fs/ceph/caps.c +++ b/fs/ceph/caps.c @@ -292,7 +292,7 @@ int ceph_reserve_caps(struct ceph_mds_client *mdsc, return err; } -int ceph_unreserve_caps(struct ceph_mds_client *mdsc, +void ceph_unreserve_caps(struct ceph_mds_client *mdsc, struct ceph_cap_reservation *ctx) { dout("unreserve caps ctx=%p count=%d\n", ctx, ctx->count); @@ -300,7 +300,6 @@ int ceph_unreserve_caps(struct ceph_mds_client *mdsc, __ceph_unreserve_caps(mdsc, ctx->count); ctx->count = 0; spin_unlock(&mdsc->caps_list_lock); - return 0; } struct ceph_cap *ceph_get_cap(struct ceph_mds_client *mdsc, diff --git a/fs/ceph/super.h b/fs/ceph/super.h index fe11d6903b29..98f464687674 100644 --- a/fs/ceph/super.h +++ b/fs/ceph/super.h @@ -659,7 +659,7 @@ extern void ceph_caps_finalize(struct ceph_mds_client *mdsc); extern void ceph_adjust_min_caps(struct ceph_mds_client *mdsc, int delta); extern int ceph_reserve_caps(struct ceph_mds_client *mdsc, struct ceph_cap_reservation *ctx, int need); -extern int ceph_unreserve_caps(struct ceph_mds_client *mdsc, +extern void ceph_unreserve_caps(struct ceph_mds_client *mdsc, struct ceph_cap_reservation *ctx); extern void ceph_reservation_status(struct ceph_fs_client *client, int *total, int *avail, int *used, From patchwork Sat Jul 28 15:15:39 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chengguang Xu X-Patchwork-Id: 10548003 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C8A3A139A for ; Sat, 28 Jul 2018 15:16:59 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B98C22B20D for ; Sat, 28 Jul 2018 15:16:59 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id AD6452B555; Sat, 28 Jul 2018 15:16:59 +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=-7.9 required=2.0 tests=BAYES_00,FREEMAIL_FROM, MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham 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 5D42E2B20D for ; Sat, 28 Jul 2018 15:16:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729072AbeG1Qns (ORCPT ); Sat, 28 Jul 2018 12:43:48 -0400 Received: from mout.gmx.net ([212.227.15.19]:43285 "EHLO mout.gmx.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729017AbeG1Qns (ORCPT ); Sat, 28 Jul 2018 12:43:48 -0400 Received: from localhost.localdomain ([113.87.89.132]) by mail.gmx.com (mrgmx003 [212.227.17.184]) with ESMTPSA (Nemesis) id 0M8ehf-1fxPPj3nbn-00wETf; Sat, 28 Jul 2018 17:16:53 +0200 From: Chengguang Xu To: ceph-devel@vger.kernel.org Cc: zyan@redhat.com, idryomov@gmail.com, Chengguang Xu Subject: [PATCH 5/6] ceph: let ceph_trim_caps() return trimmed cap number Date: Sat, 28 Jul 2018 23:15:39 +0800 Message-Id: <20180728151540.11253-6-cgxu519@gmx.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180728151540.11253-1-cgxu519@gmx.com> References: <20180728151540.11253-1-cgxu519@gmx.com> X-Provags-ID: V03:K1:epbSht+ZvG8qJmOWUIR7dI0IBVd40NuchqCRzNtXymuh4NPGHbX W/xfBG4Uu3zn1PhbuF4zreXrD1P180buG2/e4wcCTOtmusqpBd6NDHNhyad6PzrN+1QiQmx /JtYNlUE04aH+dQTHnbBvxiFr+rVEFli5eZpX+7UJTjTZVIHHS7tDEeMhG5W3MNiXrOISBN s6n9s7NhT5JgcoUfM73WA== X-UI-Out-Filterresults: notjunk:1;V01:K0:8fAxLqSonws=:h0+wPHzQXxL1cvMi/fb9Iq W6K5EaJDQb284BBJp9C8b6/XA5ODKGNS1so3SPXRfWY49iWcN6xvHjOYS+4+cAd/y8bnLjJwv eIipVLcC62bgzfQA2K64Bt/BNIfowHJ9TNmbqqquwgcYIjoYyk53VOVCiytC1gAA+URZBuZCG RPZatFBebMkax2H7zR566kzK9RBv/ptoJ4B+0nldAm9D/756nkd1Q5Y/54WrdjwUPZO9Ld2Rl F3DCJdnzbazFeqBiwdj0SS0bA7zWid7DLrJMEwQmo23rp8DxJMKLGRT1mpp/Q1evn76iuwjxE DzP5+Z6WXOmdp/5zEPqsIytktrUK+UJmroQOEAcd25hvxAc4qdM6J/kpObmy6URaOyhXrOthI L+Tjd5C/kGwqX0bgYGtRGnsQs9tE8jol83XYp2271H9J1hbaggNvjMY8GDnueZ0wRL5MrNmXu 1oH4IPWwfRNfPjgF0mC8qklQEyayVq9256CHyDD8e5vp6wSxNrv0HnxnboAdsjZWxDF5HbQ0U HLBKw3V4jvNwlDy9ffdFxmjSSJQUiSs7smTxRvrjRwRHRgvHzKJu+38PTXx/khZF0fKhmD0xU DXi07aJhKElLIdPWikD6lse5IbfcXl2sLvdYmr4541ufFWL86pkVH1EXAI0Q1Qx7lqd9N0LXO oX76HZfywPtdKt2Kagm2lH1qgPfYBI6uo6n1EC17AqMm2r3B8yloK9fF0QtoCX/40vCYtTLSo IS0WnZ4TQWqHoYsWxUHBlLOA35+18itp21WqShas54NJRY5Tc/ATNcGQ5C8= Sender: ceph-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: ceph-devel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP When we failed allocating new cap in ceph_reserve_caps(), then try to trim existing caps from every session and try to reserve caps again. However, if we do not return trimmed cap number from ceph_trim_caps(), we cannot know how many caps released by one session, so we have to wait until trimming finish on all sessions. Sometimes, maybe a few of sessions (not all) can release enough caps so that we can do reservation more effectively. This patch let ceph_trim_caps() return trimmed cap number, so ceph_reserve_caps() can use this for optimization. Signed-off-by: Chengguang Xu --- fs/ceph/mds_client.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/fs/ceph/mds_client.c b/fs/ceph/mds_client.c index d01a262ba691..edccf2353912 100644 --- a/fs/ceph/mds_client.c +++ b/fs/ceph/mds_client.c @@ -1611,20 +1611,22 @@ int ceph_trim_caps(struct ceph_mds_client *mdsc, int max_caps) { int trim_caps = session->s_nr_caps - max_caps; + int trimmed_caps = 0; dout("trim_caps mds%d start: %d / %d, trim %d\n", session->s_mds, session->s_nr_caps, max_caps, trim_caps); if (trim_caps > 0) { session->s_trim_caps = trim_caps; iterate_session_caps(session, trim_caps_cb, session); + trimmed_caps = trim_caps - session->s_trim_caps; dout("trim_caps mds%d done: %d / %d, trimmed %d\n", session->s_mds, session->s_nr_caps, max_caps, - trim_caps - session->s_trim_caps); + trimmed_caps); session->s_trim_caps = 0; } ceph_send_cap_releases(mdsc, session); - return 0; + return trimmed_caps; } static int check_caps_flush(struct ceph_mds_client *mdsc, From patchwork Sat Jul 28 15:15:40 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chengguang Xu X-Patchwork-Id: 10548005 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 3F033112E for ; Sat, 28 Jul 2018 15:17:03 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 304752B20D for ; Sat, 28 Jul 2018 15:17:03 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 24D892B555; Sat, 28 Jul 2018 15:17: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=-7.9 required=2.0 tests=BAYES_00,FREEMAIL_FROM, MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham 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 CA6962B20D for ; Sat, 28 Jul 2018 15:17:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729082AbeG1Qnw (ORCPT ); Sat, 28 Jul 2018 12:43:52 -0400 Received: from mout.gmx.net ([212.227.15.18]:43539 "EHLO mout.gmx.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729033AbeG1Qnw (ORCPT ); Sat, 28 Jul 2018 12:43:52 -0400 Received: from localhost.localdomain ([113.87.89.132]) by mail.gmx.com (mrgmx003 [212.227.17.184]) with ESMTPSA (Nemesis) id 0LrvBu-1g72qU3ZlO-013iCQ; Sat, 28 Jul 2018 17:16:57 +0200 From: Chengguang Xu To: ceph-devel@vger.kernel.org Cc: zyan@redhat.com, idryomov@gmail.com, Chengguang Xu Subject: [PATCH 6/6] ceph: minor optimization for cap reservation Date: Sat, 28 Jul 2018 23:15:40 +0800 Message-Id: <20180728151540.11253-7-cgxu519@gmx.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180728151540.11253-1-cgxu519@gmx.com> References: <20180728151540.11253-1-cgxu519@gmx.com> X-Provags-ID: V03:K1:xrAPYHWug8iFYezDcACv8XIvo4rJ3Zz4FfmdzEOEease1dKhAft 7XF/vmlq0HlkydncYZDe7LzpbP/u3BBsWSOM81BU/4eSiK/Vz+0lCpKkxXfhlS6GRonsICO egfNLCiuqt8aBNK6nSBxIMkZL6g8JHbyTKRKwG7CiQ3S4ep3X7lgChEYiY0NUDuMgnZhE/S g9RcdwmziU0dABI7jYgCA== X-UI-Out-Filterresults: notjunk:1;V01:K0:VwWEhg7EGGQ=:+Fiiwel/a5+2uiQCnSBSmn Q7/njyrP4AAVTQooddWAZrM/Oa/aTqRzvwK2qt8QQ4ZXyf+X1m4MEhNrSK9+ldkYQYXIJWDgd eDxK4ATf9QmVH50L9xZMiFeaioL/Ogm7xdGIwQJELCBl9cVoL7U62idOxMF4BpjUI7DNZMUTb HuMQlLoWQJeOssKDyNUlC8PfYlAMBdcqjw14/MB7To+cFAV0wIV2AUmglOs/F9V8LIvq6/f+m vvbxuavyktt7vTPl93OYASTC7TVpwzCzCB+tLoQ8JgzTbjHTh4+Lp0IiI0gGHkfQ3/q0CpvaZ MeID5ijGDwKVnQ01xr58p+uF/6pRehbC2kyPjY2/T1Q+8lzDuhlOumikXtl9Idb+fGBsqdMqz aTsUsboHFZJh2QUZciZDDaADMja6CcNBVRQmNC3j23A71mDZtMiVqDr5cWoqGoH1Y08bJaPpG 3MeQ+2JQCEiLyqnY3N+hIWMBltt3UaAlj6XHcdAq0wbz31U/9yvPGu4XDDXrO68av18Kuq5Zd yLQ1UeCp6X0WWtO7sx7TnO9PKw69rM+YllHr2BxFgGEmC8faisj/h2aTkZB2iXCNmlngcSyWn EIeF9DwS9zME5/IbsPCVrOPSBKRIvafqCzQyzqF2zgOOYPWNaFiM3AnVg1Miwt712GHl1B+LH l9abIY25vRjxcrhwE69jijP9kG1RoQ3XiWRTKf0GFvOTOWYbYCvDlBUZVHmTSORQWJXx1Rm0a 67OMDTM7SEJoptOVe7KOjba3Xu13yk55wdOKZaEL4s3Q5/yOo8J5Eh+2AGk= Sender: ceph-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: ceph-devel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP If trimmed caps are enough for need, then we will stop trimming and try to reserve again. Signed-off-by: Chengguang Xu --- fs/ceph/caps.c | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/fs/ceph/caps.c b/fs/ceph/caps.c index 976d283a6a4e..feba3ceda492 100644 --- a/fs/ceph/caps.c +++ b/fs/ceph/caps.c @@ -199,7 +199,9 @@ int ceph_reserve_caps(struct ceph_mds_client *mdsc, int alloc = 0; int max_caps; int err = 0; - bool trimmed = false; + int trimmed_caps; + int trim_start = 0; + bool trimmed_all = false; struct ceph_mds_session *s; LIST_HEAD(newcaps); @@ -227,8 +229,9 @@ int ceph_reserve_caps(struct ceph_mds_client *mdsc, continue; } - if (!trimmed) { - for (j = 0; j < mdsc->max_sessions; j++) { + if (!trimmed_all) { + trimmed_caps = 0; + for (j = trim_start; j < mdsc->max_sessions; j++) { s = __ceph_lookup_mds_session(mdsc, j); if (!s) continue; @@ -236,13 +239,20 @@ int ceph_reserve_caps(struct ceph_mds_client *mdsc, mutex_lock(&s->s_mutex); max_caps = s->s_nr_caps - (need - i); - ceph_trim_caps(mdsc, s, max_caps); + trimmed_caps += ceph_trim_caps(mdsc, s, + max_caps); mutex_unlock(&s->s_mutex); ceph_put_mds_session(s); mutex_lock(&mdsc->mutex); + if (trimmed_caps >= need - i) { + trim_start = j + 1; + break; + } } - trimmed = true; + + if (j == mdsc->max_sessions) + trimmed_all = true; spin_lock(&mdsc->caps_list_lock); if (mdsc->caps_avail_count) {