Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

mm: kill vma flag VM_INSERTPAGE

Merge VM_INSERTPAGE into VM_MIXEDMAP. VM_MIXEDMAP VMA can mix pure-pfn
ptes, special ptes and normal ptes.

Now copy_page_range() always copies VM_MIXEDMAP VMA on fork like
VM_PFNMAP. If driver populates whole VMA at mmap() it probably not
expects page-faults.

This patch removes special check from vma_wants_writenotify() which
disables pages write tracking for VMA populated via vm_instert_page().
BDI below mapped file should not use dirty-accounting, moreover
do_wp_page() can handle this.

vm_insert_page() still marks vma after first usage. Usually it is called
from f_op->mmap() handler under mm->mmap_sem write-lock, so it able to
change vma->vm_flags. Caller must set VM_MIXEDMAP at mmap time if it
wants to call this function from other places, for example from page-fault
handler.

Signed-off-by: Konstantin Khlebnikov <khlebnikov@openvz.org>
Cc: Alexander Viro <viro@zeniv.linux.org.uk>
Cc: Carsten Otte <cotte@de.ibm.com>
Cc: Chris Metcalf <cmetcalf@tilera.com>
Cc: Cyrill Gorcunov <gorcunov@openvz.org>
Cc: Eric Paris <eparis@redhat.com>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Hugh Dickins <hughd@google.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: James Morris <james.l.morris@oracle.com>
Cc: Jason Baron <jbaron@redhat.com>
Cc: Kentaro Takeda <takedakn@nttdata.co.jp>
Cc: Matt Helsley <matthltc@us.ibm.com>
Cc: Nick Piggin <npiggin@kernel.dk>
Cc: Oleg Nesterov <oleg@redhat.com>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Robert Richter <robert.richter@amd.com>
Cc: Suresh Siddha <suresh.b.siddha@intel.com>
Cc: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
Cc: Venkatesh Pallipadi <venki@google.com>
Acked-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

authored by

Konstantin Khlebnikov and committed by
Linus Torvalds
4b6e1e37 cc2383ec

+15 -7
-1
include/linux/mm.h
··· 103 103 #define VM_HUGETLB 0x00400000 /* Huge TLB Page VM */ 104 104 #define VM_NONLINEAR 0x00800000 /* Is non-linear (remap_file_pages) */ 105 105 #define VM_ARCH_1 0x01000000 /* Architecture-specific flag */ 106 - #define VM_INSERTPAGE 0x02000000 /* The vma has had "vm_insert_page()" done on it */ 107 106 #define VM_NODUMP 0x04000000 /* Do not include in the core dump */ 108 107 109 108 #define VM_CAN_NONLINEAR 0x08000000 /* Has ->fault & does nonlinear pages */
+1 -2
mm/huge_memory.c
··· 1491 1491 return ret; 1492 1492 } 1493 1493 1494 - #define VM_NO_THP (VM_SPECIAL|VM_INSERTPAGE|VM_MIXEDMAP| \ 1495 - VM_HUGETLB|VM_SHARED|VM_MAYSHARE) 1494 + #define VM_NO_THP (VM_SPECIAL|VM_MIXEDMAP|VM_HUGETLB|VM_SHARED|VM_MAYSHARE) 1496 1495 1497 1496 int hugepage_madvise(struct vm_area_struct *vma, 1498 1497 unsigned long *vm_flags, int advice)
+1 -1
mm/ksm.c
··· 1469 1469 */ 1470 1470 if (*vm_flags & (VM_MERGEABLE | VM_SHARED | VM_MAYSHARE | 1471 1471 VM_PFNMAP | VM_IO | VM_DONTEXPAND | 1472 - VM_RESERVED | VM_HUGETLB | VM_INSERTPAGE | 1472 + VM_RESERVED | VM_HUGETLB | 1473 1473 VM_NONLINEAR | VM_MIXEDMAP)) 1474 1474 return 0; /* just ignore the advice */ 1475 1475
+12 -2
mm/memory.c
··· 1047 1047 * readonly mappings. The tradeoff is that copy_page_range is more 1048 1048 * efficient than faulting. 1049 1049 */ 1050 - if (!(vma->vm_flags & (VM_HUGETLB|VM_NONLINEAR|VM_PFNMAP|VM_INSERTPAGE))) { 1050 + if (!(vma->vm_flags & (VM_HUGETLB | VM_NONLINEAR | 1051 + VM_PFNMAP | VM_MIXEDMAP))) { 1051 1052 if (!vma->anon_vma) 1052 1053 return 0; 1053 1054 } ··· 2086 2085 * ask for a shared writable mapping! 2087 2086 * 2088 2087 * The page does not need to be reserved. 2088 + * 2089 + * Usually this function is called from f_op->mmap() handler 2090 + * under mm->mmap_sem write-lock, so it can change vma->vm_flags. 2091 + * Caller must set VM_MIXEDMAP on vma if it wants to call this 2092 + * function from other places, for example from page-fault handler. 2089 2093 */ 2090 2094 int vm_insert_page(struct vm_area_struct *vma, unsigned long addr, 2091 2095 struct page *page) ··· 2099 2093 return -EFAULT; 2100 2094 if (!page_count(page)) 2101 2095 return -EINVAL; 2102 - vma->vm_flags |= VM_INSERTPAGE; 2096 + if (!(vma->vm_flags & VM_MIXEDMAP)) { 2097 + BUG_ON(down_read_trylock(&vma->vm_mm->mmap_sem)); 2098 + BUG_ON(vma->vm_flags & VM_PFNMAP); 2099 + vma->vm_flags |= VM_MIXEDMAP; 2100 + } 2103 2101 return insert_page(vma, addr, page, vma->vm_page_prot); 2104 2102 } 2105 2103 EXPORT_SYMBOL(vm_insert_page);
+1 -1
mm/mmap.c
··· 1190 1190 return 0; 1191 1191 1192 1192 /* Specialty mapping? */ 1193 - if (vm_flags & (VM_PFNMAP|VM_INSERTPAGE)) 1193 + if (vm_flags & VM_PFNMAP) 1194 1194 return 0; 1195 1195 1196 1196 /* Can the mapping track the dirty pages? */