Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp2285053ybl; Thu, 19 Dec 2019 11:01:10 -0800 (PST) X-Google-Smtp-Source: APXvYqxFcdV1lFnskUlcC6ju060h2oPwXkgQNz/hTBODwWtkWRwXKFrRn0MxmvSTWfv+ultiGEtz X-Received: by 2002:a05:6830:4a4:: with SMTP id l4mr10469554otd.91.1576782070733; Thu, 19 Dec 2019 11:01:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1576782070; cv=none; d=google.com; s=arc-20160816; b=O/+x4M1Yn51OaL4dZc6AcrzRKbK4UuHhCMmbGk+gYARcTgqVnGtRcrgIIbkZaW7J9t l5++ZmPhw9A/+6uHRXTrriYMRj31BEdoNtf8upJ/y9CRn1JgjS0cSf6mYMxjq05qkPNZ 4Kd95vqh98teknQyE+oM/0tzSm+gwWVQDGMWRRReWgg3JiSWgL00uVg7f51nWyZR96fT TjleZA+6Fi5wrKdHyHRw2Qb0TBg0pGWza3VVwhAL9UoJXvmeLLlpjEI22TKCPJ5LbWo5 W6pRdoAM4YdY4I4xnTPml5PdftTWAtHMJXyFdKx4PEIA/t2aHILooEfLTw1+LXK5+KOw 5MWg== 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=lRa3GDjvYJqEhPJ4TsY+omtdBykSJ1dWSi1HMYZ/qr8=; b=dL+dDP19cuUy5qFVIHdZnz3haKXCr177srPXOZ3wko0PaB5q6myEmkwkK7WCqyEtkN EF0tikPly7FcOeGbYqd7SSV1gtyD9owM68ThqqCeY8kM9hKU4sQLJSjUiPfsiYomIcwV yg6MhUQ2ge/1wuIIvbgFx5ekTOF9MBm2pefJAeHaVOB28vo4b/hhjrF/lgQF3ZlHRZ+4 J6Lb/ZqwqshzQ+UL7vw9/y2jXuTiHJOaAhHW8J6Mf6rLJAX4au4RmwjpltQwR0KvXUSc 00wxG2LysaK0mkE50KyrwEBCawmXEV7OW4i2muw5pkDLnSFVMp78aqjNZJqpZm/RXfri DL/g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=0VJjrUMn; 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 e192si3583029oib.82.2019.12.19.11.00.57; Thu, 19 Dec 2019 11:01:10 -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=0VJjrUMn; 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 S1730008AbfLSSxE (ORCPT + 99 others); Thu, 19 Dec 2019 13:53:04 -0500 Received: from mail.kernel.org ([198.145.29.99]:47790 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730083AbfLSSw7 (ORCPT ); Thu, 19 Dec 2019 13:52:59 -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 2CFFC222C2; Thu, 19 Dec 2019 18:52:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1576781578; bh=ZDWjkucWnuNDUFia2/GxQNQEtlT4iZWmBPaU8zSh7vg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=0VJjrUMnlPsaD74VfHpAe7pgwmDiezSiPubMjy2Vx0UCemjtuWJIQjppEJ35xEELf 8hJUpSda2N4eeGgtXVrkaCIegsaw7AmLQDw+UZYXCBV+fH8OGoaz5ZzMiQwW/i/YVq eyAsQWhdtONuae4E3Ie9yqsRhRDKc8caTx71JxjU= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Hou Tao , Joe Thornber , Mike Snitzer Subject: [PATCH 4.19 43/47] dm btree: increase rebalance threshold in __rebalance2() Date: Thu, 19 Dec 2019 19:34:57 +0100 Message-Id: <20191219182950.995282050@linuxfoundation.org> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20191219182857.659088743@linuxfoundation.org> References: <20191219182857.659088743@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: Hou Tao commit 474e559567fa631dea8fb8407ab1b6090c903755 upstream. We got the following warnings from thin_check during thin-pool setup: $ thin_check /dev/vdb examining superblock examining devices tree missing devices: [1, 84] too few entries in btree_node: 41, expected at least 42 (block 138, max_entries = 126) examining mapping tree The phenomenon is the number of entries in one node of details_info tree is less than (max_entries / 3). And it can be easily reproduced by the following procedures: $ new a thin pool $ presume the max entries of details_info tree is 126 $ new 127 thin devices (e.g. 1~127) to make the root node being full and then split $ remove the first 43 (e.g. 1~43) thin devices to make the children reblance repeatedly $ stop the thin pool $ thin_check The root cause is that the B-tree removal procedure in __rebalance2() doesn't guarantee the invariance: the minimal number of entries in non-root node should be >= (max_entries / 3). Simply fix the problem by increasing the rebalance threshold to make sure the number of entries in each child will be greater than or equal to (max_entries / 3 + 1), so no matter which child is used for removal, the number will still be valid. Cc: stable@vger.kernel.org Signed-off-by: Hou Tao Acked-by: Joe Thornber Signed-off-by: Mike Snitzer Signed-off-by: Greg Kroah-Hartman --- drivers/md/persistent-data/dm-btree-remove.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) --- a/drivers/md/persistent-data/dm-btree-remove.c +++ b/drivers/md/persistent-data/dm-btree-remove.c @@ -203,7 +203,13 @@ static void __rebalance2(struct dm_btree struct btree_node *right = r->n; uint32_t nr_left = le32_to_cpu(left->header.nr_entries); uint32_t nr_right = le32_to_cpu(right->header.nr_entries); - unsigned threshold = 2 * merge_threshold(left) + 1; + /* + * Ensure the number of entries in each child will be greater + * than or equal to (max_entries / 3 + 1), so no matter which + * child is used for removal, the number will still be not + * less than (max_entries / 3). + */ + unsigned int threshold = 2 * (merge_threshold(left) + 1); if (nr_left + nr_right < threshold) { /*