From patchwork Fri May 26 07:55:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luis Chamberlain X-Patchwork-Id: 13256582 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 A3BD4C7EE2D for ; Fri, 26 May 2023 07:56:09 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7B8466B0075; Fri, 26 May 2023 03:56:08 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 741986B007B; 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 593B5900002; Fri, 26 May 2023 03:56:08 -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 415986B0078 for ; Fri, 26 May 2023 03:56:08 -0400 (EDT) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 20544120117 for ; Fri, 26 May 2023 07:56:08 +0000 (UTC) X-FDA: 80831648016.03.DECA166 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf28.hostedemail.com (Postfix) with ESMTP id 6D2ACC0003 for ; Fri, 26 May 2023 07:56:05 +0000 (UTC) Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=LdiDWYPf; dmarc=fail reason="No valid SPF, DKIM not aligned (relaxed)" header.from=kernel.org (policy=none); spf=none (imf28.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=5oQ2gGbUsqL42uQDz21dyQWBbUA0px4CnOLURAD/lus=; b=E6BYNYk6r0jb2wlu76FayJqzMd9/LOIeY4GLolUAmDEWFsvyjW1Fz5l3l+zQxJAcHbSAvx mft3jAzKyFPoRBys7i4mDsN8i0DY/IQhKPlcBv53mtj7eiCoilVGu7jPC6j5JQ5kMn4CGq OaTtiQcdyerlTsGoCwiSwXmDeHgYFow= ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=LdiDWYPf; dmarc=fail reason="No valid SPF, DKIM not aligned (relaxed)" header.from=kernel.org (policy=none); spf=none (imf28.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=Yol0EL6dJxQeJvnzShc6A3FVooymheh5fkkESXaXM1ex4Erd1fWiVtJU6i2ZdyqL+N/wBI lYzWg6bJf6PHS6ysW4rVYk5qMMkFT7ARS166lb9o/X9VO4erUbpm8GX7oAOeyI8keyALS7 kCxf80I8hsDyoQRefrDjgm+dQ8+r4Tc= 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=5oQ2gGbUsqL42uQDz21dyQWBbUA0px4CnOLURAD/lus=; b=LdiDWYPfbsR2VwE3muTukBHf1n 2WKuZw7xVn16RN6k6Wo9ylU0o5DsPwzzrnruYbzYdoYyEpJt744EXDXhFgaq3aPLQM0XtiDj2f8FP 2plHBSw0sndtNX7DTHqerD4102mCieETYl1G0dRVa+cHO3vzNpp7xWDo8hVulJyMeNAOkZv4L98nW 6TmrmiHMZRz3tMGsyF1olHjbXr53o35bSOXIQ23JnCL7T/TEVq47iBber3uY3gk1HYKtkAuea4Vam CYKjwRSPO0HEhImDxfLN6W/tI67qgSTWbDSI9uMVp9MT7NiJOiaImnK7AjLb+fCQHpyGYE6dCefwT r8p56qVA==; Received: from mcgrof by bombadil.infradead.org with local (Exim 4.96 #2 (Red Hat Linux)) id 1q2SIj-001WZg-2T; 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 1/8] page_flags: add is_folio_hwpoison() Date: Fri, 26 May 2023 00:55:45 -0700 Message-Id: <20230526075552.363524-2-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-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 6D2ACC0003 X-Stat-Signature: fnpy3jaihr43466hz1ctfwkdcqkgioks X-HE-Tag: 1685087765-479923 X-HE-Meta: U2FsdGVkX1+nUZoP0JpVaO3mZF/1sccPy9ssgJCjhLHx+IHAkRgk9ALi2fmoCk/DTDd5RPd4BOlQRMmGEsNYSOPuuHr5SyV6du5rYwAS+t6aHESpUkzl6c80cCuQziNqgj04z3A4GqvT/3G8swoAZ7TC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VoGf8M3fn/chqC3XqMzSNEaNno3vqQeCgZo5Lutgc761eDcMWM5KE9qy4i6BCQkT6wLjWhb8fbnGAlFRtnjeIb6ZamG+KXb+S+W+ZR2oySyDo3hfW2xq/cpHDWTBdRQljtSic/OmmybbbHR7tkAuqv0gsXgFhC+lrtZn8nxwQEruZa9tUYblfrIQKdh6ME3D1/z+MvRrrRZUgL3nBgJdTlhYxVr6S0m7hPghf+o9ANUYpvle4fU5Dn3hoW/eMeR2AaHIDXmu+oRrEXLxwFc+RmROmSIOaFF011/I= 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: Provide a helper similar to is_page_hwpoison() for folios which tests the first head and if the folio is large any page in the folio is tested for the poison flag. Signed-off-by: Luis Chamberlain --- include/linux/page-flags.h | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/include/linux/page-flags.h b/include/linux/page-flags.h index 1c68d67b832f..4d5f395edf03 100644 --- a/include/linux/page-flags.h +++ b/include/linux/page-flags.h @@ -883,6 +883,13 @@ static inline bool is_page_hwpoison(struct page *page) return PageHuge(page) && PageHWPoison(compound_head(page)); } +static inline bool is_folio_hwpoison(struct folio *folio) +{ + if (folio_test_hwpoison(folio)) + return true; + return folio_test_large(folio) && folio_test_has_hwpoisoned(folio); +} + /* * For pages that are never mapped to userspace (and aren't PageSlab), * page_type may be used. Because it is initialised to -1, we invert the From patchwork Fri May 26 07:55:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luis Chamberlain X-Patchwork-Id: 13256608 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 0C356C7EE23 for ; Fri, 26 May 2023 08:54:12 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 68F1F6B0075; Fri, 26 May 2023 04:54:12 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 63F396B0078; Fri, 26 May 2023 04:54:12 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4E1496B007B; Fri, 26 May 2023 04:54:12 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 3A77F6B0075 for ; Fri, 26 May 2023 04:54:12 -0400 (EDT) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 09B44C030C for ; Fri, 26 May 2023 08:54:12 +0000 (UTC) X-FDA: 80831794344.12.926F079 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf19.hostedemail.com (Postfix) with ESMTP id 64D961A0013 for ; Fri, 26 May 2023 08:54:10 +0000 (UTC) Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=pl0lkfgo; dmarc=fail reason="No valid SPF, DKIM not aligned (relaxed)" header.from=kernel.org (policy=none); spf=none (imf19.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=1685091250; 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=BFzqBMItEZgQr8hCk3V5r6qhiIrmiWlEy/D5f4lnA2E=; b=Vk/GiyK1tSUXyuv5QULvN1Qlix6bVh7PmDoQAl+db45TBdKrEkxqgS5jYG5TQ0HHVd7ABf +UA86N9GQYGPVmq8sy3af2PZBtSCbxsCOYP80FPvR9Qckmx5kFvClrlVpEPj1tIm+Eqznk fwSI0IeC58I1J1/G8gaVsVpX1kB2nZA= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=pl0lkfgo; dmarc=fail reason="No valid SPF, DKIM not aligned (relaxed)" header.from=kernel.org (policy=none); spf=none (imf19.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=1685091250; a=rsa-sha256; cv=none; b=2sF1iGZhIDljl35irRmCthaF3hvXRC4ghd5st7VEOXNn+O7hr2INk/YYk5TJqOEwqHBcW4 KQ4XXlS9uAj5ZubDFfYUYp53qDOfDkhdTMmUNsz6mwAFPjkhpKCGYGK8o3HBHogybNuDW7 K5vgxjif0QIFQSlG4j3l9/AKpB/d2Vo= 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=BFzqBMItEZgQr8hCk3V5r6qhiIrmiWlEy/D5f4lnA2E=; b=pl0lkfgoZtZTjPznudekY5HK9v zjooPlpEqlCsqaFtZOKe2oOkIsjXewFeAQUggQ0csrXmSEg/LbbbdByZrqoA1JUWEE/IU4kNuymSJ 2PQI3eei+8ip/2EgJUWqJQ6fyolpTquvIN/Of0kbRh1En7RzoMnd5svO6VEDqQ5FNLqtaeoergkmA daR7xOt3hf8BaukiXWg6nQ/9K/UWIgZ0z4x0y7N0NMwIzBK8u4CbLDUJKSFkxKC+aR8FG7TqHLNvl 4k8J+vfFgnEXegtEH6jRcR3cZIkGRcxjX4qlO5MaTXcafNcifBPHAdfH3KlUS18vB41SdwI5z1HLe vCHZUpSw==; Received: from mcgrof by bombadil.infradead.org with local (Exim 4.96 #2 (Red Hat Linux)) id 1q2SIj-001WZj-2b; 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 2/8] shmem: convert to use is_folio_hwpoison() Date: Fri, 26 May 2023 00:55:46 -0700 Message-Id: <20230526075552.363524-3-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: 64D961A0013 X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: jts763c9k67ogkf8suuyucsuh3mepq6b X-HE-Tag: 1685091250-681535 X-HE-Meta: U2FsdGVkX1+B47mXApPn6OMaUEE5P0sDp4WYcgXqfK76sc1OHO4jC/dVHjgNa6l/4IQQOex9yAK8qS71DMcSCiVFYP3BET4QtC2q9GRkwtmRGYJuk5WJk+FxxW+K9dQXvOoJgkll5nzgz3LsUOlqvTXSH0xkx1wP4ydAI3qcHiz1fkzTUQ+rVL2FkbHYF8eYPbkLExB0Nxn7IFICb4prTcUoqRk1bNsjiA1Xh8ITz2CwzhoOaFhXBqHZR9eGd3rqi7GeySIN4c2zSWIm+uIpCH1GolwcHuRxzcSDQTVLRmO4cl4pi98iX0rntbSdGDrv3PM6U8xj5jvCdrPFg/yXS7DAPsusjfFbWpBZvDYEfsFVgsXaaUsOOw2E34PZXgZfs+eTqX7hOxGhYyUOIo7vdL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DksEK64ed1gQuc= 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: The PageHWPoison() call can be converted over to the respective folio call is_folio_hwpoison(). This introduces no functional changes. Signed-off-by: Luis Chamberlain --- mm/shmem.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/mm/shmem.c b/mm/shmem.c index 351803415ad2..a947f2678a39 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -3360,7 +3360,7 @@ static const char *shmem_get_link(struct dentry *dentry, folio = filemap_get_folio(inode->i_mapping, 0); if (IS_ERR(folio)) return ERR_PTR(-ECHILD); - if (PageHWPoison(folio_page(folio, 0)) || + if (is_folio_hwpoison(folio) || !folio_test_uptodate(folio)) { folio_put(folio); return ERR_PTR(-ECHILD); @@ -3371,7 +3371,7 @@ static const char *shmem_get_link(struct dentry *dentry, return ERR_PTR(error); if (!folio) return ERR_PTR(-ECHILD); - if (PageHWPoison(folio_page(folio, 0))) { + if (is_folio_hwpoison(folio)) { folio_unlock(folio); folio_put(folio); return ERR_PTR(-ECHILD); @@ -4548,7 +4548,7 @@ struct page *shmem_read_mapping_page_gfp(struct address_space *mapping, return &folio->page; page = folio_file_page(folio, index); - if (PageHWPoison(page)) { + if (is_folio_hwpoison(folio)) { folio_put(folio); return ERR_PTR(-EIO); } From patchwork Fri May 26 07:55:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luis Chamberlain X-Patchwork-Id: 13256584 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 F2314C7EE37 for ; Fri, 26 May 2023 07:56:12 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 289A4900006; Fri, 26 May 2023 03:56:09 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 14EA0900004; 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 B1BEC900005; Fri, 26 May 2023 03:56:08 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 8E6DD900004 for ; Fri, 26 May 2023 03:56:08 -0400 (EDT) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 60F67A0D67 for ; Fri, 26 May 2023 07:56:08 +0000 (UTC) X-FDA: 80831648016.03.BBCE669 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf17.hostedemail.com (Postfix) with ESMTP id AE2564001B for ; Fri, 26 May 2023 07:56:06 +0000 (UTC) Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=VIpL8dc4; spf=none (imf17.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=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=BlnfxGH65lfjvCr0EihUnLvC6Y04PW1nCflzWem/FI0=; b=sroNHDNAs2BKHsOW/ZXrPD4RgyBDBlh72YxuS6MSyucIsXZuuh4K3BykjBVyZ2f8vecsAH Kz6yMMdetrVhQU2dUb7t+y9VwK/ZJqgJ3JjJwcKm05AWqloeQDsz+D/omXMVGDrUvsdA7v zAAeQGc729VR/sbmnB9a7IFTEJtvZFA= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1685087766; a=rsa-sha256; cv=none; b=Bl6grI7tOIfscLj1mYKfhJtmiUHMoe8zx+PAMwIhyVlLlaIko/27J6RZplKV6Mbbogz80I 61yt1HIsKZ1OWi1yJ/OcSIIGleOaNES0n8IP+gg1JzqDlN/93dLuNMDfLTvGdlGVp9/X0L FB6UUNAPPNTmUjBpcPpnMXhKS6IhUQ8= ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=VIpL8dc4; spf=none (imf17.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=BlnfxGH65lfjvCr0EihUnLvC6Y04PW1nCflzWem/FI0=; b=VIpL8dc4hJnM3liOcBxChkT+dG qF/usCC/Wup5mmMJmU1p1ovRc9zKDrFe15DpGpCv7f4i3Mhkrt83uK85qdUAizZUBhBrM5tQg3muw w9qV6fP5s+45uiKWkhPQ/0p5NiELflVvmRKmEbG0pYPjuLPUHkYpxlLQuXAICLo5rrMdD6xkn+c+E rf9/tWnG/HUnZedSs/UfiehEuj5H7zzw7q2FxO93KyrsNh4jk7WDlLYwOr+uIr2u7nhmEjEfjoA1u SDKTfqMfG82ro8eQ/SBy9XVW9hsS7XM0naNEQIHkN+T3/w4EOl/8CsAlecOfKgU/m7H4ZeTp2v+wL YZeBlrZw==; Received: from mcgrof by bombadil.infradead.org with local (Exim 4.96 #2 (Red Hat Linux)) id 1q2SIj-001WZm-2k; 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 3/8] shmem: account for high order folios Date: Fri, 26 May 2023 00:55:47 -0700 Message-Id: <20230526075552.363524-4-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: AE2564001B X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: n6aiput5tnjif41wygtsi7e5dfmjd4p7 X-HE-Tag: 1685087766-279638 X-HE-Meta: U2FsdGVkX193/WiEpwxaiSAsFX+I0i/x4REnIbk9H98QmBB5vi/g1iX3RJevvWUUyvAd8mZRbigA+ErJv3/lFf+hdvaII6uXKUyZWW9MraeewvfHQ2R7ICr4r9g4aXbgMMRU1Ow9e+95P8y7XyOcBj9SfGbY0Q8l/kR2qf3USF8VNXhYOif4jz/OuR9r/5vlRaeA0WMLKq6xjR0EWpgKzatl8FeNV7wyImthCcVqnsCWkpC1jvCMInd5VOJ7b5RNq9/8TflI1P6DCv6QhzALdSf+4WW4frqmemRtKPCdqGBvD810rbTSsGcPaqb5UwO1KdHs0G2n1rLOIrMmvjTHY9JR/qEn1Pr2/WxNB0jbGnjtbCckDV6xaJF8uj3oQ47gNmxTLcivp2ZaZwsOG2GjCDXm3o1u93DOmUnaZXulfzm1DTlUPtxUUvMF499fdlpgakyyZLBPyjn0fp2hOTTRCSMl8h43TeuLO/t8LZyeuRkv+/zoGhs9wvR086Gxs8cBOKYywnSM4PHnWsyPUfZVV0gWz/T4Tz5+spTfuzuODEzZLZywKxRcOfxTDOFC06t+9Pnier2ey5jP0M75sts3x73kAFUv/nhdlEZ790kZ61WLa6kMqo37+GzPP1rE7JqjScNFZJi5giDrWmnHqR5vvsagvwBUnPT2SByadlsANrg4p6UFIec10Flohe6ur/KDmBRmc/4WQ0i5qgbeVqOlRMKnhm304gxJ1wVJt7rFNzdz0o4npGVzH7fdmfRIWVsRELuScvi6zurkTz0GrlLyilOXdAuNVz44WmGPhnEE3u9pqaqypl/mDJ7aC+EN45omRA39LGqHz3LBWtNTShk3Y8xvQ7NgbCjV/woPMVqOiz7AEAd4eN3TlXP4tqRNAIp3LZLG+vW0Ls1GJph+XHmlkNijsCpfWe0TYHvod/0FQBva4dDSC7R5QUGghrpKNi5yjAtgREC6PDPSbGxzs6V 2B1iAKlG wowvWsXqp4rMGCLVVGjwvkMK1g/DRMt/+/WSS6LKlPtg60EsOaCSOMcmGZxHMZoA0wcjDe19oZCql6fNIKlDfFPt9+xcTiP6LAJHcLgVrLXIHbVPEOWs/hLxok7B6V9mb4jUHBysNW42gL53/dS7Y9StE7okSQteOIPJBUKdKBLIX2qJcdXbFWlWl1wCs/Qvcgg89y1LlXViGUhTUUizzDbaBlw5lXrFvhmgbDN1xVtaD96T+8iHc47KTMsVWpG1aqzwvBfw1Jhpo7xFZmznDI9OCO20XHSySJ/zb8f82C3chHfB8bfBcrDquhMIUX5aQKEgnFyYt3ChtK6Kp6P/Z8eAqBUZUz0oC34Yp+gaJKgNOAnmgp6oLlQe0AEIz13RvpwA/EHXlUgB7+uxk6TIyt33aPrx7fp3XLWWbbBf/W8I+b2ybHERZXPD3f091RkD7ADzBo3gFokbIwuBU/fS7JNhckw== 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: shmem uses the shem_info_inode alloced, swapped to account for allocated pages and swapped pages. In preparation for high order folios adjust the accounting to use folio_nr_pages(). This should produce no functional changes yet as higher order folios are not yet used or supported in shmem. Signed-off-by: Luis Chamberlain --- mm/shmem.c | 34 ++++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/mm/shmem.c b/mm/shmem.c index a947f2678a39..7bea4c5cb83a 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -803,15 +803,15 @@ unsigned long shmem_partial_swap_usage(struct address_space *mapping, pgoff_t start, pgoff_t end) { XA_STATE(xas, &mapping->i_pages, start); - struct page *page; + struct folio *folio; unsigned long swapped = 0; rcu_read_lock(); - xas_for_each(&xas, page, end - 1) { - if (xas_retry(&xas, page)) + xas_for_each(&xas, folio, end - 1) { + if (xas_retry(&xas, folio)) continue; - if (xa_is_value(page)) - swapped++; + if (xa_is_value(folio)) + swapped += (folio_nr_pages(folio)); if (need_resched()) { xas_pause(&xas); @@ -938,10 +938,12 @@ static void shmem_undo_range(struct inode *inode, loff_t lstart, loff_t lend, folio = fbatch.folios[i]; if (xa_is_value(folio)) { + long swaps_freed; if (unfalloc) continue; - nr_swaps_freed += !shmem_free_swap(mapping, - indices[i], folio); + swaps_freed = folio_nr_pages(folio); + if (!shmem_free_swap(mapping, indices[i], folio)) + nr_swaps_freed += swaps_freed; continue; } @@ -1007,14 +1009,16 @@ static void shmem_undo_range(struct inode *inode, loff_t lstart, loff_t lend, folio = fbatch.folios[i]; if (xa_is_value(folio)) { + long swaps_freed; if (unfalloc) continue; + swaps_freed = folio_nr_pages(folio); if (shmem_free_swap(mapping, indices[i], folio)) { /* Swap was replaced by page: retry */ index = indices[i]; break; } - nr_swaps_freed++; + nr_swaps_freed += swaps_freed; continue; } @@ -1445,7 +1449,7 @@ static int shmem_writepage(struct page *page, struct writeback_control *wbc) NULL) == 0) { spin_lock_irq(&info->lock); shmem_recalc_inode(inode); - info->swapped++; + info->swapped += folio_nr_pages(folio); spin_unlock_irq(&info->lock); swap_shmem_alloc(swap); @@ -1720,6 +1724,7 @@ static void shmem_set_folio_swapin_error(struct inode *inode, pgoff_t index, struct shmem_inode_info *info = SHMEM_I(inode); swp_entry_t swapin_error; void *old; + long num_swap_pages; swapin_error = make_swapin_error_entry(); old = xa_cmpxchg_irq(&mapping->i_pages, index, @@ -1729,6 +1734,7 @@ static void shmem_set_folio_swapin_error(struct inode *inode, pgoff_t index, return; folio_wait_writeback(folio); + num_swap_pages = folio_nr_pages(folio); delete_from_swap_cache(folio); spin_lock_irq(&info->lock); /* @@ -1736,8 +1742,8 @@ static void shmem_set_folio_swapin_error(struct inode *inode, pgoff_t index, * be 0 when inode is released and thus trigger WARN_ON(inode->i_blocks) in * shmem_evict_inode. */ - info->alloced--; - info->swapped--; + info->alloced -= num_swap_pages; + info->swapped -= num_swap_pages; shmem_recalc_inode(inode); spin_unlock_irq(&info->lock); swap_free(swap); @@ -1827,7 +1833,7 @@ static int shmem_swapin_folio(struct inode *inode, pgoff_t index, goto failed; spin_lock_irq(&info->lock); - info->swapped--; + info->swapped -= folio_nr_pages(folio); shmem_recalc_inode(inode); spin_unlock_irq(&info->lock); @@ -2542,8 +2548,8 @@ int shmem_mfill_atomic_pte(pmd_t *dst_pmd, goto out_delete_from_cache; spin_lock_irq(&info->lock); - info->alloced++; - inode->i_blocks += PAGE_SECTORS; + info->alloced += folio_nr_pages(folio); + inode->i_blocks += PAGE_SECTORS << folio_order(folio); shmem_recalc_inode(inode); spin_unlock_irq(&info->lock); From patchwork Fri May 26 07:55:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luis Chamberlain X-Patchwork-Id: 13256587 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 D2627C7EE39 for ; Fri, 26 May 2023 07:56:18 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A2EEA280001; Fri, 26 May 2023 03:56:09 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 76E60900004; Fri, 26 May 2023 03:56:09 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2FD9C900002; Fri, 26 May 2023 03:56:09 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 08BC5900003 for ; Fri, 26 May 2023 03:56:09 -0400 (EDT) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id CA2FA809CB for ; Fri, 26 May 2023 07:56:08 +0000 (UTC) X-FDA: 80831648016.29.88984A3 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf24.hostedemail.com (Postfix) with ESMTP id 2D75E180007 for ; Fri, 26 May 2023 07:56:06 +0000 (UTC) Authentication-Results: imf24.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=Kg2LU+nC; dmarc=fail reason="No valid SPF, DKIM not aligned (relaxed)" header.from=kernel.org (policy=none); spf=none (imf24.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=1685087767; 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=YxL6e+4JH9PE9rFUlxHs00PcCr+DpK00UKDT/LTPvSQ=; b=GXt/bn5rnx0fhB5jSA1EyRkXd50C7HUR23mmuLErtSC4KygWtEZbzcSd2f0iK6BcUhTfEs cHs78kAqMsYU68nDqVKgoa9LygGSe/ftaIGJVqfxlhTJOtbKZYIii3LgiEYB5dllEa3deh YjDSeu0qduHnDhV9SGFboGebDGfWZuE= ARC-Authentication-Results: i=1; imf24.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=Kg2LU+nC; dmarc=fail reason="No valid SPF, DKIM not aligned (relaxed)" header.from=kernel.org (policy=none); spf=none (imf24.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=1685087767; a=rsa-sha256; cv=none; b=DkPL9zd2eqWgmzx87xPAoDm/Fi8i3BMr/YqSnsfo/G17pIPG7kqpXsPqRHe8mD/HKyPw/W np4RZ0fA9AFulkpDJ4lp1MQj6Gz++HhfuLccvMV2RBGX3AnH2nzBf1KzZykMl+NAncLVoo NC6g8fHoOqpz9E0eKZEDegdASVKbhxU= 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=YxL6e+4JH9PE9rFUlxHs00PcCr+DpK00UKDT/LTPvSQ=; b=Kg2LU+nCS6V/WHsqu4Zv73IGyh 2nlfdecqYINfvpx4snQrDk/Ga8HLc6qjEXZHKcFttUQa0Y65BUtUR8e+TmZmO6URv5/RN8bEUsQ/j iVw45tdhtJhhQndIluIWdstGdaR+9nsXfvAtKQ1CeTUYBs4ztqd8vRK0IhC4ppv0agrsQsa34+qcK CjlttKCbB7H76wb16hV44vAVBPFyLRn9vqDiqklO6qjnGGh0vDSiN6Ww0sOPKz4N5DRihdbEA8IGA sd9KbZHM2C2FS8qRAa3UYD1HTQlEnOFaMi/2JTLsghE4DfJfxxQqGPgyrb+ljsHjBbVeaWPxQqQ6P ETKUWerA==; Received: from mcgrof by bombadil.infradead.org with local (Exim 4.96 #2 (Red Hat Linux)) id 1q2SIj-001WZr-2s; 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 4/8] shmem: add helpers to get block size Date: Fri, 26 May 2023 00:55:48 -0700 Message-Id: <20230526075552.363524-5-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: 2D75E180007 X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: wmjdxzb9acyza8ss6j685w3c4yidjxr5 X-HE-Tag: 1685087766-913342 X-HE-Meta: U2FsdGVkX1+ZwD/rCtHJndEDSanHV1mJuHlF6TIMSjl5jQ2R6Fq0x/gfNYpaNtc7FRiqu4qC1xtr1EHfbbyatYNfh6B1/Ud+81Hb9ewvfrj7fYZIMXH2C/mhlphJovIPcH72aW5XYFjshEtHoEQCDwFyahgCTa5oif26lJilw0m4HGMxI/MtNd7URH22ZT06tpaY4LXstEwsHwJtbfh8JVhP7wjVrYq54WpwBsqjinwfQWBwUjYAwlOVsYwqB3z06zXClME0cx7VFYHoWcQ3qdsmL5XOUqbLwYEj0E2vPUc8+L30bQc3uW/2IzngZym3Tq8UvDDkFL2NIs/3EMHMNKoNDNW32WBBfxOLmnO2k/7KPCY4aIJaGNfqxoYUNqfs8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w== 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 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 --- 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; From patchwork Fri May 26 07:55:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luis Chamberlain X-Patchwork-Id: 13256583 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 4E1EFC7EE31 for ; Fri, 26 May 2023 07:56:11 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id AD5AD6B007B; Fri, 26 May 2023 03:56:08 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 8C8F1900002; 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 656E46B0078; Fri, 26 May 2023 03:56:08 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 494F26B007B for ; Fri, 26 May 2023 03:56:08 -0400 (EDT) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 180F01A0CD1 for ; Fri, 26 May 2023 07:56:08 +0000 (UTC) X-FDA: 80831648016.08.2EA0439 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf20.hostedemail.com (Postfix) with ESMTP id 0868F1C0014 for ; Fri, 26 May 2023 07:56:05 +0000 (UTC) Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b="dc/TfmJ1"; dmarc=fail reason="No valid SPF, DKIM not aligned (relaxed)" header.from=kernel.org (policy=none); spf=none (imf20.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=X5+iEoQSxU/Osj6DTwS+zZOMGO87395DKsZwMMPd0uo=; b=1Ui0L/1j1W5cHDAbNNPifBsppcDXxvtp21ihxUcMHD7w3ZkdaW6h8c6DSdpADAdMiVZ/kH ygkMbNIuB1JRoRcFIJA1AbH9Q9o5afPKbtqDMA72rAG1n2kQ+1hD7a6FqLEz2aOR9xoiBz R59WjKwp6yVH3jj7OCw5Fa/wv/qY/y4= ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b="dc/TfmJ1"; dmarc=fail reason="No valid SPF, DKIM not aligned (relaxed)" header.from=kernel.org (policy=none); spf=none (imf20.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=GxN/iFH8dTCgv0TG9huuEy2MM5iZVED3fGPN4zpGi4QNzNV0AycsEsS37lVuZSB7yqJKAM DeD/PPIBk+pjctdS/wJwzYY2JDeX2fsfkay5o1F/aWWvDuKqlmPiG27c39iUXumhUNdeVo kj657eVRJGMunuXJj4umNvuP49y/R+U= 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=X5+iEoQSxU/Osj6DTwS+zZOMGO87395DKsZwMMPd0uo=; b=dc/TfmJ1je+wYNn6ZVghaEpsuV hNonEGR/rf9ZvbCAtb5luxqhaZt290ieMP7zWmNl7lupnAdO9iA0HyVxMj1G/RoRzCtvY/M6prI9u lYnSzpeG1xbU/2p54uZWSQ88A0ZYpHndBkZvInbp17tTfW9XSan71VRDhfNHlqoumaNtcu88Wp3k4 v5FcBIFu+40VmHsGhbu9Jdd5zPt1PTCK0tbUA93ZZq2etcKHzdK8JGRPp3spp0ExpIzmQerGEiH7Q xB3QY73a5kLbfciwvYDJY/W2Eb3WRU0xJdfAs6PfVoe8OpyRuSafffwUrlDb8+X5ApvoFmqa5E3Ld TAz2AXvA==; Received: from mcgrof by bombadil.infradead.org with local (Exim 4.96 #2 (Red Hat Linux)) id 1q2SIj-001WZu-30; 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 5/8] shmem: account for larger blocks sizes for shmem_default_max_blocks() Date: Fri, 26 May 2023 00:55:49 -0700 Message-Id: <20230526075552.363524-6-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: 0868F1C0014 X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: 6js1ungmf818iqctwiprsqzyiiim9bsk X-HE-Tag: 1685087765-241511 X-HE-Meta: U2FsdGVkX1+jav/O4jzrHNJu4dTEPO0CVhgFwgfvOxzcg6z2rGffhXFsdGczCZ4IXLUqAQvIndwbM+ysWGboSf3Mp1mcdFbUi3zjR2ncqJixMtEoSWSH5UMOWXSH6MVOwRNXODKZmFHUPoZU/feWWNb/OmIfbyKpcipZQCU4UwvFThoi09eX4iDMbYKYEp4IQuecvtRW7keOcodCCKzmtpYiztrfdBOCL4YkMegAnSUn7jm3NJ2X7yX/pu1OCokm+czcz2KKtH8v9sV/xyJklQsjxWSMYZXBumRRij4LRL2YdSCN32S1ld7a5jDaeifkT6hDjZVi7ENCEMHQXOh0CVFVKfAhh1HUOcFUpTkytxrM3i2Y6UrmotdFHSKqwoVR6Z2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J9zq1sb/yrwUjdlQw0yxTQPRcUyMY/+9z8q/L/a5QoZIuI= 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: If we end up supporting a larger block size than PAGE_SIZE the calculations in shmem_default_max_blocks() need to be modified to take into account the fact that multiple pages would be required for a single block. Today the max number of blocks is computed based on the fact that we will by default use half of the available memory and each block is of PAGE_SIZE. And so we end up with: totalram_pages() / 2 That's because blocksize == PAGE_SIZE. When blocksize > PAGE_SIZE we need to consider how how many blocks fit into totalram_pages() first, then just divide by 2. This ends up being: totalram_pages * PAGE_SIZE / blocksize / 2 totalram_pages * 2^PAGE_SHIFT / 2^bbits / 2 totalram_pages * 2^(PAGE_SHIFT - bbits - 1) We know bbits > PAGE_SHIFT so we'll end up with a negative power of 2. 2^(-some_val). We can factor the -1 out by changing this to a division of power of 2 and flipping the values for the signs: -1 * (PAGE_SHIFT - bbits -1) = (-PAGE_SHIFT + bbits + 1) = (bbits - PAGE_SHIFT + 1) And so we end up with: totalram_pages / 2^(bbits - PAGE_SHIFT + 1) The bbits is just the block order. Signed-off-by: Luis Chamberlain --- mm/shmem.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/mm/shmem.c b/mm/shmem.c index c124997f8d93..179fde04f57f 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -138,9 +138,11 @@ static u64 shmem_sb_blocksize(struct shmem_sb_info *sbinfo) return 1UL << sbinfo->block_order; } -static unsigned long shmem_default_max_blocks(void) +static unsigned long shmem_default_max_blocks(unsigned char block_order) { - return totalram_pages() / 2; + if (block_order == shmem_default_block_order()) + return totalram_pages() / 2; + return totalram_pages() >> (block_order - PAGE_SHIFT + 1); } static unsigned long shmem_default_max_inodes(void) @@ -3905,7 +3907,7 @@ static int shmem_show_options(struct seq_file *seq, struct dentry *root) { struct shmem_sb_info *sbinfo = SHMEM_SB(root->d_sb); - if (sbinfo->max_blocks != shmem_default_max_blocks()) + 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()) @@ -3987,7 +3989,7 @@ static int shmem_fill_super(struct super_block *sb, struct fs_context *fc) */ if (!(sb->s_flags & SB_KERNMOUNT)) { if (!(ctx->seen & SHMEM_SEEN_BLOCKS)) - ctx->blocks = shmem_default_max_blocks(); + ctx->blocks = shmem_default_max_blocks(shmem_default_block_order()); if (!(ctx->seen & SHMEM_SEEN_INODES)) ctx->inodes = shmem_default_max_inodes(); if (!(ctx->seen & SHMEM_SEEN_INUMS)) 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/lbWFAEB0iQ+9cpyq8IOky+fuJKyQHItwc1PMAgfU2+1xvhRLVOAb7Xgfa+Rj1v311sFwwTxNyYdGd07orb+17qUPu85hISysZSbCuGQVxUt2p9pyssa+MCJLSxw8F6Mvv1xO1Bv4ePlfgwt4tLZwveQEGmKoRzZ3tt2TfBsIS2vZv87OyxzNMAKXIswSfFqMYVxvb/ZiR/2vCNJOAq/mMTCt5TKi/qiKRZ7k/HQxF+9HSb42wMbGv3E2wI9ixYrt3pwqBdhVspeK4ZRyH+w+c+5lasA5g28UIuxFZVdCwzBEewPdRwEXCVo/dqlB67FMsP2TP6LUH7BYc358zNYq9uDmvTzzXQssGhFionagDr9TNDoUfeu7Jdv4bTNjfMoiHJcL7yFgLhLEP17/1msEtYcGqgxNTtkNTPU/WaAHMAiovi86AY6i98wMV8/9DPjy4oSfEClL/7kKuNEf8/dMO/CYJ4RJMdjaTQ1Csb8pLBxdzG3+On0RjDy6ilBhGIuO01wLnqCedx+MpOPz9X0cQXBANH+8CmTEWf1bh4FPE37EpkiJvEu2IMhjIKX0Yd6wNHSatVvdUT+G+Fn8NjPGMKjn3zz6wZ5volF2cGNFyiv38UVAwMH5rFyDmMJliwqWC3UamjOTQNkNWO80Lr/6LIldZ7Km/s4gZKw3wB1BhVu/5GnOQ1uYHBWP3fMjo+ZtJLU5DQmBxWFvd14ikDTg828qIC02KK9uA3aZaOavmOFb4Q6tYk0KFZX7b1zJDuBZi9hDEGGUz1lfwUKToSGIX2VnpGHNg/LCaUfb5dTSWvPBpQliQJIc8MXyMgaudgjMEmuG+yWbnbircsc4LrF5cPlZmLau X02+kWC4 G8ISdUD3tZvzURaGn66Wi5tLLhJgKrAP95l+Quxo6eatoX5gKUzmovrptAaH0XKJEqAWOYF2ZUYydT1OSt8mM4yRT1tsHVSaoLT6xGDmLd+Q0qvIExoPkRbl2jV3hGgq04JJ66KjvCcOjHlWAGvBTwXJLN/UGpyV53bXHYlYhK7KOpJEHkhrDzPdgqGzJTRXSmGYFUkP4KtWf5jxnb75XsbZSbpqL8GAUXrIpdbXkQQ8oHiK6DUWIEpil3zFv/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; From patchwork Fri May 26 07:55:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luis Chamberlain X-Patchwork-Id: 13256585 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 C9320C7EE32 for ; Fri, 26 May 2023 07:56:14 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 508D9900003; Fri, 26 May 2023 03:56:09 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 2875B900005; Fri, 26 May 2023 03:56:09 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D5EBD900006; Fri, 26 May 2023 03:56:08 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 8DAE0900003 for ; Fri, 26 May 2023 03:56:08 -0400 (EDT) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 5B9031A0CD1 for ; Fri, 26 May 2023 07:56:08 +0000 (UTC) X-FDA: 80831648016.04.B240F82 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf25.hostedemail.com (Postfix) with ESMTP id B9A6EA000B for ; Fri, 26 May 2023 07:56:06 +0000 (UTC) Authentication-Results: imf25.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=E15C01rv; spf=none (imf25.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=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=1AhvaQEykxRfZlsh2c4Dug9Lp7odXzIMf8TvoDKNOGw=; b=FL9QTx+TIN+mBW/8mOmznq6qaay7uru1BTyZOt14BtrW4IivV8XmJ/BA4WlWmTH4vU6JmT fJ8t1iy8fcH44t5pk3sUKEO2PFpl/fOS6pwEaVRdl1iB9Gwb1khkbH9Gg5JeRqVmOunip2 i09wNKVhsAfcPceYfMRa5lrZ9QUcwzs= ARC-Authentication-Results: i=1; imf25.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b=E15C01rv; spf=none (imf25.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=1685087766; a=rsa-sha256; cv=none; b=a54fBkPDd3y7TfQUg6szd3USNXpjWnGd9M+IRxkxvlgd8Fs9tFnJhoL+41bLUFMlgMR8Ro pkKnB0SUdNPUfE8cAtNtbEga0AT/CTzbCB54FzfTeF1V7qgrDa7N+F+wUvwqR4Gs+TDjQZ y9nQHcFCEXv28C2s3ql6D8QgrxACd4Q= 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=1AhvaQEykxRfZlsh2c4Dug9Lp7odXzIMf8TvoDKNOGw=; b=E15C01rvh8qJUhFpengqZNed+/ epNw4ByYQ60Hpq6UA2LISl8vHwk8zLvgERrEfiFp3oNWfTARAPEe7kg6OrC9oLUNypcBwftohyOnf +kL6CMebLub5C8stfDZczdk0CnTJ2fgF/4xjbR58muAKAcLkhsx0UFbRGlIlzEGokmwyiQyPBh2wB bKTkZouYgrnXR+ek49+JL+J0BZFyfmAg080+gR8oRXI7sFUtk8hhGst/KBWs76xcaNZWzGmiur9Ci XJdyxvsilz8bhnSS0ZbAagO3yezv4DQzoPICC07AQImRF3Kid2X8VB9bGdRAtSfY4kFBchyEre3KY lgFf96ig==; Received: from mcgrof by bombadil.infradead.org with local (Exim 4.96 #2 (Red Hat Linux)) id 1q2SIk-001WZy-03; 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 7/8] shmem: add high order page support Date: Fri, 26 May 2023 00:55:51 -0700 Message-Id: <20230526075552.363524-8-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: B9A6EA000B X-Rspam-User: X-Stat-Signature: uk5xg1suzgedsjg93pzprtbeutyqcacp X-Rspamd-Server: rspam01 X-HE-Tag: 1685087766-420248 X-HE-Meta: U2FsdGVkX18Ar4uM2vugijVeYMlj5LQ1dRLvaKyX9odNZJ+XrVx4k4pxfYrPJ/VmGbv62NPnqeANrta1WrUxnnK+GOytG6b/5XynRMe+2YMX7wEETS6cCjNoCFbccqQF5MOWaUOXKSgDDTdLgCxmhZ2x5WyI5DpKRgSf04x87s1D+CCK0bFDIv13PwndZqpAb7V2dh87ieHj7P1UdOskwv63OfMPdSSp8iByWRh6bdRs3jAnB1gNnvSO+QUgaUJ+20zDudNoPgzLmq7oc+7jz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RqBGjX+FDuxjwZX7OxD3E7L/vuYLwfjSbVrFGftstsmIqZJaBPM3p/sOyC/EK0U+f/da7sNy4cmf0VC3LHPRAeK39B5eudKPH9g== 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: To support high order block sizes we want to support a high order folios so to treat the larger block atomically. Add support for this for tmpfs mounts. Right now this produces no functional changes since we only allow one single block size, matching the PAGE_SIZE and so the order is always 0. Signed-off-by: Luis Chamberlain --- mm/shmem.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/mm/shmem.c b/mm/shmem.c index d347a5ba49f1..080864949fe5 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -1623,9 +1623,15 @@ static struct folio *shmem_alloc_folio(gfp_t gfp, { struct vm_area_struct pvma; struct folio *folio; + struct inode *inode = &info->vfs_inode; + struct super_block *i_sb = inode->i_sb; + int order = 0; + + if (!(i_sb->s_flags & SB_KERNMOUNT)) + order = i_sb->s_blocksize_bits - PAGE_SHIFT; shmem_pseudo_vma_init(&pvma, info, index); - folio = vma_alloc_folio(gfp, 0, &pvma, 0, false); + folio = vma_alloc_folio(gfp, order, &pvma, 0, false); shmem_pseudo_vma_destroy(&pvma); return folio; 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/6HSGKMG5KU/jhz5GjbpP3hNK5Di6JKTcwKfTADaE5TmXIWCr9n0BckmhMbRRjcNNgXYOrmfig+pcPBNZsSzf/OxSEjil2TNcshA+tby0nHuBOMtNtGPh6B6yQb9Kq+CgcA9IIr9XKlh4l9JIioFgxTxcSNgjBHFJ3pbzv1C4n+0d1fsSFX5WciXaTkC0MpYNViCv5rMUxCLqe15BfrNf4ZnJ5CnD6cnNhHxktAQj9i342Yo3695KJHg39iP7y7IU0TsaSU8dnHEUx8DL4CkyLrWi+DxvM+m2w41xQBC2rMhtvshylgQO60N+sGRd3COsFunajEO2FO5FdWgP7eU0n5OSdISiIMmG+B8/MhnbeQBUrq3S8zXxj1zYKFShN2dEwOKl0uvg2VEWSMUHWGEnTQ7cZwmKyWOidwt8bj+5a87GYvBCz293Lz3mmFmkX4vLNNAD3QYdlrkcBHWtPodvU3YdjM80n50b8/pTMzJgGKjZGXNDHQYVF4Zn2ppONz38idrQ8qCjSbbrR25yRgoRsbCpO5o5layNDAahh9cgFG47nO3VwBda/QMV0aAam7TG4IGUaHxQuHufsoSxakOpY4wiHAcpqbNaKnoO7UqfZJjbczD0cQHK7bl5JcnKlIBX0VuU3CiZpaUuqHWNqQZUOSztfGGWp4cLrM4If/28Qi7lScOCs57hwB3LLA3DdikS0781KhZA70d6/BiTwyXKGclkcy8PtomTCvVA6+WiJHG9zzc7ECYQp7VjpfhT/kjIxJuDZxFl+fezLPmJ9FdK7NEz5z+qNfpyd8K6d3Fjfgi+tWQombx49I6k/tEjrj1bFX63KQo9DCuYfS pT7BBI4w JiZeR5hpvfGHwGJTGiJgZLe6lWa8qlrE9AUUBwfIYG1Q1ie1oRU8iRqDkHRb8b+ekE+nAmGwVCvmQ4jvJ1yskG9d8I0+WJbR+MCu7m/Mv4iGL1fnp/1+96QLITnwwqgv/B/1ahLf6+9lkqEi0xENd6FfC2lVGY1adtmhAIOXfoY1VMYNs0J8vM5j2ou4hGiJiihuC52UvtiV53gNfW26rPxkdR6jBMK+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;