From patchwork Sun Feb 25 05:39:09 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chengguang Xu X-Patchwork-Id: 10240675 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 EC99260233 for ; Sun, 25 Feb 2018 05:39:33 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C636B29BE3 for ; Sun, 25 Feb 2018 05:39:33 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B7B7729C42; Sun, 25 Feb 2018 05:39:33 +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.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID 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 63A7A29BE3 for ; Sun, 25 Feb 2018 05:39:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1750731AbeBYFjX (ORCPT ); Sun, 25 Feb 2018 00:39:23 -0500 Received: from mr11p00im-asmtp002.me.com ([17.110.69.253]:50551 "EHLO mr11p00im-asmtp002.me.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750720AbeBYFjX (ORCPT ); Sun, 25 Feb 2018 00:39:23 -0500 Received: from process-dkim-sign-daemon.mr11p00im-asmtp002.me.com by mr11p00im-asmtp002.me.com (Oracle Communications Messaging Server 8.0.1.2.20170607 64bit (built Jun 7 2017)) id <0P4O00200Y9BKW00@mr11p00im-asmtp002.me.com> for ceph-devel@vger.kernel.org; Sun, 25 Feb 2018 05:39:18 +0000 (GMT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=icloud.com; s=04042017; t=1519537157; bh=gfHJGiIdrqTl3ixV0M9g37/1/Dg7skvaOiMTuqWp74U=; h=From:To:Subject:Date:Message-id; b=Xz1saGAbKOXvEYYgTxhCUVDgpqUjuEnW2YH+/c9ttcZlU2fq7I+Fl5P8AjKYv404S mPOGpFzvH3LHnijj+dxD4wcdeckV7/bxjxEhBhU+8IXPZZJtyo1/Doh0mLYxhOaXcD QRkq+WQm7mnzNnf7e4GAsE1WGuv0d678z9eolPQdniEV62eT6//H8gkvrdPdeOermD UJewr58BYx/j5yvua7GgV3xS4Q6hIeYrHLQAzNUPXipqGk3QyoK0emybbJmeptlPOv wRhqzLqTwdIymQMaumsZ7WrqfhDGWuzVCwNGnfCOXdhMzbj1qsgoqQMXuGwTgvNrQN S+Xbl3pvoyZ8Q== Received: from icloud.com ([127.0.0.1]) by mr11p00im-asmtp002.me.com (Oracle Communications Messaging Server 8.0.1.2.20170607 64bit (built Jun 7 2017)) with ESMTPSA id <0P4O003KAYDC2900@mr11p00im-asmtp002.me.com>; Sun, 25 Feb 2018 05:39:17 +0000 (GMT) X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:,, definitions=2018-02-25_01:,, signatures=0 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 clxscore=1015 suspectscore=2 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1707230000 definitions=main-1802250073 From: Chengguang Xu To: zyan@redhat.com, idryomov@gmail.com Cc: ceph-devel@vger.kernel.org, Chengguang Xu Subject: [PATCH] ceph: release unreserved caps if having enough available caps Date: Sun, 25 Feb 2018 13:39:09 +0800 Message-id: <1519537149-134084-1-git-send-email-cgxu519@icloud.com> X-Mailer: git-send-email 1.8.3.1 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 unreserving caps check if there is too mamy available caps in the ->caps_list, if so release unreserved caps. Signed-off-by: Chengguang Xu --- fs/ceph/caps.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/fs/ceph/caps.c b/fs/ceph/caps.c index 6582c45..b334973 100644 --- a/fs/ceph/caps.c +++ b/fs/ceph/caps.c @@ -254,12 +254,26 @@ 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; - mdsc->caps_avail_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,