From patchwork Fri Apr 21 21:43:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luis Chamberlain X-Patchwork-Id: 13220710 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 59FF6C7EE26 for ; Fri, 21 Apr 2023 21:44:26 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 19FEE6B0071; Fri, 21 Apr 2023 17:44:21 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C8EC56B007E; Fri, 21 Apr 2023 17:44:20 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A4CB26B0072; Fri, 21 Apr 2023 17:44:20 -0400 (EDT) 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 4D8F66B0072 for ; Fri, 21 Apr 2023 17:44:20 -0400 (EDT) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 253DD16069E for ; Fri, 21 Apr 2023 21:44:20 +0000 (UTC) X-FDA: 80706727080.25.CF490A6 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf23.hostedemail.com (Postfix) with ESMTP id 8EE0F140003 for ; Fri, 21 Apr 2023 21:44:18 +0000 (UTC) Authentication-Results: imf23.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=4Ut9M+mn; spf=none (imf23.hostedemail.com: domain of mcgrof@infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=mcgrof@infradead.org; dmarc=fail reason="No valid SPF, DKIM not aligned (relaxed)" header.from=kernel.org (policy=none) ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1682113458; a=rsa-sha256; cv=none; b=2PRRlsVW9F01PhjzKLitbMlY+qt4m+0rq7HoQGTLXTGY80PlCNCE8wvJcWEVDDuwQezp9p QdRJAnUyr3eqANoHVHLhWTBdxPJ52/WE70gExg1WV2ToDFwLXeZFdHYfOFYUrX5KtP05Bn 3/zFi7PzJ132JlDAj4cNWW3EixoOOSo= ARC-Authentication-Results: i=1; imf23.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=4Ut9M+mn; spf=none (imf23.hostedemail.com: domain of mcgrof@infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=mcgrof@infradead.org; dmarc=fail reason="No valid SPF, DKIM not aligned (relaxed)" header.from=kernel.org (policy=none) ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1682113458; h=from:from:sender: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=nny3k9GHvISmRebv/wiZT4olnvrgRU1LTkzNA8FqTDM=; b=eOFvuCjzTmi+3rxICLDv28/xlkKiPySOeH/v0ij4RVzCB/s4ukrNoksjKkJXY5cWds/3/x 7vV5DuE04womn1mi1oNlrzxu2hJljm1ObpDZQSLMEsxCFqmSkp9aWrinOJJvv09AIG68C1 +Kr3HorVp/smwpuXCEU31j3In6C8G68= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Sender:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description; bh=nny3k9GHvISmRebv/wiZT4olnvrgRU1LTkzNA8FqTDM=; b=4Ut9M+mnDbLVzS5mn357NtXNVg iW973AulcqLzyWup7ygr0muRVGEjzVtqC6kqytGxva5A/sIYSQFeBlshjjpIhF6OYCvi05IojwxWE tsKCO6qUCenqfN9MsAZAdEWGPc3v0HjGDax4M6XvZmaBXtzA5v2C3KaFqloimB+8x6u/npTruKLQs 036sfUHB5iNErVxwNzS974BCSyU1Ar0fEOvtLbwggh51AghvUuMZYxAGZfc5IZ52Xmohp9mLGlsCy TaULQnEPNlB7MAFVSLGTPIcEwbgWNxO2AlGc26ENLqMM/u81jGPh5M591B/wApNppCBuEnfc313kb pACYjTwA==; Received: from mcgrof by bombadil.infradead.org with local (Exim 4.96 #2 (Red Hat Linux)) id 1ppyY1-00Btoo-2A; Fri, 21 Apr 2023 21:44:05 +0000 From: Luis Chamberlain 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, 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 4/8] shmem: add helpers to get block size Date: Fri, 21 Apr 2023 14:43:56 -0700 Message-Id: <20230421214400.2836131-5-mcgrof@kernel.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20230421214400.2836131-1-mcgrof@kernel.org> References: <20230421214400.2836131-1-mcgrof@kernel.org> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Queue-Id: 8EE0F140003 X-Rspamd-Server: rspam01 X-Stat-Signature: ai8nf6wgceg5mjx9za1da8ur8wz6hsby X-HE-Tag: 1682113458-466572 X-HE-Meta: U2FsdGVkX18tK045+uD6tt0HnAF5jbC+YVUt7BygkHrJ+nlw6pYtyzKhfc0ZgUokG830bAR1g6ybXiXtaPvDnPDP4nOFwwcf7I5odBt7M8UuVRzT4v+czLVQCVMG4ksR+yAXgGm3vEFeD6ueSuTZz0K8IVOt9zpO13pQOgP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ZmxHdSoyqGpRsQZKGvy+zV4DwuQVTHB6rHFxmw9dUsuH30YNxmlWxRpCvf0RAxp/XyLssLSavsM2Dh6azZikrtCOIVME6fNgv7g2OfUjz8t1ZuJB2CptMXj6BKu+u+8hoUsGa2Q= 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: Stuff the block size as a struct shmem_sb_info member 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 size of PAGE_SIZE is used currently. The struct super_block s_blocksize_bits represents the blocksize in power of two, since the block size is always PAGE_SIZE this is PAGE_SHIFT today, but to help make this a bit more apt to scale we can use __ffs() for it instead. This commit introduces no functional changes other than __ffs() for the s_blocksize_bits and extending the struct shmem_sb_info with the blocksize. Signed-off-by: Luis Chamberlain --- include/linux/shmem_fs.h | 3 +++ mm/shmem.c | 24 +++++++++++++++++++++--- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/include/linux/shmem_fs.h b/include/linux/shmem_fs.h index 9029abd29b1c..89e471fcde1d 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 + u64 blocksize; +#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 d76e86ff356e..162384b58a5c 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -125,7 +125,17 @@ struct shmem_options { #define SHMEM_SEEN_NOSWAP 16 }; +static u64 shmem_default_bsize(void) +{ + return PAGE_SIZE; +} + #ifdef CONFIG_TMPFS +static u64 shmem_sb_blocksize(struct shmem_sb_info *sbinfo) +{ + return sbinfo->blocksize; +} + static unsigned long shmem_default_max_blocks(void) { return totalram_pages() / 2; @@ -137,6 +147,12 @@ static unsigned long shmem_default_max_inodes(void) return min(nr_pages - totalhigh_pages(), nr_pages / 2); } +#else +static u64 shmem_sb_blocksize(struct shmem_sb_info *sbinfo) +{ + return shmem_default_bsize(); +} + #endif static int shmem_swapin_folio(struct inode *inode, pgoff_t index, @@ -3190,7 +3206,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; @@ -4100,6 +4116,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->blocksize = shmem_default_bsize(); #else sb->s_flags |= SB_NOUSER; #endif @@ -4125,8 +4142,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 = __ffs(sb->s_blocksize); + WARN_ON_ONCE(sb->s_blocksize_bits != PAGE_SHIFT); sb->s_magic = TMPFS_MAGIC; sb->s_op = &shmem_ops; sb->s_time_gran = 1;