Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp786109ybl; Wed, 11 Dec 2019 07:29:59 -0800 (PST) X-Google-Smtp-Source: APXvYqySXK+6WmxJoYydsYb8+iYYmdg78EdgWDswZN+yFRvzHxkYAZMXJ8GVXpoDvvbtHS8nlotk X-Received: by 2002:aca:be57:: with SMTP id o84mr3343082oif.138.1576078198871; Wed, 11 Dec 2019 07:29:58 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1576078198; cv=none; d=google.com; s=arc-20160816; b=oaFdmRLMVD9cT3Jjy/F22Pr9pOx6grhMbt3CNiHbEBjZMEKW/JOQ6PeZs278Vamoou VHfO4IH9yCEc3aIC9z/4BU9LSJXfUc9ObucJt8g3nPJsprA9nLsWNlIlHUrLBojfMssz wXIX2uDTaxYOaAH39/obYFmbq3cNKDmsxV/w5AD72EawJM20ZmXpESriWcWU0+IXt2As 1ofrXuJiLxmWBYea9fyOfeqamtFQIUE0jLDYzihsQNgc3OAFHOkLEoCX66bHb3dEUmPg mZWk1S0k7VljP7FtXAw+X7qqyi2+Ddnwf5SekENgS9p6wbI2AXTrX5KTpH2mhGuX0wOR cSdQ== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=UXy/Xx1MwICovBcQZ4R/JidgsFpHv7rHOz0MohxOJiI=; b=TNcoBICI4zsGO3ZEj590JBt0LKqz4FCd/hbS9YUayw+D9wPhC0dKeL5c2ZT48x3PCS lIrAe1/610E8oHoEKocMq8ygOgAoilTDgwGtqnhe5+eDl32YjoYR5Zpju7zyvVH19PVm 0zkij16Y/YdzrH0o7V9SLkeBRkmlrwFWMFFrDY9hWWjlc7R6aC7818vJkZ7Nd0MBhsTS bEpPz3IbQ7EvPE2bQ3yNAMy6l48rTD50cq0hX4lgbTjxtyIOJAefn3soSDpRUQ3uxxZ6 DXsCgNbbOdCmZOFH2S+hnYa4rVdnQJJAa88JsAVUcrnPNzpQBbTa3sJh8V12i/900bn1 /yqA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=fh+HePk7; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q25si1409951otg.128.2019.12.11.07.29.46; Wed, 11 Dec 2019 07:29:58 -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=fh+HePk7; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387832AbfLKP3P (ORCPT + 99 others); Wed, 11 Dec 2019 10:29:15 -0500 Received: from mail.kernel.org ([198.145.29.99]:35600 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387804AbfLKP3G (ORCPT ); Wed, 11 Dec 2019 10:29:06 -0500 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 2CE9E208C3; Wed, 11 Dec 2019 15:29:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1576078145; bh=6wMgZwKLgEGkwTL+1Vd9LfABc3xDvEAKNMrFn8ElL7I=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=fh+HePk7mfpLL7kyHJlnQwSBOiNinoRGBe03h8YpaH+C2FxNDv9m/TwVpci7IgeEN t127DdVBiRVoaJkU08ieomCodoFZ75ijKd5SsdKRGCSAn1rYLUxtnES9g9Yd9nWZSW i+2Hl3fX1Dy2EZqhhyMN9Ysuh3VISIEA/ZEtgWzo= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Coly Li , Jens Axboe , Sasha Levin , linux-bcache@vger.kernel.org, linux-raid@vger.kernel.org Subject: [PATCH AUTOSEL 4.14 32/58] bcache: at least try to shrink 1 node in bch_mca_scan() Date: Wed, 11 Dec 2019 10:28:05 -0500 Message-Id: <20191211152831.23507-32-sashal@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191211152831.23507-1-sashal@kernel.org> References: <20191211152831.23507-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore 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 9406326216f17..96a6583e7b522 100644 --- a/drivers/md/bcache/btree.c +++ b/drivers/md/bcache/btree.c @@ -685,6 +685,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