Received: by 2002:a17:90a:9103:0:0:0:0 with SMTP id k3csp11811035pjo; Thu, 2 Jan 2020 14:41:19 -0800 (PST) X-Google-Smtp-Source: APXvYqxbRu5Irlq72MYKOZA6LwKwHeS8E5Qx+IKbSYpt9Zc9AAAFPFEfkySjSh8SYSavapZVDTzw X-Received: by 2002:a05:6830:1651:: with SMTP id h17mr89848908otr.167.1578004879693; Thu, 02 Jan 2020 14:41:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1578004879; cv=none; d=google.com; s=arc-20160816; b=tSahyUh0Vt2rbGMOWw43KHGBBXq9iPTfsT+iwtJGBR5tDoBcaENVYU16i+tSZEmbjz mXxQsPuQEam/KXZe4Pzgiosd4gTGGJdQjir5vtwNAXbnmeWcN9UAGephh3/momZHGr4p YBLU6tp49mFxp/FZgCqtxYdvxRgfvY5Z3wskdCSlimGRofZ0fWG/R70GLuoge9f/3tEz u9f77MKpLRM5ITuBgJTSu5CiElj2k06Z0f7S16BAKpktZGVmmNyyaptOM4aOzy6etOXP 9KfzrEU2G2Drl0uqA97Pt9JomGBr7yFFYxorXFz3iJ0oLL0T+JssckMe+W2p/UfnhAWG lEsQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=E7//m5XeIqpfz4jO232Ea2wd9xT9CY3+fAC2501A9uY=; b=ZCPhiOjux5gf0ZiEOuSisP8N790DjRTx6liUtXvoxuuMMTM9//TnvyLrS8Yh9GKjbY cwHvXy6CR3KHYo9k9ivvkvs7X3lEWFO+DaDWxV3Mg40c4cJoElKJIGlBRY86N0vIzvGz yj0uuaDkC3DYs/M8LPqYuzMzm+KowuNnOwNMyovK2IIcTklHfvupYSR0yBLrnJBjCAz+ rdc+Y60QZkeEYPaThNxqzyh4krGlpUc24/RQ1ZXopNV7Vb86V2cdpO3bkkxmGJi6bhAh LQbohP4JSgT7F5fCXDQcPD2T0CqHYsrMrr/x6NEew39dBBLrRUN/viBjecoTwCvkjpoZ EHzw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=q3I7NqlD; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h28si36328456otg.63.2020.01.02.14.41.08; Thu, 02 Jan 2020 14:41:19 -0800 (PST) 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=@kernel.org header.s=default header.b=q3I7NqlD; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731442AbgABWjQ (ORCPT + 99 others); Thu, 2 Jan 2020 17:39:16 -0500 Received: from mail.kernel.org ([198.145.29.99]:54930 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731075AbgABWjQ (ORCPT ); Thu, 2 Jan 2020 17:39:16 -0500 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id E6421217F4; Thu, 2 Jan 2020 22:39:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1578004755; bh=0Uf6/eakuHv0RxJRP5QLczbHPxCFOinkZd+1IggRG1o=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=q3I7NqlDUHxrhGBGt/YFutU/QVfipgzKlOnbr+yzkpvE4Z/2FIKGPsZrmWl22WK6E tHSXRzsxtDslY1vnR+w5+GaQP3yoIqhs6qC+vzzM1auU2BgQqBN0m990uCuXEOLhwB LsANSmVDhghmVnsUMtcAVZmm5hsGbifLEhWGBSZs= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Coly Li , Jens Axboe , Sasha Levin Subject: [PATCH 4.4 114/137] bcache: at least try to shrink 1 node in bch_mca_scan() Date: Thu, 2 Jan 2020 23:08:07 +0100 Message-Id: <20200102220602.500489232@linuxfoundation.org> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200102220546.618583146@linuxfoundation.org> References: <20200102220546.618583146@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Coly Li [ Upstream commit 9fcc34b1a6dd4b8e5337e2b6ef45e428897eca6b ] In bch_mca_scan(), the number of shrinking btree node is calculated by code like this, unsigned long nr = sc->nr_to_scan; nr /= c->btree_pages; nr = min_t(unsigned long, nr, mca_can_free(c)); variable sc->nr_to_scan is number of objects (here is bcache B+tree nodes' number) to shrink, and pointer variable sc is sent from memory management code as parametr of a callback. If sc->nr_to_scan is smaller than c->btree_pages, after the above calculation, variable 'nr' will be 0 and nothing will be shrunk. It is frequeently observed that only 1 or 2 is set to sc->nr_to_scan and make nr to be zero. Then bch_mca_scan() will do nothing more then acquiring and releasing mutex c->bucket_lock. This patch checkes whether nr is 0 after the above calculation, if 0 is the result then set 1 to variable 'n'. Then at least bch_mca_scan() will try to shrink a single B+tree node. Signed-off-by: Coly Li Signed-off-by: Jens Axboe Signed-off-by: Sasha Levin --- drivers/md/bcache/btree.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/md/bcache/btree.c b/drivers/md/bcache/btree.c index 05aa3ac1381b..5c93582c71cc 100644 --- a/drivers/md/bcache/btree.c +++ b/drivers/md/bcache/btree.c @@ -686,6 +686,8 @@ static unsigned long bch_mca_scan(struct shrinker *shrink, * IO can always make forward progress: */ nr /= c->btree_pages; + if (nr == 0) + nr = 1; nr = min_t(unsigned long, nr, mca_can_free(c)); i = 0; -- 2.20.1