From patchwork Fri May 26 07:55:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luis Chamberlain X-Patchwork-Id: 13256605 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 38F40C77B7C for ; Fri, 26 May 2023 08:52:01 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id AFE246B0072; Fri, 26 May 2023 04:52:00 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id AADC3900002; Fri, 26 May 2023 04:52:00 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 974106B0075; Fri, 26 May 2023 04:52:00 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 88AC56B0072 for ; Fri, 26 May 2023 04:52:00 -0400 (EDT) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 547BFA0139 for ; Fri, 26 May 2023 08:52:00 +0000 (UTC) X-FDA: 80831788800.06.C8F4E86 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf16.hostedemail.com (Postfix) with ESMTP id CAC7D180013 for ; Fri, 26 May 2023 08:51:56 +0000 (UTC) Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=xoH7UfNZ; spf=none (imf16.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=1685091117; 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=psFng5IfKHz74jJHGQgHSSVFQ4pTJ14DfYwhK5NX3MQ=; b=zuafihpsL6p4emc4BXuBJsjxn6feo9TZ/jTRnB2ddxNExCSkCWxXX2wxgCrozPhPcsFiaU 1/D+dvB3weqoLRP3VHOyJCFN5hsqWK2MqbVonLh0NRB1gk/EJ+2sFqLCMN2HGxwt1CXiv4 9f6uuOp1dzS87pQZ8RVfyU9sDxGtIME= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1685091117; a=rsa-sha256; cv=none; b=vgAe8lqR2MIxIDJ/h0nPF3XzLJ6yKpN18VDizIqUa0KZakxziYrDg7IRQJif9kbzmRdfiV K6ueCPZc0HdzJaWCzwDO0vo4Pyjj9b6CU5to4aDLLf/HvJSc9N0qjcYLl3Sw2YN89kEYWN QQ2N1awJ9oBXiEjWfKcwVA3zjFf/kj4= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=xoH7UfNZ; spf=none (imf16.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) 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=psFng5IfKHz74jJHGQgHSSVFQ4pTJ14DfYwhK5NX3MQ=; b=xoH7UfNZuu4OOweZByfPFv0uQr AQbwg9ANaqY/qhG0wv6sLOxmNdkdtZ1pWBLCLLQSCJrCn7nP4ulbiXcVnfDtSVP0xLq1RGiysiMfP +hdw95L0XG5Z04NUiSJeSHYt2DX66Fu3FzfwjSUUF5NWBjS6sf61hOrpd79KQksg+YzjQOt4BN9XT y8n7ybw+BpRD1A502saPw5AwElzRrYe3QdibOCuYi66zgi4bTzSIqK4flERKfti2wxO6AJC7ybQv7 ZGZlcQJcDyVwuR+KnRkZjkBlFZ8gZQkwZhMfEUPoAtsqUOw7oW1U0Nv0LI44ED0adAn1Az1C2Fw1X TInKM54w==; Received: from mcgrof by bombadil.infradead.org with local (Exim 4.96 #2 (Red Hat Linux)) id 1q2SIk-001Wa1-0B; Fri, 26 May 2023 07:55:54 +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, 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 8/8] shmem: add support to customize block size order Date: Fri, 26 May 2023 00:55:52 -0700 Message-Id: <20230526075552.363524-9-mcgrof@kernel.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20230526075552.363524-1-mcgrof@kernel.org> References: <20230526075552.363524-1-mcgrof@kernel.org> MIME-Version: 1.0 X-Rspamd-Queue-Id: CAC7D180013 X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: si4zd3oh8f4csfg7ofkien78fft715my X-HE-Tag: 1685091116-976780 X-HE-Meta: U2FsdGVkX19oQJQj9L5AdHM2jk/aspAtBgExqcUh2j9GTKDXE+y2ON77dlW55HRi2ZCWyPFE0C+Tz8KaX10rnuj+neRb3RSgHrWSPUhT2YABl96aD+Vh7fT1wG1cqn41ZXJv/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eb3xdeSmINqq4y2Nmb+b3F9D+3LLxl2O4lJ9OhOx4YNlxDwllWouBGNpcIZLiMvxxQKomDqZiGTZi+ww0+76zVP8cueNRTIIVlEbivYbTwSlNWrl2wYax1OfVgExMwCZw+0lRxpUnkPMe72mdtLN2frw05iZJ1fFXafxtOP2do/FWnxzi/yVHELiD5MzhxxV6VRCrFMD5guOGRjFtovo+Zs27DdKbPwE87nnaoWERi3vqo70yeWyOzp+mFA== 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: This allows tmpfs mounts to use a custom block size order. We only allow block sizes greater than PAGE_SIZE, and these must also be a multiple of the PAGE_SIZE too. To simplify these requirements and the math we just use power of 2 order, so block order. Only simple tests have been run so far: mkdir -p /data-tmpfs/ time for i in $(seq 1 1000000); do echo $i >> /root/ordered.txt; done real 0m21.392s user 0m8.077s sys 0m13.098s du -h /root/ordered.txt 6.6M /root/ordered.txt sha1sum /root/ordered.txt 2dcc06b7ca3b7dd8b5626af83c1be3cb08ddc76c /root/ordered.txt stat /root/ordered.txt File: /root/ordered.txt Size: 6888896 Blocks: 13456 IO Block: 4096 regular file Device: 254,1 Inode: 655717 Links: 1 Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root) Access: 2023-04-21 19:34:20.709869093 +0000 Modify: 2023-04-21 19:34:43.833900042 +0000 Change: 2023-04-21 19:34:43.833900042 +0000 Birth: 2023-04-21 19:34:20.709869093 +0000 8 KiB block size: sha1sum /root/ordered.txt mount -t tmpfs -o size=10M,border=13 -o noswap tmpfs /data-tmpfs/ cp /root/ordered.txt sha1sum /data-tmpfs/ordered.txt stat /data-tmpfs/ordered.txt 2dcc06b7ca3b7dd8b5626af83c1be3cb08ddc76c /root/ordered.txt 2dcc06b7ca3b7dd8b5626af83c1be3cb08ddc76c /data-tmpfs/ordered.txt File: /data-tmpfs/ordered.txt Size: 6888896 Blocks: 13456 IO Block: 8192 regular file Device: 0,42 Inode: 2 Links: 1 Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root) Access: 2023-04-21 19:31:16.078390405 +0000 Modify: 2023-04-21 19:31:16.070391363 +0000 Change: 2023-04-21 19:31:16.070391363 +0000 Birth: 2023-04-21 19:31:16.034395676 +0000 64 KiB block size: sha1sum /root/ordered.txt mount -t tmpfs -o size=10M,border=16 -o noswap tmpfs /data-tmpfs/ cp /root/ordered.txt /data-tmpfs/; sha1sum /data-tmpfs/ordered.txt stat /data-tmpfs/ordered.txt 2dcc06b7ca3b7dd8b5626af83c1be3cb08ddc76c /root/ordered.txt 2dcc06b7ca3b7dd8b5626af83c1be3cb08ddc76c /data-tmpfs/ordered.txt File: /data-tmpfs/ordered.txt Size: 6888896 Blocks: 13568 IO Block: 65536 regular file Device: 0,42 Inode: 2 Links: 1 Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root) Access: 2023-04-21 19:32:14.669796970 +0000 Modify: 2023-04-21 19:32:14.661796959 +0000 Change: 2023-04-21 19:32:14.661796959 +0000 Birth: 2023-04-21 19:32:14.649796944 +0000 4 MiB works too. Signed-off-by: Luis Chamberlain --- mm/shmem.c | 44 +++++++++++++++++++++++++++++++++++++++----- 1 file changed, 39 insertions(+), 5 deletions(-) diff --git a/mm/shmem.c b/mm/shmem.c index 080864949fe5..777e953df62e 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -115,11 +115,13 @@ struct shmem_options { int huge; int seen; bool noswap; + unsigned char block_order; #define SHMEM_SEEN_BLOCKS 1 #define SHMEM_SEEN_INODES 2 #define SHMEM_SEEN_HUGE 4 #define SHMEM_SEEN_INUMS 8 #define SHMEM_SEEN_NOSWAP 16 +#define SHMEM_SEEN_BLOCKORDER 32 }; static u64 shmem_default_block_order(void) @@ -3661,6 +3663,7 @@ enum shmem_param { Opt_inode32, Opt_inode64, Opt_noswap, + Opt_border, }; static const struct constant_table shmem_param_enums_huge[] = { @@ -3683,6 +3686,7 @@ const struct fs_parameter_spec shmem_fs_parameters[] = { fsparam_flag ("inode32", Opt_inode32), fsparam_flag ("inode64", Opt_inode64), fsparam_flag ("noswap", Opt_noswap), + fsparam_u32 ("border", Opt_border), {} }; @@ -3709,7 +3713,15 @@ static int shmem_parse_one(struct fs_context *fc, struct fs_parameter *param) } if (*rest) goto bad_value; - ctx->blocks = DIV_ROUND_UP(size, PAGE_SIZE); + if (!(ctx->seen & SHMEM_SEEN_BLOCKORDER) || + ctx->block_order == shmem_default_block_order()) + ctx->blocks = DIV_ROUND_UP(size, PAGE_SIZE); + else { + if (size < (1UL << ctx->block_order) || + size % (1UL << ctx->block_order) != 0) + goto bad_value; + ctx->blocks = size >> ctx->block_order; + } ctx->seen |= SHMEM_SEEN_BLOCKS; break; case Opt_nr_blocks: @@ -3774,6 +3786,19 @@ static int shmem_parse_one(struct fs_context *fc, struct fs_parameter *param) ctx->noswap = true; ctx->seen |= SHMEM_SEEN_NOSWAP; break; + case Opt_border: + ctx->block_order = result.uint_32; + ctx->seen |= SHMEM_SEEN_BLOCKORDER; + if (ctx->block_order < PAGE_SHIFT) + goto bad_value; + /* + * We cap this to allow a block to be at least allowed to + * be allocated using the buddy allocator. That's MAX_ORDER + * pages. So 8 MiB on x86_64. + */ + if (ctx->block_order > (MAX_ORDER + PAGE_SHIFT)) + goto bad_value; + break; } return 0; @@ -3845,6 +3870,12 @@ static int shmem_reconfigure(struct fs_context *fc) raw_spin_lock(&sbinfo->stat_lock); inodes = sbinfo->max_inodes - sbinfo->free_inodes; + if (ctx->seen & SHMEM_SEEN_BLOCKORDER) { + if (ctx->block_order != shmem_block_order(sbinfo)) { + err = "Cannot modify block order on remount"; + goto out; + } + } if ((ctx->seen & SHMEM_SEEN_BLOCKS) && ctx->blocks) { if (!sbinfo->max_blocks) { err = "Cannot retroactively limit size"; @@ -3960,6 +3991,8 @@ static int shmem_show_options(struct seq_file *seq, struct dentry *root) shmem_show_mpol(seq, sbinfo->mpol); if (sbinfo->noswap) seq_printf(seq, ",noswap"); + if (shmem_block_order(sbinfo) != shmem_default_block_order()) + seq_printf(seq, ",border=%llu", shmem_block_order(sbinfo)); return 0; } @@ -3997,10 +4030,12 @@ static int shmem_fill_super(struct super_block *sb, struct fs_context *fc) * but the internal instance is left unlimited. */ if (!(sb->s_flags & SB_KERNMOUNT)) { + if (!(ctx->seen & SHMEM_SEEN_BLOCKORDER)) + ctx->block_order = shmem_default_block_order(); if (!(ctx->seen & SHMEM_SEEN_BLOCKS)) - ctx->blocks = shmem_default_max_blocks(shmem_default_block_order()); + ctx->blocks = shmem_default_max_blocks(ctx->block_order); if (!(ctx->seen & SHMEM_SEEN_INODES)) - ctx->inodes = shmem_default_max_inodes(shmem_default_block_order()); + ctx->inodes = shmem_default_max_inodes(ctx->block_order); if (!(ctx->seen & SHMEM_SEEN_INUMS)) ctx->full_inums = IS_ENABLED(CONFIG_TMPFS_INODE64); sbinfo->noswap = ctx->noswap; @@ -4009,7 +4044,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(); + sbinfo->block_order = ctx->block_order; #else sb->s_flags |= SB_NOUSER; #endif @@ -4037,7 +4072,6 @@ static int shmem_fill_super(struct super_block *sb, struct fs_context *fc) sb->s_maxbytes = MAX_LFS_FILESIZE; 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;