Skip to content

Commit ba37ff7

Browse files
akaherrostedt
authored andcommitted
eventfs: Implement tracefs_inode_cache
Create a kmem cache of tracefs_inodes. To be more efficient, as there are lots of tracefs inodes, create its own cache. This also allows to see how many tracefs inodes have been created. Add helper functions: tracefs_alloc_inode() tracefs_free_inode() get_tracefs() Link: https://lkml.kernel.org/r/1690568452-46553-3-git-send-email-akaher@vmware.com Signed-off-by: Ajay Kaher <akaher@vmware.com> Co-developed-by: Steven Rostedt (VMware) <rostedt@goodmis.org> Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org> Tested-by: Ching-lin Yu <chinglinyu@google.com> Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
1 parent ee41106 commit ba37ff7

2 files changed

Lines changed: 54 additions & 0 deletions

File tree

fs/tracefs/inode.c

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,33 @@
2121
#include <linux/parser.h>
2222
#include <linux/magic.h>
2323
#include <linux/slab.h>
24+
#include "internal.h"
2425

2526
#define TRACEFS_DEFAULT_MODE 0700
27+
static struct kmem_cache *tracefs_inode_cachep __ro_after_init;
2628

2729
static struct vfsmount *tracefs_mount;
2830
static int tracefs_mount_count;
2931
static bool tracefs_registered;
3032

33+
static struct inode *tracefs_alloc_inode(struct super_block *sb)
34+
{
35+
struct tracefs_inode *ti;
36+
37+
ti = kmem_cache_alloc(tracefs_inode_cachep, GFP_KERNEL);
38+
if (!ti)
39+
return NULL;
40+
41+
ti->flags = 0;
42+
43+
return &ti->vfs_inode;
44+
}
45+
46+
static void tracefs_free_inode(struct inode *inode)
47+
{
48+
kmem_cache_free(tracefs_inode_cachep, get_tracefs(inode));
49+
}
50+
3151
static ssize_t default_read_file(struct file *file, char __user *buf,
3252
size_t count, loff_t *ppos)
3353
{
@@ -346,6 +366,9 @@ static int tracefs_show_options(struct seq_file *m, struct dentry *root)
346366
}
347367

348368
static const struct super_operations tracefs_super_operations = {
369+
.alloc_inode = tracefs_alloc_inode,
370+
.free_inode = tracefs_free_inode,
371+
.drop_inode = generic_delete_inode,
349372
.statfs = simple_statfs,
350373
.remount_fs = tracefs_remount,
351374
.show_options = tracefs_show_options,
@@ -628,10 +651,26 @@ bool tracefs_initialized(void)
628651
return tracefs_registered;
629652
}
630653

654+
static void init_once(void *foo)
655+
{
656+
struct tracefs_inode *ti = (struct tracefs_inode *) foo;
657+
658+
inode_init_once(&ti->vfs_inode);
659+
}
660+
631661
static int __init tracefs_init(void)
632662
{
633663
int retval;
634664

665+
tracefs_inode_cachep = kmem_cache_create("tracefs_inode_cache",
666+
sizeof(struct tracefs_inode),
667+
0, (SLAB_RECLAIM_ACCOUNT|
668+
SLAB_MEM_SPREAD|
669+
SLAB_ACCOUNT),
670+
init_once);
671+
if (!tracefs_inode_cachep)
672+
return -ENOMEM;
673+
635674
retval = sysfs_create_mount_point(kernel_kobj, "tracing");
636675
if (retval)
637676
return -EINVAL;

fs/tracefs/internal.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/* SPDX-License-Identifier: GPL-2.0 */
2+
#ifndef _TRACEFS_INTERNAL_H
3+
#define _TRACEFS_INTERNAL_H
4+
5+
struct tracefs_inode {
6+
unsigned long flags;
7+
void *private;
8+
struct inode vfs_inode;
9+
};
10+
11+
static inline struct tracefs_inode *get_tracefs(const struct inode *inode)
12+
{
13+
return container_of(inode, struct tracefs_inode, vfs_inode);
14+
}
15+
#endif /* _TRACEFS_INTERNAL_H */

0 commit comments

Comments
 (0)