On Thu, Nov 21, 2024 at 1:50 PM Lorenzo Stoakes <lorenzo.stoakes@xxxxxxxxxx> wrote: > > On Thu, Nov 21, 2024 at 11:23:39AM +0100, Alice Ryhl wrote: > > On Wed, Nov 20, 2024 at 8:07 PM Lorenzo Stoakes > > <lorenzo.stoakes@xxxxxxxxxx> wrote: > > > > > > On Wed, Nov 20, 2024 at 02:49:56PM +0000, Alice Ryhl wrote: > > > > + #[inline] > > > > + pub fn end(&self) -> usize { > > > > + // SAFETY: By the type invariants, the caller holds at least the mmap read lock, so this > > > > + // access is not a data race. > > > > + unsafe { (*self.as_ptr()).__bindgen_anon_1.__bindgen_anon_1.vm_end as _ } > > > > + } > > > > + > > > > + /// Unmap pages in the given page range. > > > > > > This needs some more description, as 'unmapping' pages is unfortunately an > > > overloaded term in the kernel and this very much might confuse people as > > > opposed to e.g. munmap()'ing a range. > > > > > > I'd say something like 'clear page table mappings for the range at the leaf > > > level, leaving all other page tables intact, freeing any memory referenced > > > by the VMA in this range (anonymous memory is completely freed, file-backed > > > memory has its reference count on page cache folio's dropped, any dirty > > > data will still be written back to disk as usual)'. > > > > Sure, will add that to the docs. > > Thanks, I assume you mean this comment, which will form part of the docs? As > here we should at least replace the 'unmap' with 'zap' to avoid confusion > vs. munmap(). Yes. Comments with three slashes are rendered in the html documentation. > > > > + #[inline] > > > > + pub fn zap_page_range_single(&self, address: usize, size: usize) { > > > > + // SAFETY: By the type invariants, the caller has read access to this VMA, which is > > > > + // sufficient for this method call. This method has no requirements on the vma flags. Any > > > > + // value of `address` and `size` is allowed. > > > > + unsafe { > > > > + bindings::zap_page_range_single( > > > > > > Hm weirdly I see this in rust/bindings/bindings_generated.rs but not in > > > rust/helpers/mm.c is this intended? > > > > > > Is this meant to be generated _from_ somewhere? Is something missing for > > > that? > > > > The bindings_generated.rs file is generated at built-time from C > > headers. The zap_page_range_single is a real function, not a fake > > static inline header-only function, so bindgen is able to generate it > > without anything in rust/helpers. > > > > > > + self.as_ptr(), > > > > + address as _, > > > > + size as _, > > > > + core::ptr::null_mut(), > > > > + ) > > > > + }; > > > > + } > > > > +} > > > > + > > > > +/// The integer type used for vma flags. > > > > +#[doc(inline)] > > > > +pub use bindings::vm_flags_t; > > > > > > Where do you declare this type? > > > > It's declared in include/linux/mm_types.h > > I meant from a rust perspective, but I guess bindgen handles this? Yes, anything in `bindings::` is output from bindgen based on C headers. Alice