linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Luis Chamberlain <mcgrof@kernel.org>
To: hughd@google.com, akpm@linux-foundation.org, willy@infradead.org,
	brauner@kernel.org, djwong@kernel.org
Cc: p.raghav@samsung.com, da.gomez@samsung.com,
	rohan.puri@samsung.com, rpuri.linux@gmail.com,
	a.manzanares@samsung.com, dave@stgolabs.net,
	yosryahmed@google.com, keescook@chromium.org, hare@suse.de,
	kbusch@kernel.org, mcgrof@kernel.org, patches@lists.linux.dev,
	linux-block@vger.kernel.org, linux-fsdevel@vger.kernel.org,
	linux-mm@kvack.org, linux-kernel@vger.kernel.org
Subject: [RFC v2 4/8] shmem: add helpers to get block size
Date: Fri, 26 May 2023 00:55:48 -0700	[thread overview]
Message-ID: <20230526075552.363524-5-mcgrof@kernel.org> (raw)
In-Reply-To: <20230526075552.363524-1-mcgrof@kernel.org>

Stuff the block size as a struct shmem_sb_info member as a block_order
when CONFIG_TMPFS is enabled, but keep the current static value for now,
and use helpers to get the blocksize. This will make the subsequent
change easier to read.

The static value for block order is PAGE_SHIFT and so the default block
size is PAGE_SIZE.

The struct super_block s_blocksize_bits represents the blocksize in
power of two, and that will match the shmem_sb_info block_order.

This commit introduces no functional changes other than extending the
struct shmem_sb_info with the block_order.

Signed-off-by: Luis Chamberlain <mcgrof@kernel.org>
---
 include/linux/shmem_fs.h |  3 +++
 mm/shmem.c               | 34 +++++++++++++++++++++++++++++++---
 2 files changed, 34 insertions(+), 3 deletions(-)

