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 B41BDC77B7C for ; Wed, 25 Jun 2025 23:19:58 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 437618D0016; Wed, 25 Jun 2025 19:19:30 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 3EA688D0001; Wed, 25 Jun 2025 19:19:30 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1EC4F8D0016; Wed, 25 Jun 2025 19:19:30 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 0B5848D0001 for ; Wed, 25 Jun 2025 19:19:30 -0400 (EDT) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id CE180807D1 for ; Wed, 25 Jun 2025 23:19:29 +0000 (UTC) X-FDA: 83595491658.03.FE72539 Received: from mail-yb1-f177.google.com (mail-yb1-f177.google.com [209.85.219.177]) by imf20.hostedemail.com (Postfix) with ESMTP id 0D0601C0002 for ; Wed, 25 Jun 2025 23:19:27 +0000 (UTC) Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=soleen-com.20230601.gappssmtp.com header.s=20230601 header.b=VETjShYH; spf=pass (imf20.hostedemail.com: domain of pasha.tatashin@soleen.com designates 209.85.219.177 as permitted sender) smtp.mailfrom=pasha.tatashin@soleen.com; dmarc=pass (policy=none) header.from=soleen.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1750893568; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=D8ttgCxJcE3UWPna1GSp5WvPQd8LCM7eXREvoZYzvG0=; b=TolFHxr8K6Ntb54L81iqFavp26gnKwMz2WNPF93RoxkCfz4wHP4UROu2VxISus28gariEG dssOKEcwNZ871iNVHZtiRzzJBU3jq9Qd7EN8GpgnDkyzv8CjnQN7X8zcqXY95+ja8IDNs2 9mtE9iIjEKIECjf/TCWl3GCva1LWSx8= ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=pass header.d=soleen-com.20230601.gappssmtp.com header.s=20230601 header.b=VETjShYH; spf=pass (imf20.hostedemail.com: domain of pasha.tatashin@soleen.com designates 209.85.219.177 as permitted sender) smtp.mailfrom=pasha.tatashin@soleen.com; dmarc=pass (policy=none) header.from=soleen.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1750893568; a=rsa-sha256; cv=none; b=tUwnhCnTos95SfEfFPfsGDNQEyoqKxSv+NDFbCgim3Qwd1c0Pq22y0GDEXhciuJMu9KSOW EQZCE9eMUTxP6bqqpL0//2mt1EAp5jG+svEt6ty1o4HVeeE0mC++6e3hjVhKpuLBL5tPJM gBtUIr43EKTet3VFlNRxG0F7NKTbJok= Received: by mail-yb1-f177.google.com with SMTP id 3f1490d57ef6-e7311e66a8eso303865276.2 for ; Wed, 25 Jun 2025 16:19:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=soleen-com.20230601.gappssmtp.com; s=20230601; t=1750893567; x=1751498367; darn=kvack.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=D8ttgCxJcE3UWPna1GSp5WvPQd8LCM7eXREvoZYzvG0=; b=VETjShYHhfjjtAIFMcm3P8JlL8KS9ADpkAdoW0KbYhPLeduWUFTGbMSDYiKYKdfMvT VjbG08eKyBCkNvurfGDZ29UVOe2LE7Ik4SJRJ6VOT3mAxpH/aX4YBV1jgEq25XPTjLPN 5149ZzNEc8Cc3iPJOnL4Q8CyX1AbAY0WXu8LzI95gC63xBGF7ztw5b7eWINvUc+dTgcY LhuvkKMOGQ3vWLDoPhNrpoqpW+QK0hygR9Wbm0PgGlOVyU4BRu9EOAJJNnYJ34lABAkN lWii4sxQXQtjia42jVA7vWxoVmI2HzyYVaQVsgbi7qealyZ9wLsoiOtJFNLVB0XWd7mz xhLg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1750893567; x=1751498367; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=D8ttgCxJcE3UWPna1GSp5WvPQd8LCM7eXREvoZYzvG0=; b=eyo8n8wklqmvxPWKCy8F7o5uXIU6nRht917swuppTT8n2LUuYv9pPPbKhoUaegMqsD 6S4psEdPg4gVjRzlV4q+/WcXkKQBPhzGJ9G8x7F92u1CYm6tBUi/m+b5ulNHG6w25Djy 6SAx/b8/bqNVDxA0WTVOKtXEZLZCimIw464qHwJnkjwKvqXpRMTReQIx71UB7rVXoRPW 0XmC/Z3VIBrsaTZrwOS/fSahd68/oUqb9+FsDgjROIKwvnCr2DYsnnZbHTMut2KwZ89u vUGuLxMOqHITfwXc1Og4s5BJQdsnA6vdocD7ZipVKbTXgdA/+tUsALonTbT2Xfs7JZm5 MNew== X-Forwarded-Encrypted: i=1; AJvYcCX7DKiedBWkZufeenj8shC14mighLm9koOJ8iZ0zAlk3dpOQ1dkBbLpchYgQ4StJ1d/mBlbyWBkww==@kvack.org X-Gm-Message-State: AOJu0YwhK0jROFGIYxR/2W30EcatbH4ueQjc4yTKOCBiIRiKwkhV05ut 7umnqW/rO7JgTc0NyJF7AiZ/15TkA3Y7xxUoC707b5KB+rPza4gQ88AH64HHjvEMY18= X-Gm-Gg: ASbGncvhOHKtsbgCSyhWTkh1jHj2IwUM/plzmcbsQ2MAb86M+/C377MAGPDJ4nZF6Ta HS0JZ834o9Swl5c1QiMDDYntP/UNJxYLZfeaJCOeFHkgp+NqsNfd4xwXPOs74gZN5WDdybMxuBq MKkTiiMXGsPCVlgtTy2AfOUTGOz8XkWZkAWgVRTAN/iptHdu3oNkHqA8HemX46S84LJNU/oppxX ZISZegzgbtzoJiVizt2UNRYMiqhqkUHHLh6SLsHjzwCn+VANzFT9nmA1ArRnqkQxqwQ+uesrc+L x9gcjqegXxuOzlPUzHEz4AaW3xhySbUvxGixzvnlGO+zDOx1XzIHcZ8sBaG07cr6omW/yy+diST Z0LaKpQ0QnyAM4FiUh8eowlys/hTvSQNbIyYtOCdu52YKUdHw0Zfv X-Google-Smtp-Source: AGHT+IE1pma/OI7F9Z9q+/yKqcLVvi7QSXRzKzluPfGgyPm9xYfbfJNVSej/XTGmvtY9GN91WObkjQ== X-Received: by 2002:a05:690c:6082:b0:714:349:583d with SMTP id 00721157ae682-71406ca1431mr68358807b3.8.1750893566981; Wed, 25 Jun 2025 16:19:26 -0700 (PDT) Received: from soleen.c.googlers.com.com (64.167.245.35.bc.googleusercontent.com. [35.245.167.64]) by smtp.gmail.com with ESMTPSA id 3f1490d57ef6-e842ac5c538sm3942684276.33.2025.06.25.16.19.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 Jun 2025 16:19:26 -0700 (PDT) From: Pasha Tatashin To: pratyush@kernel.org, jasonmiu@google.com, graf@amazon.com, changyuanl@google.com, pasha.tatashin@soleen.com, rppt@kernel.org, dmatlack@google.com, rientjes@google.com, corbet@lwn.net, rdunlap@infradead.org, ilpo.jarvinen@linux.intel.com, kanie@linux.alibaba.com, ojeda@kernel.org, aliceryhl@google.com, masahiroy@kernel.org, akpm@linux-foundation.org, tj@kernel.org, yoann.congal@smile.fr, mmaurer@google.com, roman.gushchin@linux.dev, chenridong@huawei.com, axboe@kernel.dk, mark.rutland@arm.com, jannh@google.com, vincent.guittot@linaro.org, hannes@cmpxchg.org, dan.j.williams@intel.com, david@redhat.com, joel.granados@kernel.org, rostedt@goodmis.org, anna.schumaker@oracle.com, song@kernel.org, zhangguopeng@kylinos.cn, linux@weissschuh.net, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, linux-mm@kvack.org, gregkh@linuxfoundation.org, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, x86@kernel.org, hpa@zytor.com, rafael@kernel.org, dakr@kernel.org, bartosz.golaszewski@linaro.org, cw00.choi@samsung.com, myungjoo.ham@samsung.com, yesanishhere@gmail.com, Jonathan.Cameron@huawei.com, quic_zijuhu@quicinc.com, aleksander.lobakin@intel.com, ira.weiny@intel.com, andriy.shevchenko@linux.intel.com, leon@kernel.org, lukas@wunner.de, bhelgaas@google.com, wagi@kernel.org, djeffery@redhat.com, stuart.w.hayes@gmail.com, ptyadav@amazon.de, lennart@poettering.net, brauner@kernel.org, linux-api@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: [PATCH v1 25/32] mm: shmem: use SHMEM_F_* flags instead of VM_* flags Date: Wed, 25 Jun 2025 23:18:12 +0000 Message-ID: <20250625231838.1897085-26-pasha.tatashin@soleen.com> X-Mailer: git-send-email 2.50.0.727.gbf7dc18ff4-goog In-Reply-To: <20250625231838.1897085-1-pasha.tatashin@soleen.com> References: <20250625231838.1897085-1-pasha.tatashin@soleen.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Rspamd-Server: rspam11 X-Rspam-User: X-Rspamd-Queue-Id: 0D0601C0002 X-Stat-Signature: yci34ifm6qomwayontmexfq3imzx63aa X-HE-Tag: 1750893567-203244 X-HE-Meta: U2FsdGVkX196H6UEqGIQn94PvqpG4eoyJybx1xWsmVoUa3D5OJ4VXUzLCsm/jK0rXQFuHikPo8Wy1g2+Y6cm+25VnA8/+sWWn0/5hDHSrb/2ZZzK0QE4eRviYgPWhHTibfHrQNSkI1RD+Ul6adTxxgG3tGTdlZVE/87SB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ZPSTw0V/QobuOcVAvM3tsEYPoKV2y7dASwTeZinPfzUXOVCOpU6sDy7PCJGBU5tfxloYK4iWFLRFLtgWvw8NAGsf/PsdmwqUGawzobG81bC8yzENObur/xmS/LN2mHl5ayeoIAyPOXD07j51ogbQ0DFDBZEK65jyM0/QMD3SJGBffLvBK57QK7nlyMrcQQjTo+/JvJUS5b5vWnaL/YIVCSbWKI3Gzne01ljFbWSTi+7r9Zg3+Sgd2ejlnoKcEDIImY9acKjVaWD/ahqKAycIOoyfOrjNEY+4cncxb 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: From: Pratyush Yadav shmem_inode_info::flags can have the VM flags VM_NORESERVE and VM_LOCKED. These are used to suppress pre-accounting or to lock the pages in the inode respectively. Using the VM flags directly makes it difficult to add shmem-specific flags that are unrelated to VM behavior since one would need to find a VM flag not used by shmem and re-purpose it. Introduce SHMEM_F_NORESERVE and SHMEM_F_LOCKED which represent the same information, but their bits are independent of the VM flags. Callers can still pass VM_NORESERVE to shmem_get_inode(), but it gets transformed to the shmem-specific flag internally. No functional changes intended. Signed-off-by: Pratyush Yadav Signed-off-by: Pasha Tatashin --- include/linux/shmem_fs.h | 6 ++++++ mm/shmem.c | 24 +++++++++++++----------- 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/include/linux/shmem_fs.h b/include/linux/shmem_fs.h index 5f03a39a26f7..578a5f3d1935 100644 --- a/include/linux/shmem_fs.h +++ b/include/linux/shmem_fs.h @@ -10,6 +10,7 @@ #include #include #include +#include /* inode in-kernel data */ @@ -17,6 +18,11 @@ #define SHMEM_MAXQUOTAS 2 #endif +/* Suppress pre-accounting of the entire object size. */ +#define SHMEM_F_NORESERVE BIT(0) +/* Disallow swapping. */ +#define SHMEM_F_LOCKED BIT(1) + struct shmem_inode_info { spinlock_t lock; unsigned int seals; /* shmem seals */ diff --git a/mm/shmem.c b/mm/shmem.c index 3a5a65b1f41a..953d89f62882 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -175,20 +175,20 @@ static inline struct shmem_sb_info *SHMEM_SB(struct super_block *sb) */ static inline int shmem_acct_size(unsigned long flags, loff_t size) { - return (flags & VM_NORESERVE) ? + return (flags & SHMEM_F_NORESERVE) ? 0 : security_vm_enough_memory_mm(current->mm, VM_ACCT(size)); } static inline void shmem_unacct_size(unsigned long flags, loff_t size) { - if (!(flags & VM_NORESERVE)) + if (!(flags & SHMEM_F_NORESERVE)) vm_unacct_memory(VM_ACCT(size)); } static inline int shmem_reacct_size(unsigned long flags, loff_t oldsize, loff_t newsize) { - if (!(flags & VM_NORESERVE)) { + if (!(flags & SHMEM_F_NORESERVE)) { if (VM_ACCT(newsize) > VM_ACCT(oldsize)) return security_vm_enough_memory_mm(current->mm, VM_ACCT(newsize) - VM_ACCT(oldsize)); @@ -206,7 +206,7 @@ static inline int shmem_reacct_size(unsigned long flags, */ static inline int shmem_acct_blocks(unsigned long flags, long pages) { - if (!(flags & VM_NORESERVE)) + if (!(flags & SHMEM_F_NORESERVE)) return 0; return security_vm_enough_memory_mm(current->mm, @@ -215,7 +215,7 @@ static inline int shmem_acct_blocks(unsigned long flags, long pages) static inline void shmem_unacct_blocks(unsigned long flags, long pages) { - if (flags & VM_NORESERVE) + if (flags & SHMEM_F_NORESERVE) vm_unacct_memory(pages * VM_ACCT(PAGE_SIZE)); } @@ -1557,7 +1557,7 @@ int shmem_writeout(struct folio *folio, struct writeback_control *wbc) if (WARN_ON_ONCE(!wbc->for_reclaim)) goto redirty; - if ((info->flags & VM_LOCKED) || sbinfo->noswap) + if ((info->flags & SHMEM_F_LOCKED) || sbinfo->noswap) goto redirty; if (!total_swap_pages) @@ -2910,15 +2910,15 @@ int shmem_lock(struct file *file, int lock, struct ucounts *ucounts) * ipc_lock_object() when called from shmctl_do_lock(), * no serialization needed when called from shm_destroy(). */ - if (lock && !(info->flags & VM_LOCKED)) { + if (lock && !(info->flags & SHMEM_F_LOCKED)) { if (!user_shm_lock(inode->i_size, ucounts)) goto out_nomem; - info->flags |= VM_LOCKED; + info->flags |= SHMEM_F_LOCKED; mapping_set_unevictable(file->f_mapping); } - if (!lock && (info->flags & VM_LOCKED) && ucounts) { + if (!lock && (info->flags & SHMEM_F_LOCKED) && ucounts) { user_shm_unlock(inode->i_size, ucounts); - info->flags &= ~VM_LOCKED; + info->flags &= ~SHMEM_F_LOCKED; mapping_clear_unevictable(file->f_mapping); } retval = 0; @@ -3062,7 +3062,9 @@ static struct inode *__shmem_get_inode(struct mnt_idmap *idmap, spin_lock_init(&info->lock); atomic_set(&info->stop_eviction, 0); info->seals = F_SEAL_SEAL; - info->flags = flags & VM_NORESERVE; + info->flags = 0; + if (flags & VM_NORESERVE) + info->flags |= SHMEM_F_NORESERVE; info->i_crtime = inode_get_mtime(inode); info->fsflags = (dir == NULL) ? 0 : SHMEM_I(dir)->fsflags & SHMEM_FL_INHERITED; -- 2.50.0.727.gbf7dc18ff4-goog