]> git.neil.brown.name Git - history.git/commitdiff
[PATCH] fix madvise(MADV_DONTNEED) for nonlinear vmas
authorAndrew Morton <akpm@osdl.org>
Tue, 20 Apr 2004 00:22:03 +0000 (17:22 -0700)
committerLinus Torvalds <torvalds@ppc970.osdl.org>
Tue, 20 Apr 2004 00:22:03 +0000 (17:22 -0700)
From: Hugh Dickins <hugh@veritas.com>

Jamie points out that madvise(MADV_DONTNEED) should unmap pages from a
nonlinear area in such a way that the nonlinear offsets are preserved if the
pages do turn out to be needed later after all, instead of reverting them to
linearity: needs to pass down a zap_details block.

(But this still leaves mincore unaware of nonlinear vmas: bigger job.)

include/linux/mm.h
mm/madvise.c
mm/memory.c

index d664c4ffbcc7173afec8d111989f9856afe2eb9c..103f14358d1f4b7ad8933fcc4736e5297807c7cc 100644 (file)
@@ -439,7 +439,16 @@ struct file *shmem_file_setup(char * name, loff_t size, unsigned long flags);
 void shmem_lock(struct file * file, int lock);
 int shmem_zero_setup(struct vm_area_struct *);
 
-struct zap_details;
+/*
+ * Parameter block passed down to zap_pte_range in exceptional cases.
+ */
+struct zap_details {
+       struct vm_area_struct *nonlinear_vma;   /* Check page->index if set */
+       struct address_space *check_mapping;    /* Check page->mapping if set */
+       pgoff_t first_index;                    /* Lowest page->index to unmap */
+       pgoff_t last_index;                     /* Highest page->index to unmap */
+};
+
 void zap_page_range(struct vm_area_struct *vma, unsigned long address,
                unsigned long size, struct zap_details *);
 int unmap_vmas(struct mmu_gather **tlbp, struct mm_struct *mm,
index bfb4319503717688f8321af1039943da06bd210b..81c4ea30c75e60b9001127697045d000ae075fd1 100644 (file)
@@ -92,10 +92,19 @@ static long madvise_willneed(struct vm_area_struct * vma,
 static long madvise_dontneed(struct vm_area_struct * vma,
                             unsigned long start, unsigned long end)
 {
+       struct zap_details details;
+
        if (vma->vm_flags & VM_LOCKED)
                return -EINVAL;
 
-       zap_page_range(vma, start, end - start, NULL);
+       if (unlikely(vma->vm_flags & VM_NONLINEAR)) {
+               details.check_mapping = NULL;
+               details.nonlinear_vma = vma;
+               details.first_index = 0;
+               details.last_index = ULONG_MAX;
+               zap_page_range(vma, start, end - start, &details);
+       } else
+               zap_page_range(vma, start, end - start, NULL);
        return 0;
 }
 
index e54939da2caf92dba3f0c998aa20e45942f6cd95..5ae7c99aeaa5d96e91fa73712d8527c551d3386a 100644 (file)
@@ -384,16 +384,6 @@ nomem:
        return -ENOMEM;
 }
 
-/*
- * Parameter block passed down to zap_pte_range in exceptional cases.
- */
-struct zap_details {
-       struct vm_area_struct *nonlinear_vma;   /* Check page->index if set */
-       struct address_space *check_mapping;    /* Check page->mapping if set */
-       pgoff_t first_index;                    /* Lowest page->index to unmap */
-       pgoff_t last_index;                     /* Highest page->index to unmap */
-};
-
 static void zap_pte_range(struct mmu_gather *tlb,
                pmd_t *pmd, unsigned long address,
                unsigned long size, struct zap_details *details)