mm/vmscan: remove unnecessary lruvec adding
We don't have to add a freeable page into lru and then remove from it. This change saves a couple of actions and makes the moving more clear. The SetPageLRU needs to be kept before put_page_testzero for list integrity, otherwise: #0 move_pages_to_lru #1 release_pages if !put_page_testzero if (put_page_testzero()) !PageLRU //skip lru_lock SetPageLRU() list_add(&page->lru,) list_add(&page->lru,) [akpm@linux-foundation.org: coding style fixes] Link: https://lkml.kernel.org/r/1604566549-62481-6-git-send-email-alex.shi@linux.alibaba.com Signed-off-by: Alex Shi <alex.shi@linux.alibaba.com> Acked-by: Hugh Dickins <hughd@google.com> Acked-by: Johannes Weiner <hannes@cmpxchg.org> Acked-by: Vlastimil Babka <vbabka@suse.cz> Cc: Tejun Heo <tj@kernel.org> Cc: Matthew Wilcox <willy@infradead.org> Cc: Alexander Duyck <alexander.duyck@gmail.com> Cc: Andrea Arcangeli <aarcange@redhat.com> Cc: Andrey Ryabinin <aryabinin@virtuozzo.com> Cc: "Chen, Rong A" <rong.a.chen@intel.com> Cc: Daniel Jordan <daniel.m.jordan@oracle.com> Cc: "Huang, Ying" <ying.huang@intel.com> Cc: Jann Horn <jannh@google.com> Cc: Joonsoo Kim <iamjoonsoo.kim@lge.com> Cc: Kirill A. Shutemov <kirill.shutemov@linux.intel.com> Cc: Kirill A. Shutemov <kirill@shutemov.name> Cc: Konstantin Khlebnikov <khlebnikov@yandex-team.ru> Cc: Mel Gorman <mgorman@techsingularity.net> Cc: Michal Hocko <mhocko@kernel.org> Cc: Michal Hocko <mhocko@suse.com> Cc: Mika Penttilä <mika.penttila@nextfour.com> Cc: Minchan Kim <minchan@kernel.org> Cc: Shakeel Butt <shakeelb@google.com> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: Vladimir Davydov <vdavydov.dev@gmail.com> Cc: Wei Yang <richard.weiyang@gmail.com> Cc: Yang Shi <yang.shi@linux.alibaba.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
This commit is contained in:
parent
dcd1eceb6e
commit
e20dc86b22
1 changed files with 26 additions and 14 deletions
40
mm/vmscan.c
40
mm/vmscan.c
|
@ -1942,27 +1942,30 @@ static unsigned noinline_for_stack move_pages_to_lru(struct lruvec *lruvec,
|
||||||
while (!list_empty(list)) {
|
while (!list_empty(list)) {
|
||||||
page = lru_to_page(list);
|
page = lru_to_page(list);
|
||||||
VM_BUG_ON_PAGE(PageLRU(page), page);
|
VM_BUG_ON_PAGE(PageLRU(page), page);
|
||||||
|
list_del(&page->lru);
|
||||||
if (unlikely(!page_evictable(page))) {
|
if (unlikely(!page_evictable(page))) {
|
||||||
list_del(&page->lru);
|
|
||||||
spin_unlock_irq(&pgdat->lru_lock);
|
spin_unlock_irq(&pgdat->lru_lock);
|
||||||
putback_lru_page(page);
|
putback_lru_page(page);
|
||||||
spin_lock_irq(&pgdat->lru_lock);
|
spin_lock_irq(&pgdat->lru_lock);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
lruvec = mem_cgroup_page_lruvec(page, pgdat);
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* The SetPageLRU needs to be kept here for list integrity.
|
||||||
|
* Otherwise:
|
||||||
|
* #0 move_pages_to_lru #1 release_pages
|
||||||
|
* if !put_page_testzero
|
||||||
|
* if (put_page_testzero())
|
||||||
|
* !PageLRU //skip lru_lock
|
||||||
|
* SetPageLRU()
|
||||||
|
* list_add(&page->lru,)
|
||||||
|
* list_add(&page->lru,)
|
||||||
|
*/
|
||||||
SetPageLRU(page);
|
SetPageLRU(page);
|
||||||
lru = page_lru(page);
|
|
||||||
|
|
||||||
nr_pages = thp_nr_pages(page);
|
if (unlikely(put_page_testzero(page))) {
|
||||||
update_lru_size(lruvec, lru, page_zonenum(page), nr_pages);
|
|
||||||
list_move(&page->lru, &lruvec->lists[lru]);
|
|
||||||
trace_android_vh_add_page_to_lrulist(page, false, lru);
|
|
||||||
|
|
||||||
if (put_page_testzero(page)) {
|
|
||||||
__ClearPageLRU(page);
|
__ClearPageLRU(page);
|
||||||
__ClearPageActive(page);
|
__ClearPageActive(page);
|
||||||
del_page_from_lru_list(page, lruvec, lru);
|
|
||||||
|
|
||||||
if (unlikely(PageCompound(page))) {
|
if (unlikely(PageCompound(page))) {
|
||||||
spin_unlock_irq(&pgdat->lru_lock);
|
spin_unlock_irq(&pgdat->lru_lock);
|
||||||
|
@ -1970,11 +1973,20 @@ static unsigned noinline_for_stack move_pages_to_lru(struct lruvec *lruvec,
|
||||||
spin_lock_irq(&pgdat->lru_lock);
|
spin_lock_irq(&pgdat->lru_lock);
|
||||||
} else
|
} else
|
||||||
list_add(&page->lru, &pages_to_free);
|
list_add(&page->lru, &pages_to_free);
|
||||||
} else {
|
|
||||||
nr_moved += nr_pages;
|
continue;
|
||||||
if (PageActive(page))
|
|
||||||
workingset_age_nonresident(lruvec, nr_pages);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
lruvec = mem_cgroup_page_lruvec(page, pgdat);
|
||||||
|
lru = page_lru(page);
|
||||||
|
nr_pages = thp_nr_pages(page);
|
||||||
|
|
||||||
|
update_lru_size(lruvec, lru, page_zonenum(page), nr_pages);
|
||||||
|
list_add(&page->lru, &lruvec->lists[lru]);
|
||||||
|
trace_android_vh_add_page_to_lrulist(page, false, lru);
|
||||||
|
nr_moved += nr_pages;
|
||||||
|
if (PageActive(page))
|
||||||
|
workingset_age_nonresident(lruvec, nr_pages);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
Loading…
Reference in a new issue