On Mon, Feb 06, 2023 at 02:55:09PM -0800, Yang Shi wrote: > > I've been thinking about this a lot more, and I have changed my > > mind. It works fine to answer the question "Is any page in this > > folio mapped", but it's now hard to answer the question "I have it > > mapped, does anybody else?" That question is asked, for example, > > in madvise_cold_or_pageout_pte_range(). > > > > With this definition, if the mapcount is 1, it's definitely only mapped > > by us. If it's more than 2, it's definitely mapped by somebody else (*). > > If it's 2, maybe we have the folio mapped twice, and maybe we have it > > mapped once and somebody else has it mapped once, so we have to consult > > the rmap to find out. Not fun times. > > > > (*) If we support folios larger than PMD size, then the answer is more > > complex. > > > > I now think the mapcount has to be defined as "How many VMAs have > > one-or-more pages of this folio mapped". > > IIRC it may be still possible the folio's mapcount is two, but it is > only mapped by us (for example, two VMAs from the same process). That's true, but it's also true for single-page folios that are mapped by two VMAs from the same process. I don't want to change the definition that much!