Received: by 2002:a05:6358:489b:b0:bb:da1:e618 with SMTP id x27csp340242rwn; Thu, 8 Sep 2022 02:24:18 -0700 (PDT) X-Google-Smtp-Source: AA6agR4rUhDkXXn36CdT01zzn8nNFoFUcK+Hir7EgA2o9u9c9PaC+By7jcE/ooxZSZghiGlthClC X-Received: by 2002:a17:90b:1d8b:b0:200:5367:5ecd with SMTP id pf11-20020a17090b1d8b00b0020053675ecdmr3224461pjb.165.1662629058070; Thu, 08 Sep 2022 02:24:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662629058; cv=none; d=google.com; s=arc-20160816; b=KU7WwAhXGxeTRQ3Zuq9Rg3mc42P4z5cx0xwMNsURY8ww5FMPAC9LKbETLUG4bpRIfn w59XzR7rxGxMr4O/swFf9f/NE5jZzlB4SFjLorw7jJYlws/prE0Qtjl6fS+HYoG3WEYz P43lVDwgzXKzBmOMs2VJ7hFwOjq7lqSjgeYG3eA2UC1Wtm1ofXzzXr9x2mJIkV1RnuAP WccYU6bAKvOFpejWFKJXczi7+hfMD6MUcJPTvv/T8ZPp3VzCMzuGkqMznwRc32fIjfPF 4CtH2vK/Vjb8+d8x61FutAeQp+4oC2j+5sd84rbpPlip7rsXbeTu8ZEHww99UGUaiAoM 6ggg== 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=JTIu5g1ARjVeLQJtVEzb05xchksISn6WKWVZuhNYsXg=; b=Bozr/sITQiI2wXkxlPxsSu05+1rQc5U7kN/2diFHYXgYTWKbb6FCpweD5FNlxTv/zF AwX39NSg8Z7/KvHv0WUXg/4iW50nI7WBHOCqZdEGn6PURz+14mPfXKZH2P6a/7Dz2RyE BSJtpAjGKI45X1S8//GrDIhdtJ4OVQdsKcMoDU+hOwuIKn63+am5CVZLCnStx0xepz0q 1w89nK74Ex+Iro7mKbjpuQRH5I8ulTBDXQ2oRA4yPbf6bspw7bTmGRwrZ0HJz6E+jv1F uo2hdLk52v/oMZtImklXHksUXSo8CLdxGyRnjr4gTY/kPwXmYo93oYE6935BlpFQL5Ho DNxA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=SSzznqII; dkim=neutral (no key) header.i=@suse.cz; 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 20-20020a630214000000b00434fe5a91c8si3815078pgc.245.2022.09.08.02.24.05; Thu, 08 Sep 2022 02:24:18 -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=SSzznqII; dkim=neutral (no key) header.i=@suse.cz; 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 S231453AbiIHJXw (ORCPT + 99 others); Thu, 8 Sep 2022 05:23:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39224 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231508AbiIHJXP (ORCPT ); Thu, 8 Sep 2022 05:23:15 -0400 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4BF9BE1272; Thu, 8 Sep 2022 02:21:50 -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-out1.suse.de (Postfix) with ESMTPS id C1BB333C1E; 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=JTIu5g1ARjVeLQJtVEzb05xchksISn6WKWVZuhNYsXg=; b=SSzznqIIRfcYlw6A7Cwn98kUCioGK/RDf6uSIrDqvyUZHRYc7/Oi9qpBruzhXiZGxytAqY VO4F0Ux4Jr8msYYnShVSpBnsuriXbG36C56qP8StND6P/j+2WsADVYsNqvn/wFTSoMO/Vi yRMWxIagdS55Zhp2wkaYskBIj9c7cEc= 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=JTIu5g1ARjVeLQJtVEzb05xchksISn6WKWVZuhNYsXg=; b=FkDqDKxBCQNBNLUyGpoWZ89NqCyR9Zdnu9Duv608sGYsSTMmFe3QF05QYO09E5bRjBzDdy YipkgDpavOJHAGBQ== 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 B38A613A6D; 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 Sr85KyC0GWOxRAAAMHmgww (envelope-from ); Thu, 08 Sep 2022 09:21:36 +0000 Received: by quack3.suse.cz (Postfix, from userid 1000) id 1690CA0682; 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 2/5] ext4: Avoid unnecessary spreading of allocations among groups Date: Thu, 8 Sep 2022 11:21:25 +0200 Message-Id: <20220908092136.11770-2-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=2504; h=from:subject; bh=k7AJpELkbpX88tci6pp+mS3j4X4Sqvl1FyFZXO/4+i8=; b=owEBbQGS/pANAwAIAZydqgc/ZEDZAcsmYgBjGbQUZm3QrW9BFTtpkv6HTcPbBJfWMNIlvzLdMAi6 si70bXmJATMEAAEIAB0WIQSrWdEr1p4yirVVKBycnaoHP2RA2QUCYxm0FAAKCRCcnaoHP2RA2QIqB/ 9T0I1UEO0EZOU7x0ou7D7tp/7ccdWqnYsigNWkNqWehhxeNcRFWIHcWO/Iszv0QRz5j+e0qKB7I81X ToQQUrEDn93MtFIQL6XT/P35ZyKm/IifBfkmm1V6pw7JzeRdMCJ0ScVF2rHY/m7azgAUqr+rg+hp7c ZQgIpup0JhTcbEgVMW5hGFnF4ZHly81TPqjIjo5qS2fAPFhgWxP17CYpJTUcy+gy/vO2PU9zM6oPZu zmjOAMGMYWzNyIlaC3rt7MoYWCZiwMDGt3Y1MG267DKdSWtEvTOPjbSVduHMHQvnZ4ojnnm2pLDUM/ 9FB5vM8A5mrlkwfPOwJFxFcUSdk0/m 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 mb_set_largest_free_order() updates lists containing groups with largest chunk of free space of given order. The way it updates it leads to always moving the group to the tail of the list. Thus allocations looking for free space of given order effectively end up cycling through all groups (and due to initialization in last to first order). This spreads allocations among block groups which reduces performance for rotating disks or low-end flash media. Change mb_set_largest_free_order() to only update lists if the order of the largest free chunk in the group changed. 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) Signed-off-by: Jan Kara --- fs/ext4/mballoc.c | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c index 41e1cfecac3b..6251b4a6cc63 100644 --- a/fs/ext4/mballoc.c +++ b/fs/ext4/mballoc.c @@ -1077,23 +1077,25 @@ mb_set_largest_free_order(struct super_block *sb, struct ext4_group_info *grp) struct ext4_sb_info *sbi = EXT4_SB(sb); int i; - if (test_opt2(sb, MB_OPTIMIZE_SCAN) && grp->bb_largest_free_order >= 0) { + for (i = MB_NUM_ORDERS(sb) - 1; i >= 0; i--) + if (grp->bb_counters[i] > 0) + break; + /* No need to move between order lists? */ + if (!test_opt2(sb, MB_OPTIMIZE_SCAN) || + i == grp->bb_largest_free_order) { + grp->bb_largest_free_order = i; + return; + } + + if (grp->bb_largest_free_order >= 0) { write_lock(&sbi->s_mb_largest_free_orders_locks[ grp->bb_largest_free_order]); list_del_init(&grp->bb_largest_free_order_node); write_unlock(&sbi->s_mb_largest_free_orders_locks[ grp->bb_largest_free_order]); } - grp->bb_largest_free_order = -1; /* uninit */ - - for (i = MB_NUM_ORDERS(sb) - 1; i >= 0; i--) { - if (grp->bb_counters[i] > 0) { - grp->bb_largest_free_order = i; - break; - } - } - if (test_opt2(sb, MB_OPTIMIZE_SCAN) && - grp->bb_largest_free_order >= 0 && grp->bb_free) { + grp->bb_largest_free_order = i; + if (grp->bb_largest_free_order >= 0 && grp->bb_free) { write_lock(&sbi->s_mb_largest_free_orders_locks[ grp->bb_largest_free_order]); list_add_tail(&grp->bb_largest_free_order_node, -- 2.35.3