Skip to content

Commit b581003

Browse files
Nick PigginLinus Torvalds
authored andcommitted
[PATCH] core remove PageReserved
Remove PageReserved() calls from core code by tightening VM_RESERVED handling in mm/ to cover PageReserved functionality. PageReserved special casing is removed from get_page and put_page. All setting and clearing of PageReserved is retained, and it is now flagged in the page_alloc checks to help ensure we don't introduce any refcount based freeing of Reserved pages. MAP_PRIVATE, PROT_WRITE of VM_RESERVED regions is tentatively being deprecated. We never completely handled it correctly anyway, and is be reintroduced in future if required (Hugh has a proof of concept). Once PageReserved() calls are removed from kernel/power/swsusp.c, and all arch/ and driver code, the Set and Clear calls, and the PG_reserved bit can be trivially removed. Last real user of PageReserved is swsusp, which uses PageReserved to determine whether a struct page points to valid memory or not. This still needs to be addressed (a generic page_is_ram() should work). A last caveat: the ZERO_PAGE is now refcounted and managed with rmap (and thus mapcounted and count towards shared rss). These writes to the struct page could cause excessive cacheline bouncing on big systems. There are a number of ways this could be addressed if it is an issue. Signed-off-by: Nick Piggin <npiggin@suse.de> Refcount bug fix for filemap_xip.c Signed-off-by: Carsten Otte <cotte@de.ibm.com> Signed-off-by: Andrew Morton <akpm@osdl.org> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
1 parent f9c98d0 commit b581003

22 files changed

Lines changed: 218 additions & 134 deletions

File tree

‎arch/ppc64/kernel/vdso.c‎

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -176,13 +176,13 @@ static struct page * vdso_vma_nopage(struct vm_area_struct * vma,
176176
return NOPAGE_SIGBUS;
177177

178178
/*
179-
* Last page is systemcfg, special handling here, no get_page() a
180-
* this is a reserved page
179+
* Last page is systemcfg.
181180
*/
182181
if ((vma->vm_end - address) <= PAGE_SIZE)
183-
return virt_to_page(systemcfg);
182+
pg = virt_to_page(systemcfg);
183+
else
184+
pg = virt_to_page(vbase + offset);
184185

185-
pg = virt_to_page(vbase + offset);
186186
get_page(pg);
187187
DBG(" ->page count: %d\n", page_count(pg));
188188

@@ -259,7 +259,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int executable_stack)
259259
* gettimeofday will be totally dead. It's fine to use that for setting
260260
* breakpoints in the vDSO code pages though
261261
*/
262-
vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC;
262+
vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC | VM_RESERVED;
263263
vma->vm_flags |= mm->def_flags;
264264
vma->vm_page_prot = protection_map[vma->vm_flags & 0x7];
265265
vma->vm_ops = &vdso_vmops;
@@ -603,6 +603,8 @@ void __init vdso_init(void)
603603
ClearPageReserved(pg);
604604
get_page(pg);
605605
}
606+
607+
get_page(virt_to_page(systemcfg));
606608
}
607609

608610
int in_gate_area_no_task(unsigned long addr)

