From patchwork Tue Nov 19 09:45:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mateusz Guzik X-Patchwork-Id: 13879532 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 2ED80D62060 for ; Tue, 19 Nov 2024 09:46:19 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B53756B0085; Tue, 19 Nov 2024 04:46:18 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id B02F26B0089; Tue, 19 Nov 2024 04:46:18 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9A3256B008A; Tue, 19 Nov 2024 04:46:18 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 749706B0085 for ; Tue, 19 Nov 2024 04:46:18 -0500 (EST) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 36DBF80348 for ; Tue, 19 Nov 2024 09:46:18 +0000 (UTC) X-FDA: 82802363532.28.32FB8DC Received: from mail-ej1-f45.google.com (mail-ej1-f45.google.com [209.85.218.45]) by imf14.hostedemail.com (Postfix) with ESMTP id 9ECB6100008 for ; Tue, 19 Nov 2024 09:45:20 +0000 (UTC) Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=PEhiomJt; spf=pass (imf14.hostedemail.com: domain of mjguzik@gmail.com designates 209.85.218.45 as permitted sender) smtp.mailfrom=mjguzik@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1732009332; 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=2k+LOXLkuwwtIxGlSwTxzA89tsnqiig0usDZlI6j5Rc=; b=sQR6WBPc8Lee7Eokt7bx7x8dHak1EtYHu3+GipDb+tonYp3RAfQiU5CHjNEBgjtUne5jiW izX52k2cwSbQshgADEyP5RQCD/ai3Y9DeVxK5FHMMuMwyrBfG+qGnW+V+chd9h271XzbHz I4HOHuAwprks9c4TkXaUXxXMlhleB9s= ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=PEhiomJt; spf=pass (imf14.hostedemail.com: domain of mjguzik@gmail.com designates 209.85.218.45 as permitted sender) smtp.mailfrom=mjguzik@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1732009332; a=rsa-sha256; cv=none; b=lDGENbmM0zm/LLdLYLX5EZAosbjwOPlPZBZ1r4qsJ7Wkb4xvvL2a/GRsOChxtPixeI5OBy SaZxnuB8oby0bAuqU9DlAGNhIym1Rtv4bMLDLZYkO4XNRC6WX7L9Tfd1//0oSJNodqBMjl OVh2GNsCBap+8U1Ymr+DsaIg1InK5WA= Received: by mail-ej1-f45.google.com with SMTP id a640c23a62f3a-a99fa009adcso218275966b.0 for ; Tue, 19 Nov 2024 01:46:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1732009575; x=1732614375; 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=2k+LOXLkuwwtIxGlSwTxzA89tsnqiig0usDZlI6j5Rc=; b=PEhiomJtPZy/wl1XyzLI2OaLHKmGNvL8/q9Wyyd1kNbumSmXyoqhlIkrrpvLGVccDs N+wXGje0gtrSWdkxAx+bWql0K9mB15tOI9A8iG6PEsP+FLDjUkodSfJIYJK1IVUfyQZm YRhKQ7/S8J6e4HnLbDJyutvfRXJBWQUOmjFaWcd6UkFNRicOBLijKBJqk/qdnjVZezHE heD52BdgIeGylC3Lg9nw5C+jziB7XKcG8hQVXKIgEcfN5dE39zHt16MjnmNztkRodf1W 1UGRVuZbmvZO3oIOK0T4D1/T10hHxFWcOXp58FCPIKbRBRcjKIQNKC34oW9JL72M+Unt PLLg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732009575; x=1732614375; 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=2k+LOXLkuwwtIxGlSwTxzA89tsnqiig0usDZlI6j5Rc=; b=MeLC6rh2xwfswFyWdA/cTEv3bDy1yvQnXO1QB9onQD4rSz4cnmC0tK1qY7uKPYTGY7 tyPB61lc+rSMpTyflYgJ7/GSrcP0LfadVn+ICAB+XzZ8Q2sUyf7q3kPfnM4rkihTU/Dc eRfHybhp95UoFzoGZ75RCybc0w83HIvvHMTjdR7GqaQOkycLrogLZgJQ1wJlozMct9GO teTtMkQAWv5EN5rLPHKlNS40qeMOCan0E4CUDGGTCsN0swwKC8ROAnqeEXWaVc3zQkSm yzX3joNhZe3zjrVd+Wfg92hNPNYqrJRRL6dICmInvrjysUQSj5wA+ptB+ToV2tzXEo3v rKMg== X-Forwarded-Encrypted: i=1; AJvYcCVOkEIyFHkC6Gz4mZeMwL6kvKnM++ESW3f/nYuJvlLYyPWRVlAU9k8bA7cMqo+qnwVz04yv3jjjCQ==@kvack.org X-Gm-Message-State: AOJu0Yw5p9YfSq6Hav+tCiD5CO3krlBcHWegFSK8g8IhiH7YO7jE91NT OPw9+X7oDMqKLtQka//pxT1S5kBZGkMUsboH3tWbLm3UZxtG1n63 X-Google-Smtp-Source: AGHT+IHq3gRQkbq4vilVBjoFrqlc2rP/Dxb0QaL818D1CYDKfch0hN3L/I87OgXz6zPDisBWU8VEfw== X-Received: by 2002:a05:6402:524d:b0:5cf:c1a3:b109 with SMTP id 4fb4d7f45d1cf-5cfc1a3b3d8mr8659092a12.2.1732009574442; Tue, 19 Nov 2024 01:46:14 -0800 (PST) Received: from f.. (cst-prg-93-87.cust.vodafone.cz. [46.135.93.87]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5cfcb3edce9sm1821154a12.35.2024.11.19.01.46.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Nov 2024 01:46:13 -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 v2 1/3] vfs: support caching symlink lengths in inodes Date: Tue, 19 Nov 2024 10:45:53 +0100 Message-ID: <20241119094555.660666-2-mjguzik@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241119094555.660666-1-mjguzik@gmail.com> References: <20241119094555.660666-1-mjguzik@gmail.com> MIME-Version: 1.0 X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 9ECB6100008 X-Stat-Signature: 3tgqcjnd7upo8wpndwknic3ars96za4j X-Rspam-User: X-HE-Tag: 1732009520-503457 X-HE-Meta: U2FsdGVkX19qgkMZLP9f1qQRRhVPC3yTwjhEu6PML5MQlrgptQ18i5EtxXBskQEC2Eo/a5dKQ4SneohthHiXB6nTVXrfd9u2/V7yJDGwTjc3ui9Z2cYtFf0boqqxqiNBIr19iAwUjVXFJc+yLviCwllwoWrlLl462H+ZVzxMkbUHxsxiPjYTm3DJpzEj3w7SOTqJVPDNT8kSb9jOU48cSMiGB5ROvdDVoYozPMWchXx2788HlVkcAhZwcF6QeEa7leI/UXCIFfrM+97n1+QKq3FDrGhHWiL2olJiHIJ/sGyyxfrypmpAfnhptsYIF1y8Cl/1RVWbP8/IHBuCHgaGaE5ZNIUqMOrI9AaakdPIMrkpeHh6qZDJbsFyIoGKSQo6xLvXFvRkFU7hteCV7oaCIpqWgjuR41VicxWsQH4Dn2ETT3WRbr2ua7UobYoYtsWyra+avRVTKhrb6hyxHh1VHR6HnP9PEWun/i83J5Fr+QYOjtcOPirDnGkusIx9ltS+zzzChm+CQK6dFgozFA97HrmitwuXPKRe4W4xQOOmqif99fsp6DE43q5kWpq2axsiThxHWRQB+F8h42A1flPSzY2yQ+a6Xr1hS+ToAM0ED0bF23iMP3SOxGAEVNWft3iL1k//kbXbW5EuqDMiil/d3wp158LujcIgy1izazOxi90tJ6jeu31aZTXTGWGgX9/ndRSIsY7oF1DGrxH+pUo6TEF5OixjIjQb+R/9EuZkzAZ62TZcz7Jyp277wHpUN0aiQijevNVB+faXKDy/XIjrw1au7bOvYRE4QA1IfhaS9GLJWAgIAzi7HhME2rb2rPy+wR7X5u0l08XNedeJSCv3lPCkrqpr5eCCNUWvTwqqGUwA1lT+D1Ep3p7ZnacC9WMh+ToDxWV9z9yU3A4GsXPipY6T2MtFX2CmonQOdRGRikRs8UgMl0AYtXfbzGM3BTSfRGF2255jPk2zDYhd/5K d9YdBnAT ylHEId7S897UZoWxmFFNtiuiCOpKmhKg4DuxwzKlBwqTpnThbxM0Qp60uCcDCsJoCKIB2vUxKW6ISclMu1dQoAyeS7Q9+xFphrnpmUoIYPg/HmKVqgTJxTUC70hQ+puUWdFEt27sT/eIouVURxVCrCV1tABOjcqrAvq/4IggGabBuzCHwYYTZCchOdgu1iznZz2RbyK+/OnQVMfifLSbMwaX2Xyb3bxheQmBQHBKS5XLa37qdYV7TDCS8+UEOGQoVBKNjUbprgS7KHOuyYaOEt9WKludGqOkjypUFB7Fsk0a9ufGg1/p7y6iWiiuG9jrNL/32yybPr2sO+NUu46haoYLenMl/4tdzeNtv+m8mNdt9e2xCQUOj8/mBrg== 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 what used to be a 4-byte hole. If necessary the field can be made smaller and converted into a union with something not used with symlinks. 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 | 12 ++++++++++-- security/apparmor/apparmorfs.c | 2 +- 4 files changed, 31 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 972147da71f9..30e332fb399d 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 @@ -686,7 +687,7 @@ struct inode { /* Misc */ u32 i_state; - /* 32-bit hole */ + int i_linklen; /* for symlinks */ struct rw_semaphore i_rwsem; unsigned long dirtied_when; /* jiffies of first dirtying */ @@ -749,6 +750,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 +3359,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 Tue Nov 19 09:45:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mateusz Guzik X-Patchwork-Id: 13879533 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 7A653D6204F for ; Tue, 19 Nov 2024 09:46:24 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id F25476B008A; Tue, 19 Nov 2024 04:46:23 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id ED3FC6B0092; Tue, 19 Nov 2024 04:46:23 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D26F16B0093; Tue, 19 Nov 2024 04:46:23 -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 B2E646B008A for ; Tue, 19 Nov 2024 04:46:23 -0500 (EST) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 41FC01A02FF for ; Tue, 19 Nov 2024 09:46:23 +0000 (UTC) X-FDA: 82802362608.21.4A3B398 Received: from mail-ed1-f42.google.com (mail-ed1-f42.google.com [209.85.208.42]) by imf10.hostedemail.com (Postfix) with ESMTP id 43688C0005 for ; Tue, 19 Nov 2024 09:45:59 +0000 (UTC) Authentication-Results: imf10.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=nk9XyAqX; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf10.hostedemail.com: domain of mjguzik@gmail.com designates 209.85.208.42 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=1732009490; 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=NrbipnhGiulntBVTDYmN63nSkAsI19F9W2e2KFO2CXybFIlg30U6QCcm5mqxQbKdHnFqR7 +eg7c+5wbDTXrzH8ARjo9B4sQFhVRGkPjZOgZHUNwT9Nnqzh4f+X0P8bIsiWmeoezTAOa6 nkeFm4uY0S0cHZnBj4Clif++nIZA2GQ= ARC-Authentication-Results: i=1; imf10.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=nk9XyAqX; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf10.hostedemail.com: domain of mjguzik@gmail.com designates 209.85.208.42 as permitted sender) smtp.mailfrom=mjguzik@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1732009490; a=rsa-sha256; cv=none; b=NjTDRuZ9nxyz+8A6vgJTWFxe3zeAzB2iqZVy8DINeFwwuxXJJbBR27st3ljJXszfv9AMQp zs3J5D15MlMoAbd0Aw/jHaExbxFc1Y7vt5lt61VYswQVJHPFIRpMtxNex8LhdEl8Koinbu 0XtwYYmCadjnsPsc4gvJRrpT+CoPr0E= Received: by mail-ed1-f42.google.com with SMTP id 4fb4d7f45d1cf-5ceca0ec4e7so748948a12.0 for ; Tue, 19 Nov 2024 01:46:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1732009580; x=1732614380; 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=nk9XyAqXXn9PcUvsr7+T2ecDISd9TTnrOS7K6TyOaaYZQysPF3Y9xihrLHf5La/W5S 7svjTLOc39EP75KcQ4Gaj4/wuLpWUSkZb9hJ2aFZm+AXuADZFZ3akN9CqbOq1x0By35P HzA21zVMRYOd7U5a/iyJuVwW6+EKoUboV5JN0f7sQTjS5mDgD4U02jIyyBAOFYr+W0cN CRTHdJgYbwbQetGeB6N83ZHvrf585P9ZHvma8cfMRhkbK9wyvss8CkM36XcTed4VDp8l 48kc+YQpNp7iNXj+rltU15SAI+t0vkOloCUQZkGYtC97W5/6w0gMEHauE8AKVTm3BMJq gtCw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732009580; x=1732614380; 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=KPCrGL95UeZhZAnpZ+ZQByC3Vk9+Pmt+5oJpare+xAb1wS9s/zNaD/neetFRJt2hBd wOBjf//mUN8oFAiBKqyu0trpr/ZNEP5t2DfBT9XidWA1zlAj1IqNQOyK8j+P4myH760h zx5/0d79mtfugafXtXxQoli1VTlkqYdJUJ8fnpiGSHYS1XZcrM7QIhP3yodi6zUctOJa +Xm90SjdgRPPU/ElM//MXJ/xJ2J9XD6RdfQFi8pr8csD0AapsAv+NoKC11kA0kl9R7p0 ARRhGi01WwzrIm/JG7D+inXeQVfHy3AhzOkp+xFTC17SgogwHKmRHwSobFYcB+nGZPsC mR7w== X-Forwarded-Encrypted: i=1; AJvYcCVQNEg48GoLzRPnM+ucPIhprxsrlUVE3nWObdZS/Fh6NE3nMb8uNCB6pgcBGAfM/65NZGrLUjlPuA==@kvack.org X-Gm-Message-State: AOJu0YzsNIdkzHeHCjKv1ka5gn/cmjEGGoZziJflCnLDFik2kzXGUGEt yx3t9SvTvfLEle++elMJ388yFks54pB6XxEWUmPfYX2HsI9haEvJ X-Google-Smtp-Source: AGHT+IFp88Ev/g5mJ8o8R3VYOBPpM+QA5xyPCCcIu8wbpjjrR5KO7r2Uhp+NQwM/bCB9W1Ce+c9J4A== X-Received: by 2002:a05:6402:34c5:b0:5cf:bcc8:f490 with SMTP id 4fb4d7f45d1cf-5cfbcc8f8d1mr7093276a12.11.1732009579773; Tue, 19 Nov 2024 01:46:19 -0800 (PST) Received: from f.. (cst-prg-93-87.cust.vodafone.cz. [46.135.93.87]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5cfcb3edce9sm1821154a12.35.2024.11.19.01.46.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Nov 2024 01:46:18 -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 v2 2/3] ext4: use inode_set_cached_link() Date: Tue, 19 Nov 2024 10:45:54 +0100 Message-ID: <20241119094555.660666-3-mjguzik@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241119094555.660666-1-mjguzik@gmail.com> References: <20241119094555.660666-1-mjguzik@gmail.com> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: 43688C0005 X-Stat-Signature: n8qurhniwwdtqta47j5xaeye188p1tub X-HE-Tag: 1732009559-988087 X-HE-Meta: U2FsdGVkX19hQNtpWG/xV7JVLQnTnUshzmYyvSEh7IxVT9FyomnJ+pGquPZgbTzSozlFNyd1BFTOZi43iOBA7DFr9IL7kiR5FlPhSb/03vTWGcweD1HgzdSYPaPWDCmNL4Wpy/kEGkOBPt2+QJHex70cnnIspbIH/XWaqufTR+TTIXgfJ+KuHVsPH06048oLC9RqIqxhDuRy+9cT1qFWAC41dPYR/GS83X+UpR6kP2/rgCLL3YpMQB4P8f4+Ly8HJNWkflEuR1IalrXryNj5b+Ir7mF2F7y+n7Dub7Udcb5TvAUxRVUKP7BuawLgzNacTm+Ctr3LvG3sNhGVjMC1EBPzb0lOBBrFHm/RXFzMVH0R5Vzcg98cH5DkL1ZvMkmyLxnjFhqjriMg5qoNo+YYVOqrKCH5O1QznHkca6geZJa6WiUSKRWEOvy4+cht2j/PSgyjlZc5Em6BH9ZcDJ83L3LmcBOFiQ6M/FoMIedyEr5jqzbTWh7UibhQp/k0eleSOjxCxTH42jutWwp0z9Cm1poVP24V1V4jqrFRlRBmVT95+iOejr3UPKE1hmtzvNky/REObUyxH6/k5KfuS4oWJW8gXi8ZTFPiGuDVk5fNm+CCFKudISPKVMorJPOCkukgbAVvg8gv3pefI0cVkhhU4osqsA9+3KUrSMdQWZHxheGE/afSuhIfFsjyqR/8rIHgU/jbdj3KaocGllJKBCapyJ508RIQttD3a+Kz9XaWd4UtBiCAgZqs1sgjuDvuxOKHOPe0v+Dqa474E+0mU2K0lvhviOP7M51y+odzKUURzMcMJHp6IYa8MwEAW9ojwTgtnf2cwZHVEudZ3Z8nrNgqQLQlLJiIHi3ENSHfN/l4e9CuUwL+vplHTnME5wNNL5wzYIhP5qO9fPkitv5qAo3HLEI7Yg+dmqjjEBN8kJstKkNdHvBQuxB1iuCT4h719ilctkTSwcgleQvO/1P7O61 CTvJAcEU 6c3c6os47+I4riCOlsDVt/BIXe4eBEe1mWT3FbNjzFLgNj+jMhgh/hhqONEcFLuZP4esDOY+W9ozG5OBtR3xjQ+4K8xM/HczO5pmEQ0V7N1HobZesYjrepzAq0X09swATRLu3Sm47334feuLEvBj9tRObi01uIB0rMTSP4W4cY3XqFraJ+Vp09aabq9Et/eoPdsrYNb+GHjCZD/oUzJolsKq9sVTM5GJEZ0mCGY6UvoZBa7wGXWMDff+VkU+pQibv+4kNrvuWL4c+lt2A2OhF0WhgW075ozTeY3UOZvWhcW7Vn0vXLQ6ug/3G1/igqWSsdCHi1d15TH+mWQW85WGqyzr+efRLfXOn6+hAghOKlpFlBI3SPLmEBDOTe6ecXZoWSZX9LLTyynTk3MLz3snF5NToKqCdYY4xCPMqdMGqsIWvswM= 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 Tue Nov 19 09:45:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mateusz Guzik X-Patchwork-Id: 13879534 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 442E5D62060 for ; Tue, 19 Nov 2024 09:46:28 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D293E6B0093; Tue, 19 Nov 2024 04:46:27 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id CD7E76B0095; Tue, 19 Nov 2024 04:46:27 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B7BCE6B0096; Tue, 19 Nov 2024 04:46:27 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 97AB46B0093 for ; Tue, 19 Nov 2024 04:46:27 -0500 (EST) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 12255160300 for ; Tue, 19 Nov 2024 09:46:27 +0000 (UTC) X-FDA: 82802362818.10.A401B37 Received: from mail-ed1-f47.google.com (mail-ed1-f47.google.com [209.85.208.47]) by imf19.hostedemail.com (Postfix) with ESMTP id 4BDBF1A0002 for ; Tue, 19 Nov 2024 09:45:22 +0000 (UTC) Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=T+XRjGqf; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf19.hostedemail.com: domain of mjguzik@gmail.com designates 209.85.208.47 as permitted sender) smtp.mailfrom=mjguzik@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1732009450; a=rsa-sha256; cv=none; b=tKijPR3MIIjBj1zqUaC7jf5oWYD4cfIohUwYu68XXO7ZXBjYPXSVpcdeWc4qJ87sx/H8rB /5RNAo1J3vGaxjdcSgQBubIEx4syVanHr9Sc1TCQPJi7QWXRiFSeBEjx/GXRWymiDf4a9y G15+tC8D0Lp3D4BMaopL8RJkTmoQ8dY= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=T+XRjGqf; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf19.hostedemail.com: domain of mjguzik@gmail.com designates 209.85.208.47 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=1732009450; 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=gRjdlYzPvkDGyceNUheL6XnbeGUmofPVBhVXYJCZjS8=; b=20TdDau3rTF9Ijm1p9p2jXMYK3ExutQ9zTNTjIqHvm75Q4amgnZu8U+1/0SWPlvBvzT5h8 4YXPjtH47ipcEkoiANzmwtP4dai0qSvMJFRIPvm3G27u6MA7Y3SY/uopXaSKuQc3C3SatZ 8QSP0VKcCdJBhXRVAoCJiuRBunFvNNY= Received: by mail-ed1-f47.google.com with SMTP id 4fb4d7f45d1cf-5c96b2a10e1so1144766a12.2 for ; Tue, 19 Nov 2024 01:46:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1732009584; x=1732614384; 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=gRjdlYzPvkDGyceNUheL6XnbeGUmofPVBhVXYJCZjS8=; b=T+XRjGqfhxM0n5XmXCeuhspeZHY6xb1MLrCqWTAck93Ij3e/WAyRvyBSiMtOMI65oA dQEOiVwZ7QhzrBPjkajKFD5o2Qj69NAI6ni6lCedDL7C9PVPIB7uPyBbAtdu2AmzS0v7 RYKe943zgMsnM3oPDOTLVWqPczTjcmkPbv/P4pAvWzY3v2jIc8pRk+wHVOjSA36hWrAB EANys1ePDVMLT9lAkaG5RQ+zusLhOCnzmPMCGMn2zddwhoy86Fk1XtYZ2RGDz7Fk9z/v 2WxN3QnjLVPirFv8lp6yxPnq+Yp9v368DRdj2meLtOIgppYH4NrTAaMUEzIiHJ5FHU9M 7C5Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732009584; x=1732614384; 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=gRjdlYzPvkDGyceNUheL6XnbeGUmofPVBhVXYJCZjS8=; b=GRkey3YtB9plcA1w2Ikdrh4p+xiEUJJUfkOGKd8ksF9uwwkL4FCy0kf305DYh+u7AM rH+HhKNOL5RhoL6qqjitZ33MYtDFUEyCrgRPOq/LXB0XeWOc0MBDoLz3LpfgOztVcWEQ nO4lV92p92fzoGdhM6DgSR4ahxBa1AijlYnz43IJ/HhuAVN1WRztn+mUfyDYObxDi/Nh WoDu+THNWJlm8jrnMxnzM5vE+bxp7Gf5rU1VTCChyT+5KkPfGJCE4gSDH1gBq5pKjbfm mMvJI2uD8aFjnsOVqpg/LC3kFDIRmHf1iaYf2aGDVXEu5iKjyoUwtXZ1CC/6vsLY+wDo w3dg== X-Forwarded-Encrypted: i=1; AJvYcCXLcAfbsQwm7gfqn/scbKsyzGv5zVPGStrNvdtkM8SkBV1OZtHsPk5a39Hs6pIa4joO2uK/opwMlQ==@kvack.org X-Gm-Message-State: AOJu0YzXPx1QM+olLiffSh4Xg75ccmygUOcmMHlVHVRkWkvPfMxgkvvW IjGR9nArlCu1CMmtdr/jtmAoLLvTTxcUgj3APqMY/SfuEFHEbX51 X-Google-Smtp-Source: AGHT+IENGIigl1Ik7Rf/ZJmBgZi3Rx84+DKOI+SOYgqn4TNYTQoyphRR0vTCB3wZq2zJh9NolYXLRA== X-Received: by 2002:a05:6402:1e94:b0:5ce:af48:c2cc with SMTP id 4fb4d7f45d1cf-5cf8fcdfb82mr12601421a12.27.1732009583401; Tue, 19 Nov 2024 01:46:23 -0800 (PST) Received: from f.. (cst-prg-93-87.cust.vodafone.cz. [46.135.93.87]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5cfcb3edce9sm1821154a12.35.2024.11.19.01.46.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Nov 2024 01:46:22 -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 v2 3/3] tmpfs: use inode_set_cached_link() Date: Tue, 19 Nov 2024 10:45:55 +0100 Message-ID: <20241119094555.660666-4-mjguzik@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241119094555.660666-1-mjguzik@gmail.com> References: <20241119094555.660666-1-mjguzik@gmail.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: 4BDBF1A0002 X-Stat-Signature: bprbtwy8m6qrqnp6dicpp34thkw8ujk4 X-Rspam-User: X-Rspamd-Server: rspam05 X-HE-Tag: 1732009522-11321 X-HE-Meta: U2FsdGVkX18coCI+BzTvb3dXpxCXMYFyeGCF/TrFv+vmJzhrI8EMCQ5PA7khjvbLkJEmBEb3ztxvQpzojpyhTc4eBrTsXBG0MOVrC5OLgdJBMN4ad2OdIW9fqBlwMHe7MAroUCuWIe2pYzCxi0GBMICfAsp9WWYUeqLaLcPGK4p19rDH//TCM1M5lKgOEfVTQlEPMEcGYcyR/ci4bj/GKzjnEJ/qZIRu/4GnTS17H/wrx9fR+GnQxK2q6OMfowDVOZBCQcie1DB2v5IjD8XD4LNor5Q2VvQdKCg5qZG4xPyHIYYvXa6kSZqDhKgLeUGmWd3prNuk3JvX5cqGYk+9OVzsaYaGUr7c7OJv92prUErDiIT1gSy1Qi5G7iOqFiCBefHBJ9C48k75A6+q8EwVPwin5VLsWy9LrmRk1vgLiIJ1qCEM6Gu0X/iWihSU+UnmcbZFtqu4+YIBYhZjVmvwdt7zl7GiKG6i3vrEEIsdvc9waTGeCLtbmivt8SmuZIEm9IZCUeUmSZUzw19d+CFvyE7fGZm2aq0i7gYWbqBlmzf95FHUmOyWxA0c0TwlM8E5kYIaAoRepY2Wu6eAsnj5a0jXD0K9+pARoN7w86uY55yc8y+3/sWhhSs+YPcoDndhz3V8TGkWzDwFdAL9n8LQn158sFyXQbwEywtpHktvvk3bcmYo4v3Ody9s8g91fkUAQY70Hcu6NHL+QGGvX1QW9b1OaLm3OvSLODA8WkgHlk3rVegAiOx2Wub+/hO/pjTUp4wAvj1vvntFs686QAQmcJZsxGkOHy49guaqpyCE7smISeGEclXZ2IkFghl+a9WbayLQGefkc56THsV+IK/XVhUETOoSZXHg1zjwzJr92mn/0a/SEVnSTXRe46zT1qUJXepValAg1iNeNON1Vyx6NUTPXpU5ETcIQXY7o3AQjZeB9oHqcAEze2TvAnKbXTFV/gmn40zG9m90Wb/dsGc iFQHRadM oz0U1LTxzcEteTitnmUL8aUXvtwuIAYlNUWx341ciIA7AC1QOBnYnYarugCB1SZbFXBODgq7njG5egpdRTclnNvd21G6BOKGZV+uef6Ka5zrsn2T2VhPXfIPuWnnh1YZ8DWCXY3IAVJwjtzt+X5yFH/2jEe9vXH6z3MP9tgcNFI3jPWLJrYpcAEBwRisdjbEJ1EGGGonLRnkW6L699fIUZfxFoLEN9uXbijwxzTPPLiujssVltZE4KHY7k+SX9/u1ofINj0vEUQJCwOfFWAOpK6wS07XlpZdyXnx9AlWuYGjOvXHoZfrgNcNL23dgNGKzYUl+BZsgUtio1EWbJFl43Vq1nL7sa2DojvPe4hQT6yDgBq6Dey7gkxUF4dBjCLRYqOe9fezp2+UNnYhy6FtMOPShJa32y38cbw9o+4ZT/nCSVmk= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000001, 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 3d17753afd94..698a4bbdc21d 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -3870,6 +3870,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) @@ -3891,12 +3892,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;