Skip to content

Commit 5790b1f

Browse files
committed
eventfs: Remove eventfs_file and just use eventfs_inode
Instead of having a descriptor for every file represented in the eventfs directory, only have the directory itself represented. Change the API to send in a list of entries that represent all the files in the directory (but not other directories). The entry list contains a name and a callback function that will be used to create the files when they are accessed. struct eventfs_inode *eventfs_create_events_dir(const char *name, struct dentry *parent, const struct eventfs_entry *entries, int size, void *data); is used for the top level eventfs directory, and returns an eventfs_inode that will be used by: struct eventfs_inode *eventfs_create_dir(const char *name, struct eventfs_inode *parent, const struct eventfs_entry *entries, int size, void *data); where both of the above take an array of struct eventfs_entry entries for every file that is in the directory. The entries are defined by: typedef int (*eventfs_callback)(const char *name, umode_t *mode, void **data, const struct file_operations **fops); struct eventfs_entry { const char *name; eventfs_callback callback; }; Where the name is the name of the file and the callback gets called when the file is being created. The callback passes in the name (in case the same callback is used for multiple files), a pointer to the mode, data and fops. The data will be pointing to the data that was passed in eventfs_create_dir() or eventfs_create_events_dir() but may be overridden to point to something else, as it will be used to point to the inode->i_private that is created. The information passed back from the callback is used to create the dentry/inode. If the callback fills the data and the file should be created, it must return a positive number. On zero or negative, the file is ignored. This logic may also be used as a prototype to convert entire pseudo file systems into just-in-time allocation. The "show_events_dentry" file has been updated to show the directories, and any files they have. With just the eventfs_file allocations: Before after deltas for meminfo (in kB): MemFree: -14360 MemAvailable: -14260 Buffers: 40 Cached: 24 Active: 44 Inactive: 48 Inactive(anon): 28 Active(file): 44 Inactive(file): 20 Dirty: -4 AnonPages: 28 Mapped: 4 KReclaimable: 132 Slab: 1604 SReclaimable: 132 SUnreclaim: 1472 Committed_AS: 12 Before after deltas for slabinfo: <slab>: <objects> [ * <size> = <total>] ext4_inode_cache 27 [* 1184 = 31968 ] extent_status 102 [* 40 = 4080 ] tracefs_inode_cache 144 [* 656 = 94464 ] buffer_head 39 [* 104 = 4056 ] shmem_inode_cache 49 [* 800 = 39200 ] filp -53 [* 256 = -13568 ] dentry 251 [* 192 = 48192 ] lsm_file_cache 277 [* 32 = 8864 ] vm_area_struct -14 [* 184 = -2576 ] trace_event_file 1748 [* 88 = 153824 ] kmalloc-1k 35 [* 1024 = 35840 ] kmalloc-256 49 [* 256 = 12544 ] kmalloc-192 -28 [* 192 = -5376 ] kmalloc-128 -30 [* 128 = -3840 ] kmalloc-96 10581 [* 96 = 1015776 ] kmalloc-64 3056 [* 64 = 195584 ] kmalloc-32 1291 [* 32 = 41312 ] kmalloc-16 2310 [* 16 = 36960 ] kmalloc-8 9216 [* 8 = 73728 ] Free memory dropped by 14,360 kB Available memory dropped by 14,260 kB Total slab additions in size: 1,771,032 bytes With this change: Before after deltas for meminfo (in kB): MemFree: -12084 MemAvailable: -11976 Buffers: 32 Cached: 32 Active: 72 Inactive: 168 Inactive(anon): 176 Active(file): 72 Inactive(file): -8 Dirty: 24 AnonPages: 196 Mapped: 8 KReclaimable: 148 Slab: 836 SReclaimable: 148 SUnreclaim: 688 Committed_AS: 324 Before after deltas for slabinfo: <slab>: <objects> [ * <size> = <total>] tracefs_inode_cache 144 [* 656 = 94464 ] shmem_inode_cache -23 [* 800 = -18400 ] filp -92 [* 256 = -23552 ] dentry 179 [* 192 = 34368 ] lsm_file_cache -3 [* 32 = -96 ] vm_area_struct -13 [* 184 = -2392 ] trace_event_file 1748 [* 88 = 153824 ] kmalloc-1k -49 [* 1024 = -50176 ] kmalloc-256 -27 [* 256 = -6912 ] kmalloc-128 1864 [* 128 = 238592 ] kmalloc-64 4685 [* 64 = 299840 ] kmalloc-32 -72 [* 32 = -2304 ] kmalloc-16 256 [* 16 = 4096 ] total = 721352 Free memory dropped by 12,084 kB Available memory dropped by 11,976 kB Total slab additions in size: 721,352 bytes That's over 2 MB in savings per instance for free and available memory, and over 1 MB in savings per instance of slab memory. Link: https://lore.kernel.org/linux-trace-kernel/[email protected] Link: https://lore.kernel.org/linux-trace-kernel/[email protected] Cc: Masami Hiramatsu <[email protected]> Cc: Mark Rutland <[email protected]> Cc: Andrew Morton <[email protected]> Cc: Ajay Kaher <[email protected]> Signed-off-by: Steven Rostedt (Google) <[email protected]>
1 parent 2c6d095 commit 5790b1f

