Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp17893945ybl; Thu, 2 Jan 2020 14:15:18 -0800 (PST) X-Google-Smtp-Source: APXvYqzlDA/xabp6ci2gJAPTnbMSMnMZEcium0qTBwRKTlVWdKvXP8I+ucjxOyB/fipa3RF3Mdw+ X-Received: by 2002:a05:6830:1402:: with SMTP id v2mr82894001otp.12.1578003318117; Thu, 02 Jan 2020 14:15:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1578003318; cv=none; d=google.com; s=arc-20160816; b=zAt+Kkxv56JClE/BPdxH0ohDZOc/CdEkSdonMIu3DPgO+L2hGOIrteuT9gk6cSAnbi M3r34nYYBQL1hyrSj54t3wTAlW5AYlF7iBepPr0x2RQirWoc+1vecLqpdPsts5GxnUKO jeDVFXFvXMNGCPmj7JB7slcywRlUCrRh1gh3n6RCMRTAKRbkAhTM+1nWcWvepZ3pF0Rp KdPt6+fW8wDwLT2lr6ZILuTaiCcKAZ6AZDP3P+cAOMoOzv31d/PuA1zCCShHk3kKmsO+ fLLpZG8sCa3+5nSnw5IZAIZ55gjqrlhbJQPQRRYYONghiLeKg7cKp6+XMfk4JaVTQam2 XRfg== 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=dML4dOlv8CX28qEnrnVx+NtAiAkmWEpZ26JuoFINeUY=; b=SX4uZbw1kTCbVVNwN7o4MBHOuRekfA7GBDd4bE6KgUem9uH4RpfHF2B/5nWU27EFcT ym8RCWaZ1y+yMk0rKYlY52mapes4eoTts9FKj17El1sM2T0sboDNFmd85Yf/Kq8BsFHU VIB9qHaTKXoSIY7Zj/hiHRrY7ooxsGx3KGtucygY287H8IE98Ft4rGwrzw9UfHcqYk5b FortRocGg0DkFmV0fYDkkJCZCk8BzQivm9KVzgIPqgJma0rs+3+YtyKyP+MOAdKqAwCM UjosAeqZ4pfiEsDvlqEOOjI+NOedZWG5FSXElbbKmFtZ5dK0/dcwAaNnhDEeBmKOARR7 hH0g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=TYunpOGY; 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 l20si29171938otr.227.2020.01.02.14.15.06; Thu, 02 Jan 2020 14:15:18 -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=TYunpOGY; 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 S1727796AbgABWN6 (ORCPT + 99 others); Thu, 2 Jan 2020 17:13:58 -0500 Received: from mail.kernel.org ([198.145.29.99]:53882 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727783AbgABWNu (ORCPT ); Thu, 2 Jan 2020 17:13:50 -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 8C0D622525; Thu, 2 Jan 2020 22:13:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1578003230; bh=ab0dlAuHSLnnrDq6odW3pzClF0oFhHJ+vgkjhTlQV1Y=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=TYunpOGYoGmr8wfob90dCj6PoLn5TL8xyCJtmDHgvHaPpHD2cEON6oFLZ0oDpWoA5 RRa4pU8IQDZ9XEShWMjFXmWqfTQfGZbzae+J0LUqR8L78B5knlmjLeqc+omfemUYPj Y32Tj0wyIxiy4JMO2hOH9Qa1kEpJRt3ZDlmcFR/U= 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 5.4 074/191] bcache: at least try to shrink 1 node in bch_mca_scan() Date: Thu, 2 Jan 2020 23:05:56 +0100 Message-Id: <20200102215837.871500197@linuxfoundation.org> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200102215829.911231638@linuxfoundation.org> References: <20200102215829.911231638@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 ba434d9ac720..46a8b5a91c38 100644 --- a/drivers/md/bcache/btree.c +++ b/drivers/md/bcache/btree.c @@ -723,6 +723,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