]> git.ipfire.org Git - thirdparty/kernel/linux.git/commit
shmem: adapt to rhashtable-based simple_xattrs with lazy allocation
authorChristian Brauner <brauner@kernel.org>
Mon, 16 Feb 2026 13:31:59 +0000 (14:31 +0100)
committerChristian Brauner <brauner@kernel.org>
Mon, 23 Feb 2026 12:06:38 +0000 (13:06 +0100)
commit52b364fed6e1578e551fee20c76fecb3fc0e10ed
treea32cf3a68a18d63802d21bcd7b402c3227b04830
parentb32c4a213698ab351b44da2fd1b2a5976c7fa033
shmem: adapt to rhashtable-based simple_xattrs with lazy allocation

Adapt tmpfs/shmem to use the rhashtable-based xattr path and switch
from an embedded struct to pointer-based lazy allocation.

Change shmem_inode_info.xattrs from embedded 'struct simple_xattrs' to
a pointer 'struct simple_xattrs *', initialized to NULL. This avoids
the rhashtable overhead for every tmpfs inode, which helps when a lot of
inodes exist.

The xattr store is allocated on first use:

- shmem_initxattrs(): Allocates via simple_xattrs_alloc() when
  security modules set initial xattrs during inode creation.

- shmem_xattr_handler_set(): Allocates on first setxattr, with a
  short-circuit for removal when no xattrs are stored yet.

All read paths (shmem_xattr_handler_get, shmem_listxattr) check for
NULL xattrs pointer and return -ENODATA or 0 respectively.

Replaced xattr entries are freed via simple_xattr_free_rcu() to allow
concurrent RCU readers to finish.

shmem_evict_inode() conditionally frees the xattr store only when
allocated.

Also change simple_xattr_add() from void to int to propagate
rhashtable insertion failures. shmem_initxattrs() is the only caller.

Link: https://patch.msgid.link/20260216-work-xattr-socket-v1-3-c2efa4f74cb7@kernel.org
Acked-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Jan Kara <jack@suse.cz>
Signed-off-by: Christian Brauner <brauner@kernel.org>
fs/xattr.c
include/linux/shmem_fs.h
include/linux/xattr.h
mm/shmem.c