From: Minchan Kim <minchan@kernel.org>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org,
Michael Kerrisk <mtk.manpages@gmail.com>,
linux-api@vger.kernel.org, Hugh Dickins <hughd@google.com>,
Johannes Weiner <hannes@cmpxchg.org>,
Rik van Riel <riel@redhat.com>, Mel Gorman <mgorman@suse.de>,
KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>,
Jason Evans <je@fb.com>, Daniel Micay <danielmicay@gmail.com>,
"Kirill A. Shutemov" <kirill@shutemov.name>,
Shaohua Li <shli@kernel.org>, Michal Hocko <mhocko@suse.cz>,
yalin.wang2010@gmail.com, Minchan Kim <minchan@kernel.org>
Subject: [PATCH v3 05/17] mm: move lazily freed pages to inactive list
Date: Thu, 12 Nov 2015 13:33:01 +0900 [thread overview]
Message-ID: <1447302793-5376-6-git-send-email-minchan@kernel.org> (raw)
In-Reply-To: <1447302793-5376-1-git-send-email-minchan@kernel.org>
MADV_FREE is a hint that it's okay to discard pages if there is memory
pressure and we use reclaimers(ie, kswapd and direct reclaim) to free them
so there is no value keeping them in the active anonymous LRU so this
patch moves them to inactive LRU list's head.
This means that MADV_FREE-ed pages which were living on the inactive list
are reclaimed first because they are more likely to be cold rather than
recently active pages.
An arguable issue for the approach would be whether we should put the page
to the head or tail of the inactive list. I chose head because the kernel
cannot make sure it's really cold or warm for every MADV_FREE usecase but
at least we know it's not *hot*, so landing of inactive head would be a
comprimise for various usecases.
This fixes suboptimal behavior of MADV_FREE when pages living on the
active list will sit there for a long time even under memory pressure
while the inactive list is reclaimed heavily. This basically breaks the
whole purpose of using MADV_FREE to help the system to free memory which
is might not be used.
Cc: Johannes Weiner <hannes@cmpxchg.org>
Cc: Mel Gorman <mgorman@suse.de>
Cc: Rik van Riel <riel@redhat.com>
Cc: Shaohua Li <shli@kernel.org>
Acked-by: Hugh Dickins <hughd@google.com>
Acked-by: Michal Hocko <mhocko@suse.cz>
Signed-off-by: Minchan Kim <minchan@kernel.org>
---
include/linux/swap.h | 2 +-
mm/madvise.c | 3 +++
mm/swap.c | 62 +++++++++++++++++++++++++++++-----------------------
mm/truncate.c | 2 +-
4 files changed, 40 insertions(+), 29 deletions(-)
diff --git a/include/linux/swap.h b/include/linux/swap.h
index 7ba7dccaf0e7..8e944c0cedea 100644
--- a/include/linux/swap.h
+++ b/include/linux/swap.h
@@ -307,7 +307,7 @@ extern void lru_add_drain(void);
extern void lru_add_drain_cpu(int cpu);
extern void lru_add_drain_all(void);
extern void rotate_reclaimable_page(struct page *page);
-extern void deactivate_file_page(struct page *page);
+extern void deactivate_page(struct page *page);
extern void swap_setup(void);
extern void add_page_to_unevictable_list(struct page *page);
diff --git a/mm/madvise.c b/mm/madvise.c
index 6240a5de4a3a..3462a3ca9690 100644
--- a/mm/madvise.c
+++ b/mm/madvise.c
@@ -317,6 +317,9 @@ static int madvise_free_pte_range(pmd_t *pmd, unsigned long addr,
unlock_page(page);
}
+ if (PageActive(page))
+ deactivate_page(page);
+
if (pte_young(ptent) || pte_dirty(ptent)) {
/*
* Some of architecture(ex, PPC) don't update TLB
diff --git a/mm/swap.c b/mm/swap.c
index 983f692a47fd..a2f2cd458de0 100644
--- a/mm/swap.c
+++ b/mm/swap.c
@@ -44,7 +44,7 @@ int page_cluster;
static DEFINE_PER_CPU(struct pagevec, lru_add_pvec);
static DEFINE_PER_CPU(struct pagevec, lru_rotate_pvecs);
-static DEFINE_PER_CPU(struct pagevec, lru_deactivate_file_pvecs);
+static DEFINE_PER_CPU(struct pagevec, lru_deactivate_pvecs);
/*
* This path almost never happens for VM activity - pages are normally
@@ -733,13 +733,13 @@ void lru_cache_add_active_or_unevictable(struct page *page,
}
/*
- * If the page can not be invalidated, it is moved to the
+ * If the file page can not be invalidated, it is moved to the
* inactive list to speed up its reclaim. It is moved to the
* head of the list, rather than the tail, to give the flusher
* threads some time to write it out, as this is much more
* effective than the single-page writeout from reclaim.
*
- * If the page isn't page_mapped and dirty/writeback, the page
+ * If the file page isn't page_mapped and dirty/writeback, the page
* could reclaim asap using PG_reclaim.
*
* 1. active, mapped page -> none
@@ -752,32 +752,36 @@ void lru_cache_add_active_or_unevictable(struct page *page,
* In 4, why it moves inactive's head, the VM expects the page would
* be write it out by flusher threads as this is much more effective
* than the single-page writeout from reclaim.
+ *
+ * If @page is anonymous page, it is moved to the inactive list.
*/
-static void lru_deactivate_file_fn(struct page *page, struct lruvec *lruvec,
+static void lru_deactivate_fn(struct page *page, struct lruvec *lruvec,
void *arg)
{
- int lru, file;
- bool active;
+ int lru;
+ bool file, active;
- if (!PageLRU(page))
+ if (!PageLRU(page) || PageUnevictable(page))
return;
- if (PageUnevictable(page))
- return;
+ file = page_is_file_cache(page);
+ active = PageActive(page);
+ lru = page_lru_base_type(page);
- /* Some processes are using the page */
- if (page_mapped(page))
+ if (!file && !active)
return;
- active = PageActive(page);
- file = page_is_file_cache(page);
- lru = page_lru_base_type(page);
+ if (file && page_mapped(page))
+ return;
del_page_from_lru_list(page, lruvec, lru + active);
ClearPageActive(page);
- ClearPageReferenced(page);
add_page_to_lru_list(page, lruvec, lru);
+ if (!file)
+ goto out;
+
+ ClearPageReferenced(page);
if (PageWriteback(page) || PageDirty(page)) {
/*
* PG_reclaim could be raced with end_page_writeback
@@ -793,9 +797,10 @@ static void lru_deactivate_file_fn(struct page *page, struct lruvec *lruvec,
list_move_tail(&page->lru, &lruvec->lists[lru]);
__count_vm_event(PGROTATED);
}
-
+out:
if (active)
__count_vm_event(PGDEACTIVATE);
+
update_page_reclaim_stat(lruvec, file, 0);
}
@@ -821,22 +826,25 @@ void lru_add_drain_cpu(int cpu)
local_irq_restore(flags);
}
- pvec = &per_cpu(lru_deactivate_file_pvecs, cpu);
+ pvec = &per_cpu(lru_deactivate_pvecs, cpu);
if (pagevec_count(pvec))
- pagevec_lru_move_fn(pvec, lru_deactivate_file_fn, NULL);
+ pagevec_lru_move_fn(pvec, lru_deactivate_fn, NULL);
activate_page_drain(cpu);
}
/**
- * deactivate_file_page - forcefully deactivate a file page
+ * deactivate_page - forcefully deactivate a page
* @page: page to deactivate
*
- * This function hints the VM that @page is a good reclaim candidate,
- * for example if its invalidation fails due to the page being dirty
- * or under writeback.
+ * This function hints the VM that @page is a good reclaim candidate to
+ * accelerate the reclaim of @page.
+ * For example,
+ * 1. Invalidation of file-page fails due to the page being dirty or under
+ * writeback.
+ * 2. MADV_FREE hinted anonymous page.
*/
-void deactivate_file_page(struct page *page)
+void deactivate_page(struct page *page)
{
/*
* In a workload with many unevictable page such as mprotect,
@@ -846,11 +854,11 @@ void deactivate_file_page(struct page *page)
return;
if (likely(get_page_unless_zero(page))) {
- struct pagevec *pvec = &get_cpu_var(lru_deactivate_file_pvecs);
+ struct pagevec *pvec = &get_cpu_var(lru_deactivate_pvecs);
if (!pagevec_add(pvec, page))
- pagevec_lru_move_fn(pvec, lru_deactivate_file_fn, NULL);
- put_cpu_var(lru_deactivate_file_pvecs);
+ pagevec_lru_move_fn(pvec, lru_deactivate_fn, NULL);
+ put_cpu_var(lru_deactivate_pvecs);
}
}
@@ -882,7 +890,7 @@ void lru_add_drain_all(void)
if (pagevec_count(&per_cpu(lru_add_pvec, cpu)) ||
pagevec_count(&per_cpu(lru_rotate_pvecs, cpu)) ||
- pagevec_count(&per_cpu(lru_deactivate_file_pvecs, cpu)) ||
+ pagevec_count(&per_cpu(lru_deactivate_pvecs, cpu)) ||
need_activate_page_drain(cpu)) {
INIT_WORK(work, lru_add_drain_per_cpu);
schedule_work_on(cpu, work);
diff --git a/mm/truncate.c b/mm/truncate.c
index 76e35ad97102..cf8d44679364 100644
--- a/mm/truncate.c
+++ b/mm/truncate.c
@@ -488,7 +488,7 @@ unsigned long invalidate_mapping_pages(struct address_space *mapping,
* of interest and try to speed up its reclaim.
*/
if (!ret)
- deactivate_file_page(page);
+ deactivate_page(page);
count += ret;
}
pagevec_remove_exceptionals(&pvec);
--
1.9.1
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
next prev parent reply other threads:[~2015-11-12 4:33 UTC|newest]
Thread overview: 36+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-11-12 4:32 [PATCH v3 00/17] MADFV_FREE support Minchan Kim
2015-11-12 4:32 ` [PATCH v3 01/17] mm: support madvise(MADV_FREE) Minchan Kim
2015-11-12 4:49 ` Andy Lutomirski
2015-11-12 5:21 ` Daniel Micay
2015-11-13 6:15 ` Minchan Kim
2015-11-13 6:16 ` Daniel Micay
[not found] ` <56458056.8020105-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2015-11-13 6:38 ` Minchan Kim
2015-11-13 6:45 ` Daniel Micay
2015-11-13 7:03 ` Minchan Kim
2015-11-13 8:13 ` Daniel Micay
2015-11-13 19:46 ` Andy Lutomirski
2015-11-16 2:13 ` Minchan Kim
2015-11-16 3:14 ` yalin wang
[not found] ` <1447302793-5376-2-git-send-email-minchan-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
2015-11-12 11:26 ` Kirill A. Shutemov
[not found] ` <20151112112620.GB22481-sVvlyX1904swdBt8bTSxpkEMvNT87kid@public.gmane.org>
2015-11-13 6:17 ` Minchan Kim
2015-11-12 4:32 ` [PATCH v3 02/17] mm: define MADV_FREE for some arches Minchan Kim
2015-11-12 4:32 ` [PATCH v3 03/17] arch: uapi: asm: mman.h: Let MADV_FREE have same value for all architectures Minchan Kim
2015-11-12 11:27 ` Kirill A. Shutemov
2015-11-13 6:18 ` Minchan Kim
[not found] ` <564895F3.8090300@hotmail.com>
2015-11-15 14:23 ` Chen Gang
2015-11-12 4:33 ` [PATCH v3 04/17] mm: free swp_entry in madvise_free Minchan Kim
2015-11-12 4:33 ` Minchan Kim [this message]
2015-11-12 4:33 ` [PATCH v3 06/17] mm: clear PG_dirty to mark page freeable Minchan Kim
2015-11-12 4:33 ` [PATCH v3 07/17] mm: mark stable page dirty in KSM Minchan Kim
2015-11-12 4:33 ` [PATCH v3 08/17] x86: add pmd_[dirty|mkclean] for THP Minchan Kim
2015-11-12 4:33 ` [PATCH v3 09/17] sparc: " Minchan Kim
2015-11-12 4:33 ` [PATCH v3 10/17] powerpc: " Minchan Kim
2015-11-12 4:33 ` [PATCH v3 11/17] arm: add pmd_mkclean " Minchan Kim
2015-11-12 4:33 ` [PATCH v3 12/17] arm64: " Minchan Kim
2015-11-12 4:33 ` [PATCH v3 13/17] mm: don't split THP page when syscall is called Minchan Kim
2015-11-12 4:33 ` [PATCH v3 14/17] mm: introduce wrappers to add new LRU Minchan Kim
2015-11-12 4:33 ` [PATCH v3 15/17] mm: introduce lazyfree LRU list Minchan Kim
[not found] ` <1447302793-5376-1-git-send-email-minchan-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
2015-11-12 4:33 ` [PATCH v3 16/17] mm: support MADV_FREE on swapless system Minchan Kim
2015-11-12 4:33 ` [PATCH v3 17/17] mm: add knob to tune lazyfreeing Minchan Kim
[not found] ` <1447302793-5376-18-git-send-email-minchan-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
2015-11-12 19:44 ` Shaohua Li
[not found] ` <20151112194453.GA50352-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
2015-11-13 6:20 ` Minchan Kim
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1447302793-5376-6-git-send-email-minchan@kernel.org \
--to=minchan@kernel.org \
--cc=akpm@linux-foundation.org \
--cc=danielmicay@gmail.com \
--cc=hannes@cmpxchg.org \
--cc=hughd@google.com \
--cc=je@fb.com \
--cc=kirill@shutemov.name \
--cc=kosaki.motohiro@jp.fujitsu.com \
--cc=linux-api@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=mgorman@suse.de \
--cc=mhocko@suse.cz \
--cc=mtk.manpages@gmail.com \
--cc=riel@redhat.com \
--cc=shli@kernel.org \
--cc=yalin.wang2010@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).