Received: by 2002:a05:6358:5282:b0:b5:90e7:25cb with SMTP id g2csp3409620rwa; Tue, 23 Aug 2022 04:25:29 -0700 (PDT) X-Google-Smtp-Source: AA6agR4BcBVo/ZGYgkxpvXnT32C/RCk5SoffuzomjhxpqYo9fJfAUcxN2OlvgHf6yUZTBIO4eUYW X-Received: by 2002:a17:907:a0c7:b0:739:7ea:88ec with SMTP id hw7-20020a170907a0c700b0073907ea88ecmr16176833ejc.363.1661253929099; Tue, 23 Aug 2022 04:25:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661253929; cv=none; d=google.com; s=arc-20160816; b=s4CdGGyMgcu4+Hrlfy2gbyGz8BTca011vGNP6oBq1qqmM2zNFxrG5t9apJzI51PEM+ NcFgj3cWVwULMEwsMqnoUS1VipArItZG1CtTOLHV/YB+AbJcWKt5ufjglwmfLUA5joxl y1WfVlw30HR3sA1bPZljM3X8E/ycA3aZyJkUSeJGPl34UJvaFgnRctJlCm3vju6DNxdw gV5C30OdkZZqiJbKPl2IxPVj/hc+0bCuh6ekWGWBRP/1B1ojA9I0luVaVTE+hkDR+vG/ ZUBbu6qVWULGC+aMDTbjUDl3130iwUATqIC4SGiq7tjHnwZuCkRicPDorgVzw2Q3hQU7 i90Q== 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=yjNhfOz3JGkz4EWx3LZOfuwdgNk7AjOtgne0zMU65LU=; b=FxPvPL9uv/P5tOPMNMe+mHxR/Iulsuy1NslUFtXQlawCHRHV4jAbm1dsps7SffS7yi 3qIVwPOmuGcEWZpTa4n/VBy6GsG9frGehbYHrCrzQgAEbmRP6yG41AoPupUom1qViGuB zirQmgM3jk96+aXl3sDA22SXBkxTSWS9RNwX9ngT90ZMsqZDJtcwvlP72dfRalMtO/Hu PwKT5LJEsiGJfJ9J24EvV+NzzNGr78Fi3VYZ7to96aJOS35PW/SwatE9KaRedAQaOOjg 4C/n3tE8cCGrfidfBuJPGTr8cVz007qJm7wqZIzANSbsUFoCrzyQ8Nrmd3zdlRsrENeE J4WQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=utdOSbL+; 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 y4-20020a056402440400b00445e286d000si2579537eda.365.2022.08.23.04.25.02; Tue, 23 Aug 2022 04:25:29 -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=utdOSbL+; 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 S1354914AbiHWK36 (ORCPT + 99 others); Tue, 23 Aug 2022 06:29:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37888 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1353380AbiHWKN2 (ORCPT ); Tue, 23 Aug 2022 06:13:28 -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 8EE4572680; Tue, 23 Aug 2022 01:59:37 -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 25BC16153F; Tue, 23 Aug 2022 08:59:37 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0E3F9C433C1; Tue, 23 Aug 2022 08:59:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1661245176; bh=XDCk/CMGdbuJUzUm77jkj2+obB1j5D4sSTZ14pTCW4U=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=utdOSbL+Ob2XSGKCg8u9izndbczceiupVmMuSXQq8nD/tE8NTN1okPth6Ji84jdEa cG2auWrR/L1/6GB6uOzWekknbH+S0xj3MPJmRgIisRVc+SbFda8yvHrx62/8FJZuO0 AgcoQK9ByubD1+sHe6WeW096iKxdpP4rphGJHrgI= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Greg Kroah-Hartman , "Darrick J. Wong" , Dave Chinner , Leah Rumancik Subject: [PATCH 5.15 240/244] xfs: always succeed at setting the reserve pool size Date: Tue, 23 Aug 2022 10:26:39 +0200 Message-Id: <20220823080107.629436819@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220823080059.091088642@linuxfoundation.org> References: <20220823080059.091088642@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.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: "Darrick J. Wong" [ Upstream commit 0baa2657dc4d79202148be79a3dc36c35f425060 ] Nowadays, xfs_mod_fdblocks will always choose to fill the reserve pool with freed blocks before adding to fdblocks. Therefore, we can change the behavior of xfs_reserve_blocks slightly -- setting the target size of the pool should always succeed, since a deficiency will eventually be made up as blocks get freed. Signed-off-by: Darrick J. Wong Reviewed-by: Dave Chinner Signed-off-by: Leah Rumancik Acked-by: Darrick J. Wong Signed-off-by: Greg Kroah-Hartman --- fs/xfs/xfs_fsops.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) --- a/fs/xfs/xfs_fsops.c +++ b/fs/xfs/xfs_fsops.c @@ -434,11 +434,14 @@ xfs_reserve_blocks( * The code below estimates how many blocks it can request from * fdblocks to stash in the reserve pool. This is a classic TOCTOU * race since fdblocks updates are not always coordinated via - * m_sb_lock. + * m_sb_lock. Set the reserve size even if there's not enough free + * space to fill it because mod_fdblocks will refill an undersized + * reserve when it can. */ free = percpu_counter_sum(&mp->m_fdblocks) - xfs_fdblocks_unavailable(mp); delta = request - mp->m_resblks; + mp->m_resblks = request; if (delta > 0 && free > 0) { /* * We'll either succeed in getting space from the free block @@ -455,10 +458,8 @@ xfs_reserve_blocks( * Update the reserve counters if blocks have been successfully * allocated. */ - if (!error) { - mp->m_resblks += fdblks_delta; + if (!error) mp->m_resblks_avail += fdblks_delta; - } } out: if (outval) {