mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [RFC PATCH 0/4] rust: damon: a first small step, plus a Rust prcl sample
@ 2026-09-27  7:28 Enze Li
  2026-09-27  7:28 ` [RFC PATCH 1/4] rust: add bindings for linux/damon.h Enze Li
                   ` (4 more replies)
  0 siblings, 5 replies; 8+ messages in thread
From: Enze Li @ 2026-09-27  7:28 UTC (permalink / raw)
  To: ojeda, boqun, gary, bjorn3_gh, lossin, a.hindborg, aliceryhl,
	tmgross, dakr, daniel.almeida, tamird, acourbot, work, sj
  Cc: linux-kernel, rust-for-linux, damon, linux-mm, enze.li, lienze

Hi SJ, hi all,

Almost a year ago, right after a memory-leak fix discussion on this list, I
asked whether introducing Rust for some DAMON modules could be worth
exploring as a proactive measure.  SJ's answer was positive: he was open to
Rust adoption in DAMON, both in kernel and user space, and even mentioned
he had been wanting to write a Rust sample DAMON module himself since LPC,
but had not found the time yet [1].

So, here is my attempt at making that start happen.  This RFC is
intentionally small: it adds just enough Rust support for DAMON to port the
proactive reclamation sample (prcl.c), and nothing more.

The series has four patches:

  1. Generate Rust bindings for include/linux/damon.h.
  2. Add thin safe wrappers in a new rust::kernel::damon module: contexts,
     targets, access patterns, quotas, watermarks, schemes, plus
     start/stop.  Everything FFI-related is confined to the wrappers, with
     the usual SAFETY comments; error codes are returned as kernel::Result.
  3. Add samples/damon/rust_prcl.rs, a Rust port of prcl.c.  It watches the
     virtual address space of a target process and pages out cold regions
     with the DAMOS_PAGEOUT action, same access-pattern filter as the C
     version.
  4. Add a MAINTAINERS entry for the two new files.

Two differences from the C sample are worth noting.

First, the control interface.  The C prcl sample is driven through
runtime-writable module parameters (target_pid and enabled, the latter via
module_param_cb), neither of which Rust can express yet -- its module
parameters are load-time only and do not show up under /sys/module/, and
there is no general sysfs abstraction in mainline or the RfL rust-next
tree.  The debugfs abstraction, however, already provides the safe
read/write wrappers we need, so the Rust sample exposes the same two knobs
under /sys/kernel/debug/rust_prcl/.  This is a temporary detour, not a
design preference: the sample will be switched over to match the C
interface once Rust supports sysfs-backed module parameters.

Second, the functional scope.  The C sample also repeatedly reports the
estimated working set size via a repeating damon_call() callback.  This
initial Rust version covers only the core monitoring/reclamation path
(context, target, PAGEOUT scheme, start/stop); wss reporting needs safe
wrappers for damon_call() and region iteration, which will come in a
follow-up series that also makes the Rust sample's output match the C
one's.

A quick word on the longer-term plan, so the design discussion here can
happen with the destination in mind:

  - Over roughly the next year, I would like to port the other two DAMON
    samples (wsse and mtier) to Rust as well, and let the DAMON Rust
    compatibility layer grow together with them, wrapping only what real
    in-tree users need.
  - Once that layer has matured, I would be happy to try Rust for the
    production modules - damon/reclaim, damon/lru_sort and damon/stat.
    That is a much bigger step, of course, and it only happens if SJ is
    comfortable with it.  Consider it a willingness statement, not a
    promise.

Regarding the MAINTAINERS patch: I listed myself for the new files, but did
not add SJ as a reviewer yet, since he mentioned limited bandwidth for Rust
work in that earlier discussion.  The existing DAMON entry already covers
samples/damon/, so the sample reaches him regardless; adding him to the
RUST [DAMON] entry would only additionally route future changes to
rust/kernel/damon.rs his way.  Happy to add the R: line if he wants it, or
leave it out if he prefers.

Testing: build test kernel with CONFIG_RUST=y and
CONFIG_SAMPLE_DAMON_RUST_PRCL=y.  Functionally exercised via debugfs:

  # echo <pid> > /sys/kernel/debug/rust_prcl/target_pid
  # echo y > /sys/kernel/debug/rust_prcl/enabled
  ... cold regions of the target get paged out ...
  # echo n > /sys/kernel/debug/rust_prcl/enabled

This is an RFC, so comments on the wrapper API shape, naming and the
debugfs detour are especially welcome.

[1] https://lore.kernel.org/all/20251015150701.68087-1-sj@kernel.org/

Enze Li (4):
  rust: add bindings for linux/damon.h
  rust: damon: add basic DAMON abstractions
  samples/damon: add Rust sample for DAMON access-aware proactive reclamation
  MAINTAINERS: add entry for the DAMON Rust abstractions

 MAINTAINERS                     |   8 +
 rust/bindings/bindings_helper.h |   1 +
 rust/kernel/damon.rs            | 292 ++++++++++++++++++++++++++++++++
 rust/kernel/lib.rs              |   2 +
 samples/Makefile                |   1 +
 samples/damon/Kconfig           |  12 ++
 samples/damon/Makefile          |   1 +
 samples/damon/rust_prcl.rs      | 158 +++++++++++++++++
 8 files changed, 475 insertions(+)
 create mode 100644 rust/kernel/damon.rs
 create mode 100644 samples/damon/rust_prcl.rs

-- 
2.25.1


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

end of thread, other threads:[~2026-09-28 16:56 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-09-27  7:28 [RFC PATCH 0/4] rust: damon: a first small step, plus a Rust prcl sample Enze Li
2026-09-27  7:28 ` [RFC PATCH 1/4] rust: add bindings for linux/damon.h Enze Li
2026-09-27  7:28 ` [RFC PATCH 2/4] rust: damon: add basic DAMON abstractions Enze Li
2026-09-27  7:28 ` [RFC PATCH 3/4] samples/damon: add Rust sample for DAMON access-aware proactive reclamation Enze Li
2026-09-27  7:28 ` [RFC PATCH 4/4] MAINTAINERS: add entry for the DAMON Rust abstractions Enze Li
2026-09-27 10:07 ` [RFC PATCH 0/4] rust: damon: a first small step, plus a Rust prcl sample SJ Park
2026-09-28 12:59   ` Enze Li
2026-09-28 16:56     ` SJ Park

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®