On 26.01.22 15:31, Matthew Wilcox wrote: > On Wed, Jan 26, 2022 at 10:55:50AM +0100, David Hildenbrand wrote: >> diff --git a/mm/memory.c b/mm/memory.c >> index bcd3b7c50891..61d67ceef734 100644 >> --- a/mm/memory.c >> +++ b/mm/memory.c >> @@ -3298,7 +3298,17 @@ static vm_fault_t do_wp_page(struct vm_fault *vmf) >> * >> * PageKsm() doesn't necessarily raise the page refcount. >> */ >> - if (PageKsm(page) || page_count(page) > 1 + PageSwapCache(page)) >> + if (PageKsm(page)) >> + goto copy; >> + if (page_count(page) > 1 + PageSwapCache(page) + !PageLRU(page)) >> + goto copy; >> + if (!PageLRU(page)) >> + /* >> + * Note: We cannot easily detect+handle references from >> + * remote LRU pagevecs or references to PageLRU() pages. >> + */ >> + lru_add_drain(); >> + if (page_count(page) > 1 + PageSwapCache(page)) >> goto copy; > > I worry we're starting to get too accurate here. How about: > In that simplified case we'll essentially trylock_page() and for most pages that are ordinarily shared by e.g., 2 processes. > if (PageKsm(page) || page_count(page) > 3) > goto copy; > if (!PageLRU(page)) > lru_add_drain(); > if (!trylock_page(page)) > goto copy; > ... > I think we might at least want the if (page_count(page) > 1 + PageSwapCache(page)) goto copy; check here. >> if (!trylock_page(page)) >> goto copy; >> -- >> 2.34.1 >> > -- Thanks, David / dhildenb