Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp2341785ybz; Thu, 23 Apr 2020 16:22:00 -0700 (PDT) X-Google-Smtp-Source: APiQypIX1jbBOQ57Kvtu7WmQD6SIknrxWHicQdhT2MSC2MUaesktcN26/YlDoNT3pozQherHZ6FG X-Received: by 2002:a17:906:468c:: with SMTP id a12mr4937599ejr.149.1587684120034; Thu, 23 Apr 2020 16:22:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1587684120; cv=none; d=google.com; s=arc-20160816; b=KPX+oHi+SnCK5c/+DXzmp0vSR/plvL6UFsk0I5yd6QsLQitazn+JV1wPdiyIAeBTY/ TWZLcsuSd1y8Q6pZuhTPpu7SjfjjVK+viOE2d8zhrFw7EW2UdBLL+Os4+WDWbXZ36aMB bsPUojjZ2ubQ6ztc0XN243GTjD1VuaaMBGZU4BMF9GHoA4vFmg8jckzSeZasqquS/fmv dxlq5cYJCfMeippLWP3vxvjs5eS6KyTXieN3KV/bJyx5/jkug3f5PS+RzYfXTGf/0H9D s9ACUWf7AWzZZWhs+Qpifp5+AS2HxSXHfGQhMJ17+0KXd7ISs3HqfD8eRJERj3OuTgmO iYXw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:subject:message-id:date:cc:to :from:mime-version:content-transfer-encoding:content-disposition; bh=njvsXa9Bozy74KBKc5iLssAmzO2swptlZAWl7BEAvi4=; b=VgJSB7H/awro6+yMPwBRHPRX1SCjXTm2OcROJfsSfMvOAMPJ4CsGnerKAAOgJvSEkP IIjJdoQTCTKOgn6as9ZlwkLaIitgoUHqOJcIn2S1uTYaDXVr54w65HxBf7Z1ZdSxEtMx 7OoZBMrNaWRG6DKmBCxnCMn89doGJyTKkIhF8barImvorH0b2Yvim+j63hzRSRQ97F9W jZk30qxldTEAi+0ns9kgi81mkiJruo0xeMGcsyxKYRdi9h+bnf7LAbqjYJ+XDND2z2iR Qk0Nxah1T7NgqWD/6Zj3X27GRq2Q7VUXI0rxuPdywaOxRDVpGw3Ng1fr4ZYmJJmoMlmG XuSg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id n12si2422276eds.584.2020.04.23.16.21.35; Thu, 23 Apr 2020 16:22:00 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729594AbgDWXUP (ORCPT + 99 others); Thu, 23 Apr 2020 19:20:15 -0400 Received: from shadbolt.e.decadent.org.uk ([88.96.1.126]:48652 "EHLO shadbolt.e.decadent.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728226AbgDWXGe (ORCPT ); Thu, 23 Apr 2020 19:06:34 -0400 Received: from [192.168.4.242] (helo=deadeye) by shadbolt.decadent.org.uk with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1jRkvM-0004c4-1k; Fri, 24 Apr 2020 00:06:28 +0100 Received: from ben by deadeye with local (Exim 4.93) (envelope-from ) id 1jRkvK-00E6jG-EQ; Fri, 24 Apr 2020 00:06:26 +0100 Content-Type: text/plain; charset="UTF-8" Content-Disposition: inline Content-Transfer-Encoding: 8bit MIME-Version: 1.0 From: Ben Hutchings To: linux-kernel@vger.kernel.org, stable@vger.kernel.org CC: akpm@linux-foundation.org, Denis Kirjanov , "Joe Thornber" , "Mike Snitzer" , "Hou Tao" Date: Fri, 24 Apr 2020 00:04:51 +0100 Message-ID: X-Mailer: LinuxStableQueue (scripts by bwh) X-Patchwork-Hint: ignore Subject: [PATCH 3.16 064/245] dm btree: increase rebalance threshold in __rebalance2() In-Reply-To: X-SA-Exim-Connect-IP: 192.168.4.242 X-SA-Exim-Mail-From: ben@decadent.org.uk X-SA-Exim-Scanned: No (on shadbolt.decadent.org.uk); SAEximRunCond expanded to false Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 3.16.83-rc1 review patch. If anyone has any objections, please let me know. ------------------ 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. Signed-off-by: Hou Tao Acked-by: Joe Thornber Signed-off-by: Mike Snitzer Signed-off-by: Ben Hutchings --- 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) { /*