Skip to content

Commit 7f9bfaf

Browse files
committed
fs: use xarray for old mount id
While the ida does use the xarray internally we can use it explicitly which allows us to increment the unique mount id under the xa lock. This allows us to remove the atomic as we're now allocating both ids in one go. Link: https://lore.kernel.org/r/20241217-erhielten-regung-44bb1604ca8f@brauner Signed-off-by: Christian Brauner <[email protected]>
1 parent 87fc11a commit 7f9bfaf

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

fs/namespace.c

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,12 @@ static int __init set_mphash_entries(char *str)
6565
__setup("mphash_entries=", set_mphash_entries);
6666

6767
static u64 event;
68-
static DEFINE_IDA(mnt_id_ida);
68+
static DEFINE_XARRAY_FLAGS(mnt_id_xa, XA_FLAGS_ALLOC);
6969
static DEFINE_IDA(mnt_group_ida);
7070

7171
/* Don't allow confusion with old 32bit mount ID */
7272
#define MNT_UNIQUE_ID_OFFSET (1ULL << 31)
73-
static atomic64_t mnt_id_ctr = ATOMIC64_INIT(MNT_UNIQUE_ID_OFFSET);
73+
static u64 mnt_id_ctr = MNT_UNIQUE_ID_OFFSET;
7474

7575
static struct hlist_head *mount_hashtable __ro_after_init;
7676
static struct hlist_head *mountpoint_hashtable __ro_after_init;
@@ -267,18 +267,19 @@ static inline struct hlist_head *mp_hash(struct dentry *dentry)
267267

268268
static int mnt_alloc_id(struct mount *mnt)
269269
{
270-
int res = ida_alloc(&mnt_id_ida, GFP_KERNEL);
270+
int res;
271271

272-
if (res < 0)
273-
return res;
274-
mnt->mnt_id = res;
275-
mnt->mnt_id_unique = atomic64_inc_return(&mnt_id_ctr);
276-
return 0;
272+
xa_lock(&mnt_id_xa);
273+
res = __xa_alloc(&mnt_id_xa, &mnt->mnt_id, mnt, XA_LIMIT(1, INT_MAX), GFP_KERNEL);
274+
if (!res)
275+
mnt->mnt_id_unique = ++mnt_id_ctr;
276+
xa_unlock(&mnt_id_xa);
277+
return res;
277278
}
278279

279280
static void mnt_free_id(struct mount *mnt)
280281
{
281-
ida_free(&mnt_id_ida, mnt->mnt_id);
282+
xa_erase(&mnt_id_xa, mnt->mnt_id);
282283
}
283284

284285
/*

0 commit comments

Comments
 (0)