Re: [PATCH v4 7/7] Prevent activation of page in madvise_dontneed

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: Minchan Kim
Date: Monday, December 6, 2010 - 10:44 pm

On Tue, Dec 7, 2010 at 1:48 PM, Hugh Dickins <hughd@google.com> wrote:

Thanks for the notice.

How about this? Although it doesn't remove null dependency, it meet my
goal without big overhead.
It's just quick patch. If you agree, I will resend this version as formal patch.
(If you suffered from seeing below word-wrapped source, see the
attachment. I asked to google two time to support text-plain mode in
gmail web but I can't receive any response until now. ;(. Lots of
kernel developer in google. Please support this mode for us who can't
use SMTP although it's a very small VOC)

diff --git a/include/linux/mm.h b/include/linux/mm.h
index e097df6..14ae918 100644
--- a/include/linux/mm.h
+++ b/include/linux/mm.h
@@ -771,6 +771,7 @@ struct zap_details {
        pgoff_t last_index;                     /* Highest page->index
to unmap */
        spinlock_t *i_mmap_lock;                /* For unmap_mapping_range: */
        unsigned long truncate_count;           /* Compare vm_truncate_count */
+       int ignore_reference;
 };

 struct page *vm_normal_page(struct vm_area_struct *vma, unsigned long addr,
diff --git a/mm/madvise.c b/mm/madvise.c
index 319528b..fdb0253 100644
--- a/mm/madvise.c
+++ b/mm/madvise.c
@@ -162,18 +162,22 @@ static long madvise_dontneed(struct vm_area_struct * vma,
                             struct vm_area_struct ** prev,
                             unsigned long start, unsigned long end)
 {
+       struct zap_details details ;
+
        *prev = vma;
        if (vma->vm_flags & (VM_LOCKED|VM_HUGETLB|VM_PFNMAP))
                return -EINVAL;

        if (unlikely(vma->vm_flags & VM_NONLINEAR)) {
-               struct zap_details details = {
-                       .nonlinear_vma = vma,
-                       .last_index = ULONG_MAX,
-               };
-               zap_page_range(vma, start, end - start, &details);
-       } else
-               zap_page_range(vma, start, end - start, NULL);
+               details.nonlinear_vma = vma;
+               details.last_index = ULONG_MAX;
+       } else {
+               details.nonlinear_vma = NULL;
+               details.last_index = NULL;
+       }
+
+       details.ignore_references = true;
+       zap_page_range(vma, start, end - start, &details);
        return 0;
 }

diff --git a/mm/memory.c b/mm/memory.c
index ebfeedf..d46ac42 100644
--- a/mm/memory.c
+++ b/mm/memory.c
@@ -897,9 +897,15 @@ static unsigned long zap_pte_range(struct mmu_gather *tlb,
        pte_t *pte;
        spinlock_t *ptl;
        int rss[NR_MM_COUNTERS];
-
+       bool ignore_reference = false;
        init_rss_vec(rss);

+       if (details && ((!details->check_mapping && !details->nonlinear_vma)
+                                        || !details->ignore_reference))
+               details = NULL;
+
        pte = pte_offset_map_lock(mm, pmd, addr, &ptl);
        arch_enter_lazy_mmu_mode();
        do {
@@ -949,7 +955,8 @@ static unsigned long zap_pte_range(struct mmu_gather *tlb,
                                if (pte_dirty(ptent))
                                        set_page_dirty(page);
                                if (pte_young(ptent) &&
-                                   likely(!VM_SequentialReadHint(vma)))
+                                   likely(!VM_SequentialReadHint(vma)) &&
+                                   likely(!ignore_reference))
                                        mark_page_accessed(page);
                                rss[MM_FILEPAGES]--;
                        }
@@ -1038,8 +1045,6 @@ static unsigned long unmap_page_range(struct
mmu_gather *tlb,
        pgd_t *pgd;
        unsigned long next;

-       if (details && !details->check_mapping && !details->nonlinear_vma)
-               details = NULL;

        BUG_ON(addr >= end);
        mem_cgroup_uncharge_start();
@@ -1102,7 +1107,8 @@ unsigned long unmap_vmas(struct mmu_gather **tlbp,
        unsigned long tlb_start = 0;    /* For tlb_finish_mmu */
        int tlb_start_valid = 0;
        unsigned long start = start_addr;
-       spinlock_t *i_mmap_lock = details? details->i_mmap_lock: NULL;
+       spinlock_t *i_mmap_lock = details ?
+               (detais->check_mapping ? details->i_mmap_lock: NULL) : NULL;
        int fullmm = (*tlbp)->fullmm;
        struct mm_struct *mm = vma->vm_mm;






-- 
Kind regards,
Minchan Kim
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
[PATCH v4 0/7] f/madivse(DONTNEED) support, Minchan Kim, (Sun Dec 5, 10:29 am)
[PATCH v4 1/7] Fix checkpatch's report in swap.c, Minchan Kim, (Sun Dec 5, 10:29 am)
[PATCH v4 2/7] deactivate invalidated pages, Minchan Kim, (Sun Dec 5, 10:29 am)
[PATCH v4 4/7] Reclaim invalidated page ASAP, Minchan Kim, (Sun Dec 5, 10:29 am)
[PATCH v4 6/7] Remove zap_details NULL dependency, Minchan Kim, (Sun Dec 5, 10:29 am)
Re: [PATCH v4 1/7] Fix checkpatch's report in swap.c, Rik van Riel, (Sun Dec 5, 6:47 pm)
Re: [PATCH v4 6/7] Remove zap_details NULL dependency, Rik van Riel, (Sun Dec 5, 8:25 pm)
Re: [PATCH v4 2/7] deactivate invalidated pages, Mel Gorman, (Mon Dec 6, 7:53 am)
Re: [PATCH v4 6/7] Remove zap_details NULL dependency, Hugh Dickins, (Mon Dec 6, 9:26 pm)
Re: [PATCH v4 6/7] Remove zap_details NULL dependency, Minchan Kim, (Mon Dec 6, 10:30 pm)
Re: [PATCH v4 7/7] Prevent activation of page in madvise_d ..., Minchan Kim, (Mon Dec 6, 10:44 pm)
Re: [PATCH v4 1/7] Fix checkpatch's report in swap.c, Johannes Weiner, (Tue Dec 7, 7:37 am)
Re: [PATCH v4 2/7] deactivate invalidated pages, Johannes Weiner, (Tue Dec 7, 7:49 am)
Re: [PATCH v4 4/7] Reclaim invalidated page ASAP, Johannes Weiner, (Tue Dec 7, 8:05 am)
Re: [PATCH v4 2/7] deactivate invalidated pages, Minchan Kim, (Tue Dec 7, 8:07 am)
Re: [PATCH v4 2/7] deactivate invalidated pages, Johannes Weiner, (Tue Dec 7, 8:19 am)
Re: [PATCH v4 4/7] Reclaim invalidated page ASAP, Minchan Kim, (Tue Dec 7, 8:21 am)
Re: [PATCH v4 2/7] deactivate invalidated pages, Minchan Kim, (Tue Dec 7, 8:26 am)
Re: [PATCH v4 2/7] deactivate invalidated pages, Johannes Weiner, (Tue Dec 7, 8:56 am)
Re: [PATCH v4 2/7] deactivate invalidated pages, Minchan Kim, (Tue Dec 7, 3:51 pm)
Re: [PATCH v4 2/7] deactivate invalidated pages, KAMEZAWA Hiroyuki, (Tue Dec 7, 5:56 pm)
Re: [PATCH v4 2/7] deactivate invalidated pages, Minchan Kim, (Tue Dec 7, 6:43 pm)
Re: [PATCH v4 2/7] deactivate invalidated pages, KAMEZAWA Hiroyuki, (Tue Dec 7, 6:56 pm)
Re: [PATCH v4 2/7] deactivate invalidated pages, Minchan Kim, (Tue Dec 7, 7:15 pm)
Re: [PATCH v4 2/7] deactivate invalidated pages, Balbir Singh, (Tue Dec 7, 11:56 pm)
Re: [PATCH v4 4/7] Reclaim invalidated page ASAP, KOSAKI Motohiro, (Wed Dec 8, 1:04 am)
Re: [PATCH v4 4/7] Reclaim invalidated page ASAP, Minchan Kim, (Wed Dec 8, 1:16 am)
Re: [PATCH v4 4/7] Reclaim invalidated page ASAP, Ben Gamari, (Wed Dec 8, 6:01 am)
Re: [PATCH v4 4/7] Reclaim invalidated page ASAP, Minchan Kim, (Wed Dec 8, 4:10 pm)
Re: [PATCH v4 2/7] deactivate invalidated pages, Minchan Kim, (Wed Dec 8, 5:19 pm)
Re: [PATCH v4 4/7] Reclaim invalidated page ASAP, Minchan Kim, (Mon Dec 13, 8:31 am)
Re: [PATCH v4 4/7] Reclaim invalidated page ASAP, Ben Gamari, (Mon Dec 13, 1:06 pm)
Re: [PATCH v4 4/7] Reclaim invalidated page ASAP, KAMEZAWA Hiroyuki, (Mon Dec 13, 7:07 pm)
Re: [PATCH v4 4/7] Reclaim invalidated page ASAP, Minchan Kim, (Mon Dec 13, 7:34 pm)
Re: [PATCH v4 4/7] Reclaim invalidated page ASAP, Minchan Kim, (Mon Dec 13, 7:36 pm)