Skip to content

Commit 0b14c17

Browse files
Hugh DickinsLinus Torvalds
authored andcommitted
[PATCH] unpaged: VM_UNPAGED
Although we tend to associate VM_RESERVED with remap_pfn_range, quite a few drivers set VM_RESERVED on areas which are then populated by nopage. The PageReserved removal in 2.6.15-rc1 changed VM_RESERVED not to free pages in zap_pte_range, without changing those drivers not to set it: so their pages just leak away. Let's not change miscellaneous drivers now: introduce VM_UNPAGED at the core, to flag the special areas where the ptes may have no struct page, or if they have then it's not to be touched. Replace most instances of VM_RESERVED in core mm by VM_UNPAGED. Force it on in remap_pfn_range, and the sparc and sparc64 io_remap_pfn_range. Revert addition of VM_RESERVED to powerpc vdso, it's not needed there. Is it needed anywhere? It still governs the mm->reserved_vm statistic, and special vmas not to be merged, and areas not to be core dumped; but could probably be eliminated later (the drivers are probably specifying it because in 2.4 it kept swapout off the vma, but in 2.6 we work from the LRU, which these pages don't get on). Use the VM_SHM slot for VM_UNPAGED, and define VM_SHM to 0: it serves no purpose whatsoever, and should be removed from drivers when we clean up. Signed-off-by: Hugh Dickins <hugh@veritas.com> Acked-by: William Irwin <wli@holomorphy.com> Signed-off-by: Andrew Morton <akpm@osdl.org> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
1 parent 664beed commit 0b14c17

9 files changed

Lines changed: 30 additions & 24 deletions

File tree

‎arch/powerpc/kernel/vdso.c‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -285,8 +285,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm,
285285
* It's fine to use that for setting breakpoints in the vDSO code
286286
* pages though
287287
*/
288-
vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYWRITE |
289-
VM_MAYEXEC | VM_RESERVED;
288+
vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC;
290289
vma->vm_flags |= mm->def_flags;
291290
vma->vm_page_prot = protection_map[vma->vm_flags & 0x7];
292291
vma->vm_ops = &vdso_vmops;

