From: Joonsoo Kim <iamjoonsoo.kim@lge.com>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: Mel Gorman <mgorman@suse.de>, Hugh Dickins <hughd@google.com>,
Rik van Riel <riel@redhat.com>, Ingo Molnar <mingo@kernel.org>,
Naoya Horiguchi <n-horiguchi@ah.jp.nec.com>,
Hillf Danton <dhillf@gmail.com>,
linux-kernel@vger.kernel.org, linux-mm@kvack.org,
Joonsoo Kim <js1304@gmail.com>,
Joonsoo Kim <iamjoonsoo.kim@lge.com>
Subject: [PATCH 2/9] mm/rmap: factor nonlinear handling out of try_to_unmap_file()
Date: Thu, 28 Nov 2013 16:48:39 +0900 [thread overview]
Message-ID: <1385624926-28883-3-git-send-email-iamjoonsoo.kim@lge.com> (raw)
In-Reply-To: <1385624926-28883-1-git-send-email-iamjoonsoo.kim@lge.com>
To merge all kinds of rmap traverse functions, try_to_unmap(),
try_to_munlock(), page_referenced() and page_mkclean(), we need to
extract common parts and separate out non-common parts.
Nonlinear handling is handled just in try_to_unmap_file() and other
rmap traverse functions doesn't care of it. Therfore it is better
to factor nonlinear handling out of try_to_unmap_file() in order to
merge all kinds of rmap traverse functions easily.
Signed-off-by: Joonsoo Kim <iamjoonsoo.kim@lge.com>
diff --git a/mm/rmap.c b/mm/rmap.c
index 1214703..e6d532c 100644
--- a/mm/rmap.c
+++ b/mm/rmap.c
@@ -1422,6 +1422,79 @@ static int try_to_unmap_cluster(unsigned long cursor, unsigned int *mapcount,
return ret;
}
+static int try_to_unmap_nonlinear(struct page *page,
+ struct address_space *mapping, struct vm_area_struct *vma)
+{
+ int ret = SWAP_AGAIN;
+ unsigned long cursor;
+ unsigned long max_nl_cursor = 0;
+ unsigned long max_nl_size = 0;
+ unsigned int mapcount;
+
+ list_for_each_entry(vma,
+ &mapping->i_mmap_nonlinear, shared.nonlinear) {
+
+ cursor = (unsigned long) vma->vm_private_data;
+ if (cursor > max_nl_cursor)
+ max_nl_cursor = cursor;
+ cursor = vma->vm_end - vma->vm_start;
+ if (cursor > max_nl_size)
+ max_nl_size = cursor;
+ }
+
+ if (max_nl_size == 0) { /* all nonlinears locked or reserved ? */
+ return SWAP_FAIL;
+ }
+
+ /*
+ * We don't try to search for this page in the nonlinear vmas,
+ * and page_referenced wouldn't have found it anyway. Instead
+ * just walk the nonlinear vmas trying to age and unmap some.
+ * The mapcount of the page we came in with is irrelevant,
+ * but even so use it as a guide to how hard we should try?
+ */
+ mapcount = page_mapcount(page);
+ if (!mapcount)
+ return ret;
+
+ cond_resched();
+
+ max_nl_size = (max_nl_size + CLUSTER_SIZE - 1) & CLUSTER_MASK;
+ if (max_nl_cursor == 0)
+ max_nl_cursor = CLUSTER_SIZE;
+
+ do {
+ list_for_each_entry(vma,
+ &mapping->i_mmap_nonlinear, shared.nonlinear) {
+
+ cursor = (unsigned long) vma->vm_private_data;
+ while (cursor < max_nl_cursor &&
+ cursor < vma->vm_end - vma->vm_start) {
+ if (try_to_unmap_cluster(cursor, &mapcount,
+ vma, page) == SWAP_MLOCK)
+ ret = SWAP_MLOCK;
+ cursor += CLUSTER_SIZE;
+ vma->vm_private_data = (void *) cursor;
+ if ((int)mapcount <= 0)
+ return ret;
+ }
+ vma->vm_private_data = (void *) max_nl_cursor;
+ }
+ cond_resched();
+ max_nl_cursor += CLUSTER_SIZE;
+ } while (max_nl_cursor <= max_nl_size);
+
+ /*
+ * Don't loop forever (perhaps all the remaining pages are
+ * in locked vmas). Reset cursor on all unreserved nonlinear
+ * vmas, now forgetting on which ones it had fallen behind.
+ */
+ list_for_each_entry(vma, &mapping->i_mmap_nonlinear, shared.nonlinear)
+ vma->vm_private_data = NULL;
+
+ return ret;
+}
+
bool is_vma_temporary_stack(struct vm_area_struct *vma)
{
int maybe_stack = vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP);
@@ -1511,10 +1584,6 @@ static int try_to_unmap_file(struct page *page, enum ttu_flags flags)
pgoff_t pgoff = page->index << (PAGE_CACHE_SHIFT - PAGE_SHIFT);
struct vm_area_struct *vma;
int ret = SWAP_AGAIN;
- unsigned long cursor;
- unsigned long max_nl_cursor = 0;
- unsigned long max_nl_size = 0;
- unsigned int mapcount;
if (PageHuge(page))
pgoff = page->index << compound_order(page);
@@ -1538,64 +1607,7 @@ static int try_to_unmap_file(struct page *page, enum ttu_flags flags)
if (TTU_ACTION(flags) == TTU_MUNLOCK)
goto out;
- list_for_each_entry(vma, &mapping->i_mmap_nonlinear,
- shared.nonlinear) {
- cursor = (unsigned long) vma->vm_private_data;
- if (cursor > max_nl_cursor)
- max_nl_cursor = cursor;
- cursor = vma->vm_end - vma->vm_start;
- if (cursor > max_nl_size)
- max_nl_size = cursor;
- }
-
- if (max_nl_size == 0) { /* all nonlinears locked or reserved ? */
- ret = SWAP_FAIL;
- goto out;
- }
-
- /*
- * We don't try to search for this page in the nonlinear vmas,
- * and page_referenced wouldn't have found it anyway. Instead
- * just walk the nonlinear vmas trying to age and unmap some.
- * The mapcount of the page we came in with is irrelevant,
- * but even so use it as a guide to how hard we should try?
- */
- mapcount = page_mapcount(page);
- if (!mapcount)
- goto out;
- cond_resched();
-
- max_nl_size = (max_nl_size + CLUSTER_SIZE - 1) & CLUSTER_MASK;
- if (max_nl_cursor == 0)
- max_nl_cursor = CLUSTER_SIZE;
-
- do {
- list_for_each_entry(vma, &mapping->i_mmap_nonlinear,
- shared.nonlinear) {
- cursor = (unsigned long) vma->vm_private_data;
- while ( cursor < max_nl_cursor &&
- cursor < vma->vm_end - vma->vm_start) {
- if (try_to_unmap_cluster(cursor, &mapcount,
- vma, page) == SWAP_MLOCK)
- ret = SWAP_MLOCK;
- cursor += CLUSTER_SIZE;
- vma->vm_private_data = (void *) cursor;
- if ((int)mapcount <= 0)
- goto out;
- }
- vma->vm_private_data = (void *) max_nl_cursor;
- }
- cond_resched();
- max_nl_cursor += CLUSTER_SIZE;
- } while (max_nl_cursor <= max_nl_size);
-
- /*
- * Don't loop forever (perhaps all the remaining pages are
- * in locked vmas). Reset cursor on all unreserved nonlinear
- * vmas, now forgetting on which ones it had fallen behind.
- */
- list_for_each_entry(vma, &mapping->i_mmap_nonlinear, shared.nonlinear)
- vma->vm_private_data = NULL;
+ ret = try_to_unmap_nonlinear(page, mapping, vma);
out:
mutex_unlock(&mapping->i_mmap_mutex);
return ret;
--
1.7.9.5
next prev parent reply other threads:[~2013-11-28 7:48 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-11-28 7:48 [PATCH 0/9] mm/rmap: unify rmap traversing functions through rmap_walk Joonsoo Kim
2013-11-28 7:48 ` [PATCH 1/9] mm/rmap: recompute pgoff for huge page Joonsoo Kim
2013-12-02 20:09 ` Naoya Horiguchi
2013-12-02 22:44 ` Andrew Morton
2013-12-03 2:01 ` Joonsoo Kim
2013-11-28 7:48 ` Joonsoo Kim [this message]
2013-12-02 20:09 ` [PATCH 2/9] mm/rmap: factor nonlinear handling out of try_to_unmap_file() Naoya Horiguchi
2013-11-28 7:48 ` [PATCH 3/9] mm/rmap: factor lock function out of rmap_walk_anon() Joonsoo Kim
2013-12-02 20:09 ` Naoya Horiguchi
2013-11-28 7:48 ` [PATCH 4/9] mm/rmap: make rmap_walk to get the rmap_walk_control argument Joonsoo Kim
2013-12-02 20:09 ` Naoya Horiguchi
2013-12-02 22:51 ` Andrew Morton
2013-12-03 2:03 ` Joonsoo Kim
2013-12-02 22:52 ` Andrew Morton
2013-11-28 7:48 ` [PATCH 5/9] mm/rmap: extend rmap_walk_xxx() to cope with different cases Joonsoo Kim
2013-12-02 20:09 ` Naoya Horiguchi
2013-12-03 2:05 ` Joonsoo Kim
2013-11-28 7:48 ` [PATCH 6/9] mm/rmap: use rmap_walk() in try_to_unmap() Joonsoo Kim
2013-12-02 20:09 ` Naoya Horiguchi
2013-12-02 23:01 ` Andrew Morton
2013-12-03 2:08 ` Joonsoo Kim
2013-11-28 7:48 ` [PATCH 7/9] mm/rmap: use rmap_walk() in try_to_munlock() Joonsoo Kim
2013-12-02 20:09 ` Naoya Horiguchi
2013-11-28 7:48 ` [PATCH 8/9] mm/rmap: use rmap_walk() in page_referenced() Joonsoo Kim
2013-12-02 20:10 ` Naoya Horiguchi
2013-11-28 7:48 ` [PATCH 9/9] mm/rmap: use rmap_walk() in page_mkclean() Joonsoo Kim
2013-12-02 20:10 ` Naoya Horiguchi
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=1385624926-28883-3-git-send-email-iamjoonsoo.kim@lge.com \
--to=iamjoonsoo.kim@lge.com \
--cc=akpm@linux-foundation.org \
--cc=dhillf@gmail.com \
--cc=hughd@google.com \
--cc=js1304@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=mgorman@suse.de \
--cc=mingo@kernel.org \
--cc=n-horiguchi@ah.jp.nec.com \
--cc=riel@redhat.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).