Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp7162006rwd; Tue, 6 Jun 2023 07:10:36 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7R5Xg6FfbsEDoC1T4qvJ3TzzltkksGNLirxPOaJP/qf71Muy2rpAEiSQyBh5VEVbHs1ylj X-Received: by 2002:a05:620a:4406:b0:75b:23a1:44a with SMTP id v6-20020a05620a440600b0075b23a1044amr2680066qkp.16.1686060636583; Tue, 06 Jun 2023 07:10:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686060636; cv=none; d=google.com; s=arc-20160816; b=gMtsoiuVa7hzmErOXuHxT14OxMpdp+SGfku6aGnI4CyfuTRwipe4uRsI1Pyo7QyBP4 KUg9+gCt9wXNb2ugryBCMKpBkmVvKtgIk5YkEzSMtnGL8vdc2diz7tatg4N5vFnA+CJP TuOQ9BTSK0lxDeyoz0qvSidoYX8UB4d4Zg7JVI/87xgiPBwbPI1n51twB/rlaP5keiXJ WYev6sVc3TroqSOFiV/Dw8PMxo0Gc/+0Kj25Znaei5hFmLd0xjoTPp8UPEJrYNHWPA+4 kLfs0uBUwlhppF6MHjNJ3RLLRu75zjwYcszFruE8xiTNyc0Hw5DUNl24WDnyZtYj3X/V zv0Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to :content-language:references:cc:to:subject:from:mime-version:date :dkim-signature:message-id; bh=2uml8vTQA7Jk00qED6Wb0yWaRiW4bBmvkl2obmUQkoY=; b=OvAP9KYko//ku1Q3KLrWucInRsUe4gevjFUN+It3UX2wCK+6NnX2JtOGO97FdMjQmK fHnhy6Wu92dzMnMhh+6V08h1Cj+RM6lDtY6402MLnkmeqxW8hY4L8kpu12EWUWXChTcj TqkpKpYpIWGsk67hFffW6MLD0/4z3xrF8PF/l2P9w0o5euPVKnKIEia4DVAu8JZ/PWlj e/sCwqW6QxJAX74sxjN9INiHJcQWFM859YAnwwx8prZl5aXpkKSrkZ5+WBZHf6LJnkpk YL7BhBSMCgeDcmkZCSaiuOaP0fpd7qHJHu5wT/k8xgJ4LsRtlCxUksZcFuQLPXe/Havp l2qA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=cvjjhEbu; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id f26-20020ae9ea1a000000b0075b344f68f8si5801813qkg.728.2023.06.06.07.10.20; Tue, 06 Jun 2023 07:10:36 -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=@linux.dev header.s=key1 header.b=cvjjhEbu; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237460AbjFFOBh (ORCPT + 99 others); Tue, 6 Jun 2023 10:01:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43938 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237461AbjFFOBJ (ORCPT ); Tue, 6 Jun 2023 10:01:09 -0400 Received: from out-22.mta0.migadu.com (out-22.mta0.migadu.com [91.218.175.22]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D45A810DB for ; Tue, 6 Jun 2023 07:01:07 -0700 (PDT) Message-ID: DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1686060065; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=2uml8vTQA7Jk00qED6Wb0yWaRiW4bBmvkl2obmUQkoY=; b=cvjjhEbuIw4XMzuXB1gNKv2SDPspUiKAG9c1qfukbOq4Vu+Xvk3hRzqZTUkoLf1h8WgeIK mX4iw7SxtoUFhollyDxq/cwh3Lh7vZZIsBzxlwz6oUhiblNeM4/UDIe/0JjU4VNs7YUQW0 +fKrohXUbW3ugX9LtBnHc4V513usgsI= Date: Tue, 6 Jun 2023 22:00:57 +0800 MIME-Version: 1.0 X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Guoqing Jiang Subject: Re: [PATCH v2 09/12] ext4: Ensure ext4_mb_prefetch_fini() is called for all prefetched BGs To: Ojaswin Mujoo , linux-ext4@vger.kernel.org, Theodore Ts'o Cc: Ritesh Harjani , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, Jan Kara , Kemeng Shi , Ritesh Harjani References: <05e648ae04ec5b754207032823e9c1de9a54f87a.1685449706.git.ojaswin@linux.ibm.com> Content-Language: en-US In-Reply-To: <05e648ae04ec5b754207032823e9c1de9a54f87a.1685449706.git.ojaswin@linux.ibm.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Migadu-Flow: FLOW_OUT X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED 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 Hello, On 5/30/23 20:33, Ojaswin Mujoo wrote: > Before this patch, the call stack in ext4_run_li_request is as follows: > > /* > * nr = no. of BGs we want to fetch (=s_mb_prefetch) > * prefetch_ios = no. of BGs not uptodate after > * ext4_read_block_bitmap_nowait() > */ > next_group = ext4_mb_prefetch(sb, group, nr, prefetch_ios); > ext4_mb_prefetch_fini(sb, next_group prefetch_ios); > > ext4_mb_prefetch_fini() will only try to initialize buddies for BGs in > range [next_group - prefetch_ios, next_group). This is incorrect since > sometimes (prefetch_ios < nr), which causes ext4_mb_prefetch_fini() to > incorrectly ignore some of the BGs that might need initialization. This > issue is more notable now with the previous patch enabling "fetching" of > BLOCK_UNINIT BGs which are marked buffer_uptodate by default. > > Fix this by passing nr to ext4_mb_prefetch_fini() instead of > prefetch_ios so that it considers the right range of groups. Thanks for the series. > Similarly, make sure we don't pass nr=0 to ext4_mb_prefetch_fini() in > ext4_mb_regular_allocator() since we might have prefetched BLOCK_UNINIT > groups that would need buddy initialization. Seems ext4_mb_prefetch_fini can't be called by ext4_mb_regular_allocator if nr is 0. https://elixir.bootlin.com/linux/v6.4-rc5/source/fs/ext4/mballoc.c#L2816 Am I miss something? Thanks, Guoqing > Signed-off-by: Ojaswin Mujoo > Reviewed-by: Ritesh Harjani (IBM) > Reviewed-by: Jan Kara > --- > fs/ext4/mballoc.c | 4 ---- > fs/ext4/super.c | 11 ++++------- > 2 files changed, 4 insertions(+), 11 deletions(-) > > diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c > index 79455c7e645b..6775d73dfc68 100644 > --- a/fs/ext4/mballoc.c > +++ b/fs/ext4/mballoc.c > @@ -2735,8 +2735,6 @@ ext4_mb_regular_allocator(struct ext4_allocation_context *ac) > if ((prefetch_grp == group) && > (cr > CR1 || > prefetch_ios < sbi->s_mb_prefetch_limit)) { > - unsigned int curr_ios = prefetch_ios; > - > nr = sbi->s_mb_prefetch; > if (ext4_has_feature_flex_bg(sb)) { > nr = 1 << sbi->s_log_groups_per_flex; > @@ -2745,8 +2743,6 @@ ext4_mb_regular_allocator(struct ext4_allocation_context *ac) > } > prefetch_grp = ext4_mb_prefetch(sb, group, > nr, &prefetch_ios); > - if (prefetch_ios == curr_ios) > - nr = 0; > } > > /* This now checks without needing the buddy page */ > diff --git a/fs/ext4/super.c b/fs/ext4/super.c > index 2da5476fa48b..27c1dabacd43 100644 > --- a/fs/ext4/super.c > +++ b/fs/ext4/super.c > @@ -3692,16 +3692,13 @@ static int ext4_run_li_request(struct ext4_li_request *elr) > ext4_group_t group = elr->lr_next_group; > unsigned int prefetch_ios = 0; > int ret = 0; > + int nr = EXT4_SB(sb)->s_mb_prefetch; > u64 start_time; > > if (elr->lr_mode == EXT4_LI_MODE_PREFETCH_BBITMAP) { > - elr->lr_next_group = ext4_mb_prefetch(sb, group, > - EXT4_SB(sb)->s_mb_prefetch, &prefetch_ios); > - if (prefetch_ios) > - ext4_mb_prefetch_fini(sb, elr->lr_next_group, > - prefetch_ios); > - trace_ext4_prefetch_bitmaps(sb, group, elr->lr_next_group, > - prefetch_ios); > + elr->lr_next_group = ext4_mb_prefetch(sb, group, nr, &prefetch_ios); > + ext4_mb_prefetch_fini(sb, elr->lr_next_group, nr); > + trace_ext4_prefetch_bitmaps(sb, group, elr->lr_next_group, nr); > if (group >= elr->lr_next_group) { > ret = 1; > if (elr->lr_first_not_zeroed != ngroups &&