From patchwork Tue Feb 6 12:09:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Rostedt X-Patchwork-Id: 197412 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:168b:b0:106:860b:bbdd with SMTP id ma11csp1500986dyb; Tue, 6 Feb 2024 04:26:42 -0800 (PST) X-Google-Smtp-Source: AGHT+IHrR3nQL+SFMQmJuiH0g019yVEpXRd0xkChrODGYD7GlsgnrJV1TYlGX4sDuWA1jRxWKUOi X-Received: by 2002:a05:651c:b0a:b0:2d0:6874:b615 with SMTP id b10-20020a05651c0b0a00b002d06874b615mr1892805ljr.42.1707222402362; Tue, 06 Feb 2024 04:26:42 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707222402; cv=pass; d=google.com; s=arc-20160816; b=GNbcYsHd5Tq5Sr242HVvzLebtDwpqjZys+awmyqWmcHtQa3rWcrVH50WypOjXvaM8d 2S+/FpHSnDxmBBm7FtwE8ZZxANGjuL7bzCIQhdyxljGbUt+sbStEr72Bjk4lDiyHvlnB lh1mPE7fmbWQDJK4VT5bZYK9wA0W7lLFaU0YUqOOQPRb07FafDavtLPG+LKxFQbf95F+ n2ZyBjRusgaBlcDdtfQNGNlrC6byoRWxdq+xeskVWbWLAspvWFLQW1giZMRTlZdugAg4 xat34lXAMxRLaN8bxWhbUib5VpnDoQTXRkZmyEUZZCW0g5++5xJj301NIaLjZR7VGaQe yYCA== 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=xLbvj7i8FMTbJA4u/tA5/Pno7VKD0wiz/JSzsQXSQiM=; b=bndX98Yci3wBHO5+2CBIhPqeh/Km6k4ChHT6+mZbiRhwJF7QLfyREC3is5I6FxtLDp JsM6XYMGW4FeKrBXDmWj+wJF5oKkNdIw3/WehJUDNpzl9CRSFtqCtnYhZaCcKTnTEgGL SdhrWs9uyfQkUF3h1Ye+MnFBC/8YYabZPMIyM9lbm2Y0RzEzTy+nWk4B7mT+bO8a6Zgh GlxSGzcKyl9+8ZRXcdEb/8mAu0JLcdX+PeE5ximnoGelhWqgHaTIHmcYJk3ILz5jGZTx KVJftWFbfjj6Hyro76W9bxlOVT4X3mtD9dZFHb+7oSnkj38HXAv90Fl9RSvl3nfhVlwY LCgQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-54916-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54916-ouuuleilei=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=1; AJvYcCWvAPJd6XRFqykM11O0kfI6u6R+ABWlxtcxmsnTKSfIupUuRuEG2ZZXsTriPBTFhQc8oOa9WJ9pwmU5eSbhcQT9tD377Q== Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id j12-20020a05640211cc00b00560b530d441si393812edw.162.2024.02.06.04.26.42 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Feb 2024 04:26:42 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-54916-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-54916-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-54916-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 am.mirrors.kernel.org (Postfix) with ESMTPS id DCE981F23932 for ; Tue, 6 Feb 2024 12:26:41 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id DB15B14FFB1; Tue, 6 Feb 2024 12:09:39 +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 EAF6713AA27; Tue, 6 Feb 2024 12:09:24 +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=1707221365; cv=none; b=QZZKC95rDKtGOE1lwJM7T9lyPshhPb+3hd/dt7WtCzQEo87AmLjL4Nft3kkZ2dP2G+dARdLNZ/tCdiUB7l2uOi0xc3uyNflkPqar8W9tilLloj3KLN58RYbhHqqSPm0Bd7nvTPimJFsTSHg9K5RyNrIb3c/VWA/BWmMz2zbfYPc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707221365; c=relaxed/simple; bh=KBGhBIbjsMRKtn4hdiJH0PuIBiRoV1R54hmlDTiI6ZI=; h=Message-ID:Date:From:To:Cc:Subject:References:MIME-Version: Content-Type; b=hNqqS3brInlMhz58Js5IMEZcTU/ASKdW/2OwdP1C6kijrAg7otTpV2s7vw8373Sg7dhX1zdL8erdgFLvv5s1xlVvPEIT7miFZ3bsL+IioLvfJNyc0hI4ZatqI0fVZPho/RxzCXHQHYVawmBa2Md6xV9CMJYW3xvTMjPTckjx3uY= 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 BE464C4167E; Tue, 6 Feb 2024 12:09:24 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.97) (envelope-from ) id 1rXKGv-00000006bLq-0naA; Tue, 06 Feb 2024 07:09:53 -0500 Message-ID: <20240206120953.046426517@rostedt.homelinux.com> User-Agent: quilt/0.67 Date: Tue, 06 Feb 2024 07:09:46 -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.6][PATCH 41/57] eventfs: Shortcut eventfs_iterate() by skipping entries already read References: <20240206120905.570408983@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: 1790152437523771353 X-GMAIL-MSGID: 1790152437523771353 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)) {