Received: by 2002:a05:6a10:7420:0:0:0:0 with SMTP id hk32csp3936931pxb; Mon, 21 Feb 2022 08:39:29 -0800 (PST) X-Google-Smtp-Source: ABdhPJyCbq5/StwoTb4bbQEpW+tNssf6YzDrTIxIP5hl7VDJj7YpEKVqtI2Tap68M3TyFem7dT7T X-Received: by 2002:a05:6402:1e8c:b0:411:7180:7dfc with SMTP id f12-20020a0564021e8c00b0041171807dfcmr22536148edf.74.1645461569122; Mon, 21 Feb 2022 08:39:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1645461569; cv=none; d=google.com; s=arc-20160816; b=u4u+QQXxMOhmw336IBmVulGnM8byDenOYVAcSWMN/nAv7oTkRZDysaEwb5Vxi6n7+y nkf7RPxz50Jo31ORo7CWDJ6shde+C9Ah2T+ie2KPDDZzvQPV5LVEnzG5kFPw+TyTSbJi trTb5raD/Ig6iFPBbSNqR4Th+vbG5sXui3YYJ1OnwJhcRrmZZnMNQDTwkOXOYNr2iYmg pmemqKmRqqYHDkSA8yb5MAJcxs03VO33Oa5KOQkXhg03qKAvFnxjiIMg33XyYIFZhXYT 7cOjRIVyiLg8fJY5F90snAlzKYX7mNOPaod2yEez1c87NOSLwpbLRj4ObeCfeIQwpTjb LWSQ== 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=FpjROIRWG68DI0BhzpXVIQfUCpq63orxWTVS2mpPV6g=; b=GmQTnV40LNuQ3CaNGT3ul+lSChqOUaNwSaO8F2kqzCDAirhSr1Bo7xbczEFiQDWksS IeUXMk/R5xsefEfGE+tusbqejuLLDEb+tuXQ8gLUSOW2eTg+z7L1lSmn9V3PFsn8UKDG UReV4lBTfowVyyMqx/SRP9TyhcHgHoolB/rJR88Km4YyUr5TFjf26w6lRbNLxe16Ukcd X0Oj1m5+huSZOndNlg7YEMh4rcBPaZUEsDFl0HP5M85JMaolqgo9cysGENGADZW31sAA yRKKA2hVt6T+778hhJW/ExXOsdO0UZ5izrZE8qIMCMp7fb1NHS07hRoO5pTU82p7kKDu BgwA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=EiSLghU7; 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 du1si3887310ejc.6.2022.02.21.08.39.06; Mon, 21 Feb 2022 08:39:29 -0800 (PST) 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=EiSLghU7; 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 S1352998AbiBUJsG (ORCPT + 99 others); Mon, 21 Feb 2022 04:48:06 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:57762 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1351170AbiBUJmN (ORCPT ); Mon, 21 Feb 2022 04:42:13 -0500 Received: from sin.source.kernel.org (sin.source.kernel.org [IPv6:2604:1380:40e1:4800::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 57A813E0DF; Mon, 21 Feb 2022 01:17:44 -0800 (PST) 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 sin.source.kernel.org (Postfix) with ESMTPS id C757BCE0E88; Mon, 21 Feb 2022 09:17:42 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B7E46C340E9; Mon, 21 Feb 2022 09:17:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1645435061; bh=8Fp2icFelVe5cF2glrfpTqMr4PApFbTngg78rssYqCo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=EiSLghU7ftsr2F6ZcndNAM0JbGntvVM6sXn3yjAheU0m6bPT7zVwyCnS6P5oHvKpQ bt2Ul8QrPZCp1OuqBug5nN7haM4eKoozpFIWT2fq38rn9iNuvFmPxrZu45QQ6ZYCAX BRWrr9D1/FDB0tqoF7u1OibKxfXArEjzDJjEw6v0= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Filipe Manana , Qu Wenruo , David Sterba Subject: [PATCH 5.16 030/227] btrfs: defrag: dont try to defrag extents which are under writeback Date: Mon, 21 Feb 2022 09:47:29 +0100 Message-Id: <20220221084935.841579106@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220221084934.836145070@linuxfoundation.org> References: <20220221084934.836145070@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 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,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-kernel@vger.kernel.org From: Qu Wenruo commit 0d1ffa2228cb34f485f8fe927f134b82a0ea62ae upstream. Once we start writeback (have called btrfs_run_delalloc_range()), we allocate an extent, create an extent map point to that extent, with a generation of (u64)-1, created the ordered extent and then clear the DELALLOC bit from the range in the inode's io tree. Such extent map can pass the first call of defrag_collect_targets(), as its generation is (u64)-1, meets any possible minimal generation check. And the range will not have DELALLOC bit, also passing the DELALLOC bit check. It will only be re-checked in the second call of defrag_collect_targets(), which will wait for writeback. But at that stage we have already spent our time waiting for some IO we may or may not want to defrag. Let's reject such extents early so we won't waste our time. CC: stable@vger.kernel.org # 5.16 Reviewed-by: Filipe Manana Signed-off-by: Qu Wenruo Signed-off-by: David Sterba Signed-off-by: Greg Kroah-Hartman --- fs/btrfs/ioctl.c | 4 ++++ 1 file changed, 4 insertions(+) --- a/fs/btrfs/ioctl.c +++ b/fs/btrfs/ioctl.c @@ -1184,6 +1184,10 @@ static int defrag_collect_targets(struct if (em->generation < newer_than) goto next; + /* This em is under writeback, no need to defrag */ + if (em->generation == (u64)-1) + goto next; + /* * Our start offset might be in the middle of an existing extent * map, so take that into account.