vmscan.c (e27be240df53f1a20c659168e722b5d9f16cc7f4) vmscan.c (b93b016313b3ba8003c3b8bb71f569af91f19fc7)
1// SPDX-License-Identifier: GPL-2.0
2/*
3 * linux/mm/vmscan.c
4 *
5 * Copyright (C) 1991, 1992, 1993, 1994 Linus Torvalds
6 *
7 * Swap reorganised 29.12.95, Stephen Tweedie.
8 * kswapd added: 7.1.96 sct

--- 679 unchanged lines hidden (view full) ---

688 bool reclaimed)
689{
690 unsigned long flags;
691 int refcount;
692
693 BUG_ON(!PageLocked(page));
694 BUG_ON(mapping != page_mapping(page));
695
1// SPDX-License-Identifier: GPL-2.0
2/*
3 * linux/mm/vmscan.c
4 *
5 * Copyright (C) 1991, 1992, 1993, 1994 Linus Torvalds
6 *
7 * Swap reorganised 29.12.95, Stephen Tweedie.
8 * kswapd added: 7.1.96 sct

--- 679 unchanged lines hidden (view full) ---

688 bool reclaimed)
689{
690 unsigned long flags;
691 int refcount;
692
693 BUG_ON(!PageLocked(page));
694 BUG_ON(mapping != page_mapping(page));
695
696 spin_lock_irqsave(&mapping->tree_lock, flags);
696 xa_lock_irqsave(&mapping->i_pages, flags);
697 /*
698 * The non racy check for a busy page.
699 *
700 * Must be careful with the order of the tests. When someone has
701 * a ref to the page, it may be possible that they dirty it then
702 * drop the reference. So if PageDirty is tested before page_count
703 * here, then the following race may occur:
704 *

--- 7 unchanged lines hidden (view full) ---

712 *
713 * [oops, our write_to data is lost]
714 *
715 * Reversing the order of the tests ensures such a situation cannot
716 * escape unnoticed. The smp_rmb is needed to ensure the page->flags
717 * load is not satisfied before that of page->_refcount.
718 *
719 * Note that if SetPageDirty is always performed via set_page_dirty,
697 /*
698 * The non racy check for a busy page.
699 *
700 * Must be careful with the order of the tests. When someone has
701 * a ref to the page, it may be possible that they dirty it then
702 * drop the reference. So if PageDirty is tested before page_count
703 * here, then the following race may occur:
704 *

--- 7 unchanged lines hidden (view full) ---

712 *
713 * [oops, our write_to data is lost]
714 *
715 * Reversing the order of the tests ensures such a situation cannot
716 * escape unnoticed. The smp_rmb is needed to ensure the page->flags
717 * load is not satisfied before that of page->_refcount.
718 *
719 * Note that if SetPageDirty is always performed via set_page_dirty,
720 * and thus under tree_lock, then this ordering is not required.
720 * and thus under the i_pages lock, then this ordering is not required.
721 */
722 if (unlikely(PageTransHuge(page)) && PageSwapCache(page))
723 refcount = 1 + HPAGE_PMD_NR;
724 else
725 refcount = 2;
726 if (!page_ref_freeze(page, refcount))
727 goto cannot_free;
728 /* note: atomic_cmpxchg in page_freeze_refs provides the smp_rmb */
729 if (unlikely(PageDirty(page))) {
730 page_ref_unfreeze(page, refcount);
731 goto cannot_free;
732 }
733
734 if (PageSwapCache(page)) {
735 swp_entry_t swap = { .val = page_private(page) };
736 mem_cgroup_swapout(page, swap);
737 __delete_from_swap_cache(page);
721 */
722 if (unlikely(PageTransHuge(page)) && PageSwapCache(page))
723 refcount = 1 + HPAGE_PMD_NR;
724 else
725 refcount = 2;
726 if (!page_ref_freeze(page, refcount))
727 goto cannot_free;
728 /* note: atomic_cmpxchg in page_freeze_refs provides the smp_rmb */
729 if (unlikely(PageDirty(page))) {
730 page_ref_unfreeze(page, refcount);
731 goto cannot_free;
732 }
733
734 if (PageSwapCache(page)) {
735 swp_entry_t swap = { .val = page_private(page) };
736 mem_cgroup_swapout(page, swap);
737 __delete_from_swap_cache(page);
738 spin_unlock_irqrestore(&mapping->tree_lock, flags);
738 xa_unlock_irqrestore(&mapping->i_pages, flags);
739 put_swap_page(page, swap);
740 } else {
741 void (*freepage)(struct page *);
742 void *shadow = NULL;
743
744 freepage = mapping->a_ops->freepage;
745 /*
746 * Remember a shadow entry for reclaimed file cache in

--- 4 unchanged lines hidden (view full) ---

751 * inode reclaim needs to empty out the radix tree or
752 * the nodes are lost. Don't plant shadows behind its
753 * back.
754 *
755 * We also don't store shadows for DAX mappings because the
756 * only page cache pages found in these are zero pages
757 * covering holes, and because we don't want to mix DAX
758 * exceptional entries and shadow exceptional entries in the
739 put_swap_page(page, swap);
740 } else {
741 void (*freepage)(struct page *);
742 void *shadow = NULL;
743
744 freepage = mapping->a_ops->freepage;
745 /*
746 * Remember a shadow entry for reclaimed file cache in

--- 4 unchanged lines hidden (view full) ---

751 * inode reclaim needs to empty out the radix tree or
752 * the nodes are lost. Don't plant shadows behind its
753 * back.
754 *
755 * We also don't store shadows for DAX mappings because the
756 * only page cache pages found in these are zero pages
757 * covering holes, and because we don't want to mix DAX
758 * exceptional entries and shadow exceptional entries in the
759 * same page_tree.
759 * same address_space.
760 */
761 if (reclaimed && page_is_file_cache(page) &&
762 !mapping_exiting(mapping) && !dax_mapping(mapping))
763 shadow = workingset_eviction(mapping, page);
764 __delete_from_page_cache(page, shadow);
760 */
761 if (reclaimed && page_is_file_cache(page) &&
762 !mapping_exiting(mapping) && !dax_mapping(mapping))
763 shadow = workingset_eviction(mapping, page);
764 __delete_from_page_cache(page, shadow);
765 spin_unlock_irqrestore(&mapping->tree_lock, flags);
765 xa_unlock_irqrestore(&mapping->i_pages, flags);
766
767 if (freepage != NULL)
768 freepage(page);
769 }
770
771 return 1;
772
773cannot_free:
766
767 if (freepage != NULL)
768 freepage(page);
769 }
770
771 return 1;
772
773cannot_free:
774 spin_unlock_irqrestore(&mapping->tree_lock, flags);
774 xa_unlock_irqrestore(&mapping->i_pages, flags);
775 return 0;
776}
777
778/*
779 * Attempt to detach a locked page from its ->mapping. If it is dirty or if
780 * someone else has a ref on the page, abort and return 0. If it was
781 * successfully detached, return 1. Assumes the caller has a single ref on
782 * this page.

--- 3220 unchanged lines hidden ---
775 return 0;
776}
777
778/*
779 * Attempt to detach a locked page from its ->mapping. If it is dirty or if
780 * someone else has a ref on the page, abort and return 0. If it was
781 * successfully detached, return 1. Assumes the caller has a single ref on
782 * this page.

--- 3220 unchanged lines hidden ---