From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 36001C47DAF for ; Thu, 18 Jan 2024 22:55:17 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C63CA6B009A; Thu, 18 Jan 2024 17:55:16 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id C143A6B009B; Thu, 18 Jan 2024 17:55:16 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id AB7056B009C; Thu, 18 Jan 2024 17:55:16 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 988226B009A for ; Thu, 18 Jan 2024 17:55:16 -0500 (EST) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 676E540726 for ; Thu, 18 Jan 2024 22:55:16 +0000 (UTC) X-FDA: 81693939432.07.41E2B1C Received: from sin.source.kernel.org (sin.source.kernel.org [145.40.73.55]) by imf10.hostedemail.com (Postfix) with ESMTP id 183FEC0011 for ; Thu, 18 Jan 2024 22:55:13 +0000 (UTC) Authentication-Results: imf10.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b="tmO/y/jY"; spf=pass (imf10.hostedemail.com: domain of djwong@kernel.org designates 145.40.73.55 as permitted sender) smtp.mailfrom=djwong@kernel.org; dmarc=pass (policy=none) header.from=kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1705618514; h=from:from:sender: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: in-reply-to:in-reply-to:references:references:dkim-signature; bh=BtM+6sA8lciHWWLYvlYzPH2N3zW/ohv0SZoGPKI7JrQ=; b=C7A4MFMk9Y6aLknyQ+vK93UWR3UtMWYDX+SjEKGmQ7tal5++QNfvVXOT23khVWODgGPXI2 dOYwdtWA/nQpkkN87c+n/UjYmtlWSskeNn4jl1Kg0BEBxH94at2geMPMo7q3rTTnn/mUP4 DWKtpahx66JvvJBnp9JOPFiVcLzerok= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1705618514; a=rsa-sha256; cv=none; b=o9S7bagRMOTaoOZB40ncUN5gEKGybMjAOaHvNCHNnCdtBJooPDCLMsaW5NvA9w/I/a1kZz 58GW9WxFzn8rj3RSkojgcPmrC5yPzVObESwoXsPO9RsebOYqrdmPyL7tSU7g592BX/fS7X 1vpIMDbhe2nZbCy9mKgqKLaKThTjnCY= ARC-Authentication-Results: i=1; imf10.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b="tmO/y/jY"; spf=pass (imf10.hostedemail.com: domain of djwong@kernel.org designates 145.40.73.55 as permitted sender) smtp.mailfrom=djwong@kernel.org; dmarc=pass (policy=none) header.from=kernel.org Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sin.source.kernel.org (Postfix) with ESMTP id 3F049CE20E7; Thu, 18 Jan 2024 22:55:10 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7291FC433C7; Thu, 18 Jan 2024 22:55:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1705618509; bh=6Xc+hJEOHcGZNL60PrMUfAVBgiMTqZn8i1oGmkQOc+Y=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=tmO/y/jY9e4gzstbCXFK/w0BjT0CPzWa5hDJ90qZ5MUhvj11JkyEbnn/WTqsgPM6M yEIT2ghSHHzO4k3dIXio42BtBzBX9OyA1fwpNRHjfan+sYGoTOzNdENviVcRx+GdGo G3FgLfhgE5qXqnTqyw4mXeT8nyI/xFJSyzquo55YcOefjmyRKTq3t39LVybwrfUDf3 IWGD+/sLdnUuLX69e7q0cYw3tXKfdMkvjmHTbmMba3mWwH1wlIKlPgjV9FBK1Na5id XYFXXV6g6mPcO6qgWB4U+jD9g5u2Ga76hMDn1t10FlFZTBmdgIrWMTFSptoTXw0zvp V3JTudBg4p58w== Date: Thu, 18 Jan 2024 14:55:08 -0800 From: "Darrick J. Wong" To: Dave Chinner Cc: linux-xfs@vger.kernel.org, willy@infradead.org, linux-mm@kvack.org Subject: Re: [PATCH 06/12] xfs: use an empty transaction for fstrim Message-ID: <20240118225508.GI674499@frogsfrogsfrogs> References: <20240115230113.4080105-1-david@fromorbit.com> <20240115230113.4080105-7-david@fromorbit.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20240115230113.4080105-7-david@fromorbit.com> X-Rspamd-Queue-Id: 183FEC0011 X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: fmkbumkmnpi1en9a1p68y779i6783at9 X-HE-Tag: 1705618513-985536 X-HE-Meta: U2FsdGVkX19SmGNyQ6ThgfzIX9gDxdCVtNVfDv3BgqxMZVSDMxoxfbGnXUxRVr0xbRafVDkRHSLpFlA8qjBN9zvJNZLgjuKrYe7llDlObAtrP2WoZoLWG6F+qh4sqGyvSPCvd1099IcSFV8UHyNbUkJgY41Mdi9f/E5YE/CbkE0uAzjTBfpHPb1c++j+hWRY2VMivyALPkYRqdVTXzjQqio6sV4ZENJYcfmludDLrJ7K+SF4MtLhPjCbo3hOXyenGRX2R34vBGpqIgz8I1LPbqcDrN7H9+9fIfgVgOVncaC8MffSOnJSs5fE4AnjZsnZJ5xoYR9ipT5WPFhPOhFB9KJZBQu/rZeiaW3tYVuTc+JRf6igt4vzfPVG8+SzJQTupjGWU/S45pepjboIOqK+lnupCESiUiThyPRLB2g2X+pP6gDEDeHmZnkjz4r4j2YaGuMsNIbjVPrzFfleuYKUiTdlRthJJhBCL//F6C8S0lfa+WJ7WBOUrARECa6jWUjMMtis7j3ilRLRAQ1vEBScgyfMaGJcU/bL6+m9ScBX8Dy3GW4PhSlcgwoRqnvQLyVoVhQX9qqZhY0tkXWgi+TnfN7LUUk7IvhxwsM28ZHiZTujd8W5aB1VZDReotvgJU+ThNoPY59ZnKKQunlqiXrg8y3OPmfTLpU9U0P3E5aV7UUuED9xY3tghznWJqA2eApVgGxJ/KJqWbWcAcfIIMeLy0+AVj2C51iW5mAhC/UJRrSBi+vbM6gDogHGekNSC6jWjPonI7BV0k3ZD2F8OUmBi9Rctyqn4fi3sbMtYy0IrZVDOz4ab4zMTrWExTAzQMl3ZzepZTZk8fFxxhdBFeOSKB7ZEA361mE2CLE1h8CWbgO/weEpjD/v6OnP00LoMeGNDKSai4PL1X5zkEQk1cthrJfVr5DSzsXT8bw455hJDU1q75I973DipKxrjqxHJlCEMtNl4e3pPiF1BWzRTRQ Ury6kdBt gMaBxOlYx7CJjHzyJzEPFnvdXtJwNg6C4gat2Yyo74Bv4Suc6WQm3v8fut6r6RxUQa90d/msKdByQtUOBCY5Q4Y+yrtSWoC535GemDRI1BdsIRgWN+g0f8/GqnhvrydanVMx1ZFk+4qRiZrVd4ej3Y0aqvz4/qMp2FyNK0eKDR0lBnjM7wDLYTYiIe5YKEmWTtOBQENKQgz8rBZEp52YmrwAJ9plsmrV/ul6xaVcbw7zc8ulr9hsnx604t6kTcM+uVQM0hdBddl01CO8= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: On Tue, Jan 16, 2024 at 09:59:44AM +1100, Dave Chinner wrote: > From: Dave Chinner > > We currently use a btree walk in the fstrim code. This requires a > btree cursor and btree cursors are only used inside transactions > except for the fstrim code. This means that all the btree operations > that allocate memory operate in both GFP_KERNEL and GFP_NOFS > contexts. > > This causes problems with lockdep being unable to determine the > difference between objects that are safe to lock both above and > below memory reclaim. Free space btree buffers are definitely locked > both above and below reclaim and that means we have to mark all > btree infrastructure allocations with GFP_NOFS to avoid potential > lockdep false positives. > > If we wrap this btree walk in an empty cursor, all btree walks are > now done under transaction context and so all allocations inherit > GFP_NOFS context from the tranaction. This enables us to move all > the btree allocations to GFP_KERNEL context and hence help remove > the explicit use of GFP_NOFS in XFS. > > Signed-off-by: Dave Chinner LOL I just wrote this exact patch to shut up lockdep. Reviewed-by: Darrick J. Wong --D > --- > fs/xfs/xfs_discard.c | 15 +++++++++++---- > 1 file changed, 11 insertions(+), 4 deletions(-) > > diff --git a/fs/xfs/xfs_discard.c b/fs/xfs/xfs_discard.c > index 8539f5c9a774..299b8f907292 100644 > --- a/fs/xfs/xfs_discard.c > +++ b/fs/xfs/xfs_discard.c > @@ -8,6 +8,7 @@ > #include "xfs_format.h" > #include "xfs_log_format.h" > #include "xfs_trans_resv.h" > +#include "xfs_trans.h" > #include "xfs_mount.h" > #include "xfs_btree.h" > #include "xfs_alloc_btree.h" > @@ -120,7 +121,7 @@ xfs_discard_extents( > error = __blkdev_issue_discard(mp->m_ddev_targp->bt_bdev, > XFS_AGB_TO_DADDR(mp, busyp->agno, busyp->bno), > XFS_FSB_TO_BB(mp, busyp->length), > - GFP_NOFS, &bio); > + GFP_KERNEL, &bio); > if (error && error != -EOPNOTSUPP) { > xfs_info(mp, > "discard failed for extent [0x%llx,%u], error %d", > @@ -155,6 +156,7 @@ xfs_trim_gather_extents( > uint64_t *blocks_trimmed) > { > struct xfs_mount *mp = pag->pag_mount; > + struct xfs_trans *tp; > struct xfs_btree_cur *cur; > struct xfs_buf *agbp; > int error; > @@ -168,11 +170,15 @@ xfs_trim_gather_extents( > */ > xfs_log_force(mp, XFS_LOG_SYNC); > > - error = xfs_alloc_read_agf(pag, NULL, 0, &agbp); > + error = xfs_trans_alloc_empty(mp, &tp); > if (error) > return error; > > - cur = xfs_allocbt_init_cursor(mp, NULL, agbp, pag, XFS_BTNUM_CNT); > + error = xfs_alloc_read_agf(pag, tp, 0, &agbp); > + if (error) > + goto out_trans_cancel; > + > + cur = xfs_allocbt_init_cursor(mp, tp, agbp, pag, XFS_BTNUM_CNT); > > /* > * Look up the extent length requested in the AGF and start with it. > @@ -279,7 +285,8 @@ xfs_trim_gather_extents( > xfs_extent_busy_clear(mp, &extents->extent_list, false); > out_del_cursor: > xfs_btree_del_cursor(cur, error); > - xfs_buf_relse(agbp); > +out_trans_cancel: > + xfs_trans_cancel(tp); > return error; > } > > -- > 2.43.0 > >