From patchwork Mon Jan 15 22:59:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dave Chinner X-Patchwork-Id: 13520253 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 E457BC3DA79 for ; Mon, 15 Jan 2024 23:01:24 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id CF4776B006E; Mon, 15 Jan 2024 18:01:22 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id CADCC6B0074; Mon, 15 Jan 2024 18:01:22 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9E5816B006E; Mon, 15 Jan 2024 18:01:22 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 86DAA6B006E for ; Mon, 15 Jan 2024 18:01:22 -0500 (EST) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 548F94087B for ; Mon, 15 Jan 2024 23:01:22 +0000 (UTC) X-FDA: 81683068404.03.4BAA298 Received: from mail-pl1-f173.google.com (mail-pl1-f173.google.com [209.85.214.173]) by imf02.hostedemail.com (Postfix) with ESMTP id 8EFCF80011 for ; Mon, 15 Jan 2024 23:01:20 +0000 (UTC) Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=fromorbit-com.20230601.gappssmtp.com header.s=20230601 header.b=MOUA4iCY; dmarc=pass (policy=quarantine) header.from=fromorbit.com; spf=pass (imf02.hostedemail.com: domain of david@fromorbit.com designates 209.85.214.173 as permitted sender) smtp.mailfrom=david@fromorbit.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1705359680; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=bprujdq9x6vGUjX7hmrzPJN/IZ+ZvLny33A51Hvuzf0=; b=4G2P/TexYULZ7ut7OsGbj3msUX4DUJBHlV77vcvvTDhnToDWtpARfqGR5euB83lMGG/c0v cKbjpSafUWLs9h1DWgnuYh+urD+t4pdhN0SL9lguq/sl9ymSOuL5WV9+G0nKKvZG+p0udn 77tQ5TkDqpcDgew0H/kMc8L6vBuL2lw= ARC-Authentication-Results: i=1; imf02.hostedemail.com; dkim=pass header.d=fromorbit-com.20230601.gappssmtp.com header.s=20230601 header.b=MOUA4iCY; dmarc=pass (policy=quarantine) header.from=fromorbit.com; spf=pass (imf02.hostedemail.com: domain of david@fromorbit.com designates 209.85.214.173 as permitted sender) smtp.mailfrom=david@fromorbit.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1705359680; a=rsa-sha256; cv=none; b=RMvAp/7+h7ECNP7Guq+UPEzTC3zjPCwAhgjmJwltbKYuMijbHZaGnHJ3PY6AxrhpgYV5Oc IgspgGbXptNzxoTZNyTunxqBBCDARkZNXNxHa9173yQA1+SMUsvuFoyD/HCEsLJSOa8K5r 4mTsLpQLRgtSBVbZucCfOdAyxC33XAo= Received: by mail-pl1-f173.google.com with SMTP id d9443c01a7336-1d3eae5c1d7so46816735ad.2 for ; Mon, 15 Jan 2024 15:01:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fromorbit-com.20230601.gappssmtp.com; s=20230601; t=1705359679; x=1705964479; darn=kvack.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=bprujdq9x6vGUjX7hmrzPJN/IZ+ZvLny33A51Hvuzf0=; b=MOUA4iCYlX33jeHYDKlg014XSEJkrP3kG7wbAKdZoJ4xAOZi9QVrJEY+3OK/pUNCig AWNvWLABVBrP9fmMavV9cuZsWN0xK6YnC/WEE2z8z2GbDVrRqiLC3dbmGWONj2vYoLIy /2KN8dOdKV90t3SIsbMiNd5ew850yqlxNOm7BAtUE039OvfcpqLKflrDNkbRCYZbKkWv 9rqnsxE3je0XJTK82CTtqBBEizQZZBc7B/iMn5g8i6WCP9lRpm+R7UKST9ggz0lK3MHp uxWqjS1Gpu/MXUZTgC3NIVEQhPBZ16uvRQhsvnltvpnOzOTro35M2CiPrxYpT4FL7BGW kBcw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1705359679; x=1705964479; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=bprujdq9x6vGUjX7hmrzPJN/IZ+ZvLny33A51Hvuzf0=; b=n03G89FIeWqK6pBGkd4SE5GQFzB2ZyuTRO55wP9Ab46FlKFxpTJ96roWJq11n3VjJX GpuM2347duyScZFN2fqOdLb4HIQZKlocYzixguV715WMeYdfpHj6N3mqeFrsnBc7RA36 fgNf8ip7p314PKm2xtW6zxvrdtrezIR7tmUF7qzqas25d0osSfl9nfT9rpg61QzcmCag ttsd6JHltIM1V8q9PzM2V2Nl5dbm1HGY4vs3iom+rWxODFsQpYc95X9CvBWTiXLGuSyk jAZbY2nPyEc2yR2hYPI9ksOYLlzv4GrQ/dGXwWWdYPQQ/xmWckwzR093EY2yv/K6R2pB kUMQ== X-Gm-Message-State: AOJu0YwBc1GZyKIkTJskRXtbBdOzY6DuXXHk5VrvaM3V2tE8p9zvtgRJ mLSJuwFLYsFnd3sGCG7/CtiqkG1FGrQHXg== X-Google-Smtp-Source: AGHT+IEiof1jeUl/P8MCSvHO3zALDxYJPl6CwcuUzGZhqGNXCpwzMiN1PzBQ1/m0xGV6eG7CXA73PA== X-Received: by 2002:a17:902:e751:b0:1d4:6429:4e1c with SMTP id p17-20020a170902e75100b001d464294e1cmr4036272plf.4.1705359679338; Mon, 15 Jan 2024 15:01:19 -0800 (PST) Received: from dread.disaster.area (pa49-180-249-6.pa.nsw.optusnet.com.au. [49.180.249.6]) by smtp.gmail.com with ESMTPSA id i10-20020a170902c94a00b001d538ee9ff3sm8076467pla.183.2024.01.15.15.01.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Jan 2024 15:01:18 -0800 (PST) Received: from [192.168.253.23] (helo=devoid.disaster.area) by dread.disaster.area with esmtp (Exim 4.96) (envelope-from ) id 1rPVxE-00AtKA-0Z; Tue, 16 Jan 2024 10:01:15 +1100 Received: from dave by devoid.disaster.area with local (Exim 4.97) (envelope-from ) id 1rPVxD-0000000H8fn-2ghT; Tue, 16 Jan 2024 10:01:15 +1100 From: Dave Chinner To: linux-xfs@vger.kernel.org Cc: willy@infradead.org, linux-mm@kvack.org Subject: [PATCH 06/12] xfs: use an empty transaction for fstrim Date: Tue, 16 Jan 2024 09:59:44 +1100 Message-ID: <20240115230113.4080105-7-david@fromorbit.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240115230113.4080105-1-david@fromorbit.com> References: <20240115230113.4080105-1-david@fromorbit.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: 8EFCF80011 X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: wmde3i5fr1cxufkadqgr8n6apc48ixbd X-HE-Tag: 1705359680-989504 X-HE-Meta: U2FsdGVkX19e7ypyvR5fRcMeDcUso2X3xsEtESKWvrYABV7IZxj3+X8tT6mOtHv9P3NFsATGX5e6oucvbtglvO55T7yYAD+004OQJsBXhnnwKU7fzQ5qLTrqUtzjSCKYJMbYE7Ke/7pYH9MN5I37aB5HCPnp5JSXCughba+C+9ymfG/SeY1Bj8q7JtwMA1pKGioKbLESZ/HRn4jRxXxcegdotrb0g4Rc0wC+Vdleo7URCgjRvb0y03of5b/lWiSRsqkALzUH0qL6APeZXErQjkOLFmtWUZZxTm1OxpP//XSuySvYPvYOxPa1a1Tdyb+6sG/8eFCNhW3MnIcV5+XUpBUA21WZT6drWYxVXUlXVzy6E46JGfH3sw4GrNvRFxtloedQO2SH8r4oxEqJXpcbgp1eS2R7M2obJFENJ7ucqHq0834BsJQ6rLX6N8/FfEqDAyLwiz9vz5b/R0SNhfXMcu1NuIdJWu3KjXkxvjPswN1bTuOgPecKRDBnYKtQC28j9SkEAu7nBD5tHhmODDCzxxnClTxFDCeeqABTdhunrlFHaWPpZWgg/jjNIdXXPJ1R9Lq5DTppn2+vQEpt9BAHn8jHo0t9rsqlpyKWPuvwSc8ZQEAHGn0tKIAwFq5hD3iBz4lgjZ/k2Fz+u3dvDIqN4q+N9C6AxamZhD+MlKqhD31qmjX0XX3bKTd/xaUCTBvSW7k6ACG16XCUv8tyGbNhF9pcRBpehfoq4314Gu4lhezZqJ5jeCiyFxiDuCOOdmC34xA4BEwmoKiBQbb8Q4NkKBBxtcFEUM24Rc+0xqT9SXnixkWB88TpInRhEpne9holHG9UAZHsoDEpVEJlpDKUVDPH8oyI40LKIVUoZXJZPP9DDMhqjayMea9SlvxWxvJmyQqJxrVViQwXfYWUQvJjU+ymg8Q6AK1cm4dnngNE6RpiM08K2mb2wudgwHwb0xtlRS0ostYZEgWGia4BRiv kMaiU8/x 2zl9XDgSiizC/eF6EN7to6sNa+TiJoAaBTfS7Q+8K7+GjtcU/DQTKkwhmo8jRZ3M81aPKwZO/n9uzG1L5SmbbRxOj3h2BqY9i385MJtMDtskK8B2r5xQriGxBxfQrxPSczhH8KRqaCsKQeEISemQE2MMbV1LWJqQxu3nU1SvxHzhVfCLXvJjjZr7Eb9KDWG4ZE5bl 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: 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 Reviewed-by: Darrick J. Wong --- 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; }