Received: by 2002:a05:6358:bb9e:b0:b9:5105:a5b4 with SMTP id df30csp4579674rwb; Tue, 6 Sep 2022 09:24:03 -0700 (PDT) X-Google-Smtp-Source: AA6agR6OZIWEmHwc3G2tHePLw5p4cBN5pkKqA/CyROEmepBX9M1/r3Qm6NT6pLN5JxfVai7FuFs6 X-Received: by 2002:a17:90b:4c42:b0:1fd:a491:5a8a with SMTP id np2-20020a17090b4c4200b001fda4915a8amr25749921pjb.40.1662481443518; Tue, 06 Sep 2022 09:24:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662481443; cv=none; d=google.com; s=arc-20160816; b=vpm/LZSsk8PUbrLiEy2/gaam1HDXZvkxWa4FuE/g136KIpCR1LHSC7KZbUuHx6MRdW AG0/vlCDVrAw0M0NTq4xbusi512jD1o+XhXvucuxnDYDcqwut6DOBSIDFSpHiUPdIfAo CnIdhef33ezQhfRjn6F1zL/ns7028qmRtPX7wOz2pE4/g86eVfPvIEeN4zQFASbMDcMO P7AlsdPviNjY7Vns7D3024x6ewuFqVeRdu8uYKfqTyVM5B5ECv4OtCQN+MYb56Qdbgm/ 1TQlzyNwuKIm2AC05WCmRV0hWZYvGV3qk/4vohpcmbyn6wMgf5N6dI76goToMuSY/TiH roVg== 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=sHfiS/b/jr0z+nZX9qn+yA+fZvMUIZsYHb/HlwCGYjo=; b=wYhF3ci0mUT8vBwcH7TTuxFdXcC9KyBvCGo/Sh4Ri+EBgi6+pykiv6py1yp7JwIERP 6qryTLQl2nQKvj7GT5ZB87ePMBS5v0rO4N3U+GwYmlX+CU3P2a6tHOAQAgkhYrDZp06O 7plUKR9Qfr8y6S7/rBmr6d6Tf3LeSWUFC+x7LlgZoin4pl1S1awwxDeWRrZbKndG101Q 8w2RQt6XkL4BgSFNvsrdxVQLl0KsT3EbMt8ZKIwccpQy6RrQjkZjYfqw+ylceV3bnj8s kAjHq86YTzGUuZnRHLr2bogQ821+uNcHtxVT56ox697vTnNl/UGoJc9KJ4010GNXYZ9m sl3w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=jYVy4+zx; dkim=neutral (no key) header.i=@suse.cz header.b="lHf7B6/x"; 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 x20-20020a63db54000000b0041b671665a6si14109659pgi.76.2022.09.06.09.23.50; Tue, 06 Sep 2022 09:24:03 -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=jYVy4+zx; dkim=neutral (no key) header.i=@suse.cz header.b="lHf7B6/x"; 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 S234173AbiIFQGR (ORCPT + 99 others); Tue, 6 Sep 2022 12:06:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50146 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234950AbiIFQFu (ORCPT ); Tue, 6 Sep 2022 12:05:50 -0400 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4F843FC1 for ; Tue, 6 Sep 2022 08:29:23 -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 4AA0433906; Tue, 6 Sep 2022 15:29:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1662478161; 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=sHfiS/b/jr0z+nZX9qn+yA+fZvMUIZsYHb/HlwCGYjo=; b=jYVy4+zx52xttmLZL6K1ReSJTivUpSODPhEL5mJd6FTd6KBg7dnTvtu/eTHHO/rZIEQ9/b SCgnKFZlHvUgGH+GxcRO7AYExkNTY8fLz8AH2htSaa94Q9gGM/U4LUGkGzz91c0cv6GNNr 83Vxk9Eo09/kwF+SXW7gYr9Ep2bLFwk= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1662478161; 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=sHfiS/b/jr0z+nZX9qn+yA+fZvMUIZsYHb/HlwCGYjo=; b=lHf7B6/xPTAwgUvn6CC+87Qy3nHORD8/QDkT7nJM4gqL1H8JacjXkxkXMwK+NNfnVnfayB e+kEKSaiAhkdZhCA== 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 3A34613B2C; Tue, 6 Sep 2022 15:29:21 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id 5DYXDlFnF2NUHAAAMHmgww (envelope-from ); Tue, 06 Sep 2022 15:29:21 +0000 Received: by quack3.suse.cz (Postfix, from userid 1000) id 7F179A0682; Tue, 6 Sep 2022 17:29:20 +0200 (CEST) From: Jan Kara To: Ted Tso Cc: , Thorsten Leemhuis , Ojaswin Mujoo , Stefan Wahren , Andreas Dilger , Jan Kara Subject: [PATCH 2/5] ext4: Avoid unnecessary spreading of allocations among groups Date: Tue, 6 Sep 2022 17:29:08 +0200 Message-Id: <20220906152920.25584-2-jack@suse.cz> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20220906150803.375-1-jack@suse.cz> References: <20220906150803.375-1-jack@suse.cz> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=2237; h=from:subject; bh=A+cK0EozPU0BdTnQ78Cn9BdsS9WnVEc8rshrdjI8jdM=; b=owEBbQGS/pANAwAIAZydqgc/ZEDZAcsmYgBjF2dD3Ju0FE1b6l1/Rs2jKV/urmQzOkBya05HI1UP wqktssSJATMEAAEIAB0WIQSrWdEr1p4yirVVKBycnaoHP2RA2QUCYxdnQwAKCRCcnaoHP2RA2cnIB/ 9Vdhs9tEvnA1YNXIoJp1gFuQuxJvkVIeyh2NqL5Ex/CHY1240ZLAz9hutPEeokh13QS6zNqnOb00rk 0HCpJ+pQcXv0R2O8zjd5EKLqecKNQTCEqyjyPpIDkDnjEpRZIkmJTlJEg2f7UmmgazX8iZCSD2NDnL PSLKcC8Q2n2myx5gi4cxYEUIXADgFatgKppF7lnZjAb2lUvbW40WURrDCXBJrLYmnMttXr6q+mqEo8 Etfvzx8KZcdXl4ymRpmtR1HjPSPPoOOf6vPes3mqzGt3weGmvP8A1xVRl2nvevImovKmzn8ZHuFMju t/jqclEDq6JLSajy8kNE0nY8La6xkC 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. 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