From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (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 44FDD579822 for ; Wed, 23 Sep 2026 22:44:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790203466; cv=none; b=I/J6kQiggr0UjqT4m7k5RDpKEgREkItuwMXApgVK3lYqubYWzH5632ONUNnwWkVw7vhfgNEn3hwew3OFdGc+v4+4OopghEa4f9QkL+iVouW8ND/piqi0FAgM/QWJ6vlhazMDENccVj74jg8rl1tu4xHBgWla11laBaz/hcAqy5Y= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790203466; c=relaxed/simple; bh=b2FD4HnaecV/favYI7++QkP0O3dptt9tpaa+kslwvlQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Ya/ruUOquhH8RsSSFa5927mO8CzyIDdF4L+JMROGXazYPHpnQWuaXWlTU++dxX/BVJwYAiXFnbYjAykMSeE9MGNtXVRMkL2nXnrpYgN+7O2yazbX2kW67wXjoXh0ouRqpDbUYJAQ7yN6L7YultJ8/2uxMoSgSjqJSWT98ou8VCg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=i6SWVv8J; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="i6SWVv8J" Received: by smtp.kernel.org (Postfix) with ESMTPSA id B9D4C1F000FF; Wed, 23 Sep 2026 22:44:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1790203465; bh=5nQ+hBf6qVec8z+IXo2hdLde0/quAUf4P/g17WYv1iw=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=i6SWVv8JLcwPyjTj/ZDmJk2VviUSkDwPsJXxoiR+68IM0XkG2b/fK11NvvSzU1pUr 1QY4Nv5LrjQFn+aUKbtb0oehm0nI8M4hQNRrQSnb8f8Vk+4Nwg61O4TVn/5bfO7kDG WRJgBF0aN5ghNfbptXbCvvvM/IHl2/k3bBVfQ699CFcZgTxhuMoaxWde76uHDTD1AJ esysnoUGA8ha6czLuP7V5/2FL0G7zB6+NtUSaKQ3nVu9yEO/Hgi0kQpXMymT0AF2xx a4L+ue7xBokmi5+T5BLMctK8w6q7SJ7KjPf+fDarlrpngQ2DmuhEyTyjGKQyUoeMR1 gbdRrYSdIIc0Q== From: Pratyush Yadav To: Pasha Tatashin , Mike Rapoport , Pratyush Yadav , Andrew Morton , David Hildenbrand , Lorenzo Stoakes , Alexander Graf , Hugh Dickins , Baolin Wang , David Matlack , Samiullah Khawaja Cc: kexec@lists.infradead.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [RFC PATCH 2/6] shmem: add tmpfs_create_mount() to create tmpfs mounts internally Date: Thu, 24 Sep 2026 00:44:01 +0200 Message-ID: <20260923224408.3745689-3-pratyush@kernel.org> X-Mailer: git-send-email 2.56.0.rc1.310.g51773c2048-goog In-Reply-To: <20260923224408.3745689-1-pratyush@kernel.org> References: <20260923224408.3745689-1-pratyush@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: "Pratyush Yadav (Google)" Upcoming commits will add support for preserving a tmpfs mount via LUO. While the retrieve logic can create the mount by constructing an options string from its preserved data, it is simpler to let it directly pass the parameters. tmpfs_create_mount() allows creating a mount with the specified max_blocks and mode. The function only takes max_blocks and mode for now because that is all the tmpfs preservation will use. All other values are left to their defaults. Signed-off-by: Pratyush Yadav (Google) --- mm/internal.h | 1 + mm/shmem.c | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/mm/internal.h b/mm/internal.h index 38b1165212c9..d82c92c8fddd 100644 --- a/mm/internal.h +++ b/mm/internal.h @@ -1436,6 +1436,7 @@ int shmem_add_to_page_cache(struct folio *folio, pgoff_t index, void *expected, gfp_t gfp); int shmem_inode_acct_blocks(struct inode *inode, long pages); bool shmem_recalc_inode(struct inode *inode, long alloced, long swapped); +struct vfsmount *tmpfs_create_mount(unsigned long max_blocks, umode_t mode); #ifdef CONFIG_SHRINKER_DEBUG static inline __printf(2, 0) int shrinker_debugfs_name_alloc( diff --git a/mm/shmem.c b/mm/shmem.c index 897fa2b61346..8660405b6ab8 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -5313,6 +5313,44 @@ static struct file_system_type shmem_fs_type = { .fs_flags = FS_USERNS_MOUNT | FS_ALLOW_IDMAP | FS_MGTIME, }; +/** + * tmpfs_create_mount - Create a new tmpfs instance from explicit parameters. + * @max_blocks: Block limit of the filesystem, in PAGE_SIZE units, as held by + * shmem_sb_info::max_blocks. + * @mode: Mode of the root directory. + * + * Creates a new tmpfs superblock and returns a mount for it. Everything not + * named above is left at its default. + * + * The returned mount belongs to no mount namespace and is owned by the caller, + * who must either mntput() it or hand it to something that takes it over. + * + * Return: the new mount, or an ERR_PTR. + */ +struct vfsmount *tmpfs_create_mount(unsigned long max_blocks, umode_t mode) +{ + struct shmem_options *ctx; + struct fs_context *fc; + struct vfsmount *mnt; + + if (!IS_ENABLED(CONFIG_TMPFS)) + return ERR_PTR(-EOPNOTSUPP); + + fc = fs_context_for_mount(&shmem_fs_type, 0); + if (IS_ERR(fc)) + return ERR_CAST(fc); + + ctx = fc->fs_private; + ctx->blocks = max_blocks; + ctx->seen |= SHMEM_SEEN_BLOCKS; + ctx->mode = mode; + + mnt = fc_mount(fc); + put_fs_context(fc); + + return mnt; +} + #if defined(CONFIG_SYSFS) && defined(CONFIG_TMPFS) #define __INIT_KOBJ_ATTR(_name, _mode, _show, _store) \ -- 2.56.0.rc1.310.g51773c2048-goog