Skip to content

Guaranteed CMA

Suren Baghdasaryan linux-block linux-doc linux-fsdevel linux-iommu linux-mm lkml 2 versions – In review

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v2 Latest8 patches 6 repliesIn review
  2. v18 patches 12 repliesSuperseded

Patches in v2 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/8mm: implement cleancacheMAINTAINERS block/bdev.c fs/super.c +10 more+998 -20 replies
2/8mm/cleancache: add cleancache LRU for folio agingmm/cleancache.c+89 -20 replies
3/8mm/cleancache: readahead supportinclude/linux/cleancache.h mm/cleancache.c mm/readahead.c+125 -00 replies
4/8mm/cleancache: add sysfs interfaceMAINTAINERS mm/Kconfig mm/Makefile +3 more+383 -80 replies
5/8mm/tests: add cleancache kunit testMAINTAINERS mm/Kconfig.debug mm/Makefile +3 more+475 -10 replies
6/8add cleancache documentationDocumentation/admin-guide/mm/cleancache_sysfs.rst Documentation/admin-guide/mm/index.rst Documentation/mm/cleancache.rst +2 more+123 -00 replies
7/8mm: introduce GCMAMAINTAINERS include/linux/gcma.h mm/Kconfig +2 more+298 -00 replies
8/8mm: integrate GCMA with CMA using dt-bindingsinclude/linux/cma.h kernel/dma/contiguous.c mm/Kconfig +4 more+59 -150 replies

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v2 yet.

Read the v2 thread

Cover letter [PATCH v2 0/8] Guaranteed CMA

Guaranteed CMA (GCMA) is designed to improve utilization of reserved memory carveouts without compromising their advantages of:
1. Guaranteed success of allocation (as long as total allocation size is below the size of the reservation.
2. Low allocation latency.
The idea is that carved out memory when not used for its primary purpose can be donated and used as an extension of the pagecache and any donated folio can be taken back at any moment with minimal latency and guaranteed success.

To achieve this, GCMA needs to use memory that is not addressable by the kernel (can't be pinned) and that contains content that can be discarded. To provide such memory we reintroduce cleancache idea [1] with two major changes. New implementation:
1. Avoids intrusive hooks into filesystem code, limiting them to two hooks for filesystem mount/unmount events and a hook for bdev invalidation.
2. Manages inode to folio association and handles pools of donated folios inside cleancache itself, freeing backends of this burden.

Cleancache provides a simple interface to its backends which lets them donate folios to cleancache, take a folio back for own use and return the folio back to cleancache when not needed.

With cleancache in place, GCMA becomes a thin layer linking CMA allocator to cleancache, which allows existing CMA API to be used for continuous memory allocations with additional guarantees listed above. The limitation of GCMA is that its donated memory can be used only to extend file-backed pagecache. Note that both CMA and GCMA can be used at the same time.

Accounting for folios allocated from GCMA is implemented the same way as for CMA. The reasoning is that both CMA and GCMA use reserved memory for contiguous allocations with the only difference in how that memory gets donated while not in use. CMA donates its memory to the system for movable allocations with expectation that it will be returned when it is needed. GCMA donatest its memory to cleancache with the same expectation. Once CMA or GCMA use that memory for contiguous allocation, the difference between them disappears, therefore accounting at that point should not differ.

The patchset borrows some ideas and code from previous implementations of the cleancache and GCMA [2] as well as Android's reference patchset [3] implemented by Minchan Kim and used by many Android vendors.

[1] https://elixir.bootlin.com/linux/v5.16.20/source/Documentation/vm/cleancache.rst
[2] https://lore.kernel.org/lkml/[email protected]/
[3] https://android-review.googlesource.com/q/topic:%22gcma_6.12%22

Patchset is based on mm-new.

Changes since v1 [1]:
- Removed extra address_space parameter in cleancache hooks, per Matthew Wilcox
- Updated comments to replace page with folio, per Matthew Wilcox
- Removed unnecessary new abbreviations from Kconfig, changelog and documentation, per Matthew Wilcox
- Removed unnecessary comment about lock protecting xarray, per Matthew Wilcox
- Replaced IDR with xarray for storage, per Matthew Wilcox
- Added unions in the folio for aliased fields, per Matthew Wilcox
- Removed an unused variable in the test, per kernel test robot
- Linked the cleancache document in mm/index.rst, per SeongJae Park
- Split cleancache sysfs documenation into cleancache_sysfs.rst and linked it in Documentation/admin-guide/mm/index.rst, per SeongJae Park
- Cleaned up free_folio_range() code, per SeongJae Park
- Reworked gcma_free_range() to handle failures and properly rollback refcount changes, per SeongJae Park
- Removed references to transcendent memory, per SeongJae Park
- Other minor documentation fixups, per SeongJae Park
- Added Minchan Kim as cleancache maintainer
- Minor code and documentation cleanups

Minchan Kim (1):
mm: introduce GCMA

Suren Baghdasaryan (7):
mm: implement cleancache
mm/cleancache: add cleancache LRU for folio aging mm/cleancache: readahead support mm/cleancache: add sysfs interface mm/tests: add cleancache kunit test
add cleancache documentation
mm: integrate GCMA with CMA using dt-bindings

 .../admin-guide/mm/cleancache_sysfs.rst       |   51 +
 Documentation/admin-guide/mm/index.rst        |    1 +
 Documentation/mm/cleancache.rst               |   68 +
 Documentation/mm/index.rst                    |    1 +
 MAINTAINERS                                   |   15 +
 block/bdev.c                                  |    6 +
 fs/super.c                                    |    3 +
 include/linux/cleancache.h                    |   77 ++
 include/linux/cma.h                           |   11 +-
 include/linux/fs.h                            |    6 +
 include/linux/gcma.h                          |   36 +
 include/linux/mm_types.h                      |   12 +-
 include/linux/pagemap.h                       |    1 +
 kernel/dma/contiguous.c                       |   11 +-
 mm/Kconfig                                    |   39 +
 mm/Kconfig.debug                              |   13 +
 mm/Makefile                                   |    4 +
 mm/cleancache.c                               | 1127 +++++++++++++++++
 mm/cleancache_sysfs.c                         |  209 +++
 mm/cleancache_sysfs.h                         |   58 +
 mm/cma.c                                      |   37 +-
 mm/cma.h                                      |    1 +
 mm/cma_sysfs.c                                |   10 +
 mm/filemap.c                                  |   26 +
 mm/gcma.c                                     |  244 ++++
 mm/readahead.c                                |   54 +
 mm/tests/Makefile                             |    6 +
 mm/tests/cleancache_kunit.c                   |  420 ++++++
 mm/truncate.c                                 |    4 +
 mm/vmscan.c                                   |    1 +
 30 files changed, 2537 insertions(+), 15 deletions(-)
 create mode 100644 Documentation/admin-guide/mm/cleancache_sysfs.rst
 create mode 100644 Documentation/mm/cleancache.rst
 create mode 100644 include/linux/cleancache.h
 create mode 100644 include/linux/gcma.h
 create mode 100644 mm/cleancache.c
 create mode 100644 mm/cleancache_sysfs.c
 create mode 100644 mm/cleancache_sysfs.h
 create mode 100644 mm/gcma.c
 create mode 100644 mm/tests/Makefile
 create mode 100644 mm/tests/cleancache_kunit.c

base-commit: 752c460b5865d87117095c915addcce7a68296f2

Signature · 1 line
2.51.1.851.g4ebd6896fd-goog