Linux EXT4 FS development
 help / color / mirror / Atom feed
* [PATCH] ext4: free HTree fname rb-tree at EOF in ext4_dx_readdir()
@ 2026-11-16  2:25 Chris Wiseman
  2026-11-16  2:30 ` sashiko-bot
  0 siblings, 1 reply; 2+ messages in thread
From: Chris Wiseman @ 2026-11-16  2:25 UTC (permalink / raw)
  To: Theodore Ts'o, Andreas Dilger
  Cc: Jan Kara, Baokun Li, Ojaswin Mujoo, Ritesh Harjani (IBM),
	Zhang Yi, linux-ext4, linux-kernel, Chris Wiseman

When ext4_dx_readdir() finishes scanning the last HTree leaf block of
an indexed directory, ext4_htree_fill_tree() sets info->next_hash to
~0.  On the final iteration, once rb_next(info->curr_node) returns NULL,
ext4_dx_readdir() sets ctx->pos to ext4_get_htree_eof(file) and breaks
out of the loop without calling free_rb_tree_fname(&info->root).

While ext4_dx_readdir() frees info->root when advancing across leaf
blocks or resetting on seek, reaching EOF leaves the final leaf block's
red-black tree of struct fname nodes pinned in file->private_data until
the directory fd is closed in ext4_release_dir().  Processes and daemons
that keep directory descriptors open after reading to EOF retain those
slab allocations for the lifetime of the open fd.

Free info->root before returning EOF when info->next_hash == ~0.  If the
caller later seeks back, the existing !info->curr_node check at the top
of the loop repopulates the tree on demand.

Benchmark results (/proc/allocinfo, 256 open HTree dirs at EOF):

  Metric                                  Before        After     Delta
  ----------------------------------  -----------  ----------  --------
  ext4_htree_store_dirent live slab   1,007,616 B         0 B   -100.0%
  ext4_htree_store_dirent live objs        10,496           0   -100.0%
  /proc/meminfo SUnreclaim delta        +1,246 kB     +133 kB    -89.3%

Signed-off-by: Chris Wiseman <chriswiseman@google.com>
---
 fs/ext4/dir.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/fs/ext4/dir.c b/fs/ext4/dir.c
index 8d7b81e6948e..435300cd2c61 100644
--- a/fs/ext4/dir.c
+++ b/fs/ext4/dir.c
@@ -640,6 +640,7 @@ static int ext4_dx_readdir(struct file *file, struct dir_context *ctx)
 			info->curr_minor_hash = fname->minor_hash;
 		} else {
 			if (info->next_hash == ~0) {
+				free_rb_tree_fname(&info->root);
 				ctx->pos = ext4_get_htree_eof(file);
 				break;
 			}
-- 
2.56.0


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] ext4: free HTree fname rb-tree at EOF in ext4_dx_readdir()
  2026-11-16  2:25 [PATCH] ext4: free HTree fname rb-tree at EOF in ext4_dx_readdir() Chris Wiseman
@ 2026-11-16  2:30 ` sashiko-bot
  0 siblings, 0 replies; 2+ messages in thread
From: sashiko-bot @ 2026-11-16  2:30 UTC (permalink / raw)
  To: Chris Wiseman; +Cc: linux-ext4, tytso

> When ext4_dx_readdir() finishes scanning the last HTree leaf block of
> an indexed directory, ext4_htree_fill_tree() sets info->next_hash to
> ~0.  On the final iteration, once rb_next(info->curr_node) returns NULL,
> ext4_dx_readdir() sets ctx->pos to ext4_get_htree_eof(file) and breaks
> out of the loop without calling free_rb_tree_fname(&info->root).
> 
> While ext4_dx_readdir() frees info->root when advancing across leaf
> blocks or resetting on seek, reaching EOF leaves the final leaf block's
> red-black tree of struct fname nodes pinned in file->private_data until
> the directory fd is closed in ext4_release_dir().  Processes and daemons
> that keep directory descriptors open after reading to EOF retain those
> slab allocations for the lifetime of the open fd.
> 
> Free info->root before returning EOF when info->next_hash == ~0.  If the
> caller later seeks back, the existing !info->curr_node check at the top
> of the loop repopulates the tree on demand.
> 
> Benchmark results (/proc/allocinfo, 256 open HTree dirs at EOF):
> 
>   Metric                                  Before        After     Delta
>   ----------------------------------  -----------  ----------  --------
>   ext4_htree_store_dirent live slab   1,007,616 B         0 B   -100.0%
>   ext4_htree_store_dirent live objs        10,496           0   -100.0%
>   /proc/meminfo SUnreclaim delta        +1,246 kB     +133 kB    -89.3%
> 
> Signed-off-by: Chris Wiseman <chriswiseman@google.com>

Sashiko has reviewed this patch and found no issues.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/18e865672dda2d41.3137322e32332e3235332e313736.36f4d7.0000sendgmr@google.com?part=1


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-11-16  2:30 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-16  2:25 [PATCH] ext4: free HTree fname rb-tree at EOF in ext4_dx_readdir() Chris Wiseman
2026-11-16  2:30 ` sashiko-bot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox