Received: by 2002:a05:6a10:7420:0:0:0:0 with SMTP id hk32csp3893506pxb; Mon, 21 Feb 2022 07:49:28 -0800 (PST) X-Google-Smtp-Source: ABdhPJyhLuc99FxLioWW2C7/MkHmkYM5nTAzdBTAFSCwBgmq3/H9cjbh04ULUvens/k/yLdPaA0O X-Received: by 2002:a17:902:d647:b0:14e:ec42:2d86 with SMTP id y7-20020a170902d64700b0014eec422d86mr19058776plh.38.1645458568307; Mon, 21 Feb 2022 07:49:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1645458568; cv=none; d=google.com; s=arc-20160816; b=EQn9dqgvz0uzfq3TbM62sL9RF9FozpsejmOAjdHKbc83IUjYOacyCrlIuAlDQmbroc kin0kO48W7tBt2rOtn+Rcia2X6zwsCi6rB0XjhAIFMIeei/2gUWLV0KMBLGz5HAqMYt0 iqzQuDpBvfpnP8WT+WoO4Mo9Te+ude++SDiavRpl3Y21L3IF9xqTTuyOad06KsiywUOo ot/lEdXPwttdLPZBTPDKp+KpDZVT8tLBGeNIuvQSlJteyhpkCq7EobXAWLT6U1Lk8yfE 9SQSQHLTwvrE0RJefrcRkihIEy895uwLIpNaLcmjTFjarNQj6OPm6uG241cCGwrX5Ndi BtOA== 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=Wx/ObuGHzWENwigbhALmNTKV5o7heUEM1TdGFd70C1g=; b=KLEYSRRC6O3mds7jjIB3yzcXmhNQKScipBP4tHrfVSFChl6nI0UJumdQBkTitxAGXD J4EO4AqlDbK/Is7N3lxsaVC/Ra+d9eFVy+zUL7zjm/wCQU8/tyiR2bVExCNRhVSSSFjt UuDRsdxB9sexL9agdjvaSzB2JQq7LZz2JyVULMhhD+MOJymtRFBaFVDB5IE+NxXXDWxc 3X40cOQ9t5uK8aSGTYC3vkWkLGBqcc6gvB4uG9gwnqlEZTjzN+9Tp7NXIv8PzdCUHL0a O0riP75CM5G9FjWT63MNkgaBJWxldIp+MobRn12Mw4QuqJT9pDPGa4Bjxichuro/8wYI u4WA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=VbHYUU54; 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 67si18492266pga.632.2022.02.21.07.49.10; Mon, 21 Feb 2022 07:49:28 -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=VbHYUU54; 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 S1352920AbiBUJsC (ORCPT + 99 others); Mon, 21 Feb 2022 04:48:02 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:57294 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1351121AbiBUJmD (ORCPT ); Mon, 21 Feb 2022 04:42:03 -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 EEE8D3DDC4; Mon, 21 Feb 2022 01:17:38 -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 0A55CCE0E66; Mon, 21 Feb 2022 09:17:37 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id E7442C340E9; Mon, 21 Feb 2022 09:17:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1645435055; bh=6MdpUBQxcDitTQho4a+UV0MhACP/cQqImZDNH/2Z29w=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=VbHYUU54W+6iiraL5xAlvfTsHu11KXq5sWOwYh7npZRMKBs7gAeUxKbHI6CMkQSMI 52E6PYJnEe8JC/xgMrPdjHZI0IfyKCHygOsvfezLXtKjcgvxDpvCre0Dts0oIv6giu DM1W60HpOCzuJLYkSm64WV4WrKuk9BzQflFhS5KY= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Qu Wenruo , David Sterba Subject: [PATCH 5.16 028/227] btrfs: dont hold CPU for too long when defragging a file Date: Mon, 21 Feb 2022 09:47:27 +0100 Message-Id: <20220221084935.777644127@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 ea0eba69a2a8125229b1b6011644598039bc53aa upstream. There is a user report about "btrfs filesystem defrag" causing 120s timeout problem. For btrfs_defrag_file() it will iterate all file extents if called from defrag ioctl, thus it can take a long time. There is no reason not to release the CPU during such a long operation. Add cond_resched() after defragged one cluster. CC: stable@vger.kernel.org # 5.16 Link: https://lore.kernel.org/linux-btrfs/10e51417-2203-f0a4-2021-86c8511cc367@gmx.com Signed-off-by: Qu Wenruo Reviewed-by: David Sterba Signed-off-by: David Sterba Signed-off-by: Greg Kroah-Hartman --- fs/btrfs/ioctl.c | 1 + 1 file changed, 1 insertion(+) --- a/fs/btrfs/ioctl.c +++ b/fs/btrfs/ioctl.c @@ -1603,6 +1603,7 @@ int btrfs_defrag_file(struct inode *inod ret = 0; break; } + cond_resched(); } if (ra_allocated)