From mboxrd@z Thu Jan 1 00:00:00 1970 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 E4782C83F07 for ; Mon, 7 Jul 2025 14:23:37 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6EB446B02E6; Mon, 7 Jul 2025 10:23:37 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 69BA66B02E7; Mon, 7 Jul 2025 10:23:37 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5B1866B02E8; Mon, 7 Jul 2025 10:23:37 -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 47A276B02E6 for ; Mon, 7 Jul 2025 10:23:37 -0400 (EDT) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 1D605C011B for ; Mon, 7 Jul 2025 14:23:37 +0000 (UTC) X-FDA: 83637686874.19.8C4EF3D Received: from mout-p-103.mailbox.org (mout-p-103.mailbox.org [80.241.56.161]) by imf13.hostedemail.com (Postfix) with ESMTP id 17EA32000D for ; Mon, 7 Jul 2025 14:23:34 +0000 (UTC) Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=pankajraghav.com header.s=MBO0001 header.b="MehnIVD/"; spf=pass (imf13.hostedemail.com: domain of kernel@pankajraghav.com designates 80.241.56.161 as permitted sender) smtp.mailfrom=kernel@pankajraghav.com; dmarc=pass (policy=quarantine) header.from=pankajraghav.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1751898215; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding:in-reply-to: references:dkim-signature; bh=s4EZdHf+U3R+v43lcZijWizNqsqKvK4IRVcr5nu5cj0=; b=ekwfbdXjChG8xjlq1qcbuJYAAddi5WqVS3YQwgjvjlK33/DOuUmvYraLVG+Ou584Pffrgc MlnjeymafJCnhFEb1IerzPc/OJXxu57Nw6XVQCy/ja2gH704lW8cuNjr/M2jJISRFNkXzY utkDSKS0mrPEcL4ystUj2ywcnOt5+JY= ARC-Authentication-Results: i=1; imf13.hostedemail.com; dkim=pass header.d=pankajraghav.com header.s=MBO0001 header.b="MehnIVD/"; spf=pass (imf13.hostedemail.com: domain of kernel@pankajraghav.com designates 80.241.56.161 as permitted sender) smtp.mailfrom=kernel@pankajraghav.com; dmarc=pass (policy=quarantine) header.from=pankajraghav.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1751898215; a=rsa-sha256; cv=none; b=vL1fcfGtv5FdiwE3Zvop0wrWEJSxuczl6pg/XxxK3+9FE5vQ4jhaU9EG/ooz5saNDdXtG6 hmPXrV3PB4vrjatECQBIsbCIlbnvhcZEivB8BsxGqLCYZK6CI5hc/7IACkHo8oZPThftm7 iack99DvnHyawuSzP2Str+JNArBzosc= Received: from smtp2.mailbox.org (smtp2.mailbox.org [10.196.197.2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-p-103.mailbox.org (Postfix) with ESMTPS id 4bbRLB14fvz9tCk; Mon, 7 Jul 2025 16:23:30 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pankajraghav.com; s=MBO0001; t=1751898210; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=s4EZdHf+U3R+v43lcZijWizNqsqKvK4IRVcr5nu5cj0=; b=MehnIVD/KloRf9rrD61bo8uVvO5mi99kSgMuUHeUYXOq1A2yxGunRzTwFMljMjGdO3rsq4 k78IzmiGbP2h2P76t6xsZOb4fGQgYFde80jo21p6JNNwqoTMjKQw/sZW2ykSSNq7su0VrS 3JObETkyU/36rBzUEKeXhn3//bturtQRiYGi/g2CeeEIL6XfqDdADkRFgSjuhQBhd01HlL fD0+wRlqHp9eWWZBEkUgNgwTfd1vUi2VbSQEpXffRiw5zX6Am92eIxHm6snQlXBeylxkOk aUR/7HreJ2iBQWDgQYtNyQRLg83nDzPRFd5YzQeNMcwJRPe1BN/UrM54QIfV9g== From: "Pankaj Raghav (Samsung)" To: Suren Baghdasaryan , Ryan Roberts , Baolin Wang , Borislav Petkov , Ingo Molnar , "H . Peter Anvin" , Vlastimil Babka , Zi Yan , Mike Rapoport , Dave Hansen , Michal Hocko , David Hildenbrand , Lorenzo Stoakes , Andrew Morton , Thomas Gleixner , Nico Pache , Dev Jain , "Liam R . Howlett" , Jens Axboe Cc: linux-kernel@vger.kernel.org, willy@infradead.org, linux-mm@kvack.org, x86@kernel.org, linux-block@vger.kernel.org, linux-fsdevel@vger.kernel.org, "Darrick J . Wong" , mcgrof@kernel.org, gost.dev@samsung.com, kernel@pankajraghav.com, hch@lst.de, Pankaj Raghav Subject: [PATCH v2 0/5] add static PMD zero page support Date: Mon, 7 Jul 2025 16:23:14 +0200 Message-ID: <20250707142319.319642-1-kernel@pankajraghav.com> Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Stat-Signature: zndp5bdtxpiu1am5o5oendi1k1zq6rai X-Rspam-User: X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: 17EA32000D X-HE-Tag: 1751898214-548600 X-HE-Meta: U2FsdGVkX18IPVTTZQEGR+csvAhwIMqdJujmzJcjTWOaRMXMNApzTid3+iJQZSW54ColbJSdFQ0oCQVCrqX0GHTK+BUc0pio42GrOTNptt9cwuh7vRu8b9wKrcW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StC0kGDa7fI8Xg1gN8ncvztRclmuucn33Mjo+mjSIcZ2UuJHSbM71MS6oTML/mR+bWCh+fxgwIcapdfSX4JguC72pBcIhPZw4PuR+R0OWcDvFBzOVRtB7nHnayl0ysxbX7AVBrUV5Me1JepunB1oKp177WvOZHwZqxE/XRFT45ecl01gHFU/O2TMHZIyH5lwYWIvGU= 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: List-Subscribe: List-Unsubscribe: From: Pankaj Raghav There are many places in the kernel where we need to zeroout larger chunks but the maximum segment we can zeroout at a time by ZERO_PAGE is limited by PAGE_SIZE. This concern was raised during the review of adding Large Block Size support to XFS[1][2]. This is especially annoying in block devices and filesystems where we attach multiple ZERO_PAGEs to the bio in different bvecs. With multipage bvec support in block layer, it is much more efficient to send out larger zero pages as a part of a single bvec. Some examples of places in the kernel where this could be useful: - blkdev_issue_zero_pages() - iomap_dio_zero() - vmalloc.c:zero_iter() - rxperf_process_call() - fscrypt_zeroout_range_inline_crypt() - bch2_checksum_update() ... We already have huge_zero_folio that is allocated on demand, and it will be deallocated by the shrinker if there are no users of it left. At moment, huge_zero_folio infrastructure refcount is tied to the process lifetime that created it. This might not work for bio layer as the completions can be async and the process that created the huge_zero_folio might no longer be alive. Add a config option STATIC_PMD_ZERO_PAGE that will always allocate the huge_zero_folio via memblock, and it will never be freed. I have converted blkdev_issue_zero_pages() as an example as a part of this series. I will send patches to individual subsystems using the huge_zero_folio once this gets upstreamed. Looking forward to some feedback. [1] https://lore.kernel.org/linux-xfs/20231027051847.GA7885@lst.de/ [2] https://lore.kernel.org/linux-xfs/ZitIK5OnR7ZNY0IG@infradead.org/ Changes since v1: - Move from .bss to allocating it through memblock(David) Changes since RFC: - Added the config option based on the feedback from David. - Encode more info in the header to avoid dead code (Dave hansen feedback) - The static part of huge_zero_folio in memory.c and the dynamic part stays in huge_memory.c - Split the patches to make it easy for review. Pankaj Raghav (5): mm: move huge_zero_page declaration from huge_mm.h to mm.h huge_memory: add huge_zero_page_shrinker_(init|exit) function mm: add static PMD zero page mm: add largest_zero_folio() routine block: use largest_zero_folio in __blkdev_issue_zero_pages() block/blk-lib.c | 17 +++++---- include/linux/huge_mm.h | 31 ---------------- include/linux/mm.h | 81 +++++++++++++++++++++++++++++++++++++++++ mm/Kconfig | 9 +++++ mm/huge_memory.c | 62 +++++++++++++++++++++++-------- mm/memory.c | 25 +++++++++++++ mm/mm_init.c | 1 + 7 files changed, 173 insertions(+), 53 deletions(-) base-commit: d7b8f8e20813f0179d8ef519541a3527e7661d3a -- 2.49.0