File tree

8 files changed

+705
-536
lines changed

8 files changed

+705
-536
lines changed

fs/tracefs/event_inode.c

Lines changed: 432 additions & 415 deletions
Large diffs are not rendered by default.

fs/tracefs/inode.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,7 @@ static void tracefs_dentry_iput(struct dentry *dentry, struct inode *inode)
385385

386386
ti = get_tracefs(inode);
387387
if (ti && ti->flags & TRACEFS_EVENT_INODE)
388-
eventfs_set_ef_status_free(ti, dentry);
388+
eventfs_set_ei_status_free(ti, dentry);
389389
iput(inode);
390390
}
391391

fs/tracefs/internal.h

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,41 @@ struct tracefs_inode {
1313
struct inode vfs_inode;
1414
};
1515

16+
/*
17+
* struct eventfs_inode - hold the properties of the eventfs directories.
18+
* @list: link list into the parent directory
19+
* @entries: the array of entries representing the files in the directory
20+
* @name: the name of the directory to create
21+
* @children: link list into the child eventfs_inode
22+
* @dentry: the dentry of the directory
23+
* @d_parent: pointer to the parent's dentry
24+
* @d_children: The array of dentries to represent the files when created
25+
* @data: The private data to pass to the callbacks
26+
* @nr_entries: The number of items in @entries
27+
*/
28+
struct eventfs_inode {
29+
struct list_head list;
30+
const struct eventfs_entry *entries;
31+
const char *name;
32+
struct list_head children;
33+
struct dentry *dentry;
34+
struct dentry *d_parent;
35+
struct dentry **d_children;
36+
void *data;
37+
/*
38+
* Union - used for deletion
39+
* @del_list: list of eventfs_inode to delete
40+
* @rcu: eventfs_indoe to delete in RCU
41+
* @is_freed: node is freed if one of the above is set
42+
*/
43+
union {
44+
struct list_head del_list;
45+
struct rcu_head rcu;
46+
unsigned long is_freed;
47+
};
48+
int nr_entries;
49+
};
50+
1651
static inline struct tracefs_inode *get_tracefs(const struct inode *inode)
1752
{
1853
return container_of(inode, struct tracefs_inode, vfs_inode);
@@ -25,6 +60,6 @@ struct inode *tracefs_get_inode(struct super_block *sb);
2560
struct dentry *eventfs_start_creating(const char *name, struct dentry *parent);
2661
struct dentry *eventfs_failed_creating(struct dentry *dentry);
2762
struct dentry *eventfs_end_creating(struct dentry *dentry);
28-
void eventfs_set_ef_status_free(struct tracefs_inode *ti, struct dentry *dentry);
63+
void eventfs_set_ei_status_free(struct tracefs_inode *ti, struct dentry *dentry);
2964

3065
#endif /* _TRACEFS_INTERNAL_H */

include/linux/trace_events.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -649,7 +649,7 @@ struct trace_event_file {
649649
struct list_head list;
650650
struct trace_event_call *event_call;
651651
struct event_filter __rcu *filter;
652-
struct eventfs_file *ef;
652+
struct eventfs_inode *ei;
653653
struct trace_array *tr;
654654
struct trace_subsystem_dir *system;
655655
struct list_head triggers;

include/linux/tracefs.h

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -23,26 +23,25 @@ struct file_operations;
2323

2424
struct eventfs_file;
2525

26-
struct dentry *eventfs_create_events_dir(const char *name,
27-
struct dentry *parent);
26+
typedef int (*eventfs_callback)(const char *name, umode_t *mode, void **data,
27+
const struct file_operations **fops);
2828

29-
struct eventfs_file *eventfs_add_subsystem_dir(const char *name,
30-
struct dentry *parent);
29+
struct eventfs_entry {
30+
const char *name;
31+
eventfs_callback callback;
32+
};
3133

32-
struct eventfs_file *eventfs_add_dir(const char *name,
33-
struct eventfs_file *ef_parent);
34+
struct eventfs_inode;
3435

35-
int eventfs_add_file(const char *name, umode_t mode,
36-
struct eventfs_file *ef_parent, void *data,
37-
const struct file_operations *fops);
36+
struct eventfs_inode *eventfs_create_events_dir(const char *name, struct dentry *parent,
37+
const struct eventfs_entry *entries,
38+
int size, void *data);
3839

39-
int eventfs_add_events_file(const char *name, umode_t mode,
40-
struct dentry *parent, void *data,
41-
const struct file_operations *fops);
40+
struct eventfs_inode *eventfs_create_dir(const char *name, struct eventfs_inode *parent,
41+
const struct eventfs_entry *entries,
42+
int size, void *data);
4243

43-
void eventfs_remove(struct eventfs_file *ef);
44-
45-
void eventfs_remove_events_dir(struct dentry *dentry);
44+
void eventfs_remove_dir(struct eventfs_inode *ei);
4645

4746
struct dentry *tracefs_create_file(const char *name, umode_t mode,
4847
struct dentry *parent, void *data,

kernel/trace/trace.c

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9764,7 +9764,6 @@ static __init void create_trace_instances(struct dentry *d_tracer)
97649764
static void
97659765
init_tracer_tracefs(struct trace_array *tr, struct dentry *d_tracer)
97669766
{
9767-
struct trace_event_file *file;
97689767
int cpu;
97699768

97709769
trace_create_file("available_tracers", TRACE_MODE_READ, d_tracer,
@@ -9797,11 +9796,7 @@ init_tracer_tracefs(struct trace_array *tr, struct dentry *d_tracer)
97979796
trace_create_file("trace_marker", 0220, d_tracer,
97989797
tr, &tracing_mark_fops);
97999798

9800-
file = __find_event_file(tr, "ftrace", "print");
9801-
if (file && file->ef)
9802-
eventfs_add_file("trigger", TRACE_MODE_WRITE, file->ef,
9803-
file, &event_trigger_fops);
9804-
tr->trace_marker_file = file;
9799+
tr->trace_marker_file = __find_event_file(tr, "ftrace", "print");
98059800

98069801
trace_create_file("trace_marker_raw", 0220, d_tracer,
98079802
tr, &tracing_mark_raw_fops);

kernel/trace/trace.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,7 @@ struct trace_array {
381381
struct dentry *dir;
382382
struct dentry *options;
383383
struct dentry *percpu_dir;
384-
struct dentry *event_dir;
384+
struct eventfs_inode *event_dir;
385385
struct trace_options *topts;
386386
struct list_head systems;
387387
struct list_head events;
@@ -1349,7 +1349,7 @@ struct trace_subsystem_dir {
13491349
struct list_head list;
13501350
struct event_subsystem *subsystem;
13511351
struct trace_array *tr;
1352-
struct eventfs_file *ef;
1352+
struct eventfs_inode *ei;
13531353
int ref_count;
13541354
int nr_events;
13551355
};

0 commit comments

Comments
 (0)