From patchwork Tue Feb 6 11:32:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Rostedt X-Patchwork-Id: 197338 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:168b:b0:106:860b:bbdd with SMTP id ma11csp1480965dyb; Tue, 6 Feb 2024 03:49:18 -0800 (PST) X-Google-Smtp-Source: AGHT+IGMx7sN72i0VHEf4nNKbSajKySQLxZhDK82wRfE6fxZfOmOl3PcyqiCYXTQIVKS5Oy1zs9r X-Received: by 2002:a05:6122:16a4:b0:4c0:2332:5b5e with SMTP id 36-20020a05612216a400b004c023325b5emr2626125vkl.0.1707220158409; Tue, 06 Feb 2024 03:49:18 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707220158; cv=pass; d=google.com; s=arc-20160816; b=No4WDWb+rrCyjgdtjvkhPhB1kKL352w6M9PaSnlT174jnBp7cfoJuf7VhTKihlIyAq JQjb1zpkrXi+qdjeOgEIKClt1eZwxFhBRcGormCP7PsSVn9F/7XP60D9jKchleJDxEcv 606gib8pUwoLHVzyzS5+GQofvt/n1Mo4r3cu0QB4e7A0DQzh/GjmOROsoUuwDTY2P4dG 6f49Vsj2WNLbRHexun001dg5IEhjWHpH54kQbmxqPwAw/+CmJG24Y6NWhyb56WNrKsZQ 0BmibaWvcFX0qjdhvROJ7krrg5a+Qu66xTVpeUYTqMook/A4ar7m1hg3oUMjO2qG2WoU ZCoQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:list-unsubscribe:list-subscribe:list-id:precedence :references:subject:cc:to:from:date:user-agent:message-id; bh=mZzhfG64JOfp2veODtxBU/uq10vZEr4hoZ4aj1eAhnY=; fh=tN0UuEIWJEavcDR2EkpJjml1yKZ5hKvbw1KCU9KDgu4=; b=Z6Mr0gP4uMzCV3qoE5eY31kMXWWbViTl4ldeOhjSmxEFBYGGzLIHzEpSfo00wJa/J/ 99osn7OIKgsKIbzRHWUpBvCCzwep0CEgWjdzx0KjBa0Uw4+ULP9xgz3mPtXqySZfaVHv GP+7/GZDivA34cBRB5WvNtYPomdH0LyxxaQ3+nqaiIHhsTfah6mmAygFww/2t6vNxBW4 BWte8C/oIPvLGOCXBuAPtstYCUlTOJxT20s0BUsx2XejVmA/nOrzIK0xRBCkDYZs05PC gqFkTmdQqNl8Fbq/QQ5DSJJZAV8ucq68qIx8jRyUTjTX+nOqWxm+iv9cfnZoJuVvkkKA Guxw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-54796-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54796-ouuuleilei=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=1; AJvYcCX8wVmLKP9Le3bQCspA6+fEJ+UoPSadbwc9Gc7E/m3OA1IH929jwLROKe1un9NySP0hZy8SYvMUlaEHsNAwGvN1Y2nskA== Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id jk8-20020ad45d48000000b0068cb7c04c0csi354009qvb.186.2024.02.06.03.49.18 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Feb 2024 03:49:18 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-54796-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-54796-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54796-ouuuleilei=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 337C51C21C70 for ; Tue, 6 Feb 2024 11:49:18 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 993A81369A3; Tue, 6 Feb 2024 11:33:36 +0000 (UTC) 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 873BC13399F; Tue, 6 Feb 2024 11:33:31 +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=1707219211; cv=none; b=Hbi3YIqnCcpGxKoFQnTYNQtcZ3QLovp2pE3ErykzzTulWA1HhGK8n3TQOoiJhpCeVh6Z2f4TAx+OFGzPbLYtxx0sy7+6UHjyg3Y76tAXF3vK1XVal9pkyD9+tcmftcyOAbHcVTw4H+9u7PvIe6WhkA1mN5hWH5XZEPwXwrdJTVY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707219211; c=relaxed/simple; bh=KBGhBIbjsMRKtn4hdiJH0PuIBiRoV1R54hmlDTiI6ZI=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=gGHJi9W05AmW0q/MANbK6ReNScgqdc/PMfeYtgwS9vVRhqchugnLaiPPolJdFj1LMCaIDjQdEXsBgatMIX4s1wYuBzbYmlxjncL6nY5Fox/zC6MGX42aLpjc56inf5mJRZ5f5RgEYbLnASsyXQrV2g+VoxKtx7v4kRziaFeqr3s= 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 10A93C3277D; Tue, 6 Feb 2024 11:33:31 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.97) (envelope-from ) id 1rXJiB-00000006aJp-1YvH; Tue, 06 Feb 2024 06:33:59 -0500 Message-ID: <20240206113359.229236339@rostedt.homelinux.com> User-Agent: quilt/0.67 Date: Tue, 06 Feb 2024 06:32:05 -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 v2 07/23] eventfs: Shortcut eventfs_iterate() by skipping entries already read References: <20240206113158.822006147@rostedt.homelinux.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790150084610032262 X-GMAIL-MSGID: 1790150084610032262 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-=wiKwDUDv3+jCsv-uacDcHDVTYsXtBR9=6sGM5mqX+DhOg@mail.gmail.com/ Link: https://lore.kernel.org/linux-trace-kernel/20240104220048.494956957@goodmis.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) (cherry picked from commit 1de94b52d5e8d8b32f0252f14fad1f1edc2e71f1) --- 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; - ret = 0; - /* * Need to create the dentries and inodes to have a consistent * inode number. */ - for (i = 0; i < ei->nr_entries; i++) { - void *cdata = ei->data; - - if (c > 0) { - c--; - continue; - } + ret = 0; - ctx->pos++; + /* Start at 'c' to jump over already read entries */ + for (i = c; i < ei->nr_entries; i++, ctx->pos++) { + void *cdata = ei->data; entry = &ei->entries[i]; name = entry->name; @@ -769,7 +763,7 @@ static int eventfs_iterate(struct file *file, struct dir_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 = 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) dentry = create_file_dentry(ei, i, ei_dentry, name, mode, cdata, fops); if (!dentry) - goto out_dec; + goto out; ino = dentry->d_inode->i_ino; dput(dentry); if (!dir_emit(ctx, name, strlen(name), ino, DT_REG)) - goto out_dec; + goto out; } + /* Subtract the skipped entries above */ + c -= 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)) {