munlock_page(page);
 }
 
-/*
- * Clear the page's PageMlocked().  This can be useful in a situation where
- * we want to unconditionally remove a page from the pagecache -- e.g.,
- * on truncation or freeing.
- *
- * It is legal to call this function for any page, mlocked or not.
- * If called for a page that is still mapped by mlocked vmas, all we do
- * is revert to lazy LRU behaviour -- semantics are not broken.
- */
-extern void clear_page_mlock(struct page *page);
-
 extern pmd_t maybe_pmd_mkwrite(pmd_t pmd, struct vm_area_struct *vma);
 
 /*
 }
 #else /* !CONFIG_MMU */
 static inline void unmap_mapping_folio(struct folio *folio) { }
-static inline void clear_page_mlock(struct page *page) { }
 static inline void mlock_vma_page(struct page *page,
                        struct vm_area_struct *vma, bool compound) { }
 static inline void munlock_vma_page(struct page *page,
 
  * PageUnevictable is set to indicate the unevictable state.
  */
 
-/*
- *  LRU accounting for clear_page_mlock()
- */
-void clear_page_mlock(struct page *page)
-{
-       int nr_pages;
-
-       if (!TestClearPageMlocked(page))
-               return;
-
-       nr_pages = thp_nr_pages(page);
-       mod_zone_page_state(page_zone(page), NR_MLOCK, -nr_pages);
-       count_vm_events(UNEVICTABLE_PGCLEARED, nr_pages);
-       /*
-        * The previous TestClearPageMlocked() corresponds to the smp_mb()
-        * in __pagevec_lru_add_fn().
-        *
-        * See __pagevec_lru_add_fn for more explanation.
-        */
-       if (!isolate_lru_page(page)) {
-               putback_lru_page(page);
-       } else {
-               /*
-                * We lost the race. the page already moved to evictable list.
-                */
-               if (PageUnevictable(page))
-                       count_vm_events(UNEVICTABLE_PGSTRANDED, nr_pages);
-       }
-}
-
 /**
  * mlock_page - mlock a page
  * @page: page to be mlocked, either a normal page or a THP head.
 
         * pte lock(a spinlock) is held, which implies preemption disabled.
         */
        __mod_lruvec_page_state(page, NR_FILE_MAPPED, -nr);
-
-       if (unlikely(PageMlocked(page)))
-               clear_page_mlock(page);
 }
 
 static void page_remove_anon_compound_rmap(struct page *page)
                nr = thp_nr_pages(page);
        }
 
-       if (unlikely(PageMlocked(page)))
-               clear_page_mlock(page);
-
        if (nr)
                __mod_lruvec_page_state(page, NR_ANON_MAPPED, -nr);
 }
         */
        __dec_lruvec_page_state(page, NR_ANON_MAPPED);
 
-       if (unlikely(PageMlocked(page)))
-               clear_page_mlock(page);
-
        if (PageTransCompound(page))
                deferred_split_huge_page(compound_head(page));
 
 
 };
 
 /*
- * This path almost never happens for VM activity - pages are normally
- * freed via pagevecs.  But it gets used by networking.
+ * This path almost never happens for VM activity - pages are normally freed
+ * via pagevecs.  But it gets used by networking - and for compound pages.
  */
 static void __page_cache_release(struct page *page)
 {
                __clear_page_lru_flags(page);
                unlock_page_lruvec_irqrestore(lruvec, flags);
        }
+       /* See comment on PageMlocked in release_pages() */
+       if (unlikely(PageMlocked(page))) {
+               int nr_pages = thp_nr_pages(page);
+
+               __ClearPageMlocked(page);
+               mod_zone_page_state(page_zone(page), NR_MLOCK, -nr_pages);
+               count_vm_events(UNEVICTABLE_PGCLEARED, nr_pages);
+       }
        __ClearPageWaiters(page);
 }
 
        unevictable = (vma->vm_flags & (VM_LOCKED | VM_SPECIAL)) == VM_LOCKED;
        if (unlikely(unevictable) && !TestSetPageMlocked(page)) {
                int nr_pages = thp_nr_pages(page);
-               /*
-                * We use the irq-unsafe __mod_zone_page_state because this
-                * counter is not modified from interrupt context, and the pte
-                * lock is held(spinlock), which implies preemption disabled.
-                */
-               __mod_zone_page_state(page_zone(page), NR_MLOCK, nr_pages);
+
+               mod_zone_page_state(page_zone(page), NR_MLOCK, nr_pages);
                count_vm_events(UNEVICTABLE_PGMLOCKED, nr_pages);
        }
        lru_cache_add(page);
                        __clear_page_lru_flags(page);
                }
 
+               /*
+                * In rare cases, when truncation or holepunching raced with
+                * munlock after VM_LOCKED was cleared, Mlocked may still be
+                * found set here.  This does not indicate a problem, unless
+                * "unevictable_pgs_cleared" appears worryingly large.
+                */
+               if (unlikely(PageMlocked(page))) {
+                       __ClearPageMlocked(page);
+                       dec_zone_page_state(page, NR_MLOCK);
+                       count_vm_event(UNEVICTABLE_PGCLEARED);
+               }
+
                __ClearPageWaiters(page);
 
                list_add(&page->lru, &pages_to_free);