linux-xfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "user.mail" <sandeen@redhat.com>
To: linux-xfs@vger.kernel.org
Cc: "user.mail" <sandeen@redhat.com>
Subject: [PATCH 2/2] xfs_repair: distinguish true ENOMEM from "not found" in cache_node_get
Date: Mon, 24 Aug 2026 14:59:00 -0500	[thread overview]
Message-ID: <20260824214056.400740-3-sandeen@redhat.com> (raw)
In-Reply-To: <20260824214056.400740-1-sandeen@redhat.com>

In the cache_node_get() callchain, we may fail in cache_node_allocate
for two distinct reasons:
 - The cache may be at its current size limit, and must be expanded
 - An underlying allocation may have actually failed with ENOMEM

Today, we do not distinguish these 2 failure modes and will try to
expand the cache size even in the face of an ENOMEM, which won't help.
We can distinguish these two failures, because:

If cache_node_allocate fails because all slots are full, c_count is
untouched, and it is >= c_maxcount (all slots full.)

If cache_node_allocate fails due to an underlying ENOMEM, c_count is
decremented before return and c_count will remain < c_maxcount.

So, if the cache has been fully shaken, cache_node_allocate stil
fails, and c_count < c_maxcount, this is a true ENOMEM situation, and
we should give up and tell the caller.

This adds yet another return value to cache_node_get (-1) for ENOMEM
failures, and corrects the comment about the existing 0-vs-1 returns
- though nobody looks at that return value today.

Signed-off-by: Eric Sandeen <sandeen@redhat.com>
Signed-off-by: user.mail <sandeen@redhat.com>
---
 libxfs/cache.c | 16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)

diff --git a/libxfs/cache.c b/libxfs/cache.c
index f8be9b89..63224e58 100644
--- a/libxfs/cache.c
+++ b/libxfs/cache.c
@@ -373,8 +373,8 @@ __cache_node_purge(
  * hit, in which case this will all be over quickly and painlessly.
  * Otherwise, we allocate a new node, taking care not to expand the
  * cache beyond the requested maximum size (shrink it if it would).
- * Returns one if hit in cache, otherwise zero.  A node is _always_
- * returned, however.
+ * Returns zero if hit in cache, otherwise return 1 for new node;
+ * allocation failures return -1 and a null nodep.
  */
 int
 cache_node_get(
@@ -474,6 +474,18 @@ next_object:
 		 * If we exceed CACHE_MAX_PRIORITY all slots are full; grow it.
 		 */
 		if (priority > CACHE_MAX_PRIORITY) {
+			/*
+			 * Shaking failed to make room. If the cache is not
+			 * full, expanding the limit won't help - this is a
+			 * genuine ENOMEM. Tell the caller.
+			 */
+			pthread_mutex_lock(&cache->c_mutex);
+			if (cache->c_count < cache->c_maxcount) {
+				pthread_mutex_unlock(&cache->c_mutex);
+				*nodep = NULL;
+				return -1;
+			}
+			pthread_mutex_unlock(&cache->c_mutex);
 			priority = 0;
 			if (!cache_expand(cache))
 				goto fail;
-- 
2.55.0


  parent reply	other threads:[~2026-08-24 21:41 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-24 19:58 [PATCH 0/2] xfs_repair: improve caching in the face of ENOMEM user.mail
2026-08-24 19:58 ` [PATCH 1/2] xfs_repair: do not allow cache growth to overflow user.mail
2026-08-25  3:17   ` Darrick J. Wong
2026-08-25 12:36     ` Eric Sandeen
2026-08-24 19:59 ` user.mail [this message]
2026-08-25  3:18   ` [PATCH 2/2] xfs_repair: distinguish true ENOMEM from "not found" in cache_node_get Darrick J. Wong
2026-08-25 15:39     ` Eric Sandeen
2026-08-25 15:49       ` Darrick J. Wong
2026-08-25 15:50         ` Eric Sandeen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260824214056.400740-3-sandeen@redhat.com \
    --to=sandeen@redhat.com \
    --cc=linux-xfs@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).