Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp800194rwb; Mon, 26 Sep 2022 06:07:19 -0700 (PDT) X-Google-Smtp-Source: AMsMyM751fk1C9wWPbjw3kJ1sClY+Ysz1EAilRH61pg2vXuaspAHZAh6rmfa09N61Cpwq9ebGdtw X-Received: by 2002:a17:90b:1d8a:b0:203:6db:ed6f with SMTP id pf10-20020a17090b1d8a00b0020306dbed6fmr25103645pjb.228.1664197638553; Mon, 26 Sep 2022 06:07:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1664197638; cv=none; d=google.com; s=arc-20160816; b=yct79ZgXTNnN5QvvCPnuyAVc8ad42Dfo24S7bUI1vpxWzZ+A7D+uPeppoX/IYheuM/ sVl3+TRkFCCuBlrkY2vIE3YYwS9TvmHQEsXLhgSBqyq4bOyhaLFD3q4mx+UlBH/iO/qe j5WuG5qkP1wAL6iuXLOOtrwP/9WRJtj2Q1D3G/1E0O2tH6jg1NVC4/A43meCKuK7wpfY zO0TAG02ZCRv4UG7Ojpm5YdTDLhCtsPJ5NQBJvWoS4keVmttKj5SjoIrr+p1Tfi6S/ou NOBoIeXNf3cpzj2VK7b9EWOK7A9fStF3qRvm64PPtDhuJ15Kq+06CjOnZPMjucVZdrx0 tywg== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=L7RyqyU4JMHjl2nLUNtsdfqY5LJtJDPgWxxbD66TVhM=; b=jFbIiU1XJs22aicRl4DEsakmzVy3TyjBxpyMrPusgrwlbO1/zi5zHqkYSWHrFOEsll 8ubs90DLqEfclgq4nz3qs0oPCCh+YPLrV/zQiWJcBlMEy4PBJ/4s2dt2uqzVaXwad23j +xjpI78ETDW6QzHyNa08jCgDU/Us67JI0IKzI0v89hsbtJ19Cord05K1qhD9bcEhcvhq wOT8rShQtSW06jHMIv5j1yTFauG13PFwn8wYdOLyRMWAXy662+rlV+82RGaM1XiF3bvE oeIg7F1prp74+Xv0mCuzDtIU5DDlqwAw8ruVtbvAGvQ5uZs363aU6rESNU4Tkt6FsddR 0TIA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=wRgEcgJA; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id np9-20020a17090b4c4900b001f31f339134si12215532pjb.152.2022.09.26.06.07.06; Mon, 26 Sep 2022 06:07:18 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-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=@linuxfoundation.org header.s=korg header.b=wRgEcgJA; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237982AbiIZLcR (ORCPT + 99 others); Mon, 26 Sep 2022 07:32:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60102 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237969AbiIZLbk (ORCPT ); Mon, 26 Sep 2022 07:31:40 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8C0806CF58; Mon, 26 Sep 2022 03:42:24 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 81F3F60B55; Mon, 26 Sep 2022 10:41:03 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 84E39C433D6; Mon, 26 Sep 2022 10:41:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1664188862; bh=toUUouetlZRIXmkiri2EZheDfq1KdSJxqrtjKWnPrkk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=wRgEcgJA5XVJsYWrfIpA1DWHNbyKJpX91avIdehhu/6MqPu8u0oNrpxry1LnsBikh l5lKk+BmkyS62d5jScV0oM3CvWFRkhrjiEOeudOwYwHIou13Xk2wzvsp3hdoxd+hVQ FKiD8yqr+g2nuc61x6vo0yKyYKt/QoOj3/6pBcNU= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, stable@kernel.org, Ojaswin Mujoo , "Ritesh Harjani (IBM)" , Jan Kara , Theodore Tso , Stefan Wahren Subject: [PATCH 5.15 145/148] ext4: make mballoc try target group first even with mb_optimize_scan Date: Mon, 26 Sep 2022 12:12:59 +0200 Message-Id: <20220926100801.658538565@linuxfoundation.org> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20220926100756.074519146@linuxfoundation.org> References: <20220926100756.074519146@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.2 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS 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-kernel@vger.kernel.org From: Jan Kara commit 4fca50d440cc5d4dc570ad5484cc0b70b381bc2a upstream. 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@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 Link: https://lore.kernel.org/r/20220908092136.11770-1-jack@suse.cz Signed-off-by: Theodore Ts'o Signed-off-by: Greg Kroah-Hartman --- fs/ext4/mballoc.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) --- a/fs/ext4/mballoc.c +++ b/fs/ext4/mballoc.c @@ -1052,8 +1052,10 @@ static void ext4_mb_choose_next_group(st { *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); @@ -2633,7 +2635,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; @@ -2708,13 +2710,11 @@ repeat: 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;