‎arch/sparc/mm/generic.c‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,9 @@ int io_remap_pfn_range(struct vm_area_struct *vma, unsigned long from,
7373
int space = GET_IOSPACE(pfn);
7474
unsigned long offset = GET_PFN(pfn) << PAGE_SHIFT;
7575

76+
/* See comment in mm/memory.c remap_pfn_range */
77+
vma->vm_flags |= VM_IO | VM_RESERVED;
78+
7679
prot = __pgprot(pg_iobits);
7780
offset -= from;
7881
dir = pgd_offset(mm, from);

‎arch/sparc64/mm/generic.c‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,9 @@ int io_remap_pfn_range(struct vm_area_struct *vma, unsigned long from,
127127
int space = GET_IOSPACE(pfn);
128128
unsigned long offset = GET_PFN(pfn) << PAGE_SHIFT;
129129

130+
/* See comment in mm/memory.c remap_pfn_range */
131+
vma->vm_flags |= VM_IO | VM_RESERVED;
132+
130133
prot = __pgprot(pg_iobits);
131134
offset -= from;
132135
dir = pgd_offset(mm, from);

‎drivers/scsi/sg.c‎

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1886,13 +1886,17 @@ st_unmap_user_pages(struct scatterlist *sgl, const unsigned int nr_pages,
18861886
int i;
18871887

18881888
for (i=0; i < nr_pages; i++) {
1889-
if (dirtied && !PageReserved(sgl[i].page))
1890-
SetPageDirty(sgl[i].page);
1891-
/* unlock_page(sgl[i].page); */
1889+
struct page *page = sgl[i].page;
1890+
1891+
/* XXX: just for debug. Remove when PageReserved is removed */
1892+
BUG_ON(PageReserved(page));
1893+
if (dirtied)
1894+
SetPageDirty(page);
1895+
/* unlock_page(page); */
18921896
/* FIXME: cache flush missing for rw==READ
18931897
* FIXME: call the correct reference counting function
18941898
*/
1895-
page_cache_release(sgl[i].page);
1899+
page_cache_release(page);
18961900
}
18971901

18981902
return 0;

‎drivers/scsi/st.c‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4526,12 +4526,16 @@ static int sgl_unmap_user_pages(struct scatterlist *sgl, const unsigned int nr_p
45264526
int i;
45274527

45284528
for (i=0; i < nr_pages; i++) {
4529-
if (dirtied && !PageReserved(sgl[i].page))
4530-
SetPageDirty(sgl[i].page);
4529+
struct page *page = sgl[i].page;
4530+
4531+
/* XXX: just for debug. Remove when PageReserved is removed */
4532+
BUG_ON(PageReserved(page));
4533+
if (dirtied)
4534+
SetPageDirty(page);
45314535
/* FIXME: cache flush missing for rw==READ
45324536
* FIXME: call the correct reference counting function
45334537
*/
4534-
page_cache_release(sgl[i].page);
4538+
page_cache_release(page);
45354539
}
45364540

45374541
return 0;

‎fs/direct-io.c‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,14 +162,16 @@ static int dio_refill_pages(struct dio *dio)
162162
up_read(&current->mm->mmap_sem);
163163

164164
if (ret < 0 && dio->blocks_available && (dio->rw == WRITE)) {
165+
struct page *page = ZERO_PAGE(dio->curr_user_address);
165166
/*
166167
* A memory fault, but the filesystem has some outstanding
167168
* mapped blocks. We need to use those blocks up to avoid
168169
* leaking stale data in the file.
169170
*/
170171
if (dio->page_errors == 0)
171172
dio->page_errors = ret;
172-
dio->pages[0] = ZERO_PAGE(dio->curr_user_address);
173+
page_cache_get(page);
174+
dio->pages[0] = page;
173175
dio->head = 0;
174176
dio->tail = 1;
175177
ret = 0;

‎include/linux/mm.h‎

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

158158
#define VM_DONTCOPY 0x00020000 /* Do not copy this vma on fork */
159159
#define VM_DONTEXPAND 0x00040000 /* Cannot expand with mremap() */
160-
#define VM_RESERVED 0x00080000 /* Don't unmap it from swap_out */
160+
#define VM_RESERVED 0x00080000 /* Pages managed in a special way */
161161
#define VM_ACCOUNT 0x00100000 /* Is a VM accounted object */
162162
#define VM_HUGETLB 0x00400000 /* Huge TLB Page VM */
163163
#define VM_NONLINEAR 0x00800000 /* Is non-linear (remap_file_pages) */
@@ -338,7 +338,7 @@ static inline void get_page(struct page *page)
338338

339339
static inline void put_page(struct page *page)
340340
{
341-
if (!PageReserved(page) && put_page_testzero(page))
341+
if (put_page_testzero(page))
342342
__page_cache_release(page);
343343
}
344344

@@ -723,6 +723,7 @@ void install_arg_page(struct vm_area_struct *, struct page *, unsigned long);
723723

724724
int get_user_pages(struct task_struct *tsk, struct mm_struct *mm, unsigned long start,
725725
int len, int write, int force, struct page **pages, struct vm_area_struct **vmas);
726+
void print_bad_pte(struct vm_area_struct *, pte_t, unsigned long);
726727

727728
int __set_page_dirty_buffers(struct page *page);
728729
int __set_page_dirty_nobuffers(struct page *page);

‎kernel/power/swsusp.c‎

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -578,15 +578,23 @@ static int save_highmem_zone(struct zone *zone)
578578
continue;
579579
page = pfn_to_page(pfn);
580580
/*
581-
* This condition results from rvmalloc() sans vmalloc_32()
582-
* and architectural memory reservations. This should be
583-
* corrected eventually when the cases giving rise to this
584-
* are better understood.
581+
* PageReserved results from rvmalloc() sans vmalloc_32()
582+
* and architectural memory reservations.
583+
*
584+
* rvmalloc should not cause this, because all implementations
585+
* appear to always be using vmalloc_32 on architectures with
586+
* highmem. This is a good thing, because we would like to save
587+
* rvmalloc pages.
588+
*
589+
* It appears to be triggered by pages which do not point to
590+
* valid memory (see arch/i386/mm/init.c:one_highpage_init(),
591+
* which sets PageReserved if the page does not point to valid
592+
* RAM.
593+
*
594+
* XXX: must remove usage of PageReserved!
585595
*/
586-
if (PageReserved(page)) {
587-
printk("highmem reserved page?!\n");
596+
if (PageReserved(page))
588597
continue;
589-
}
590598
BUG_ON(PageNosave(page));
591599
if (PageNosaveFree(page))
592600
continue;
@@ -672,10 +680,9 @@ static int saveable(struct zone * zone, unsigned long * zone_pfn)
672680
return 0;
673681

674682
page = pfn_to_page(pfn);
675-
BUG_ON(PageReserved(page) && PageNosave(page));
676683
if (PageNosave(page))
677684
return 0;
678-
if (PageReserved(page) && pfn_is_nosave(pfn)) {
685+
if (pfn_is_nosave(pfn)) {
679686
pr_debug("[nosave pfn 0x%lx]", pfn);
680687
return 0;
681688
}

‎mm/bootmem.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,7 @@ static unsigned long __init free_all_bootmem_core(pg_data_t *pgdat)
305305
if (j + 16 < BITS_PER_LONG)
306306
prefetchw(page + j + 16);
307307
__ClearPageReserved(page + j);
308+
set_page_count(page + j, 0);
308309
}
309310
__free_pages(page, order);
310311
i += BITS_PER_LONG;

‎mm/filemap_xip.c‎

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@ __xip_unmap (struct address_space * mapping,
174174
unsigned long address;
175175
pte_t *pte;
176176
pte_t pteval;
177+
struct page *page = ZERO_PAGE(address);
177178

178179
spin_lock(&mapping->i_mmap_lock);
179180
vma_prio_tree_foreach(vma, &iter, &mapping->i_mmap, pgoff, pgoff) {
@@ -185,15 +186,17 @@ __xip_unmap (struct address_space * mapping,
185186
* We need the page_table_lock to protect us from page faults,
186187
* munmap, fork, etc...
187188
*/
188-
pte = page_check_address(ZERO_PAGE(address), mm,
189-
address);
189+
pte = page_check_address(page, mm, address);
190190
if (!IS_ERR(pte)) {
191191
/* Nuke the page table entry. */
192192
flush_cache_page(vma, address, pte_pfn(*pte));
193193
pteval = ptep_clear_flush(vma, address, pte);
194+
page_remove_rmap(page);
195+
dec_mm_counter(mm, file_rss);
194196
BUG_ON(pte_dirty(pteval));
195197
pte_unmap(pte);
196198
spin_unlock(&mm->page_table_lock);
199+
page_cache_release(page);
197200
}
198201
}
199202
spin_unlock(&mapping->i_mmap_lock);
@@ -228,7 +231,7 @@ xip_file_nopage(struct vm_area_struct * area,
228231

229232
page = mapping->a_ops->get_xip_page(mapping, pgoff*(PAGE_SIZE/512), 0);
230233
if (!IS_ERR(page)) {
231-
return page;
234+
goto out;
232235
}
233236
if (PTR_ERR(page) != -ENODATA)
234237
return NULL;
@@ -249,6 +252,8 @@ xip_file_nopage(struct vm_area_struct * area,
249252
page = ZERO_PAGE(address);
250253
}
251254

255+
out:
256+
page_cache_get(page);
252257
return page;
253258
}
254259

0 commit comments

Comments
 (0)