diff --git a/include/linux/shmem_fs.h b/include/linux/shmem_fs.h
index 9029abd29b1c..2d0a4311fdbf 100644
--- a/include/linux/shmem_fs.h
+++ b/include/linux/shmem_fs.h
@@ -36,6 +36,9 @@ struct shmem_inode_info {
 #define SHMEM_FL_INHERITED		(FS_NODUMP_FL | FS_NOATIME_FL)
 
 struct shmem_sb_info {
+#ifdef CONFIG_TMPFS
+	unsigned char block_order;
+#endif
 	unsigned long max_blocks;   /* How many blocks are allowed */
 	struct percpu_counter used_blocks;  /* How many are allocated */
 	unsigned long max_inodes;   /* How many inodes are allowed */
diff --git a/mm/shmem.c b/mm/shmem.c
index 7bea4c5cb83a..c124997f8d93 100644
--- a/mm/shmem.c
+++ b/mm/shmem.c
@@ -122,7 +122,22 @@ struct shmem_options {
 #define SHMEM_SEEN_NOSWAP 16
 };
 
+static u64 shmem_default_block_order(void)
+{
+	return PAGE_SHIFT;
+}
+
 #ifdef CONFIG_TMPFS
+static u64 shmem_block_order(struct shmem_sb_info *sbinfo)
+{
+	return sbinfo->block_order;
+}
+
+static u64 shmem_sb_blocksize(struct shmem_sb_info *sbinfo)
+{
+	return 1UL << sbinfo->block_order;
+}
+
 static unsigned long shmem_default_max_blocks(void)
 {
 	return totalram_pages() / 2;
@@ -134,6 +149,17 @@ static unsigned long shmem_default_max_inodes(void)
 
 	return min(nr_pages - totalhigh_pages(), nr_pages / 2);
 }
+#else
+static u64 shmem_block_order(struct shmem_sb_info *sbinfo)
+{
+	return PAGE_SHIFT;
+}
+
+static u64 shmem_sb_blocksize(struct shmem_sb_info *sbinfo)
+{
+	return PAGE_SIZE;
+}
+
 #endif
 
 static int shmem_swapin_folio(struct inode *inode, pgoff_t index,
@@ -3062,7 +3088,7 @@ static int shmem_statfs(struct dentry *dentry, struct kstatfs *buf)
 	struct shmem_sb_info *sbinfo = SHMEM_SB(dentry->d_sb);
 
 	buf->f_type = TMPFS_MAGIC;
-	buf->f_bsize = PAGE_SIZE;
+	buf->f_bsize = shmem_sb_blocksize(sbinfo);
 	buf->f_namelen = NAME_MAX;
 	if (sbinfo->max_blocks) {
 		buf->f_blocks = sbinfo->max_blocks;
@@ -3972,6 +3998,7 @@ static int shmem_fill_super(struct super_block *sb, struct fs_context *fc)
 	}
 	sb->s_export_op = &shmem_export_ops;
 	sb->s_flags |= SB_NOSEC | SB_I_VERSION;
+	sbinfo->block_order = shmem_default_block_order();
 #else
 	sb->s_flags |= SB_NOUSER;
 #endif
@@ -3997,8 +4024,9 @@ static int shmem_fill_super(struct super_block *sb, struct fs_context *fc)
 	INIT_LIST_HEAD(&sbinfo->shrinklist);
 
 	sb->s_maxbytes = MAX_LFS_FILESIZE;
-	sb->s_blocksize = PAGE_SIZE;
-	sb->s_blocksize_bits = PAGE_SHIFT;
+	sb->s_blocksize = shmem_sb_blocksize(sbinfo);
+	sb->s_blocksize_bits = shmem_block_order(sbinfo);
+	WARN_ON_ONCE(sb->s_blocksize_bits != PAGE_SHIFT);
 	sb->s_magic = TMPFS_MAGIC;
 	sb->s_op = &shmem_ops;
 	sb->s_time_gran = 1;
-- 
2.39.2



  parent reply	other threads:[~2023-05-26  7:56 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-26  7:55 [RFC v2 0/8] add support for blocksize > PAGE_SIZE Luis Chamberlain
2023-05-26  7:55 ` [RFC v2 1/8] page_flags: add is_folio_hwpoison() Luis Chamberlain
2023-05-26 13:51   ` Matthew Wilcox
2023-05-26 15:40     ` Keith Busch
2023-05-26  7:55 ` [RFC v2 2/8] shmem: convert to use is_folio_hwpoison() Luis Chamberlain
2023-05-26 14:32   ` Matthew Wilcox
2023-05-26 17:41     ` Luis Chamberlain
2023-05-26 18:41       ` Matthew Wilcox
2023-05-26  7:55 ` [RFC v2 3/8] shmem: account for high order folios Luis Chamberlain
2023-05-26  7:55 ` Luis Chamberlain [this message]
2023-05-26  7:55 ` [RFC v2 5/8] shmem: account for larger blocks sizes for shmem_default_max_blocks() Luis Chamberlain
2023-05-26  7:55 ` [RFC v2 6/8] shmem: consider block size in shmem_default_max_inodes() Luis Chamberlain
2023-05-26  7:55 ` [RFC v2 7/8] shmem: add high order page support Luis Chamberlain
2023-05-26  7:55 ` [RFC v2 8/8] shmem: add support to customize block size order Luis Chamberlain
2023-05-26  8:07 ` [RFC v2 0/8] add support for blocksize > PAGE_SIZE Luis Chamberlain
2023-05-26  8:14 ` Christoph Hellwig
2023-05-26  8:18   ` Luis Chamberlain
2023-05-26  8:28     ` Christoph Hellwig
2023-05-26  8:35       ` Luis Chamberlain
2023-05-26 13:54 ` Matthew Wilcox
2023-05-26 17:33   ` Luis Chamberlain
2023-05-26 18:43     ` Matthew Wilcox

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230526075552.363524-5-mcgrof@kernel.org \
    --to=mcgrof@kernel.org \
    --cc=a.manzanares@samsung.com \
    --cc=akpm@linux-foundation.org \
    --cc=brauner@kernel.org \
    --cc=da.gomez@samsung.com \
    --cc=dave@stgolabs.net \
    --cc=djwong@kernel.org \
    --cc=hare@suse.de \
    --cc=hughd@google.com \
    --cc=kbusch@kernel.org \
    --cc=keescook@chromium.org \
    --cc=linux-block@vger.kernel.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=p.raghav@samsung.com \
    --cc=patches@lists.linux.dev \
    --cc=rohan.puri@samsung.com \
    --cc=rpuri.linux@gmail.com \
    --cc=willy@infradead.org \
    --cc=yosryahmed@google.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).