Skip to content

Commit 1de94b5

Browse files
committed
eventfs: Shortcut eventfs_iterate() by skipping entries already read
As the ei->entries array is fixed for the duration of the eventfs_inode, it can be used to skip over already read entries in eventfs_iterate(). That is, if ctx->pos is greater than zero, there's no reason in doing the loop across the ei->entries array for the entries less than ctx->pos. Instead, start the lookup of the entries at the current ctx->pos. Link: https://lore.kernel.org/all/CAHk-=wiKwDUDv3+jCsv-uacDcHDVTYsXtBR9=6sGM5mqX+DhOg@mail.gmail.com/ Link: https://lore.kernel.org/linux-trace-kernel/20240104220048.494956957@goodmis.org Cc: Masami Hiramatsu <mhiramat@kernel.org> Cc: Mark Rutland <mark.rutland@arm.com> Cc: Mathieu Desnoyers <mathieu.desnoyers@efficios.com> Cc: Andrew Morton <akpm@linux-foundation.org> Cc: Al Viro <viro@zeniv.linux.org.uk> Cc: Christian Brauner <brauner@kernel.org> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Suggested-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
1 parent 704f960 commit 1de94b5

1 file changed

Lines changed: 10 additions & 13 deletions

File tree

fs/tracefs/event_inode.c

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -746,21 +746,15 @@ static int eventfs_iterate(struct file *file, struct dir_context *ctx)
746746
if (!ei || !ei_dentry)
747747
goto out;
748748

749-
ret = 0;
750-
751749
/*
752750
* Need to create the dentries and inodes to have a consistent
753751
* inode number.
754752
*/
755-
for (i = 0; i < ei->nr_entries; i++) {
756-
void *cdata = ei->data;
757-
758-
if (c > 0) {
759-
c--;
760-
continue;
761-
}
753+
ret = 0;
762754

763-
ctx->pos++;
755+
/* Start at 'c' to jump over already read entries */
756+
for (i = c; i < ei->nr_entries; i++, ctx->pos++) {
757+
void *cdata = ei->data;
764758

765759
entry = &ei->entries[i];
766760
name = entry->name;
@@ -769,7 +763,7 @@ static int eventfs_iterate(struct file *file, struct dir_context *ctx)
769763
/* If ei->is_freed then just bail here, nothing more to do */
770764
if (ei->is_freed) {
771765
mutex_unlock(&eventfs_mutex);
772-
goto out_dec;
766+
goto out;
773767
}
774768
r = entry->callback(name, &mode, &cdata, &fops);
775769
mutex_unlock(&eventfs_mutex);
@@ -778,14 +772,17 @@ static int eventfs_iterate(struct file *file, struct dir_context *ctx)
778772

779773
dentry = create_file_dentry(ei, i, ei_dentry, name, mode, cdata, fops);
780774
if (!dentry)
781-
goto out_dec;
775+
goto out;
782776
ino = dentry->d_inode->i_ino;
783777
dput(dentry);
784778

785779
if (!dir_emit(ctx, name, strlen(name), ino, DT_REG))
786-
goto out_dec;
780+
goto out;
787781
}
788782

783+
/* Subtract the skipped entries above */
784+
c -= min((unsigned int)c, (unsigned int)ei->nr_entries);
785+
789786
list_for_each_entry_srcu(ei_child, &ei->children, list,
790787
srcu_read_lock_held(&eventfs_srcu)) {
791788

0 commit comments

Comments
 (0)