From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-yx1-f73.google.com (mail-yx1-f73.google.com [74.125.224.73]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C3D7323875D for ; Sun, 26 Oct 2025 20:36:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.224.73 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1761510979; cv=none; b=dWIO8HUjrqxu+muZ4/5KH1+WsnS3fRvLvt8tEbs5JiDqFCoCILaSCeRrxzOJS0SHXOWvCVLaxQiIHbP+Ke/q3Z/bI2S8XMpVi3iw+h7/NpaQPFO0ycUiItdpFDVYIcbXbvO24FczAz2M9lapg0QVlpCtdLrCx4XwPfA9SRu0Mx8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1761510979; c=relaxed/simple; bh=EtPHM/rxvf1s6wpudENnj+c1ViV9senew6m5yYbiKog=; h=Date:Mime-Version:Message-ID:Subject:From:To:Cc:Content-Type; b=Vv/EPZtCjzS9iNujPHJltMLK4AIQyngh4Y3PMpnwHc5vUg0qTL+s6IIRhNXaTup9bNcRnWta/8Xlfj/spp5pRZUSpyZf05lCqE3/N8D5bBn70ZKDi+4aPw2/1CUx+3p6ZKesIQmqjHtX8tq1e9PNqv2vnYqmec1u3BD9AMJtHDw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--surenb.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=nnPUUDOP; arc=none smtp.client-ip=74.125.224.73 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--surenb.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="nnPUUDOP" Received: by mail-yx1-f73.google.com with SMTP id 956f58d0204a3-63e33859d16so4619820d50.2 for ; Sun, 26 Oct 2025 13:36:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1761510976; x=1762115776; darn=vger.kernel.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=oIYNgmwaiZev52ielsOny0g8kp/qW6C19JMGXvUOw8g=; b=nnPUUDOP4vNpiN1JkUwR2VQk5zKdhdf6YMDBHoaqPiKQbK7V78fPyfor29DYhtdN1N rnGgSXXLyrG4LgPUV09tkDDyAZ5VHm8p0h8d6+YYegZMKZWcaMEt17AO2MkJSiEGju0X v0tsRA3l3YDp0Ug/Y0jDFW0Nj7/otmw0Q1/4ugJVReLbW2XMT8n30IEajT2mlc+7RNA9 DxkVjsVGpalDNfgZPF0f1AhtuHDDbQ1/kF9rO9jxo/FjiL1zQeo7ySGeYXLOmVVofIhF NM3k7tXzPWeKCsCvueA1wNx7vrAgVD7AUjNQecdUHlZIG2Na/UGb/1loPWMG+3n1yAwt sUzA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1761510976; x=1762115776; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=oIYNgmwaiZev52ielsOny0g8kp/qW6C19JMGXvUOw8g=; b=iVsGAO7O5EOFsS1lsz+R51nK+ITR28aJ5ew3P4c+yhQ9xHututepexIiTMjM1EZjl9 Woz2CihTG3oZGIc4/oCvNht7A6H/TUSYkGxMj7wnDRcKTbfsr09Grl1GzBlzhWyUiySI H3vDIVLTE9tCJNQ51diGTf12gl4uMn4DDtlyN45MMcOAJqLPgLZbjixZ0lbmJaOU07GI 3q+a1KCUEk5yjHSmWrsk1XdmCtndHKmMgD94h566pYHAZP09Q7CPAgNJ2FzsoSH4816v auLJ5Y7ESdahBJHWM80MLHo49pjO/8WhD8K9kZhmTdtY8rPEYICJ5JwbrEuLTMcOZJIp qjaA== X-Forwarded-Encrypted: i=1; AJvYcCVsOfu/irvuBN9hXbm9a9xoQvSvxSK9QoEtxB8nMDvfhDSw5ldGM2PGqKZZJ27X7cQMUPCRwb1YPWmIm50=@vger.kernel.org X-Gm-Message-State: AOJu0YyKZ2HZJZ+NAfP+xXtnOQcJrp6Er6dliD0094h9V88/ApGpJRpk OmJE4uQ00S06r+v2kevoPZ/CS7Zp8SRtAeDvmQ+Pi65G+HOFjw+wlLQVcrr1vznsQAY/AfE5ht/ 68sLy3A== X-Google-Smtp-Source: AGHT+IEQ9Pwyyd7kjVHYsKEBM6jXV+KGbNmmj3ZfQc3rnB2XqZ4bQZDKRwRIjK4vvzIoUgZwP2mnd9XDO/0= X-Received: from yxdd3.prod.google.com ([2002:a05:690e:2443:b0:63f:2d9a:656b]) (user=surenb job=prod-delivery.src-stubby-dispatcher) by 2002:a05:690c:9a07:b0:784:8620:1c49 with SMTP id 00721157ae682-78486201eacmr444866607b3.30.1761510975632; Sun, 26 Oct 2025 13:36:15 -0700 (PDT) Date: Sun, 26 Oct 2025 13:36:03 -0700 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 X-Mailer: git-send-email 2.51.1.851.g4ebd6896fd-goog Message-ID: <20251026203611.1608903-1-surenb@google.com> Subject: [PATCH v2 0/8] Guaranteed CMA From: Suren Baghdasaryan To: akpm@linux-foundation.org Cc: david@redhat.com, lorenzo.stoakes@oracle.com, Liam.Howlett@oracle.com, vbabka@suse.cz, alexandru.elisei@arm.com, peterx@redhat.com, sj@kernel.org, rppt@kernel.org, mhocko@suse.com, corbet@lwn.net, axboe@kernel.dk, viro@zeniv.linux.org.uk, brauner@kernel.org, hch@infradead.org, jack@suse.cz, willy@infradead.org, m.szyprowski@samsung.com, robin.murphy@arm.com, hannes@cmpxchg.org, zhengqi.arch@bytedance.com, shakeel.butt@linux.dev, axelrasmussen@google.com, yuanchu@google.com, weixugc@google.com, minchan@kernel.org, surenb@google.com, linux-mm@kvack.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-block@vger.kernel.org, linux-fsdevel@vger.kernel.org, iommu@lists.linux.dev Content-Type: text/plain; charset="UTF-8" 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/1424721263-25314-1-git-send-email-sj38.park@gmail.com/ [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 -- 2.51.1.851.g4ebd6896fd-goog