From patchwork Wed Nov 20 11:20:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mateusz Guzik X-Patchwork-Id: 13881064 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 8682ED6392E for ; Wed, 20 Nov 2024 11:20:53 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 19E856B0085; Wed, 20 Nov 2024 06:20:53 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 1277E6B0088; Wed, 20 Nov 2024 06:20:53 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E6BE96B0089; Wed, 20 Nov 2024 06:20:52 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id C029E6B0085 for ; Wed, 20 Nov 2024 06:20:52 -0500 (EST) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 738BF80AFF for ; Wed, 20 Nov 2024 11:20:52 +0000 (UTC) X-FDA: 82806227532.17.E0FE82A Received: from mail-ed1-f54.google.com (mail-ed1-f54.google.com [209.85.208.54]) by imf29.hostedemail.com (Postfix) with ESMTP id F3E7B120013 for ; Wed, 20 Nov 2024 11:19:40 +0000 (UTC) Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=jQR0DE7Y; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf29.hostedemail.com: domain of mjguzik@gmail.com designates 209.85.208.54 as permitted sender) smtp.mailfrom=mjguzik@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1732101465; a=rsa-sha256; cv=none; b=Hqxh8a5o9Br/AaVnmn7VVZEq2p4EMQkgW11z7ElRm/xVZv8RFA41+T0GUjdxeNTo0Smjge uvWbk6dFy9KBIIU9EvouZ3y/luq+GKci14W4Y4hKi5/0pI8KQmZ0iTAVAQXiPg3e6T4gvX /9MXBz0OD5GESgApbcaqwfhr8KMNIKI= ARC-Authentication-Results: i=1; imf29.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=jQR0DE7Y; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf29.hostedemail.com: domain of mjguzik@gmail.com designates 209.85.208.54 as permitted sender) smtp.mailfrom=mjguzik@gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1732101465; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=vUaKEruejfDCGRJdpj1eBL3gJs8S2bH9vNecg7yvIhA=; b=FR+2nnQ6R+s4bhPEX1jYE7UqKkUl3agslqgr9K1n9LlpXsEG/EEJqUYOljTzpHGlOMTfOs JTGAuGCs0pH801tZOxdMSKPfbG3j3SmP66mNwMeUyqKWXm9VUmSvDR1EVa7ePVmnSQYWZ7 BaShMxLAIQGA8F9o11Cgn5/xDytm72c= Received: by mail-ed1-f54.google.com with SMTP id 4fb4d7f45d1cf-5cedf5fe237so5233212a12.3 for ; Wed, 20 Nov 2024 03:20:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1732101649; x=1732706449; darn=kvack.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=vUaKEruejfDCGRJdpj1eBL3gJs8S2bH9vNecg7yvIhA=; b=jQR0DE7YLaL8Jo4SAUoJ0JLhaH0PHa6VvXiM2YL052fCHZlD4Y79FwTJKVZv1sBs8o Nfl2q2X6QA6CxIy0AI547yh5VFK6FNhnF3VMGtHD3OJAIrEP17U2gU8J1MyCN6CCAz6Y VHfA5qtr6E3zVq4eZHLtqaD5hQxfN+0Ue2Q74dymUNwXZQq7ZnpXWX0sbM/UR8T5/QDi 10XsgGg0hEJoTeO7BRlne79flXRTStaVktxdZQLsEfDNk/6duo1TLOs1aOJo1w/jPd8d jz9Tb3VZw1VloDNo+Yj77yoiiXthv4pQqfGhh1lorbSJXMhWFAy9vpSnCPTyjMuSFd/f l+Ow== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732101649; x=1732706449; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=vUaKEruejfDCGRJdpj1eBL3gJs8S2bH9vNecg7yvIhA=; b=bRmw7WUBM4ulrQ5XLLJUSWOWdeguMin7ZhNWfVVGKZTAvE1HnwZXuubtG/qnIwvMMA 8L8eigzzcqJ53YuUYfysDjXNYcszWAh4EM9KaUy6pL78wTNM6tGEHC00PZ8SOSYjBLb/ yrtg2mQsl+DkgIsXGvO7uVE5q4BxkcxWVHCvdrZG6SfQLd4neKfy7paHAEtfHVoxQgGD q9oblqvRhSW2/nV/HoSEAJJlBrqxih55PhgA99/4d3n5m7evkKYz2aSflMKTqiWYdPmY qQJF/pxaOROCQ/Ey4wKxErbVFDbcSSTXrZBI3cvLHgtCK861CXG/Qm/Znj7hSeRwFgd4 Ihjw== X-Forwarded-Encrypted: i=1; AJvYcCVHJ42m8gD+HfTBjnwSWMqbyHqp+KlQgkWOBP+/2oRiECZ6EX0nq84+dha1E718DlTgWJ3oVKvzMA==@kvack.org X-Gm-Message-State: AOJu0Yz2MqN6sVatc49UdhJ+i9mSzB7woRfIw1/X1dtmU2WyjljrkKD6 sufX7SccTQWZ1rQHgWe9CH2B9K9iQQnI56V/gpzYumY1LMtBBXZM X-Google-Smtp-Source: AGHT+IF/eB9UNR6VnoZKt3nFhYHrh56urFiBKWBZ6vnCYzDyugb1WbUzdkpcnja3XeP3jZyhS9PA3Q== X-Received: by 2002:a17:907:c1f:b0:a9d:e1d6:42a1 with SMTP id a640c23a62f3a-aa4dd57c0ecmr210229766b.30.1732101648787; Wed, 20 Nov 2024 03:20:48 -0800 (PST) Received: from f.. (cst-prg-93-87.cust.vodafone.cz. [46.135.93.87]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-aa20df5690csm758559566b.75.2024.11.20.03.20.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Nov 2024 03:20:48 -0800 (PST) From: Mateusz Guzik To: brauner@kernel.org 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, Mateusz Guzik Subject: [PATCH v3 1/3] vfs: support caching symlink lengths in inodes Date: Wed, 20 Nov 2024 12:20:34 +0100 Message-ID: <20241120112037.822078-2-mjguzik@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241120112037.822078-1-mjguzik@gmail.com> References: <20241120112037.822078-1-mjguzik@gmail.com> MIME-Version: 1.0 X-Stat-Signature: db7mu9nex4t9jm8ypu5m54era41kyyrw X-Rspamd-Queue-Id: F3E7B120013 X-Rspamd-Server: rspam08 X-Rspam-User: X-HE-Tag: 1732101580-804806 X-HE-Meta: U2FsdGVkX18niNVHBR/UEWdzuU3d7k4oJ3AdJMHlEGHRlIi/+jl0OvIRH45na4QA6cxukUfAwyfb+3Iyecyg/598vkfQHUcP8snyDoN+Kyy86l/dS96qnIwZQWpZkheREEr9pdpmqnyv+Or4zNkyN8acsxC7aYopdy1ipo/a0/O+8QS9V6js7KgvvU+pamiTqke0Tcf06EcLasAa3RQ+t3icrtULQqvPXR3nHMCrzKludIsppj/3YY5cqV7iEc7WWcrDjbuLDRz915wJgbF72vQwQ4a2rQefFS6Rqbi0ajCfbMrO12CUQilMx4FgTFs6YplPaBigAuYx86dNZj5poUop0wXSdecfD0kVKgT0wkeMny0NWUp0x6ovmaCK5eySO+G6ja14xF9UWU1vfnuXVSkniF80Wyr0a3eXUOE8MNJNl8El6Rf3xW6FLtdB7WAgvK9d7OibduLDrM8BFJ/hu1m++ey6zt/SJuHTadwmGxVDjmrhjfFYONnqGOTz36VAyqIDlpuQ+DAcflsdmhvZgMuXbCHzLk/jih38fYiFYhKIXt2+PRZJICniQSvnjVvuo2r7ivVj4GVTME+y3/WrQGJ3AQz0LMEuCHr2hVFdhjtoZ1GCw2L6FB4OharccDiSp7445uBECilb5u6/osA0Io0bqzu7ziVlWNQqXoTTzxBMm4riFXC1sa2AQWcoXOWMgQZUgn31ZrNQ2hPtymPN27HupuX3Wq4iLvYX8L3SUK61q+qOYwe6PMa1hK1cIp4NkQnP/4A5WVHNMRuuOluMUy1uxwmZ1vTBES6FwS0jMpRcWBh0I3IuxWnPbcMfde4rNlsb2DVjYhMdAxEmT53GZod0avM7S6gxtpbGvMTqRvOxQH4UVrD+SVZFTPAtMVSwrUIAbX27mv0n8QfNWzkXtN6IBPFkpEJqcvlNJA09Ftb2Z3lou020D5oI1yOPbDAkFPTwFfcFnCjlSx3QtCH uijCrJB5 VChFUPiSwIWBo3b5oC8wC4FMEBkfPvxWkqC8p+QZiYQVhkm1ndvoVbPyhsNcB641qMooGaQba7b+fM4pp8CZT4vzypc0qUSi/YyQAfeH5zKihjebggsjjYSGVRAiCsYbGIlo0HFPdfUbGqv1AKK/gC6eQTr+4rhqJMTCTuHdfEWe30qZnwwNQiMQLRV0wWP1udsooWif2rRi3j2uoUWBm1ROk9rPHIX0oSVuB32W9A17cE4oAa/3w5xWKW2gdRQnU8cTBIsBcGNNdUvvRAzYQnn8Ki7wa23Ja9w6AY5eIHEuJWaIf4sZTlcy3sEbXD37y3zjZqR9IcG203s4oes2dKFEo2OVPWbsrl92S/tY8jFownoQRwmBD1BrgVA== 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: 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; + }; union { struct pipe_inode_info *i_pipe; struct cdev *i_cdev; @@ -749,6 +753,13 @@ struct inode { void *i_private; /* fs or device private pointer */ } __randomize_layout; +static inline void inode_set_cached_link(struct inode *inode, char *link, int linklen) +{ + inode->i_link = link; + inode->i_linklen = linklen; + inode->i_opflags |= IOP_CACHED_LINK; +} + /* * Get bit address from inode->i_state to use with wait_var_event() * infrastructre. @@ -3351,7 +3362,7 @@ extern const struct file_operations generic_ro_fops; #define special_file(m) (S_ISCHR(m)||S_ISBLK(m)||S_ISFIFO(m)||S_ISSOCK(m)) -extern int readlink_copy(char __user *, int, const char *); +extern int readlink_copy(char __user *, int, const char *, int); extern int page_readlink(struct dentry *, char __user *, int); extern const char *page_get_link(struct dentry *, struct inode *, struct delayed_call *); diff --git a/security/apparmor/apparmorfs.c b/security/apparmor/apparmorfs.c index 01b923d97a44..60959cfba672 100644 --- a/security/apparmor/apparmorfs.c +++ b/security/apparmor/apparmorfs.c @@ -2611,7 +2611,7 @@ static int policy_readlink(struct dentry *dentry, char __user *buffer, res = snprintf(name, sizeof(name), "%s:[%lu]", AAFS_NAME, d_inode(dentry)->i_ino); if (res > 0 && res < sizeof(name)) - res = readlink_copy(buffer, buflen, name); + res = readlink_copy(buffer, buflen, name, strlen(name)); else res = -ENOENT; From patchwork Wed Nov 20 11:20:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mateusz Guzik X-Patchwork-Id: 13881065 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 0643FD6392D for ; Wed, 20 Nov 2024 11:20:56 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 917BE6B0088; Wed, 20 Nov 2024 06:20:55 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 8A03C6B0089; Wed, 20 Nov 2024 06:20:55 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 71A7D6B008A; Wed, 20 Nov 2024 06:20:55 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 4E8F66B0088 for ; Wed, 20 Nov 2024 06:20:55 -0500 (EST) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 00D72160A0E for ; Wed, 20 Nov 2024 11:20:54 +0000 (UTC) X-FDA: 82806228624.13.7B25320 Received: from mail-ej1-f44.google.com (mail-ej1-f44.google.com [209.85.218.44]) by imf12.hostedemail.com (Postfix) with ESMTP id 114B94001B for ; Wed, 20 Nov 2024 11:20:29 +0000 (UTC) Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=aH8KFZnP; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf12.hostedemail.com: domain of mjguzik@gmail.com designates 209.85.218.44 as permitted sender) smtp.mailfrom=mjguzik@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1732101517; a=rsa-sha256; cv=none; b=U7vdWQrMlARtPPMzmjFAz6S912RpBIw7CPZlJOz/zFFvogV3TRSiXlW7xKyX/IbW09kJxL 3jYhQRhOWAHaJnxS0G2DUxue/ak/AZmXJm0PU0HQVrfjxzib5lvkyKCP3EhAgrsmaK5LqH TK6HeqgoyTcMHJbfQKydc4WuZmYGkRc= ARC-Authentication-Results: i=1; imf12.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=aH8KFZnP; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf12.hostedemail.com: domain of mjguzik@gmail.com designates 209.85.218.44 as permitted sender) smtp.mailfrom=mjguzik@gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1732101517; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=YMDpr51HGMdjTn/zZt2QmbhLNhc4xxoRwRH832sAaPM=; b=1/zq/bIv3KvQLJr3cqkEqZLbTxSoBaBsOP2WYemIM9zp/R5cU1Ly8vNDMnyMOAs5d0LvS6 9/Ogn6oeqkmUDubRJ6AQw4M2fZp+mQ9iVc89fQeaQPy5QpvvCDJqZOIIUtQ5e6d0bAIQId QIes9HSggrTfgTlqeaUXQ9L49RAV+d8= Received: by mail-ej1-f44.google.com with SMTP id a640c23a62f3a-a9ed0ec0e92so584991666b.0 for ; Wed, 20 Nov 2024 03:20:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1732101652; x=1732706452; darn=kvack.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=YMDpr51HGMdjTn/zZt2QmbhLNhc4xxoRwRH832sAaPM=; b=aH8KFZnPhgrTeVHZ8X1sT56zQez1aXy++qrZBfECt5iUJ6Uei10HwOon48X3ALPvxl uCUA4oo33amJxw8yjC8hWEardEYekzJgP0Ez65iTpjLi7N03RDeLQITfRT6ck6lu1ds0 h1sR1UaV78ZxcwJzv2Nta9RnjRJZ6EnHK/5ZAiFERR4QfZDTsyzu3X6xRgyrI/Maz3ga wVFtLI1nloCoRFe8fn78nE9qx2stOBdfxQYQH2vDFyXeHXblZahlgfhes8SZHpEWabNV pnPZ95tC8XGrbR7iSV/i67UVF5/lysi03/xYbGNt2cWeGrQolTRvT2bs++5rkLAMWsMX 9srQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732101652; x=1732706452; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=YMDpr51HGMdjTn/zZt2QmbhLNhc4xxoRwRH832sAaPM=; b=fAayyCRsS/vm/MqzjrJBQ+MEL1ubBnIqpZQoG63j3UkchD+jQKoM6eLtIO4Nrs4P1Z 4zkeVLJLemzCKd81uvnOOZL9iIo9rzyk3vTv/wL2vg7yyvL0TsGbSFQF5QLjrLNa+eTt Fyf/Cf0Ic1TUTqFcZg4oIT1BWUbQk6Tj6rabNcvpr5LWDvmnHPK34MQqaHE/JK7JDj3R 0i6b96qh+oX52/uLpItogWnZcOSAdyoqKiIggK+PC8Yk1HvucfC5J1rNiviJTBeWgjV9 MaPA0yt6ITryY5NJhTFjhw8/hihU4a+eG2yS5KgsgaP2PxHzR5QUI5bKgmAtEwqvdKGP Fu3Q== X-Forwarded-Encrypted: i=1; AJvYcCVEIrEEpHzrG7meWHBRd3drjZqgmHc/ThwiW3VKniiZcWzHMpu0Zn/xznPtRAkLg8js3aK0wFVvBw==@kvack.org X-Gm-Message-State: AOJu0YxUWutXtI1KHkyqS1KwR9FM4212uGGTHfGz37eIH6tTf0CyFde9 TwplgYzZi+hWkgmV8N3iRM9oeryCrFuXpCUawX2wmprdvH8WcESC X-Google-Smtp-Source: AGHT+IGME9zrR7PEmCppueSU0EVvlvlY9LrKb85f85FZGjKra7l7vMMQegldnpEbAzUI5fVhjh2VUg== X-Received: by 2002:a17:906:c102:b0:aa4:7905:b823 with SMTP id a640c23a62f3a-aa4dd6b0c82mr252771066b.32.1732101651378; Wed, 20 Nov 2024 03:20:51 -0800 (PST) Received: from f.. (cst-prg-93-87.cust.vodafone.cz. [46.135.93.87]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-aa20df5690csm758559566b.75.2024.11.20.03.20.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Nov 2024 03:20:50 -0800 (PST) From: Mateusz Guzik To: brauner@kernel.org 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, Mateusz Guzik Subject: [PATCH v3 2/3] ext4: use inode_set_cached_link() Date: Wed, 20 Nov 2024 12:20:35 +0100 Message-ID: <20241120112037.822078-3-mjguzik@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241120112037.822078-1-mjguzik@gmail.com> References: <20241120112037.822078-1-mjguzik@gmail.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: 114B94001B X-Stat-Signature: 4718mhszduke9ya9caca41wb973jsbsh X-Rspam-User: X-Rspamd-Server: rspam05 X-HE-Tag: 1732101629-348920 X-HE-Meta: U2FsdGVkX1+dEB55h+itDXeasq9a6oVv2u1mBynfE9BlxCd9nwum36HKJ4l/+QFIiynGjo5eBhaqwg0QfnTG1qzxhhGuql3RoU0cY5yQtb0F6Q0Rut/kvMFuJnGQDTpTeexCS/Iyh9nuLIWNPr8mjdzUK2IWXIB1ANIbd2gPo84JfuYKVNiBqPtI5/fj1z98Eqf84wltfl1Qp4zq7CKuzfsdIdq/h71v7T6stczY1h2Xnnml4n0mfcD9KZvPSBsTfPQK+xpYvZ44XQqt/OH7cSRp8lnFeb+KgGwt9WLs3F0JEUMpA2UIg8EsCIxeRiSmhMu/8I1Ky1zNAanB7OhZ56wqy4ZRCN58ipnRQzqRbU0ew10YNvxwQROCH55MgJCUvD1ZI7ILce1SETGMWtmsbsgSxFb0gGZOrAwLn37zPmy7TGU2GcjHV3rTq/BWAyY6Dpz3yWQFtd1XS5bkvO91pUEz/xBfCmsmvfONYCOkwqAedOqAWejXa+G4zb2wJELvpkJdWvanSdUNhBEh8ht9w4HU6XLbBLStYkjA+bCHTw3W7b8eosD2lumM8qQeUafkxv4ahNlDuoDqX60gsub9G6MebPatFHCeFPSGCffmPLWganD859yfodhG9AtLtMjdhVKS7TzYbvZT9JTEvTC7BidForzJZ/xg4vagQ9nj6r2toA5CrSNB0qe1eSb13oMlzRs08qcloFe2KdySJwKczKVLShybxbtfMBXI4wKZZqWdZobr8SX9vOAIVxg0ZCzn7t8iJuj9rgM1isXV3wP83ZU6LhGXTfGA2SeEUhGmYC17IuxAXrkfbPi4X/EHlh/2DCPa8b0orWocnjLMv3/+3DLY8dm26Nl2Hkl+iEqKLyTx4jbb5yjiWkD98doZ499BcnD62ip6YUQSQO6Oh35lONyTWChWI6oORxoobeE7JOnpkRiKwh3a1d3moyB1pgR9BvZ9jyAb1J5gO1DSnCO 2yAorsaC DQtrJ7DePvtPqdLvDv5XnmLGXJe/ib4LNKqUesQfwS2ghna6MIhPL2BuOHPS7YhKgfulTpYsDLCQMVESMlQYYMYEL2L7SOUhF1xSYKc/tV9EVQRxYw/Qjk7AVdQbxpNnOeCcpcN5XTHyjKs7CTPJ5nPxyHK+72piV7eXPyqbVC5YwJWbSqbuC0dIlB8rnhS//iw2nrHlqsVzBxRd9palOMxxoh0szkIkgrzclAFAUpgucb6qlHd2c6p/o9pBSb9+jrEmXzUd6dF4fNGRetmlNTo6PhVeYUa+u9n2nbgRkcVUZgdiUjAISluUlZ0rxH/VqxusLDe81BYkm1zOnBrBcKTOGH+zW50aKRUNez0csoDB5nrn0nBoZ+7qIhvZuGcc/MyjEbE4Ochmg+nCZuCXBHQyQ7Le9tH0kfsRP+w5gMhgaTZA= 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: Signed-off-by: Mateusz Guzik --- fs/ext4/inode.c | 3 ++- fs/ext4/namei.c | 4 +++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c index 89aade6f45f6..7c54ae5fcbd4 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c @@ -5006,10 +5006,11 @@ struct inode *__ext4_iget(struct super_block *sb, unsigned long ino, if (IS_ENCRYPTED(inode)) { inode->i_op = &ext4_encrypted_symlink_inode_operations; } else if (ext4_inode_is_fast_symlink(inode)) { - inode->i_link = (char *)ei->i_data; inode->i_op = &ext4_fast_symlink_inode_operations; nd_terminate_link(ei->i_data, inode->i_size, sizeof(ei->i_data) - 1); + inode_set_cached_link(inode, (char *)ei->i_data, + inode->i_size); } else { inode->i_op = &ext4_symlink_inode_operations; } diff --git a/fs/ext4/namei.c b/fs/ext4/namei.c index bcf2737078b8..536d56d15072 100644 --- a/fs/ext4/namei.c +++ b/fs/ext4/namei.c @@ -3418,7 +3418,6 @@ static int ext4_symlink(struct mnt_idmap *idmap, struct inode *dir, inode->i_op = &ext4_symlink_inode_operations; } else { inode->i_op = &ext4_fast_symlink_inode_operations; - inode->i_link = (char *)&EXT4_I(inode)->i_data; } } @@ -3434,6 +3433,9 @@ static int ext4_symlink(struct mnt_idmap *idmap, struct inode *dir, disk_link.len); inode->i_size = disk_link.len - 1; EXT4_I(inode)->i_disksize = inode->i_size; + if (!IS_ENCRYPTED(inode)) + inode_set_cached_link(inode, (char *)&EXT4_I(inode)->i_data, + inode->i_size); } err = ext4_add_nondir(handle, dentry, &inode); if (handle) From patchwork Wed Nov 20 11:20:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mateusz Guzik X-Patchwork-Id: 13881066 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 707D8D6392E for ; Wed, 20 Nov 2024 11:21:00 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id EBC9A6B008C; Wed, 20 Nov 2024 06:20:59 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id E44D86B0092; Wed, 20 Nov 2024 06:20:59 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C98146B0093; Wed, 20 Nov 2024 06:20:59 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id A65C56B008C for ; Wed, 20 Nov 2024 06:20:59 -0500 (EST) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 52942C0A7E for ; Wed, 20 Nov 2024 11:20:59 +0000 (UTC) X-FDA: 82806230388.16.3986E44 Received: from mail-ed1-f48.google.com (mail-ed1-f48.google.com [209.85.208.48]) by imf10.hostedemail.com (Postfix) with ESMTP id B799AC0005 for ; Wed, 20 Nov 2024 11:20:34 +0000 (UTC) Authentication-Results: imf10.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=iZHYaoCw; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf10.hostedemail.com: domain of mjguzik@gmail.com designates 209.85.208.48 as permitted sender) smtp.mailfrom=mjguzik@gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1732101566; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=kLyrUQbJ7DreZ+2eCL0QXJjGPutHdXgYXLv04PixPtY=; b=mfcW8si+aMlNXiqz9x78iOYUeNvGCUcN884IwtmQyoF3Cwnp2jfyY6WKOJzGd9Tw9W31e0 uZi01ggKYTdBv37EWWB1O984mEmuuPWxoMOJfpflxrbB0Yr+Kd9sELDAmwoQsFSQgW6nnb lb+Nu9NKww5wlI4P6lxq02XwXEZSBek= ARC-Authentication-Results: i=1; imf10.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=iZHYaoCw; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf10.hostedemail.com: domain of mjguzik@gmail.com designates 209.85.208.48 as permitted sender) smtp.mailfrom=mjguzik@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1732101566; a=rsa-sha256; cv=none; b=GiNQDxvgdoJBXU7tDKjAASYUSE8EW1k2gUcDoljJQ4V/IsGc5V0AWabFTXm079ntNJ06QE Or/jsfy9smzlFq7XWm1780tLrzbSQWhA8Db6uPEpENeBmebzy7IL7xWy/yH83zhNkCMPdU Lgaccte5MUZni1dLrI4rd7qsBRjNOMc= Received: by mail-ed1-f48.google.com with SMTP id 4fb4d7f45d1cf-5cece886771so1480680a12.0 for ; Wed, 20 Nov 2024 03:20:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1732101656; x=1732706456; darn=kvack.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=kLyrUQbJ7DreZ+2eCL0QXJjGPutHdXgYXLv04PixPtY=; b=iZHYaoCwkxzCl6LkZ4sWdJmLkv83OvG1YUYdF1pEQApiAI5hdZSIo9muPhsEiwQVhu ubn9Ny/MdhFJ8/rrbDuDKIrHBDK2xXSVEzIEks/IZko9ms489/U8s7ZxInqYYi8m9M5L VkcSn73GC7a+I6W+oXWyX8gRN4yT7ooVd3xmBmO6Rx/muFCVmWqc2FLydXOhSrt6tTl+ MMvROKpHjt1Us1mHWONkETesqbCneel85ackkMcYS4B8/sO7hXHzu8+lgZP6mnFOOaM8 PiPS+u17g8qST/J5EHC5G/0zHOHMAEhHWdhzUYEnMSThBdhPLRlMT9zgE5dyeOymS6jc 7baQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732101656; x=1732706456; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=kLyrUQbJ7DreZ+2eCL0QXJjGPutHdXgYXLv04PixPtY=; b=PnEyXgm7Azj12zVlCBhldMLf1OJDTkw5WjTpmzxFf4QcQqt4TPXgsRt9BkKKw9KYHi 6ZJad0L/7wY7+ANIGZNV5JBZAX3CvjaGRMcxHyF6YZnCVpevNYhlVvhsx4PUZt5H6hps /gK6xY6FoLZp2kTEGVVd94PD7m+JuCgpiY5RVgai22MI9iv/u+rDVf/N2VtwDhugzs1n HcuwmxVtHG9RNEwMw3Un7PoCIDUnr3/cn0mEtnMp36aQ7tCJdpEaOIJ4p44AUrn7dJrX b+8h+MX9JwuaJps8/uNCYG8CmnHxN3BMY0pj9bj3kqmbacqcbktYeC1Rx+QvIWULKKwF jppg== X-Forwarded-Encrypted: i=1; AJvYcCUoeKU0Rc+/c6L0WBTr9BJO80rkQwXFrKnDlE8hZcgoRswSjnlxJ4k4J2NMMB8961tocXU0iRbH9A==@kvack.org X-Gm-Message-State: AOJu0Yyx8NpZgr4tzI4DrwA2yHhGGYIwBUJ3GrGBIYAzsr873XS7EErI a6tcB4hyzm+CmM+j2mgad9gkSjLcENu2GDYwAaS91DoStokxjZPd X-Google-Smtp-Source: AGHT+IG7pW3Dxr7KS89kSKjBWsHbI31GbaM1tb6J62zSZ1xqBnHqjvWaYalwKIjlxD/g6vIF9K38rA== X-Received: by 2002:a05:6402:320c:b0:5cf:e218:9b08 with SMTP id 4fb4d7f45d1cf-5cfe218aad9mr5811934a12.15.1732101655755; Wed, 20 Nov 2024 03:20:55 -0800 (PST) Received: from f.. (cst-prg-93-87.cust.vodafone.cz. [46.135.93.87]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-aa20df5690csm758559566b.75.2024.11.20.03.20.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Nov 2024 03:20:55 -0800 (PST) From: Mateusz Guzik To: brauner@kernel.org 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, Mateusz Guzik Subject: [PATCH v3 3/3] tmpfs: use inode_set_cached_link() Date: Wed, 20 Nov 2024 12:20:36 +0100 Message-ID: <20241120112037.822078-4-mjguzik@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241120112037.822078-1-mjguzik@gmail.com> References: <20241120112037.822078-1-mjguzik@gmail.com> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: B799AC0005 X-Stat-Signature: 31mkzuzxro8j4fih6i5h5qimxsc5aky6 X-HE-Tag: 1732101634-740329 X-HE-Meta: U2FsdGVkX18ZxriAGWdTdJ3PICTOfIMZJ13NOB+i4TLHWsdSVbyWeT+rO3P9refmfjiYZx86kGZYixzqqgptBaK0KtLtitzKH4UeMtXAO7Pj+ZQPjXuXhBQT3zEzvwraeK6W2K6yUVkKyYH7PGguq18jAtOPuS+OZxe6bi49zjnOm6Ph517dJTLSBUFd5fvIXOXpKISNP3+A6iR+ntQikzsqhdLxSSFO4Q3Ym++IcVuabKHWv0IyNoUHnzni6zeiuRpMfKbn+/DhfuV3E/3X2P4XZ539HIPE3n3UbI2KAPW1MNeCqOBAY7kHINnlLANmRCG5Bcmyd5cHyjwO8gZE3ENa5rKWYm6P4AeF3ZElLXf+cKFgkOaW6V44z90qQUc/EPNoLuCnW/rFVEEuB8GoZIZ+053adSrEHR+6RdrX1zoJHX1EOmWHdB2zcYwrgr/vplufqDearTg9FWxU4lgmPzcj3Wwqlelu1GswTm+Ibj9vSK8bBWeHI8T6uyOLqxX/SOE8X4sCeR6EEClvcTP9BM4JVbC6d42ofPB2R/IpcWpV928ihh1MavzCpMwOz4l6PLDDLYrlJ74jd431oP/+Lk+qzUIrW+RZILCW4OOGnr/OWzVEe+B1CtNWcwzFFgNXIJzk1rPoNPDa2bJS4okAb3OW4D/9Vmei/PXkrx5qrf3CZL3VoNnmLE9A3zzA1FkOf7OI+bOe99ejmfAECtHfkd0sERrBTq5JAUbwkqG4yDqev0feHmbsi/GWAZ/xlXuF1usgyrzmFtM1NLFYrZhK7xirC5eQxP46qm8ZNkBz78zfdwenI4RN5JQQssWZUVp974Xcc2xv0qxD5K5ZdbeKe6k5KkKhnds6QooIDwFzrJbDjmDkF4pm9+HZba7k4sRzQ22taDZPBnOf9IZVTtKkt3Gv5Tb/AVcJUYJyR9ChIRj6bgQjsLJHnxhhZ8OudWeA/C1AaHoS3tnyx75as7V YZaxsauk Yu4Ex2BjeGrUg7JBzqlqQZ11NGZzWJLA9khxcMqFLilk+ny6egTrOudy7To2TT86ch/YBfCJkmqufiI3GME9jXelL7kZQY1dhVl+6p0IvM2dFZuUZ7ihdWchPrWfeKsEVUoUdfSsTjzD345yj266zMKykmBqq7rUcmCaG3conoHZ4FKGlv4ZQYDA2E7U7ZuRyGjGwWnM4Pd//ZLnZUky0BSxMq/o8ECBhjzMq0poPXWjp2qmq4uMgPp/MVXsCRyJHsMX4CzqiVxJU3yaWGyeelC0nIgIQUB2l6Ja2Byz1Nj4GvSYSmxEMLZZ5bol0XfMwfynJdxo80K7Tkbwou2sv5TCFf/h3MAFIie8FtAMnpEOgHrUDTlN3tJ0I4PcxKNA01PvxMinXAJTZmUYtHGwnq2YU2NUFJHWrgitfEULZ90IkUks= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000004, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Signed-off-by: Mateusz Guzik --- mm/shmem.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/mm/shmem.c b/mm/shmem.c index c7881e16f4be..135f38eb2ff1 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -3868,6 +3868,7 @@ static int shmem_symlink(struct mnt_idmap *idmap, struct inode *dir, int len; struct inode *inode; struct folio *folio; + char *link; len = strlen(symname) + 1; if (len > PAGE_SIZE) @@ -3889,12 +3890,13 @@ static int shmem_symlink(struct mnt_idmap *idmap, struct inode *dir, inode->i_size = len-1; if (len <= SHORT_SYMLINK_LEN) { - inode->i_link = kmemdup(symname, len, GFP_KERNEL); - if (!inode->i_link) { + link = kmemdup(symname, len, GFP_KERNEL); + if (!link) { error = -ENOMEM; goto out_remove_offset; } inode->i_op = &shmem_short_symlink_operations; + inode_set_cached_link(inode, link, len - 1); } else { inode_nohighmem(inode); inode->i_mapping->a_ops = &shmem_aops;