Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp2295754ybl; Thu, 19 Dec 2019 11:09:40 -0800 (PST) X-Google-Smtp-Source: APXvYqyX4PTFXri9chmug6Ua8eqK2oC5LcxQKiqXJP2ZvpbYROa5bbN6mi8jKFukZM/aB7jULWuC X-Received: by 2002:aca:3c83:: with SMTP id j125mr2998326oia.163.1576782580779; Thu, 19 Dec 2019 11:09:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1576782580; cv=none; d=google.com; s=arc-20160816; b=V0/6e2Bt7HPcxVNsJxs6gnMrinf+/RNhUdUg/gbSFqq1Bxe6orLXja/SOcu3+mkhNs egqtqlS+PiDfAqG7NCVLMdxualf8eTFamx+SfbAXIbZ97B8ahKID3Yl7uTSAQs3MAQHV 8iT4a+sa/FsFbYhjKTizvarTg38D2F4tcQL/Qv670KOmN2s3ZTnlrIT0rGJ2U/QoouCS 469hF0QrQRQEGC5iH2HOxLg6DnWjy4ZGxwg8PkztojEFeci6mdmiI4h4AZbsNr2pfvkR x8ioc+kfg5Y/VaD3EFo0LSITbOz+k0K4lNHFXcddT9HagwHdGo8XDAYLVDj2JTXui2M8 /6ng== 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=P5rddgXAh7gZbUQcwThTevE/ipG2TrppBOlA09JdbFwd1dZO3g+zd3J/EKxrrSqzuD +Mtt0Fqx2Zl8XjUlU/LrySCYsChTOEvxR835tuq0rlkkY4mGWI9Yasyae/gp/g5ChrvQ hLkExT4/DEp5MCKh8lwycwbvVGa6u+jmcffUw8FAzV0mL8VB0SX9dvXw+g34IiKdd3ze es8S0iE27kKRgWx0IRGm7C0lYL5CAv+//b2uLdC2my2CA6aHQPcQgo3Ms+SJTGlnormx cZbiFNtKnfgh30qehA5cyvUE5MvWJZI+GSeLHvXcvoFSeyvnpGG83RqaJJ96hhVricbd zuGg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=Jdn7XuUi; 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 w64si3408566oif.51.2019.12.19.11.09.28; Thu, 19 Dec 2019 11:09:40 -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=Jdn7XuUi; 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 S1728183AbfLSTIc (ORCPT + 99 others); Thu, 19 Dec 2019 14:08:32 -0500 Received: from mail.kernel.org ([198.145.29.99]:32782 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728592AbfLSSlu (ORCPT ); Thu, 19 Dec 2019 13:41: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 27DE824672; Thu, 19 Dec 2019 18:41:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1576780909; bh=ZDWjkucWnuNDUFia2/GxQNQEtlT4iZWmBPaU8zSh7vg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Jdn7XuUiAUTGsl4evuknHJ31GQwDUG5MIC38UJymiSAuEancUBOG0mxYBvOcGqVty 3grl7wtTSzfvEQXhcOh/kTAmBCCkijJnv4UAnGwpMVw/Xd+OvSxsAcaI3a7meLpL/Z 61xeNJngW+YrA5DrEiSVMwp4QWr5t1oRYCL1gB9Y= 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.4 158/162] dm btree: increase rebalance threshold in __rebalance2() Date: Thu, 19 Dec 2019 19:34:26 +0100 Message-Id: <20191219183217.385922830@linuxfoundation.org> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20191219183150.477687052@linuxfoundation.org> References: <20191219183150.477687052@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) { /*