On Tue, Feb 07, 2023 at 11:06:13AM +0800, Yin, Fengwei wrote: > On 2/7/2023 4:34 AM, Matthew Wilcox wrote: > > On Tue, Jan 24, 2023 at 06:13:21PM +0000, Matthew Wilcox wrote: > >> Once we get to the part of the folio journey where we have > >> one-pointer-per-page, we can't afford to maintain per-page state. > >> Currently we maintain a per-page mapcount, and that will have to go. > >> We can maintain extra state for a multi-page folio, but it has to be a > >> constant amount of extra state no matter how many pages are in the folio. > >> > >> My proposal is that we maintain a single mapcount per folio, and its > >> definition is the number of (vma, page table) tuples which have a > >> reference to any pages in this folio. > > > > 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. > Naive question: If it's 2, why do we need to know whether it's mapped twice > by us or one by us and one by somebody else? Does that mean we allow some > operations if only us mapped it even it's 2? Thanks. Yes, see the aforementioned madvise_cold_or_pageout_pte_range(): (in mainline, it's different in -next): /* Do not interfere with other mappings of this page */ if (page_mapcount(page) != 1) goto huge_unlock;