Skip to content

Commit 268b361

Browse files
Al Virogregkh
authored andcommitted
debugfs: separate cache for debugfs inodes
Embed them into container (struct debugfs_inode_info, with nothing else in it at the moment), set the cache up, etc. Just the infrastructure changes letting us augment debugfs inodes here; adding stuff will come at the next step. Signed-off-by: Al Viro <[email protected]> Reviewed-by: Christian Brauner <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent ee9c693 commit 268b361

File tree

2 files changed

+43
-6
lines changed

2 files changed

+43
-6
lines changed

fs/debugfs/inode.c

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -208,16 +208,34 @@ static int debugfs_show_options(struct seq_file *m, struct dentry *root)
208208
return 0;
209209
}
210210

211+
static struct kmem_cache *debugfs_inode_cachep __ro_after_init;
212+
213+
static void init_once(void *foo)
214+
{
215+
struct debugfs_inode_info *info = foo;
216+
inode_init_once(&info->vfs_inode);
217+
}
218+
219+
static struct inode *debugfs_alloc_inode(struct super_block *sb)
220+
{
221+
struct debugfs_inode_info *info;
222+
info = alloc_inode_sb(sb, debugfs_inode_cachep, GFP_KERNEL);
223+
if (!info)
224+
return NULL;
225+
return &info->vfs_inode;
226+
}
227+
211228
static void debugfs_free_inode(struct inode *inode)
212229
{
213230
if (S_ISLNK(inode->i_mode))
214231
kfree(inode->i_link);
215-
free_inode_nonrcu(inode);
232+
kmem_cache_free(debugfs_inode_cachep, DEBUGFS_I(inode));
216233
}
217234

218235
static const struct super_operations debugfs_super_operations = {
219236
.statfs = simple_statfs,
220237
.show_options = debugfs_show_options,
238+
.alloc_inode = debugfs_alloc_inode,
221239
.free_inode = debugfs_free_inode,
222240
};
223241

@@ -939,12 +957,22 @@ static int __init debugfs_init(void)
939957
if (retval)
940958
return retval;
941959

942-
retval = register_filesystem(&debug_fs_type);
943-
if (retval)
960+
debugfs_inode_cachep = kmem_cache_create("debugfs_inode_cache",
961+
sizeof(struct debugfs_inode_info), 0,
962+
SLAB_RECLAIM_ACCOUNT | SLAB_ACCOUNT,
963+
init_once);
964+
if (debugfs_inode_cachep == NULL) {
944965
sysfs_remove_mount_point(kernel_kobj, "debug");
945-
else
946-
debugfs_registered = true;
966+
return -ENOMEM;
967+
}
947968

948-
return retval;
969+
retval = register_filesystem(&debug_fs_type);
970+
if (retval) { // Really not going to happen
971+
sysfs_remove_mount_point(kernel_kobj, "debug");
972+
kmem_cache_destroy(debugfs_inode_cachep);
973+
return retval;
974+
}
975+
debugfs_registered = true;
976+
return 0;
949977
}
950978
core_initcall(debugfs_init);

fs/debugfs/internal.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,15 @@
1111

1212
struct file_operations;
1313

14+
struct debugfs_inode_info {
15+
struct inode vfs_inode;
16+
};
17+
18+
static inline struct debugfs_inode_info *DEBUGFS_I(struct inode *inode)
19+
{
20+
return container_of(inode, struct debugfs_inode_info, vfs_inode);
21+
}
22+
1423
/* declared over in file.c */
1524
extern const struct file_operations debugfs_noop_file_operations;
1625
extern const struct file_operations debugfs_open_proxy_file_operations;

0 commit comments

Comments
 (0)