Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp17925561ybl; Thu, 2 Jan 2020 14:57:03 -0800 (PST) X-Google-Smtp-Source: APXvYqyEPMeLlqxRO9hBdRLzUUaCrmWuB0gQIOvecDoySatXGyGJfZtOgshmXYvIDu9AA/v4UOO/ X-Received: by 2002:a9d:4692:: with SMTP id z18mr92024049ote.163.1578005823798; Thu, 02 Jan 2020 14:57:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1578005823; cv=none; d=google.com; s=arc-20160816; b=UsLu3ubJb/x30QW/Ap5xl8D82Mxd+OujsrCC3mJqj+PRpMt/4gQrYbnYMkplCZDmWr 0CMnk2AU0Vom1xB2Je3C1Vg5dmY/7D7cbB/GVBXu7EyrEQL6o9QGZL9AohIDu+3Bgtl5 fGiubvy0rX0bqbu9+vx/0ljTDxf4t1ZQobPL6R4L38YqH85pS5rI37INVYj59z/h2Co9 McbH+ovbvM3ZQC8mNzyXBGajOLkPyBDoFiXlL0vhzd5uCx9M3kVYJ/rQ4Ju7gkNKlI0d 1xZoqvJxlEknWg52OTwczpFS+B/0l49fAv+pFlS5Pb1YmqUGuaQV7dpeGlyR+RlGxW6o qTmA== 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=F5kwpvuXlPiuiy1U7TeHDLax9dweCYiislulFWosDcc=; b=T4Tl0ljb46jIgYtw3Q4VycWDkxF02HR3hsxtrLkKKM8TsEyZdkE4vTCVD36Y/Pz1R8 NKXDeM3A/wMZfgYRooa6H4jYNf3yw/LglfAewSShd96msEbbDRqxQBXm+E3hhDgx3RY5 X1TGf9HsBofzVB0XmU08tXm9MNpzCfWyyFzzqYdNfMXrjLWqPPDGZYYP5nyrWWaQ6QKy 3dBSoCgDUg1GvnoSPoW5EePh3tCqcdEEoH8QqSkAuc1YqsC0VjU4aaZS9PMRcF+yErSG icrJMkcmEUi3upiMEuSCq1eM0i31IPx1ZGMCmI9Cb7WCmUUm4jonY6g8vHndY8gYMu0z Pd+Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=kyPrkMmW; 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 u16si27784677otq.92.2020.01.02.14.56.52; Thu, 02 Jan 2020 14:57:03 -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=kyPrkMmW; 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 S1729029AbgABWyu (ORCPT + 99 others); Thu, 2 Jan 2020 17:54:50 -0500 Received: from mail.kernel.org ([198.145.29.99]:37672 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728287AbgABWUV (ORCPT ); Thu, 2 Jan 2020 17:20:21 -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 E32692253D; Thu, 2 Jan 2020 22:20:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1578003620; bh=X+Do8u5S6VNWIX901s2stI315wdsbjiGl6J8hVjzR6A=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=kyPrkMmWqLvNC/AVRakl0cvVPcOpizbFeR0/cF+FvCVKSvgfkSuGMs8ox39fz/Dbi ZTfdJ7NMpVxUyeg+bZ0SJY8Z7UuDhdFnTrVMjafzXpeURPesCbZxLpOj0QpEbvB6dX wwvGgQYW5om0ECh114vGVIFaVc0OxIEySxnCYDcc= 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.19 044/114] bcache: at least try to shrink 1 node in bch_mca_scan() Date: Thu, 2 Jan 2020 23:06:56 +0100 Message-Id: <20200102220033.534038277@linuxfoundation.org> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200102220029.183913184@linuxfoundation.org> References: <20200102220029.183913184@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 45f684689c35..bb40bd66a10e 100644 --- a/drivers/md/bcache/btree.c +++ b/drivers/md/bcache/btree.c @@ -713,6 +713,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