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 9284FC71136 for ; Thu, 12 Jun 2025 10:51:18 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id F367E6B007B; Thu, 12 Jun 2025 06:51:17 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id EC1056B0088; Thu, 12 Jun 2025 06:51:17 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D891C6B0089; Thu, 12 Jun 2025 06:51:17 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id B6ADD6B007B for ; Thu, 12 Jun 2025 06:51:17 -0400 (EDT) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 6AE071A1178 for ; Thu, 12 Jun 2025 10:51:17 +0000 (UTC) X-FDA: 83546431794.07.FFF913F Received: from mout-p-103.mailbox.org (mout-p-103.mailbox.org [80.241.56.161]) by imf24.hostedemail.com (Postfix) with ESMTP id 959C018000A for ; Thu, 12 Jun 2025 10:51:15 +0000 (UTC) Authentication-Results: imf24.hostedemail.com; dkim=none; spf=pass (imf24.hostedemail.com: domain of kernel@pankajraghav.com designates 80.241.56.161 as permitted sender) smtp.mailfrom=kernel@pankajraghav.com; dmarc=fail reason="SPF not aligned (relaxed), No valid DKIM" header.from=samsung.com (policy=none) ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1749725475; 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; bh=3RLQx9ulRM3pl2EH5yKHY8gaX65v/gsEhV3sOf7swxc=; b=Hle2FUBYmIvhudISR8OsDaoV/F6GfncrF5D3V+ocW6iBf2+8lmHc9sD08kZ3bEMeKK6alN KmCpF9PaWIh/Cnjxhp2TAV0yK6dFq2vazTfK79DXrwbVQuRW6WZufGuvobTwMyGsHOt+nR YhFaTHZ9AL5RelJQN79NVo5cH2DrpkY= ARC-Authentication-Results: i=1; imf24.hostedemail.com; dkim=none; spf=pass (imf24.hostedemail.com: domain of kernel@pankajraghav.com designates 80.241.56.161 as permitted sender) smtp.mailfrom=kernel@pankajraghav.com; dmarc=fail reason="SPF not aligned (relaxed), No valid DKIM" header.from=samsung.com (policy=none) ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1749725475; a=rsa-sha256; cv=none; b=gCcXfvFnEkvCe3ZEdUa2iRE0qhsIsfiLepEETeTZk8CbUz90gqDZdIjMvr6JBstwqTXwol drvqA0CM9eJRBVK+b0ELZgYZgE5RVkW2smmPUF7jGLMdn7T2LpBBMzpQZ20q2wZ9n5TjSN lGdReYrWXxOdCTaBkJT1vA2SdAXiXPA= 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 4bHzpk5YtZz9t13; Thu, 12 Jun 2025 12:51:10 +0200 (CEST) From: Pankaj Raghav To: Suren Baghdasaryan , Ryan Roberts , Mike Rapoport , Michal Hocko , Thomas Gleixner , Nico Pache , Dev Jain , Baolin Wang , Borislav Petkov , Ingo Molnar , "H . Peter Anvin" , Vlastimil Babka , Zi Yan , Dave Hansen , David Hildenbrand , Lorenzo Stoakes , Andrew Morton , "Liam R . Howlett" , Jens Axboe Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, willy@infradead.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 0/5] add STATIC_PMD_ZERO_PAGE config option Date: Thu, 12 Jun 2025 12:50:55 +0200 Message-ID: <20250612105100.59144-1-p.raghav@samsung.com> Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Stat-Signature: 1y8i7s7apbghwjckht1mb7arkm8kssp5 X-Rspamd-Queue-Id: 959C018000A X-Rspam-User: X-Rspamd-Server: rspam09 X-HE-Tag: 1749725475-916265 X-HE-Meta: U2FsdGVkX1802y7K6sYDzpz78cN2GpVGjNTTzJRGvg07uPSMSO5dIc5eKj8Dn/GcLG7aruJrH1F5rg+DtDDmeLFCk6KUbZVYbKj8QX1k/0arcT3tVVqMOHOnNO99jY5axaZWV5PdiWw36gSwzk3EJgPWwKO32TDxxEkPt4aH2/QLINhgr8Wzhu5oUvHxzvwIKFMfoAkQDN7x1IyNWX3s+say2D3U9+4pztLO8gjBNzNPOW8PG4k/xb2WLJ3EmsbVXihd+ed4C5iesfW2Cmrd7PPAJPhxnVQEGFY53rIB0UJTrv0+M6kqEHyvQ4fQOJqiUF/HRQl+pqKOc4QxE2Bnp2VX1/PAz8FbhgpR3Xb85AcjiyHudsSACaKVjDaAubfuOpdOcnvtyDKYOAVt825Gh2Zkuk+5NAM4NsXDjm9YoKZKueEmqktlPqc0NhjkTdRcwxKlR4fvzTVfj9J7OB0x4qb4DLMeKME5ghR2SA4Jy2EpPMfhNwlWOEiAbfh3pN2zBssrHiSvzi4bRgGqEgX30vBLCVUMixferzY1xrJ9zZL/5swVEnuaXuXcezkVmDcsc6kpyADEnl7sJmL9jDgVGFCr8xceVcT34pjJXsgkfCHoB4WoHuKsESnKcALHwB12ji+2+H6IYaOdg8zpdUe8g8rm5JTLZWRioc67ti7Zxuzn0eiAEQNOrSci302d2g1sLT3NitD0gvUNYYYAdoKhavaWjS2dJY8N4VK0KLYPhxyfiTbgZmkh6dyTN3V+T8UNMSepFEiPLgdEf9dlh6BzBr9l2RSJVKNt+vYHS3vaM4AsRASz9gNEASgumUWzgc7Mcrbk8xI8j5tgaKGrnhll40TtlTwpwTchSQ+rrcPFxZNRAkfF6pnkDjo6an2+WdQRgClCX7vuvWi2JknYMMdq0o7NvDtiJ+IN0CpNfqmPyS+71gtSt0Gk8UJh3N6h+JAaf2YF1esRQ17YlUQex/6 /7MWbnzK Lc9DbeNaR+g5pMmBfK/KUusRNBqcCQRx4VQy61FN0WGTcit3HCNO5g21LVLJ7H+Y8iPSO0SbeYM6b+JrzvvV1X3Bp15iJe9k2wvuUOBVgHRAcCddzcI2RdjKsQotcLg38x7Y0IPOdU8ebze/GN5So/VNvAxLZEWUxisLaKCyIBBLWT4WsApM6yLwuEdGyEzf5TeE79aS4k1IitqT1SKnYVhkrdaTvDUMakPFPWAO509Fn0c9Zo6fSnmkFv7NfaKsLsVv763MmX7MVuSz/2nHrsWR52KJGB6lSBJvj49oUFVOt9F48SVdaTJ5OPh9ZSGWg+S77ACpTVsNko8K5ayQqrZj85HPlBRIv3P4046uKah9wwR5mWEpEDJZZp3dc4bauOc1Apmh4twjHiVMlIyMPX2DB7MqWWcqDxJvwj/QjBWmijxSddWl9+hrRjIsFdpfrhpNial7lJzgnDrlRNVlv0igTT5kh/67cIMNcyydMgIVXzFCfo9SMUrPNig== 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: 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. But to use huge_zero_folio, we need to pass a mm struct and the put_folio needs to be called in the destructor. This makes sense for systems that have memory constraints but for bigger servers, it does not matter if the PMD size is reasonable (like in x86). Add a config option STATIC_PMD_ZERO_PAGE that will always allocate the huge_zero_folio in .bss, and it will never be freed. The static PMD page is reused by huge_zero_folio when this config option is enabled. 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 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 mm_get_static_huge_zero_folio() routine block: use mm_huge_zero_folio in __blkdev_issue_zero_pages() arch/x86/Kconfig | 1 + arch/x86/include/asm/pgtable.h | 8 +++++ arch/x86/kernel/head_64.S | 8 +++++ block/blk-lib.c | 17 +++++---- include/linux/huge_mm.h | 31 ---------------- include/linux/mm.h | 64 ++++++++++++++++++++++++++++++++++ mm/Kconfig | 13 +++++++ mm/huge_memory.c | 62 ++++++++++++++++++++++++-------- mm/memory.c | 19 ++++++++++ 9 files changed, 170 insertions(+), 53 deletions(-) base-commit: 19272b37aa4f83ca52bdf9c16d5d81bdd1354494 -- 2.49.0