From patchwork Fri May 26 07:55:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luis Chamberlain X-Patchwork-Id: 13256581 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 A0053C7EE23 for ; Fri, 26 May 2023 07:56:08 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2D7D26B0074; Fri, 26 May 2023 03:56:08 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 260866B0075; Fri, 26 May 2023 03:56:08 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0B2DC900002; Fri, 26 May 2023 03:56:08 -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 EFE116B0074 for ; Fri, 26 May 2023 03:56:07 -0400 (EDT) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id C45531A0CD1 for ; Fri, 26 May 2023 07:56:07 +0000 (UTC) X-FDA: 80831647974.09.7D3B31C Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf12.hostedemail.com (Postfix) with ESMTP id 19D5240005 for ; Fri, 26 May 2023 07:56:03 +0000 (UTC) Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=WnxjNjU6; dmarc=fail reason="No valid SPF, DKIM not aligned (relaxed)" header.from=kernel.org (policy=none); spf=none (imf12.hostedemail.com: domain of mcgrof@infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=mcgrof@infradead.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1685087766; 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=NWUBmxTvJYmgTPK2izgiLtu8bfX6PD49E6ZFMW3sIA8=; b=wQFA6O/YAjmYwLCZSIIb/rPJMvy0EJ05iYBgrrZ1Fat0yeVTZkB2L9THEOjcuCiHyPmpXs vHJ5sLWk4Kp2G41lgc/ihJIOmoVbdF5UR0Ezmqz1gYt/Cuq+VGkupkjC+6Tmh/zE8Jc/b2 h8eHlEav8YANvySufS5t8V/1LdzRc+k= ARC-Authentication-Results: i=1; imf12.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=WnxjNjU6; dmarc=fail reason="No valid SPF, DKIM not aligned (relaxed)" header.from=kernel.org (policy=none); spf=none (imf12.hostedemail.com: domain of mcgrof@infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=mcgrof@infradead.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1685087766; a=rsa-sha256; cv=none; b=e5Q5oMZv7aMdmVE2PabMzN+Ie3xZV4JZCXfOnNroq06erKrq0/ju1FhtiQ3vB6F0qkAtTD w7wfLK1Dmlz0GSGtewW4ib6pjwSdJsmn+wzSj17dERoMNCKTcAGmZIyNoGeOkcQGM/DWKw DtWnNMS82jKFDCNrrBmiGduR1hLOpWI= 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=NWUBmxTvJYmgTPK2izgiLtu8bfX6PD49E6ZFMW3sIA8=; b=WnxjNjU6yVkEoG/2yJlDTptWs+ IG4CY/nxbwF8l4vRcxt8rVMn+9Dke0fLaHt3F5PKjYHOCuggCCfmh6i38zB5Gx5JOJLWasGkYjxH0 QrvgHFxs3p0IHA4D2naeXZvojSzJjquvJ8IOoTDRqg0KY+GyKnG89UoXRje+tPiuSXfkrionjwvMZ WwhJR2wNNcLjSsxhHhxiIqnT8Nk9scxo6r5Gv7Jlz/qvE29q34PedlMGogFKJpYEFffHm4TubN+Al +neu4w739RAZ/MuaXB06KM7rPauhpBwSTQwxfDsOHTDhLQFP7KD43o6lXsgWZlGEsM6hpYLW48oqt TUayW7nw==; Received: from mcgrof by bombadil.infradead.org with local (Exim 4.96 #2 (Red Hat Linux)) id 1q2SIj-001WZw-39; Fri, 26 May 2023 07:55:53 +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 6/8] shmem: consider block size in shmem_default_max_inodes() Date: Fri, 26 May 2023 00:55:50 -0700 Message-Id: <20230526075552.363524-7-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: 19D5240005 X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: fwbi9cc7os6dmhxuunjkmjushozpoqgp X-HE-Tag: 1685087763-329223 X-HE-Meta: U2FsdGVkX19C2lEPEOlZV1q+Nk92/xVY7pn+Cv7ueOKF/DS/LHGmmapY0Oawj/ccy2QUyCpcbNgqQbMn6ndxZ8mmWsO9c2fqcilr/DuVAyuIJ5T+cglJTq/l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4KtWf5jxnb75XsbZSbpqL8GAUXrIpdbXkQQ8oHiK6DUWIEpil3zFv/V/LXClGthxzk5kk3BA9K4ZuO3BI5qJFYTR5nE+U95Dmpb6bX5dB4lsvj84G+47LUfPXSI8I6mWKSUy46AM0EHoAGIEizOENq79B/BOY5q5pDVMh+cUfkZkgDQ6D6jVqWKRl/218sHSOu/ZZYExBLb6YHaeXcziNme1PCCsiOfmMG3iRmFgvX3a6Zng3ATNzQNeN9KkqYjXH2BKUnm7koiR6c2HsuRSQN+/71JqLWDQAjppUXkD8okdS5NcAYhfUQt84ou0rARYap+VAFUE= 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: Today we allow for a max number of inodes in consideration for the smallest possible inodes with just one block of size PAGE_SIZE. The max number of inodes depend on the size of the block size then, and if we want to support higher block sizes we end up with less number of inodes. Account for this in the computation for the max number of inodes. If the blocksize is greater than the PAGE_SIZE, we simply divide the number of pages usable, multiply by the page size and divide by the blocksize. This produces no functional changes right now as we don't support larger block sizes yet. Signed-off-by: Luis Chamberlain --- mm/shmem.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/mm/shmem.c b/mm/shmem.c index 179fde04f57f..d347a5ba49f1 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -145,11 +145,14 @@ static unsigned long shmem_default_max_blocks(unsigned char block_order) return totalram_pages() >> (block_order - PAGE_SHIFT + 1); } -static unsigned long shmem_default_max_inodes(void) +static unsigned long shmem_default_max_inodes(unsigned char block_order) { unsigned long nr_pages = totalram_pages(); + unsigned long pages_for_inodes = min(nr_pages - totalhigh_pages(), nr_pages / 2); - return min(nr_pages - totalhigh_pages(), nr_pages / 2); + if (block_order == shmem_default_block_order()) + return pages_for_inodes; + return pages_for_inodes >> (block_order - PAGE_SHIFT); } #else static u64 shmem_block_order(struct shmem_sb_info *sbinfo) @@ -3910,7 +3913,7 @@ static int shmem_show_options(struct seq_file *seq, struct dentry *root) if (sbinfo->max_blocks != shmem_default_max_blocks(shmem_default_block_order())) seq_printf(seq, ",size=%luk", sbinfo->max_blocks << (PAGE_SHIFT - 10)); - if (sbinfo->max_inodes != shmem_default_max_inodes()) + if (sbinfo->max_inodes != shmem_default_max_inodes(shmem_default_block_order())) seq_printf(seq, ",nr_inodes=%lu", sbinfo->max_inodes); if (sbinfo->mode != (0777 | S_ISVTX)) seq_printf(seq, ",mode=%03ho", sbinfo->mode); @@ -3991,7 +3994,7 @@ static int shmem_fill_super(struct super_block *sb, struct fs_context *fc) if (!(ctx->seen & SHMEM_SEEN_BLOCKS)) ctx->blocks = shmem_default_max_blocks(shmem_default_block_order()); if (!(ctx->seen & SHMEM_SEEN_INODES)) - ctx->inodes = shmem_default_max_inodes(); + ctx->inodes = shmem_default_max_inodes(shmem_default_block_order()); if (!(ctx->seen & SHMEM_SEEN_INUMS)) ctx->full_inums = IS_ENABLED(CONFIG_TMPFS_INODE64); sbinfo->noswap = ctx->noswap;