Received: by 2002:a05:6358:489b:b0:bb:da1:e618 with SMTP id x27csp340076rwn; Thu, 8 Sep 2022 02:24:06 -0700 (PDT) X-Google-Smtp-Source: AA6agR4MAdJj0dW9igZJuAlOWa6DIM4ZK1WLGtbm0ZCrNQa1JMlcO70dUWMtRJGbLxZdeb98KBgc X-Received: by 2002:a17:906:7950:b0:741:856f:caa5 with SMTP id l16-20020a170906795000b00741856fcaa5mr5282515ejo.574.1662629046736; Thu, 08 Sep 2022 02:24:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662629046; cv=none; d=google.com; s=arc-20160816; b=pEM+V4VpbY8eJASWnGDdjUq96a8qrW1AqInJ9WpV6JMOCb8mkz99XEZ5MOwIFpE461 UNoLIUEpvRoNhdGQ2zdVe7HtdSpDgvCNnSFikNvMzmx9NIqR5HyO0UEckGx0b9fJrFVs QLSOGNtb0WxNA7g4dBka1xBtbUzEPTZdOyLgv191MSt9PRJ9WjWMA2rSlHjzrfL7Eyw9 vd6/aCU8Ab9E/aOyjN1um2x+KnfjlE3jHyIrLNHehFajijLFptXmPl71On4fpI+M3ORZ LoEt4zR3oolwEbmyJ8+EbnFxfA5hGnauvjEA6hHRYZitc3sDnwvn7P/iLh+Wv3QHlMzl d6Dg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature:dkim-signature; bh=/T2gqCnaVMIrnu1bhWes7S5rCxq+aYcfojkZpwhcK9A=; b=eEod4tQJ/serrXCCPDupd6B++wXw6JxR3ocHE9WgarwBDn0SjPou+7LLkT6ydL6nO/ t6Andye6UFjjKBpf30CMUQQRvuJtdOweMLy0DfqEgx/Tvwkha4h/N+3Urzg2ms+KPC4V 8ErUwk1Yup9nHQlPJ0N9+dJyV+HYiq+oyXLqAYEli9iW/XmlWgrs8asxXj0tC4SVP2b0 8a/UDoxhHSbOf6/7QkyRdoQFcCr7uJckiEAxSvSlg5TyHqgu7aVHvlYm5Mmkuq8fBbGB uZecaSezO9Lc0YkNMjI6rrpOEWIDrNBqVo9E0f9ALdIsIThMfn99cdeUkT1bjDzRFHwV GLww== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=1iD0FmZ2; dkim=neutral (no key) header.i=@suse.cz header.b=Y0dxXbRF; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id r2-20020a170906550200b007307c356ccesi1233773ejp.720.2022.09.08.02.23.42; Thu, 08 Sep 2022 02:24:06 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=1iD0FmZ2; dkim=neutral (no key) header.i=@suse.cz header.b=Y0dxXbRF; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231830AbiIHJXf (ORCPT + 99 others); Thu, 8 Sep 2022 05:23:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37654 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231406AbiIHJXN (ORCPT ); Thu, 8 Sep 2022 05:23:13 -0400 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 09C0ED99D4; Thu, 8 Sep 2022 02:21:49 -0700 (PDT) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id C1F131FA79; Thu, 8 Sep 2022 09:21:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1662628896; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=/T2gqCnaVMIrnu1bhWes7S5rCxq+aYcfojkZpwhcK9A=; b=1iD0FmZ2Hqf6ExZ1fYkyqZwh8HMtyvulzgY35X+wPBUntqmvkPIXkH6WH7UwYUwlMNOGZe nbL7GHSPZEqzZevFGONipjMu6jkqmCyHUy+p4KWElkqzBls3dx+axlG75IqI5LTRUCW4vi 5HCZnIguR+PRlk4p7/PkrBqnmzPjmRg= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1662628896; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=/T2gqCnaVMIrnu1bhWes7S5rCxq+aYcfojkZpwhcK9A=; b=Y0dxXbRFjhvwaSKAgai3TNOVz9e/REPRoTBDQKNvjVyUHkkZrmo5Oxtlexwe6CTjsFbE3y vaudJVTr5VUo5tCA== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id B0E8913B5D; Thu, 8 Sep 2022 09:21:36 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id TDiYKiC0GWOsRAAAMHmgww (envelope-from ); Thu, 08 Sep 2022 09:21:36 +0000 Received: by quack3.suse.cz (Postfix, from userid 1000) id 125BAA066D; Thu, 8 Sep 2022 11:21:36 +0200 (CEST) From: Jan Kara To: Ted Tso Cc: , Thorsten Leemhuis , Ojaswin Mujoo , Stefan Wahren , Harshad Shirwadkar , Jan Kara , stable@vger.kernel.org, Ritesh Harjani Subject: [PATCH 1/5] ext4: Make mballoc try target group first even with mb_optimize_scan Date: Thu, 8 Sep 2022 11:21:24 +0200 Message-Id: <20220908092136.11770-1-jack@suse.cz> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20220908091301.147-1-jack@suse.cz> References: <20220908091301.147-1-jack@suse.cz> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=3349; h=from:subject; bh=Q57kHbUxIETSpSaq6MNvVeGwmpZn+1WoPPXosbRjvag=; b=owEBbQGS/pANAwAIAZydqgc/ZEDZAcsmYgBjGbQTGiXzCo2TURk0pEcrqRNL51jM02ZiWkmK4rjf 0rsh8+iJATMEAAEIAB0WIQSrWdEr1p4yirVVKBycnaoHP2RA2QUCYxm0EwAKCRCcnaoHP2RA2bD/B/ 4laWY+bgTBXzPo3DEqJfOY61ewWFro5p8X8qt2B1GedixLoOe1hhl4y37TXJF9snAXLhYTe3fO4S1L j4/6/SSQw6QaFBGJL4K/v7SmtL0foQr8cXRKe+GzvHmQjYVbV0riwqPQ0Y1xE3YyKxG+K0uhzB39eu 0Vo5FkJJ15NeHZbVmwdcn4GarWXEgef/EhsyKt+5uQAHpyGlSUo5Wx8eOLEhmlTuhJFm6X3SSMzb57 Dm655daizo7qaIbQs5/YboH/tIWx7w0cnk+kgfLAN/VvtTM8ZzH+gKkvj1T7mpVKC78z74ypA+X4S1 K7Enghi0I6OFZwKU+A4oalGE+wCctB X-Developer-Key: i=jack@suse.cz; a=openpgp; fpr=93C6099A142276A28BBE35D815BC833443038D8C Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org One of the side-effects of mb_optimize_scan was that the optimized functions to select next group to try were called even before we tried the goal group. As a result we no longer allocate files close to corresponding inodes as well as we don't try to expand currently allocated extent in the same group. This results in reaim regression with workfile.disk workload of upto 8% with many clients on my test machine: baseline mb_optimize_scan Hmean disk-1 2114.16 ( 0.00%) 2099.37 ( -0.70%) Hmean disk-41 87794.43 ( 0.00%) 83787.47 * -4.56%* Hmean disk-81 148170.73 ( 0.00%) 135527.05 * -8.53%* Hmean disk-121 177506.11 ( 0.00%) 166284.93 * -6.32%* Hmean disk-161 220951.51 ( 0.00%) 207563.39 * -6.06%* Hmean disk-201 208722.74 ( 0.00%) 203235.59 ( -2.63%) Hmean disk-241 222051.60 ( 0.00%) 217705.51 ( -1.96%) Hmean disk-281 252244.17 ( 0.00%) 241132.72 * -4.41%* Hmean disk-321 255844.84 ( 0.00%) 245412.84 * -4.08%* Also this is causing huge regression (time increased by a factor of 5 or so) when untarring archive with lots of small files on some eMMC storage cards. Fix the problem by making sure we try goal group first. Fixes: 196e402adf2e ("ext4: improve cr 0 / cr 1 group scanning") CC: stable@vger.kernel.org Reported-and-tested-by: Stefan Wahren Tested-by: Ojaswin Mujoo Reviewed-by: Ritesh Harjani (IBM) Link: https://lore.kernel.org/all/20220727105123.ckwrhbilzrxqpt24@quack3/ Link: https://lore.kernel.org/all/0d81a7c2-46b7-6010-62a4-3e6cfc1628d6@i2se.com/ Signed-off-by: Jan Kara --- fs/ext4/mballoc.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c index bd8f8b5c3d30..41e1cfecac3b 100644 --- a/fs/ext4/mballoc.c +++ b/fs/ext4/mballoc.c @@ -1049,8 +1049,10 @@ static void ext4_mb_choose_next_group(struct ext4_allocation_context *ac, { *new_cr = ac->ac_criteria; - if (!should_optimize_scan(ac) || ac->ac_groups_linear_remaining) + if (!should_optimize_scan(ac) || ac->ac_groups_linear_remaining) { + *group = next_linear_group(ac, *group, ngroups); return; + } if (*new_cr == 0) { ext4_mb_choose_next_group_cr0(ac, new_cr, group, ngroups); @@ -2636,7 +2638,7 @@ static noinline_for_stack int ext4_mb_regular_allocator(struct ext4_allocation_context *ac) { ext4_group_t prefetch_grp = 0, ngroups, group, i; - int cr = -1; + int cr = -1, new_cr; int err = 0, first_err = 0; unsigned int nr = 0, prefetch_ios = 0; struct ext4_sb_info *sbi; @@ -2711,13 +2713,11 @@ ext4_mb_regular_allocator(struct ext4_allocation_context *ac) ac->ac_groups_linear_remaining = sbi->s_mb_max_linear_groups; prefetch_grp = group; - for (i = 0; i < ngroups; group = next_linear_group(ac, group, ngroups), - i++) { - int ret = 0, new_cr; + for (i = 0, new_cr = cr; i < ngroups; i++, + ext4_mb_choose_next_group(ac, &new_cr, &group, ngroups)) { + int ret = 0; cond_resched(); - - ext4_mb_choose_next_group(ac, &new_cr, &group, ngroups); if (new_cr != cr) { cr = new_cr; goto repeat; -- 2.35.3