From nobody Sun Feb 8 08:22:30 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 01B6E5660; Sun, 4 Feb 2024 01:18:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707009486; cv=none; b=XIOFKkvJAJozx0jkBmDoOyq+zdrB0Mkj/M+KS6+uJslKLv/bdbUyFJGEab4hsUqU2CKNtCDiYf/79EXNIUsrzmcKjksYbePHYVbkPrqdyo8rXlpv8sftbsjkKQGTES5CFJRBlzB7wZdGJpUqNfle1j/6Xhar9fx/exD4Fxm6cYQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707009486; c=relaxed/simple; bh=/JpS99lNgHIlmUQoiQN2u6X1Nyd8YU3yIhcsAIJ1oQc=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=pyZwXklrAueG4tjuwnfkUCYcnuXU1RV23o2R2fDk8+mpddGSPomXhqXwt9h4M7arnMWcybY3SIHu1BS+suM5ZK9pvk0ddjCF4uQ+ivbD8CheI7DxX1aBCien4k12KSoBpWgLs7TZ3agxzXOvTgarNDm6Wlt18dM6OCsZY/InpvY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8B658C32789; Sun, 4 Feb 2024 01:18:05 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.97) (envelope-from ) id 1rWR9Q-00000006Onr-0hp8; Sat, 03 Feb 2024 20:18:28 -0500 Message-ID: <20240204011828.022360802@goodmis.org> User-Agent: quilt/0.67 Date: Sat, 03 Feb 2024 20:16:22 -0500 From: Steven Rostedt To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Linus Torvalds , Greg Kroah-Hartman , Sasha Levin , Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Andrew Morton , Al Viro , Christian Brauner Subject: [v6.7][PATCH 07/23] eventfs: Shortcut eventfs_iterate() by skipping entries already read References: <20240204011615.703023949@goodmis.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: "Steven Rostedt (Google)" 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-=3DwiKwDUDv3+jCsv-uacDcHDVTYsXtBR9= =3D6sGM5mqX+DhOg@mail.gmail.com/ Link: https://lore.kernel.org/linux-trace-kernel/20240104220048.494956957@g= oodmis.org Cc: Masami Hiramatsu Cc: Mark Rutland Cc: Mathieu Desnoyers Cc: Andrew Morton Cc: Al Viro Cc: Christian Brauner Cc: Greg Kroah-Hartman Suggested-by: Linus Torvalds Signed-off-by: Steven Rostedt (Google) --- fs/tracefs/event_inode.c | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/fs/tracefs/event_inode.c b/fs/tracefs/event_inode.c index a1934e0eea3b..fdff53d5a1f8 100644 --- a/fs/tracefs/event_inode.c +++ b/fs/tracefs/event_inode.c @@ -746,21 +746,15 @@ static int eventfs_iterate(struct file *file, struct = dir_context *ctx) if (!ei || !ei_dentry) goto out; =20 - ret =3D 0; - /* * Need to create the dentries and inodes to have a consistent * inode number. */ - for (i =3D 0; i < ei->nr_entries; i++) { - void *cdata =3D ei->data; - - if (c > 0) { - c--; - continue; - } + ret =3D 0; =20 - ctx->pos++; + /* Start at 'c' to jump over already read entries */ + for (i =3D c; i < ei->nr_entries; i++, ctx->pos++) { + void *cdata =3D ei->data; =20 entry =3D &ei->entries[i]; name =3D entry->name; @@ -769,7 +763,7 @@ static int eventfs_iterate(struct file *file, struct di= r_context *ctx) /* If ei->is_freed then just bail here, nothing more to do */ if (ei->is_freed) { mutex_unlock(&eventfs_mutex); - goto out_dec; + goto out; } r =3D entry->callback(name, &mode, &cdata, &fops); mutex_unlock(&eventfs_mutex); @@ -778,14 +772,17 @@ static int eventfs_iterate(struct file *file, struct = dir_context *ctx) =20 dentry =3D create_file_dentry(ei, i, ei_dentry, name, mode, cdata, fops); if (!dentry) - goto out_dec; + goto out; ino =3D dentry->d_inode->i_ino; dput(dentry); =20 if (!dir_emit(ctx, name, strlen(name), ino, DT_REG)) - goto out_dec; + goto out; } =20 + /* Subtract the skipped entries above */ + c -=3D min((unsigned int)c, (unsigned int)ei->nr_entries); + list_for_each_entry_srcu(ei_child, &ei->children, list, srcu_read_lock_held(&eventfs_srcu)) { =20 --=20 2.43.0