‎arch/sparc/mm/generic.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ int io_remap_pfn_range(struct vm_area_struct *vma, unsigned long from,
7474
unsigned long offset = GET_PFN(pfn) << PAGE_SHIFT;
7575

7676
/* See comment in mm/memory.c remap_pfn_range */
77-
vma->vm_flags |= VM_IO | VM_RESERVED;
77+
vma->vm_flags |= VM_IO | VM_RESERVED | VM_UNPAGED;
7878

7979
prot = __pgprot(pg_iobits);
8080
offset -= from;

‎arch/sparc64/mm/generic.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ int io_remap_pfn_range(struct vm_area_struct *vma, unsigned long from,
128128
unsigned long offset = GET_PFN(pfn) << PAGE_SHIFT;
129129

130130
/* See comment in mm/memory.c remap_pfn_range */
131-
vma->vm_flags |= VM_IO | VM_RESERVED;
131+
vma->vm_flags |= VM_IO | VM_RESERVED | VM_UNPAGED;
132132

133133
prot = __pgprot(pg_iobits);
134134
offset -= from;

‎include/linux/mm.h‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,8 @@ extern unsigned int kobjsize(const void *objp);
144144

145145
#define VM_GROWSDOWN 0x00000100 /* general info on the segment */
146146
#define VM_GROWSUP 0x00000200
147-
#define VM_SHM 0x00000400 /* shared memory area, don't swap out */
147+
#define VM_SHM 0x00000000 /* Means nothing: delete it later */
148+
#define VM_UNPAGED 0x00000400 /* Pages managed without map count */
148149
#define VM_DENYWRITE 0x00000800 /* ETXTBSY on write attempts.. */
149150

150151
#define VM_EXECUTABLE 0x00001000
@@ -157,7 +158,7 @@ extern unsigned int kobjsize(const void *objp);
157158

158159
#define VM_DONTCOPY 0x00020000 /* Do not copy this vma on fork */
159160
#define VM_DONTEXPAND 0x00040000 /* Cannot expand with mremap() */
160-
#define VM_RESERVED 0x00080000 /* Pages managed in a special way */
161+
#define VM_RESERVED 0x00080000 /* Count as reserved_vm like IO */
161162
#define VM_ACCOUNT 0x00100000 /* Is a VM accounted object */
162163
#define VM_HUGETLB 0x00400000 /* Huge TLB Page VM */
163164
#define VM_NONLINEAR 0x00800000 /* Is non-linear (remap_file_pages) */

‎mm/fremap.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ int install_page(struct mm_struct *mm, struct vm_area_struct *vma,
6565
pte_t pte_val;
6666
spinlock_t *ptl;
6767

68-
BUG_ON(vma->vm_flags & VM_RESERVED);
68+
BUG_ON(vma->vm_flags & VM_UNPAGED);
6969

7070
pgd = pgd_offset(mm, addr);
7171
pud = pud_alloc(mm, pgd, addr);
@@ -122,7 +122,7 @@ int install_file_pte(struct mm_struct *mm, struct vm_area_struct *vma,
122122
pte_t pte_val;
123123
spinlock_t *ptl;
124124

125-
BUG_ON(vma->vm_flags & VM_RESERVED);
125+
BUG_ON(vma->vm_flags & VM_UNPAGED);
126126

127127
pgd = pgd_offset(mm, addr);
128128
pud = pud_alloc(mm, pgd, addr);

‎mm/madvise.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ static long madvise_dontneed(struct vm_area_struct * vma,
126126
unsigned long start, unsigned long end)
127127
{
128128
*prev = vma;
129-
if (vma->vm_flags & (VM_LOCKED|VM_HUGETLB|VM_RESERVED))
129+
if (vma->vm_flags & (VM_LOCKED|VM_HUGETLB|VM_UNPAGED))
130130
return -EINVAL;
131131

132132
if (unlikely(vma->vm_flags & VM_NONLINEAR)) {

‎mm/memory.c‎

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ static inline void add_mm_rss(struct mm_struct *mm, int file_rss, int anon_rss)
334334

335335
/*
336336
* This function is called to print an error when a pte in a
337-
* !VM_RESERVED region is found pointing to an invalid pfn (which
337+
* !VM_UNPAGED region is found pointing to an invalid pfn (which
338338
* is an error.
339339
*
340340
* The calling function must still handle the error.
@@ -381,15 +381,15 @@ copy_one_pte(struct mm_struct *dst_mm, struct mm_struct *src_mm,
381381
goto out_set_pte;
382382
}
383383

384-
/* If the region is VM_RESERVED, the mapping is not
384+
/* If the region is VM_UNPAGED, the mapping is not
385385
* mapped via rmap - duplicate the pte as is.
386386
*/
387-
if (vm_flags & VM_RESERVED)
387+
if (vm_flags & VM_UNPAGED)
388388
goto out_set_pte;
389389

390390
pfn = pte_pfn(pte);
391391
/* If the pte points outside of valid memory but
392-
* the region is not VM_RESERVED, we have a problem.
392+
* the region is not VM_UNPAGED, we have a problem.
393393
*/
394394
if (unlikely(!pfn_valid(pfn))) {
395395
print_bad_pte(vma, pte, addr);
@@ -528,7 +528,7 @@ int copy_page_range(struct mm_struct *dst_mm, struct mm_struct *src_mm,
528528
* readonly mappings. The tradeoff is that copy_page_range is more
529529
* efficient than faulting.
530530
*/
531-
if (!(vma->vm_flags & (VM_HUGETLB|VM_NONLINEAR|VM_RESERVED))) {
531+
if (!(vma->vm_flags & (VM_HUGETLB|VM_NONLINEAR|VM_UNPAGED))) {
532532
if (!vma->anon_vma)
533533
return 0;
534534
}
@@ -572,7 +572,7 @@ static unsigned long zap_pte_range(struct mmu_gather *tlb,
572572

573573
(*zap_work) -= PAGE_SIZE;
574574

575-
if (!(vma->vm_flags & VM_RESERVED)) {
575+
if (!(vma->vm_flags & VM_UNPAGED)) {
576576
unsigned long pfn = pte_pfn(ptent);
577577
if (unlikely(!pfn_valid(pfn)))
578578
print_bad_pte(vma, ptent, addr);
@@ -1191,10 +1191,16 @@ int remap_pfn_range(struct vm_area_struct *vma, unsigned long addr,
11911191
* rest of the world about it:
11921192
* VM_IO tells people not to look at these pages
11931193
* (accesses can have side effects).
1194-
* VM_RESERVED tells the core MM not to "manage" these pages
1195-
* (e.g. refcount, mapcount, try to swap them out).
1194+
* VM_RESERVED is specified all over the place, because
1195+
* in 2.4 it kept swapout's vma scan off this vma; but
1196+
* in 2.6 the LRU scan won't even find its pages, so this
1197+
* flag means no more than count its pages in reserved_vm,
1198+
* and omit it from core dump, even when VM_IO turned off.
1199+
* VM_UNPAGED tells the core MM not to "manage" these pages
1200+
* (e.g. refcount, mapcount, try to swap them out): in
1201+
* particular, zap_pte_range does not try to free them.
11961202
*/
1197-
vma->vm_flags |= VM_IO | VM_RESERVED;
1203+
vma->vm_flags |= VM_IO | VM_RESERVED | VM_UNPAGED;
11981204

11991205
BUG_ON(addr >= end);
12001206
pfn -= addr >> PAGE_SHIFT;
@@ -1276,7 +1282,7 @@ static int do_wp_page(struct mm_struct *mm, struct vm_area_struct *vma,
12761282
pte_t entry;
12771283
int ret = VM_FAULT_MINOR;
12781284

1279-
BUG_ON(vma->vm_flags & VM_RESERVED);
1285+
BUG_ON(vma->vm_flags & VM_UNPAGED);
12801286

12811287
if (unlikely(!pfn_valid(pfn))) {
12821288
/*
@@ -1924,7 +1930,7 @@ static int do_no_page(struct mm_struct *mm, struct vm_area_struct *vma,
19241930
inc_mm_counter(mm, anon_rss);
19251931
lru_cache_add_active(new_page);
19261932
page_add_anon_rmap(new_page, vma, address);
1927-
} else if (!(vma->vm_flags & VM_RESERVED)) {
1933+
} else if (!(vma->vm_flags & VM_UNPAGED)) {
19281934
inc_mm_counter(mm, file_rss);
19291935
page_add_file_rmap(new_page);
19301936
}
@@ -2203,7 +2209,7 @@ static int __init gate_vma_init(void)
22032209
gate_vma.vm_start = FIXADDR_USER_START;
22042210
gate_vma.vm_end = FIXADDR_USER_END;
22052211
gate_vma.vm_page_prot = PAGE_READONLY;
2206-
gate_vma.vm_flags = VM_RESERVED;
2212+
gate_vma.vm_flags = 0;
22072213
return 0;
22082214
}
22092215
__initcall(gate_vma_init);

‎mm/mempolicy.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ check_range(struct mm_struct *mm, unsigned long start, unsigned long end,
269269
first = find_vma(mm, start);
270270
if (!first)
271271
return ERR_PTR(-EFAULT);
272-
if (first->vm_flags & VM_RESERVED)
272+
if (first->vm_flags & VM_UNPAGED)
273273
return ERR_PTR(-EACCES);
274274
prev = NULL;
275275
for (vma = first; vma && vma->vm_start < end; vma = vma->vm_next) {

‎mm/msync.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,9 @@ static void msync_page_range(struct vm_area_struct *vma,
9797
/* For hugepages we can't go walking the page table normally,
9898
* but that's ok, hugetlbfs is memory based, so we don't need
9999
* to do anything more on an msync().
100-
* Can't do anything with VM_RESERVED regions either.
100+
* Can't do anything with VM_UNPAGED regions either.
101101
*/
102-
if (vma->vm_flags & (VM_HUGETLB|VM_RESERVED))
102+
if (vma->vm_flags & (VM_HUGETLB|VM_UNPAGED))
103103
return;
104104

105105
BUG_ON(addr >= end);

0 commit comments

Comments
 (0)