linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/5] add STATIC_PMD_ZERO_PAGE config option
@ 2025-06-12 10:50 Pankaj Raghav
  2025-06-12 10:50 ` [PATCH 1/5] mm: move huge_zero_page declaration from huge_mm.h to mm.h Pankaj Raghav
                   ` (6 more replies)
  0 siblings, 7 replies; 19+ messages in thread
From: Pankaj Raghav @ 2025-06-12 10:50 UTC (permalink / raw)
  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, linux-mm, willy, x86, linux-block, linux-fsdevel,
	Darrick J . Wong, mcgrof, gost.dev, kernel, hch, 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.

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


^ permalink raw reply	[flat|nested] 19+ messages in thread

end of thread, other threads:[~2025-06-24  8:51 UTC | newest]

Thread overview: 19+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-06-12 10:50 [PATCH 0/5] add STATIC_PMD_ZERO_PAGE config option Pankaj Raghav
2025-06-12 10:50 ` [PATCH 1/5] mm: move huge_zero_page declaration from huge_mm.h to mm.h Pankaj Raghav
2025-06-12 10:50 ` [PATCH 2/5] huge_memory: add huge_zero_page_shrinker_(init|exit) function Pankaj Raghav
2025-06-12 10:50 ` [PATCH 3/5] mm: add static PMD zero page Pankaj Raghav
2025-06-24  8:51   ` kernel test robot
2025-06-12 10:50 ` [PATCH 4/5] mm: add mm_get_static_huge_zero_folio() routine Pankaj Raghav
2025-06-12 14:09   ` Dave Hansen
2025-06-12 20:54     ` Pankaj Raghav (Samsung)
2025-06-16  9:14       ` David Hildenbrand
2025-06-16 10:41         ` Pankaj Raghav (Samsung)
2025-06-12 10:51 ` [PATCH 5/5] block: use mm_huge_zero_folio in __blkdev_issue_zero_pages() Pankaj Raghav
2025-06-12 13:50 ` [PATCH 0/5] add STATIC_PMD_ZERO_PAGE config option Dave Hansen
2025-06-12 20:36   ` Pankaj Raghav (Samsung)
2025-06-12 21:46     ` Dave Hansen
2025-06-13  8:58       ` Pankaj Raghav (Samsung)
2025-06-16  9:12         ` David Hildenbrand
2025-06-16 10:49           ` Pankaj Raghav (Samsung)
2025-06-16  5:40 ` Christoph Hellwig
2025-06-16  9:00   ` Pankaj Raghav

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).