Re: [PATCH v7 4/6] ksm: add pgoff into ksm_rmap_item

From: xu.xin16

Date: Tue Jun 09 2026 - 00:53:15 EST


[...]

> Is the "maybe" stuff really something we should put into a comment?
>
> What about something like:
>
> "Must can only reference the VMA while still holding the mmap lock, so
> reference the anon_vma and calculate the linear page index early, before
> stable_tree_append(). If anything goes wrong, break_cow() will clean it up."
>
> > + */
> > rmap_item->anon_vma = vma->anon_vma;
> > + rmap_item->pgoff = linear_page_index(vma, rmap_item->address);
> > get_anon_vma(vma->anon_vma);
> > out:
> > mmap_read_unlock(mm);
> > @@ -2458,6 +2481,10 @@ static bool should_skip_rmap_item(struct folio *folio,
> > if (folio_test_ksm(folio))
> > return false;
> >
> > + /* There is no age information in stable-tree nodes. */
>
> Maybe we can make it clearer here:
>
> "There is no age information in stable-tree nodes. We might end up here without
> a KSM page for example after COW."
>
> > + if (rmap_item->address & STABLE_FLAG)
> > + return false;
> > +
> > age = rmap_item->age;
> > if (age != U8_MAX)
> > rmap_item->age++;
>
> I think with these things addressed, this LGTM.

Thank you for the thorough review. I agree with your suggestions and have sent v8.