Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp348416ybl; Wed, 11 Dec 2019 19:53:07 -0800 (PST) X-Google-Smtp-Source: APXvYqxU5UvKPCj/kFBLHafekFWBJQ0WlMYl+baLAfqoBItwE5ZBqwLlCSHw8rVLpQSI5T3zBu5G X-Received: by 2002:a05:6830:1116:: with SMTP id w22mr5907916otq.216.1576122787281; Wed, 11 Dec 2019 19:53:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1576122787; cv=none; d=google.com; s=arc-20160816; b=i3lDiE3+73bOlgipPfDB3G03mi4JJiRU2Q+abLyWxsJjKWvfyJbVkYF9gJuZ3aUQHa 5bTd7FoMq1SE0iU3oI5rGuEAlcGR2pmYtG+Czn8JrTQ+jflinApPIL/L/2+zeheRhIf0 IQfA/BZIVqKUZlPiN5eRP4+nsjXbbxDdAHCSulmvRoYvrcQMOqyUqSheUZXeU30R6BRw xYnPcl285y81IYp3ezMC7dmsrAgGtiMqpoCIjhaJjSaO4j6Wlq8RltmMWj9jFgjlXPlg ugRItltJvI0TlNXCPK4j/D2JnzB7jDSjEIvGh9ctaI39I7sr9oW521xv5qrh1CvtXd4o e70w== 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 :content-language:in-reply-to:mime-version:user-agent:date :message-id:organization:from:references:cc:to:subject; bh=y9R3YRQgzC+HIdwRS8u+zhD1slvsc8imPocfhPrTSsM=; b=OUn44604yOYi1cwtMkTHKyQnZ/4gdV4D5eHrVgZ1ftkzL5EqTP096Ud4hKyys7dMGa szRlvYBZpvKmG/C4hGwZ5yXr3mpm1EW339U0aOSSurnask1WizEef7/fGMcPzXrH9mQu fVFReHHvF7Wq/l7eyv7Se75ZjhOJRQsD3e+rDCaStPHR+WusXm0YBjY1urYOowhVxgJl RlXwO2Id6pIeQJ333/n/I4ONf1SLMw5EACwCeVt2Z91pk9QBI8WsiRM2LvGThn7F1B9Q +5uoT0hj/Cq0inDa3kcbGJvKy/WYE40nNcYrnRag/fRBo21oPRI0NKsuYUI24oYUZaEW G/hA== ARC-Authentication-Results: i=1; mx.google.com; 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 o21si2654301ote.320.2019.12.11.19.52.55; Wed, 11 Dec 2019 19:53:07 -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; 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 S1727668AbfLLDwZ (ORCPT + 99 others); Wed, 11 Dec 2019 22:52:25 -0500 Received: from mx2.suse.de ([195.135.220.15]:33742 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727421AbfLLDwZ (ORCPT ); Wed, 11 Dec 2019 22:52:25 -0500 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id D78AAABE9; Thu, 12 Dec 2019 03:52:22 +0000 (UTC) Subject: Re: [PATCH AUTOSEL 4.14 32/58] bcache: at least try to shrink 1 node in bch_mca_scan() To: John Stoffel , Sasha Levin Cc: linux-kernel@vger.kernel.org, stable@vger.kernel.org, Jens Axboe , linux-bcache@vger.kernel.org, linux-raid@vger.kernel.org References: <20191211152831.23507-1-sashal@kernel.org> <20191211152831.23507-32-sashal@kernel.org> <24049.47251.286105.88377@quad.stoffel.home> From: Coly Li Organization: SUSE Labs Message-ID: <3363848c-6422-31b7-4ec2-0899f605a7f5@suse.de> Date: Thu, 12 Dec 2019 11:52:13 +0800 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:68.0) Gecko/20100101 Thunderbird/68.2.2 MIME-Version: 1.0 In-Reply-To: <24049.47251.286105.88377@quad.stoffel.home> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2019/12/12 11:48 上午, John Stoffel wrote: >>>>>> "Sasha" == Sasha Levin writes: > > Sasha> From: Coly Li > Sasha> [ Upstream commit 9fcc34b1a6dd4b8e5337e2b6ef45e428897eca6b ] > > Sasha> In bch_mca_scan(), the number of shrinking btree node is calculated > Sasha> by code like this, > Sasha> unsigned long nr = sc->nr_to_scan; > > Sasha> nr /= c->btree_pages; > Sasha> nr = min_t(unsigned long, nr, mca_can_free(c)); > Sasha> variable sc->nr_to_scan is number of objects (here is bcache B+tree > Sasha> nodes' number) to shrink, and pointer variable sc is sent from memory > Sasha> management code as parametr of a callback. > > Sasha> If sc->nr_to_scan is smaller than c->btree_pages, after the above > Sasha> calculation, variable 'nr' will be 0 and nothing will be shrunk. It is > Sasha> frequeently observed that only 1 or 2 is set to sc->nr_to_scan and make > Sasha> nr to be zero. Then bch_mca_scan() will do nothing more then acquiring > Sasha> and releasing mutex c->bucket_lock. > > Sasha> This patch checkes whether nr is 0 after the above calculation, if 0 > Sasha> is the result then set 1 to variable 'n'. Then at least bch_mca_scan() > Sasha> will try to shrink a single B+tree node. > > Sasha> nr /= c->btree_pages; > Sasha> + if (nr == 0) > Sasha> + nr = 1; > > > Wouldn't it be even more clear with: > > nr /= c->bree_pages || 1; > > instead? No, it is not more clear. At least to me, I may confuse does it mean, - nr = (nr / c->btree_pages) || 1; - or nr = nr / (c->btree_pages || 1) If I don't check C manual, I am not able to tell the correct calculate at first time. Thanks. -- Coly Li