From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 827FBD6E2CA for ; Thu, 21 Nov 2024 10:13:01 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id EA1216B0082; Thu, 21 Nov 2024 05:13:00 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id E50C86B0088; Thu, 21 Nov 2024 05:13:00 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D3F736B008C; Thu, 21 Nov 2024 05:13:00 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id B4EBC6B0082 for ; Thu, 21 Nov 2024 05:13:00 -0500 (EST) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 6795B140FA6 for ; Thu, 21 Nov 2024 10:13:00 +0000 (UTC) X-FDA: 82809687702.05.E5DE981 Received: from nyc.source.kernel.org (nyc.source.kernel.org [147.75.193.91]) by imf05.hostedemail.com (Postfix) with ESMTP id 4823C100003 for ; Thu, 21 Nov 2024 10:11:19 +0000 (UTC) Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=KyZX4BaO; dmarc=pass (policy=quarantine) header.from=kernel.org; spf=pass (imf05.hostedemail.com: domain of brauner@kernel.org designates 147.75.193.91 as permitted sender) smtp.mailfrom=brauner@kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1732183911; a=rsa-sha256; cv=none; b=gNpygkE07BylFoVcfBLGvK+E0nOOv5BNUqpOJMxDNPpsxVhUSzW2zQeCmxh7WNHWGLy9KH y0NHHga1KF+WfneFknkL6X4NxPjbEAoaLfffeUTietxYpKmwN/msArckqI+aqun5ucA80i JOY4VA8IxKU2C5ybLtksNpPVwsvmwFA= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=KyZX4BaO; dmarc=pass (policy=quarantine) header.from=kernel.org; spf=pass (imf05.hostedemail.com: domain of brauner@kernel.org designates 147.75.193.91 as permitted sender) smtp.mailfrom=brauner@kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1732183911; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=enA1bnk7tgFVREvIcywoLHNJKF7Lg7dtzqpY1gHucOY=; b=AQ5Hf606+YJ8dN2aELRzhzGnTNWzfOzS4oL5oVsMPGVqsk5lAVSRrKslEgCJ7u/i81Nrmu LHE0Z+kbmJ0ekzWjvhYINoGSBKUq9kBxGm+MXyQ+RBp/hnyyxtL8cLm4V0OZsYXJ+VQOj4 SMYAvnyfF+0rqdG08MGHiMJ27Mma7uw= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by nyc.source.kernel.org (Postfix) with ESMTP id E1211A402D6; Thu, 21 Nov 2024 10:11:04 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 83098C4CECC; Thu, 21 Nov 2024 10:12:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1732183978; bh=6eiFaJrYM90rvCLkLlof6VzZqT6tcdWrRcNLWTHa+aA=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=KyZX4BaOE2H7wAKl0O4Zee18KkAzJdiHIfODYDQuNXKcfovxm323pwz+3QZPrBAmh 0JAhgsyCbo+vdhaoU2q9euo7AkaJO2nnm8I53iUHX6gLg75iXuHCm8UUsDjv6+H83L t5m3215mGYygSkP8Z2delemLfw8jmry/2v2f4Odhm1TVRbP+UrUZHBhmtWbzF7PQjH DmntSFVpYMD4YZ4jlF+nMxZbycIvFpQhYVwKdhsZyQ/+T1qQjzOtR16ymwkslVlHcX 4CHAWz651aJ0U7LZM+6E7/lwV0qag5NpOeeFudZtTQH7zTinK7rKsw/Ht5e+bgmaWy FRnJkMICYv+GA== Date: Thu, 21 Nov 2024 11:12:52 +0100 From: Christian Brauner To: Mateusz Guzik Cc: viro@zeniv.linux.org.uk, jack@suse.cz, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, hughd@google.com, linux-ext4@vger.kernel.org, tytso@mit.edu, linux-mm@kvack.org Subject: Re: [PATCH v3 1/3] vfs: support caching symlink lengths in inodes Message-ID: <20241121-seilschaft-zeitig-7c8c3431bd00@brauner> References: <20241120112037.822078-1-mjguzik@gmail.com> <20241120112037.822078-2-mjguzik@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20241120112037.822078-2-mjguzik@gmail.com> X-Rspam-User: X-Rspamd-Queue-Id: 4823C100003 X-Rspamd-Server: rspam11 X-Stat-Signature: qnbxymjagmfs3duzjhutcrg43g7qdgdm X-HE-Tag: 1732183879-652385 X-HE-Meta: U2FsdGVkX19fwxBErhOSvINHNYuuKGLmg9D/0XGrwTeM6mJOEVDQzuBVQr2lgxOMupQ439jnlVwG7LGivWBs846D5OKqBMplYD+1yXlfHIpeDUg8lcLFg1ZvxI/20erH9Hxiq6VxrcocDqVFGzpqyT+Pd1kvjYjuon79gzgYsajAywHVWgm0yTi5G+njeyCqx6SAiNULmOHiCz2es8MJZN1+asw5iDKWmvMVVIDdKy1Ge8TFHRoAUaXULQNOmBxU8NkV3l0Aqb4+TWRmGK2Q/T+FH9AIZLMvWM0r1lTQxEOAmM580x59ykSwsfV5839wMeK7zhBjcG1/msNcgkASYSg0vrThACj3Z7mnAJyEwxDL0cDiAxO9ThBDHYFfYHBViln05PYJcdB8vXUyNAs+NWx3k8efkNSX/dZg0w7pjlLDGeP7UEJi7jc/EOceIoElKQlvUyiQqtv31sUYBUa8YO487NuC0+bgrSXzc9rBxAsEDmAu+7+IcC5XEh3VK8ywb8Vtw78EvpOxKLbHoZGewSOrwbetdZjvAnGkW4LMzHmlIkxvoPs0X5/f3IQf8EzCWP/a+9qooXJ1D9UiW+SJDnE9ZeaGOACWpHzH16IkO1p1iYTcl95edTXvG+tOvwmfmTubwjpqYh0ARBRKyJz8VLSl6LVyjePxnQdOuKEcPnNsNQptKJx2/TRNvfTo8doDeav2ALG+uMkt9kRx13JbE5JyuMvQrbS93KfvdIbzcDjcnsBjYPr92NMFeaHDvDLUIvvNLdudT1Js9tJ6mVsGDahBcdBpL9nfSpcmewvYu8KR2TOFw9lMtj0uPc7y/M5PckOrrQQafA9byEyz3OlnhDvQcTUXNJezqi4MvZarDDjMzccV4/RjLLyyJiDyBzehy20zkDUzxSiuHnGXZb/a5qt5hkSpMbdhb4qPJWzDalnoWYZLv8X7DyWwEuhDrENy+uqyrYj1SJFpU1D/3bA qAduTP// DrQ2G1HZEu2LASP6378sb14FiAwwnK3TinePhWG8KMxwn3OuzTeP5aTKIVExSe5SFLPIgKdiVqqoT/JRJeT2eAOga9tkMJxt6qL1G1yDBShzQDLp61x7O4kFQMvWYnYJ4yPha8abx+3APJuPia0VHzy7L/S6esJ8S/pZ7q+7V+ESF36z+LJWYqdumMnH/7a77XcauP55l9P/o1TW8YrqtFJ1Zw8qT8nkBQGRvQldcij/+2jBzxfjuq1261yuhJRwkJz3zVIwHYUGZ2uTArohTHxsJMWUUjH2Yqkwn7FRrZpN5wP2aGHSW+SQ03w2tqrpb4W+j X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: On Wed, Nov 20, 2024 at 12:20:34PM +0100, Mateusz Guzik wrote: > When utilized it dodges strlen() in vfs_readlink(), giving about 1.5% > speed up when issuing readlink on /initrd.img on ext4. > > Filesystems opt in by calling inode_set_cached_link() when creating an > inode. > > The size is stored in a new union utilizing the same space as i_devices, > thus avoiding growing the struct or taking up any more space. > > Churn-wise the current readlink_copy() helper is patched to accept the > size instead of calculating it. > > Signed-off-by: Mateusz Guzik > --- > fs/namei.c | 34 +++++++++++++++++++--------------- > fs/proc/namespaces.c | 2 +- > include/linux/fs.h | 15 +++++++++++++-- > security/apparmor/apparmorfs.c | 2 +- > 4 files changed, 34 insertions(+), 19 deletions(-) > > diff --git a/fs/namei.c b/fs/namei.c > index 9d30c7aa9aa6..e56c29a22d26 100644 > --- a/fs/namei.c > +++ b/fs/namei.c > @@ -5272,19 +5272,16 @@ SYSCALL_DEFINE2(rename, const char __user *, oldname, const char __user *, newna > getname(newname), 0); > } > > -int readlink_copy(char __user *buffer, int buflen, const char *link) > +int readlink_copy(char __user *buffer, int buflen, const char *link, int linklen) > { > - int len = PTR_ERR(link); > - if (IS_ERR(link)) > - goto out; > + int copylen; > > - len = strlen(link); > - if (len > (unsigned) buflen) > - len = buflen; > - if (copy_to_user(buffer, link, len)) > - len = -EFAULT; > -out: > - return len; > + copylen = linklen; > + if (unlikely(copylen > (unsigned) buflen)) > + copylen = buflen; > + if (copy_to_user(buffer, link, copylen)) > + copylen = -EFAULT; > + return copylen; > } > > /** > @@ -5304,6 +5301,9 @@ int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen) > const char *link; > int res; > > + if (inode->i_opflags & IOP_CACHED_LINK) > + return readlink_copy(buffer, buflen, inode->i_link, inode->i_linklen); > + > if (unlikely(!(inode->i_opflags & IOP_DEFAULT_READLINK))) { > if (unlikely(inode->i_op->readlink)) > return inode->i_op->readlink(dentry, buffer, buflen); > @@ -5322,7 +5322,7 @@ int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen) > if (IS_ERR(link)) > return PTR_ERR(link); > } > - res = readlink_copy(buffer, buflen, link); > + res = readlink_copy(buffer, buflen, link, strlen(link)); > do_delayed_call(&done); > return res; > } > @@ -5391,10 +5391,14 @@ EXPORT_SYMBOL(page_put_link); > > int page_readlink(struct dentry *dentry, char __user *buffer, int buflen) > { > + const char *link; > + int res; > + > DEFINE_DELAYED_CALL(done); > - int res = readlink_copy(buffer, buflen, > - page_get_link(dentry, d_inode(dentry), > - &done)); > + link = page_get_link(dentry, d_inode(dentry), &done); > + res = PTR_ERR(link); > + if (!IS_ERR(link)) > + res = readlink_copy(buffer, buflen, link, strlen(link)); > do_delayed_call(&done); > return res; > } > diff --git a/fs/proc/namespaces.c b/fs/proc/namespaces.c > index 8e159fc78c0a..c610224faf10 100644 > --- a/fs/proc/namespaces.c > +++ b/fs/proc/namespaces.c > @@ -83,7 +83,7 @@ static int proc_ns_readlink(struct dentry *dentry, char __user *buffer, int bufl > if (ptrace_may_access(task, PTRACE_MODE_READ_FSCREDS)) { > res = ns_get_name(name, sizeof(name), task, ns_ops); > if (res >= 0) > - res = readlink_copy(buffer, buflen, name); > + res = readlink_copy(buffer, buflen, name, strlen(name)); > } > put_task_struct(task); > return res; > diff --git a/include/linux/fs.h b/include/linux/fs.h > index 7e29433c5ecc..2cc98de5af43 100644 > --- a/include/linux/fs.h > +++ b/include/linux/fs.h > @@ -626,6 +626,7 @@ is_uncached_acl(struct posix_acl *acl) > #define IOP_XATTR 0x0008 > #define IOP_DEFAULT_READLINK 0x0010 > #define IOP_MGTIME 0x0020 > +#define IOP_CACHED_LINK 0x0040 > > /* > * Keep mostly read-only and often accessed (especially for > @@ -723,7 +724,10 @@ struct inode { > }; > struct file_lock_context *i_flctx; > struct address_space i_data; > - struct list_head i_devices; > + union { > + struct list_head i_devices; > + int i_linklen; > + }; I think that i_devices should be moved into the union as it's really only used with i_cdev but it's not that easily done because list_head needs to be initialized. I roughly envisioned something like: union { struct { struct cdev *i_cdev; struct list_head i_devices; }; struct { char *i_link; unsigned int i_link_len; }; struct pipe_inode_info *i_pipe; unsigned i_dir_seq; }; But it's not important enough imho.