remove PageReserved
Subsystems (14)
cover remove PageReserved
Hi Andrew,
If you're feeling like -mm is getting too stable, then you might consider giving these patches a spin? (unless anyone else raises an objection).
Ben thought I should get moving with them soon.
Not much change from last time. A bit of ppc64 input from Ben, and some rmap.c input from Hugh. Boots and runs on a few machines I have lying around here.
The only remaining places that *test* PageReserved are swsusp, a trivial useage in drivers/char/agp/amd64-agp.c, and arch/ code.
Most of the arch code is just reserved memory reporting, which isn't very interesting and could easily be removed. Some arch users are a bit more subtle, however they *should not* break, because all the places that set and clear PageReserved are basically intact.
We can phase PageReserved out of the tree completely when the core becomes stable.
Now the main problems we might have are the introduction of some tighter checks introduced by this patchset - for example 'bad_page' is triggered on PG_reserved.
The other thing is - MAP_PRIVATE of VM_RESERVED regions becomes disallowed. Any program that attempts such a thing prints a warning. Hugh has some code which handles this case but he suggested that we should first see whether it is even required.
Any thoughts? Comments?
Signature · 3 lines
SUSE Labs, Novell Inc. Send instant messages to your online friends http://au.messenger.yahoo.com
PATCH 1/6 mm: comment rmap
1/6
Just be clear that VM_RESERVED pages here are a bug, and the test is not there because they are expected.
mm/rmap.c +2 -0
@@ -532,6 +532,8 @@ static int try_to_unmap_one(struct page* If the page is mlock()d, we cannot swap it out. * If it's recently referenced (perhaps page_referenced * skipped over this mm) then we should reactivate it. +* +* Pages belonging to VM_RESERVED regions should not happen here. */ if ((vma->vm_flags & (VM_LOCKED |VM_RESERVED )) ||ptep_clear_flush_young (vma, address, pte)) {
PATCH 2/6 mm: micro-optimise rmap
2/6
Microoptimise page_add_anon_rmap. Although these expressions are used only in the taken branch of the if() statement, the compiler can't reorder them inside because atomic_inc_and_test is a barrier.
mm/rmap.c +11 -10
@@ -442,22 +442,23 @@ int page_referenced(struct page *page, ivoid page_add_anon_rmap (struct page *page,struct vm_area_struct *vma,unsigned long address) { -struct anon_vma *anon_vma = vma->anon_vma; -pgoff_t index; -BUG_ON (PageReserved (page)); -BUG_ON (!anon_vma);inc_mm_counter (vma->vm_mm, anon_rss); - anon_vma = (void *) anon_vma +PAGE_MAPPING_ANON ; - index = (address - vma->vm_start) >>PAGE_SHIFT ; - index += vma->vm_pgoff; - index >>=PAGE_CACHE_SHIFT -PAGE_SHIFT ; -if (atomic_inc_and_test (&page->_mapcount)) { - page->index = index; +struct anon_vma *anon_vma = vma->anon_vma; +pgoff_t index; + +BUG_ON (!anon_vma); + anon_vma = (void *) anon_vma +PAGE_MAPPING_ANON ; page->mapping = (struct address_space *) anon_vma; + + index = (address - vma->vm_start) >>PAGE_SHIFT ; + index += vma->vm_pgoff; + index >>=PAGE_CACHE_SHIFT -PAGE_SHIFT ; + page->index = index; +inc_page_state (nr_mapped); }/* else checking page index and mapping is racy */
PATCH 3/6 mm: cleanup rmap
3/6
Thanks to Bill Irwin for pointing this out.
mm/rmap.c +1 -5
@@ -448,16 +448,12 @@ void page_add_anon_rmap(struct page *pagif (atomic_inc_and_test (&page->_mapcount)) {struct anon_vma *anon_vma = vma->anon_vma; -pgoff_t index;BUG_ON (!anon_vma); anon_vma = (void *) anon_vma +PAGE_MAPPING_ANON ; page->mapping = (struct address_space *) anon_vma; - index = (address - vma->vm_start) >>PAGE_SHIFT ; - index += vma->vm_pgoff; - index >>=PAGE_CACHE_SHIFT -PAGE_SHIFT ; - page->index = index; + page->index =linear_page_index (vma, address);inc_page_state (nr_mapped); }
PATCH 4/6 mm: remove atomic
4/6
OK, these first 4 patches don't have much to do with removing PageReserved, but I put them in this series because that's how I have them arranged.
This bitop does not need to be atomic because it is performed when there will be no references to the page (ie. the page is being freed).
mm/page_alloc.c +1 -1
@@ -329,7 +329,7 @@ static inline void free_pages_check(cons 1 << PG_writeback )))bad_page (function, page);if (PageDirty (page)) -ClearPageDirty (page); +__ClearPageDirty (page); }/*
include/linux/page-flags.h +1 -0
@@ -194,6 +194,7 @@ extern void __mod_page_state(unsigned lo#define SetPageDirty (page) set_bit(PG_dirty, &(page)->flags)#define TestSetPageDirty (page) test_and_set_bit(PG_dirty, &(page)->flags)#define ClearPageDirty (page) clear_bit(PG_dirty, &(page)->flags) +#define __ClearPageDirty (page) __clear_bit(PG_dirty, &(page)->flags)#define TestClearPageDirty (page) test_and_clear_bit(PG_dirty, &(page)->flags)#define SetPageLRU (page) set_bit(PG_lru, &(page)->flags)
PATCH 5/6 mm: remap ZERO_PAGE mappings
5/6
Remap ZERO_PAGE ptes when remapping memory. This is currently just an optimisation for MIPS, which is the only architecture with multiple zero pages - it now retains the mapping it needs for good cache performance, and as well do_wp_page is now able to always correctly detect and optimise zero page COW faults.
This change is required in order to be able to detect whether a pte points to a ZERO_PAGE using only its (pte, vaddr) pair.
mm/mremap.c +4 -0
@@ -141,6 +141,10 @@ move_one_page(struct vm_area_struct *vmaif (dst) {pte_t pte; pte =ptep_clear_flush (vma, old_addr, src); +/* ZERO_PAGE can be dependant on virtual addr */ +if (pfn_valid (pte_pfn (pte)) && +pte_page (pte) ==ZERO_PAGE (old_addr)) + pte =pte_wrprotect (mk_pte (ZERO_PAGE (new_addr), new_vma->vm_page_prot));set_pte_at (mm, new_addr, dst, pte); }else error = -ENOMEM ;
PATCH 6/6 mm: core remove PageReserved
6/6
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 clearning 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 difficult to handle nicely - difficult but not impossible, it could 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.
Many thanks to Hugh Dickins for input.
include/linux/mm.h +4 -2
@@ -156,7 +156,8 @@ extern unsigned int kobjsize(const void#define VM_DONTCOPY 0x00020000/* Do not copy this vma on fork */ #define VM_DONTEXPAND 0x00040000/* Cannot expand with mremap() */ -#define VM_RESERVED 0x00080000/* Don't unmap it from swap_out */ +#define VM_RESERVED 0x00080000/* Pages and ptes in region aren't managed with regular pagecache or rmap routines */ +#define VM_ACCOUNT 0x00100000/* Is a VM accounted object */ #define VM_HUGETLB 0x00400000/* Huge TLB Page VM */ #define VM_NONLINEAR 0x00800000/* Is non-linear (remap_file_pages) */
@@ -337,7 +338,7 @@ static inline void get_page(struct pagestatic inline void put_page (struct page *page) { -if (!PageReserved (page) &&put_page_testzero (page)) +if (put_page_testzero (page))__page_cache_release (page); }
@@ -711,6 +712,7 @@ void install_arg_page(struct vm_area_strint get_user_pages (struct task_struct *tsk,struct mm_struct *mm,unsigned long start,int len,int write,int force,struct page **pages,struct vm_area_struct **vmas); +void print_invalid_pfn (const char *,pte_t ,unsigned long ,unsigned long );int __set_page_dirty_buffers (struct page *page);int __set_page_dirty_nobuffers (struct page *page);
mm/madvise.c +1 -1
@@ -126,7 +126,7 @@ static long madvise_dontneed(struct vm_a unsigned long start, unsigned long end) { *prev = vma; -if ((vma->vm_flags &VM_LOCKED ) ||is_vm_hugetlb_page (vma)) +if ((vma->vm_flags & (VM_LOCKED |VM_RESERVED )) ||is_vm_hugetlb_page (vma))return -EINVAL ;if (unlikely (vma->vm_flags &VM_NONLINEAR )) {
mm/memory.c +79 -46
267 lines not on this page · raw message
mm/page_alloc.c +8 -6
@@ -113,7 +113,8 @@ static void bad_page(const char *functio1 << PG_reclaim |1 << PG_slab |1 << PG_swapcache | - 1 << PG_writeback); +1 << PG_writeback | + 1 << PG_reserved );set_page_count (page,0 );reset_page_mapcount (page); page->mapping =NULL ;
@@ -243,7 +244,6 @@ static inline int page_is_buddy(struct p {if (PagePrivate (page) && (page_order (page) == order) && - !PageReserved (page) &&page_count (page) ==0 )return 1 ;return 0 ;
@@ -326,7 +326,8 @@ static inline void free_pages_check(cons 1 << PG_reclaim | 1 << PG_slab | 1 << PG_swapcache | - 1 << PG_writeback ))) + 1 << PG_writeback | + 1 << PG_reserved )))bad_page (function, page);if (PageDirty (page))__ClearPageDirty (page);
@@ -454,7 +455,8 @@ static void prep_new_page(struct page *p 1 << PG_reclaim | 1 << PG_slab | 1 << PG_swapcache | - 1 << PG_writeback ))) + 1 << PG_writeback | + 1 << PG_reserved )))bad_page (__FUNCTION__, page); page->flags &= ~(1 << PG_uptodate | 1 << PG_error |
@@ -1011,7 +1013,7 @@ void __pagevec_free(struct pagevec *pvec fastcall void __free_pages(struct page *page, unsigned int order) { -if (!PageReserved (page) &&put_page_testzero (page)) { +if (put_page_testzero (page)) {if (order ==0 )free_hot_page (page);else
@@ -1654,7 +1656,7 @@ void __init memmap_init_zone(unsigned locontinue ; page =pfn_to_page (pfn);set_page_links (page, zone, nid, pfn); -set_page_count (page,0 ); +set_page_count (page,1 );reset_page_mapcount (page);SetPageReserved (page);INIT_LIST_HEAD (&page->lru);
mm/swap.c +2 -2
@@ -48,7 +48,7 @@ void put_page(struct page *page) }return ; } -if (!PageReserved (page) &&put_page_testzero (page)) +if (put_page_testzero (page))__page_cache_release (page); }EXPORT_SYMBOL (put_page);
@@ -215,7 +215,7 @@ void release_pages(struct page **pages,struct page *page = pages[i];struct zone *pagezone; -if (PageReserved (page) || !put_page_testzero (page)) +if (!put_page_testzero (page))continue ; pagezone =page_zone (page);
mm/fremap.c +16 -9
@@ -29,18 +29,21 @@ static inline void zap_pte(struct mm_strreturn ;if (pte_present (pte)) {unsigned long pfn =pte_pfn (pte); +struct page *page;flush_cache_page (vma, addr, pfn); pte =ptep_clear_flush (vma, addr, ptep); -if (pfn_valid (pfn)) { -struct page *page =pfn_to_page (pfn); -if (!PageReserved (page)) { -if (pte_dirty (pte)) -set_page_dirty (page); -page_remove_rmap (page); -page_cache_release (page); -dec_mm_counter (mm, rss); - } +if (unlikely (!pfn_valid (pfn))) { +print_invalid_pfn ("zap_pte" , pte, vma->vm_flags, addr); +return ; + } + page =pfn_to_page (pfn); +if (page !=ZERO_PAGE (addr)) { +if (pte_dirty (pte)) +set_page_dirty (page); +page_remove_rmap (page); +dec_mm_counter (mm, rss); +page_cache_release (page); } }else {if (!pte_file (pte))
@@ -65,6 +68,8 @@ int install_page(struct mm_struct *mm, spgd_t *pgd;pte_t pte_val; +BUG_ON (vma->vm_flags &VM_RESERVED ); + pgd =pgd_offset (mm, addr);spin_lock (&mm->page_table_lock);
@@ -122,6 +127,8 @@ int install_file_pte(struct mm_struct *mpgd_t *pgd;pte_t pte_val; +BUG_ON (vma->vm_flags &VM_RESERVED ); + pgd =pgd_offset (mm, addr);spin_lock (&mm->page_table_lock);
mm/msync.c +7 -3
@@ -37,11 +37,12 @@ static void sync_pte_range(struct vm_areif (!pte_maybe_dirty (*pte))continue ; pfn =pte_pfn (*pte); -if (!pfn_valid (pfn)) +if (unlikely (!pfn_valid (pfn))) { +print_invalid_pfn ("sync_pte_range" , *pte, + vma->vm_flags, addr);continue ; + } page =pfn_to_page (pfn); -if (PageReserved (page)) -continue ;if (ptep_clear_flush_dirty (vma, addr, pte) ||page_test_and_clear_dirty (page))
@@ -149,6 +150,9 @@ static int msync_interval(struct vm_areaif ((flags &MS_INVALIDATE ) && (vma->vm_flags &VM_LOCKED ))return -EBUSY ; +if (vma->vm_flags &VM_RESERVED ) +return -EINVAL ; +if (file && (vma->vm_flags &VM_SHARED )) {filemap_sync (vma, addr, end);
mm/rmap.c +5 -10
@@ -442,8 +442,6 @@ int page_referenced(struct page *page, ivoid page_add_anon_rmap (struct page *page,struct vm_area_struct *vma,unsigned long address) { -BUG_ON (PageReserved (page)); -inc_mm_counter (vma->vm_mm, anon_rss);if (atomic_inc_and_test (&page->_mapcount)) {
@@ -469,8 +467,7 @@ void page_add_anon_rmap(struct page *pagvoid page_add_file_rmap (struct page *page) {BUG_ON (PageAnon (page)); -if (!pfn_valid (page_to_pfn (page)) ||PageReserved (page)) -return ; +BUG_ON (!pfn_valid (page_to_pfn (page)));if (atomic_inc_and_test (&page->_mapcount))inc_page_state (nr_mapped);
@@ -484,8 +481,6 @@ void page_add_file_rmap(struct page *pag*/ void page_remove_rmap (struct page *page) { -BUG_ON (PageReserved (page)); -if (atomic_add_negative (-1 , &page->_mapcount)) {BUG_ON (page_mapcount (page) <0 );/*
@@ -643,13 +638,14 @@ static void try_to_unmap_cluster(unsignecontinue ; pfn =pte_pfn (*pte); -if (!pfn_valid (pfn)) +if (unlikely (!pfn_valid (pfn))) { +print_invalid_pfn ("try_to_unmap_cluster" , *pte, + vma->vm_flags, address);continue ; + } page =pfn_to_page (pfn);BUG_ON (PageAnon (page)); -if (PageReserved (page)) -continue ;if (ptep_clear_flush_young (vma, address, pte))continue ;
@@ -812,7 +808,6 @@ int try_to_unmap(struct page *page) {int ret; -BUG_ON (PageReserved (page));BUG_ON (!PageLocked (page));if (PageAnon (page))
drivers/scsi/sg.c +8 -4
@@ -1887,13 +1887,17 @@ st_unmap_user_pages(struct scatterlist *int i;for (i=0 ; i < nr_pages; i++) { -if (dirtied && !PageReserved (sgl[i].page)) -SetPageDirty (sgl[i].page); -/* unlock_page(sgl[i].page); */ +struct page *page = sgl[i].page; + +/* XXX: just for debug. Remove when PageReserved is removed */ +BUG_ON (PageReserved (page)); +if (dirtied) +SetPageDirty (page); +/* unlock_page(page); */ /* FIXME: cache flush missing for rw==READ * FIXME: call the correct reference counting function */ -page_cache_release (sgl[i].page); +page_cache_release (page); }return 0 ;
drivers/scsi/st.c +7 -3
@@ -4435,12 +4435,16 @@ static int sgl_unmap_user_pages(struct sint i;for (i=0 ; i < nr_pages; i++) { -if (dirtied && !PageReserved (sgl[i].page)) -SetPageDirty (sgl[i].page); +struct page *page = sgl[i].page; + +/* XXX: just for debug. Remove when PageReserved is removed */ +BUG_ON (PageReserved (page)); +if (dirtied) +SetPageDirty (page);/* FIXME: cache flush missing for rw==READ * FIXME: call the correct reference counting function */ -page_cache_release (sgl[i].page); +page_cache_release (page); }return 0 ;
sound/core/pcm_native.c +3 -6
@@ -2944,8 +2944,7 @@ static struct page * snd_pcm_mmap_statusreturn NOPAGE_OOM ; runtime = substream->runtime; page =virt_to_page (runtime->status); -if (!PageReserved (page)) -get_page (page); +get_page (page);if (type) *type =VM_FAULT_MINOR ;return page;
@@ -2987,8 +2986,7 @@ static struct page * snd_pcm_mmap_controreturn NOPAGE_OOM ; runtime = substream->runtime; page =virt_to_page (runtime->control); -if (!PageReserved (page)) -get_page (page); +get_page (page);if (type) *type =VM_FAULT_MINOR ;return page;
@@ -3061,8 +3059,7 @@ static struct page *snd_pcm_mmap_data_no vaddr = runtime->dma_area + offset; page =virt_to_page (vaddr); } -if (!PageReserved (page)) -get_page (page); +get_page (page);if (type) *type =VM_FAULT_MINOR ;return page;
mm/mmap.c +11 -0
@@ -1073,6 +1073,17 @@ munmap_back: error = file->f_op->mmap (file, vma);if (error) goto unmap_and_free_vma; +if ((vma->vm_flags & (VM_SHARED |VM_WRITE |VM_RESERVED )) + == (VM_WRITE |VM_RESERVED )) { +printk (KERN_WARNING "program %s is using MAP_PRIVATE, " +"PROT_WRITE mmap of VM_RESERVED memory, which " +"is deprecated. Please report this to " +"[email protected]\n" ,current->comm); +if (vma->vm_ops && vma->vm_ops->close) + vma->vm_ops->close (vma); + error = -EACCES ; + goto unmap_and_free_vma; + } }else if (vm_flags &VM_SHARED ) { error =shmem_zero_setup (vma);if (error)
mm/mprotect.c +8 -0
@@ -131,6 +131,14 @@ mprotect_fixup(struct vm_area_struct *vmreturn -ENOMEM ; newflags |=VM_ACCOUNT ; } +if (oldflags &VM_RESERVED ) { +BUG_ON (oldflags &VM_WRITE ); +printk (KERN_WARNING "program %s is using MAP_PRIVATE, " +"PROT_WRITE mprotect of VM_RESERVED memory, " +"which is deprecated. Please report this to " +"[email protected]\n" ,current->comm); +return -EACCES ; + } } newprot = protection_map[newflags &0xf ];
mm/bootmem.c +1 -0
@@ -297,6 +297,7 @@ static unsigned long __init free_all_booif (j +16 <BITS_PER_LONG )prefetchw (page + j +16 );__ClearPageReserved (page + j); +set_page_count (page + j,0 ); }__free_pages (page, order); i +=BITS_PER_LONG ;
mm/mempolicy.c +5 -1
@@ -253,8 +253,10 @@ static int check_pte_range(struct mm_strif (!pte_present (*pte))continue ; pfn =pte_pfn (*pte); -if (!pfn_valid (pfn)) +if (unlikely (!pfn_valid (pfn))) { +print_invalid_pfn ("check_pte_range" , *pte,-1UL , addr);continue ; + } nid =pfn_to_nid (pfn);if (!test_bit (nid, nodes))break ;
@@ -326,6 +328,8 @@ check_range(struct mm_struct *mm, unsign first =find_vma (mm, start);if (!first)return ERR_PTR (-EFAULT ); +if (first->vm_flags &VM_RESERVED ) +return ERR_PTR (-EACCES ); prev =NULL ;for (vma = first; vma && vma->vm_start < end; vma = vma->vm_next) {if (!vma->vm_next && vma->vm_end < end)
arch/ppc64/kernel/vdso.c +6 -4
@@ -176,13 +176,13 @@ static struct page * vdso_vma_nopage(strreturn NOPAGE_SIGBUS ;/* -* Last page is systemcfg, special handling here, no get_page() a -* this is a reserved page +* Last page is systemcfg. */ if ((vma->vm_end - address) <=PAGE_SIZE ) -return virt_to_page (systemcfg); + pg =virt_to_page (systemcfg); +else + pg =virt_to_page (vbase + offset); - pg =virt_to_page (vbase + offset);get_page (pg);DBG (" ->page count: %d\n" ,page_count (pg));
@@ -600,6 +600,8 @@ void __init vdso_init(void)ClearPageReserved (pg);get_page (pg); } + +get_page (virt_to_page (systemcfg)); }int in_gate_area_no_task (unsigned long addr)
kernel/power/swsusp.c +16 -9
@@ -434,15 +434,23 @@ static int save_highmem_zone(struct zonecontinue ; page =pfn_to_page (pfn);/* -* This condition results from rvmalloc() sans vmalloc_32() -* and architectural memory reservations. This should be -* corrected eventually when the cases giving rise to this -* are better understood. +* PageReserved results from rvmalloc() sans vmalloc_32() +* and architectural memory reservations. +* +* rvmalloc should not cause this, because all implementations +* appear to always be using vmalloc_32 on architectures with +* highmem. This is a good thing, because we would like to save +* rvmalloc pages. +* +* It appears to be triggered by pages which do not point to +* valid memory (see arch/i386/mm/init.c:one_highpage_init(), +* which sets PageReserved if the page does not point to valid +* RAM. +* +* XXX: must remove usage of PageReserved! */ -if (PageReserved (page)) { -printk ("highmem reserved page?!\n" ); +if (PageReserved (page))continue ; - }BUG_ON (PageNosave (page));if (PageNosaveFree (page))continue ;
@@ -528,10 +536,9 @@ static int saveable(struct zone * zone,return 0 ; page =pfn_to_page (pfn); -BUG_ON (PageReserved (page) &&PageNosave (page));if (PageNosave (page))return 0 ; -if (PageReserved (page) &&pfn_is_nosave (pfn)) { +if (pfn_is_nosave (pfn)) {pr_debug ("[nosave pfn 0x%lx]" , pfn);return 0 ; }
mm/shmem.c +2 -1
@@ -1523,7 +1523,8 @@ static void do_shmem_file_read(struct fi index += offset >>PAGE_CACHE_SHIFT ; offset &= ~PAGE_CACHE_MASK ; -page_cache_release (page); +if (page !=ZERO_PAGE (0 )) +page_cache_release (page);if (ret != nr || !desc->count)break ;
PATCH 6/6 mm: core remove PageReserved (take 2)
Quoted 2 lines · Nick Piggin
6/6
Actually I think Hugh gave me some feedback about the introduced print_invalid_pfn function, which I ignored.
So here is patch 6 again, with print_invalid_pfn renamed invalid_pfn, and using a macro to alleviate the requirement of passing in the function name by hand.
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 clearning 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 difficult to handle nicely - difficult but not impossible, it could 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.
Many thanks to Hugh Dickins for input.
include/linux/mm.h +6 -2
@@ -156,7 +156,8 @@ extern unsigned int kobjsize(const void#define VM_DONTCOPY 0x00020000/* Do not copy this vma on fork */ #define VM_DONTEXPAND 0x00040000/* Cannot expand with mremap() */ -#define VM_RESERVED 0x00080000/* Don't unmap it from swap_out */ +#define VM_RESERVED 0x00080000/* Pages and ptes in region aren't managed with regular pagecache or rmap routines */ +#define VM_ACCOUNT 0x00100000/* Is a VM accounted object */ #define VM_HUGETLB 0x00400000/* Huge TLB Page VM */ #define VM_NONLINEAR 0x00800000/* Is non-linear (remap_file_pages) */
@@ -337,7 +338,7 @@ static inline void get_page(struct pagestatic inline void put_page (struct page *page) { -if (!PageReserved (page) &&put_page_testzero (page)) +if (put_page_testzero (page))__page_cache_release (page); }
@@ -711,6 +712,9 @@ void install_arg_page(struct vm_area_strint get_user_pages (struct task_struct *tsk,struct mm_struct *mm,unsigned long start,int len,int write,int force,struct page **pages,struct vm_area_struct **vmas); +#define invalid_pfn (pte, vm_flags, vaddr) \ + __invalid_pfn(__FUNCTION__, pte, vm_flags, vaddr) +void __invalid_pfn (const char *,pte_t ,unsigned long ,unsigned long );int __set_page_dirty_buffers (struct page *page);int __set_page_dirty_nobuffers (struct page *page);
mm/madvise.c +1 -1
@@ -126,7 +126,7 @@ static long madvise_dontneed(struct vm_a unsigned long start, unsigned long end) { *prev = vma; -if ((vma->vm_flags &VM_LOCKED ) ||is_vm_hugetlb_page (vma)) +if ((vma->vm_flags & (VM_LOCKED |VM_RESERVED )) ||is_vm_hugetlb_page (vma))return -EINVAL ;if (unlikely (vma->vm_flags &VM_NONLINEAR )) {
mm/memory.c +78 -46
266 lines not on this page · raw message
mm/page_alloc.c +8 -6
@@ -113,7 +113,8 @@ static void bad_page(const char *functio1 << PG_reclaim |1 << PG_slab |1 << PG_swapcache | - 1 << PG_writeback); +1 << PG_writeback | + 1 << PG_reserved );set_page_count (page,0 );reset_page_mapcount (page); page->mapping =NULL ;
@@ -243,7 +244,6 @@ static inline int page_is_buddy(struct p {if (PagePrivate (page) && (page_order (page) == order) && - !PageReserved (page) &&page_count (page) ==0 )return 1 ;return 0 ;
@@ -326,7 +326,8 @@ static inline void free_pages_check(cons 1 << PG_reclaim | 1 << PG_slab | 1 << PG_swapcache | - 1 << PG_writeback ))) + 1 << PG_writeback | + 1 << PG_reserved )))bad_page (function, page);if (PageDirty (page))__ClearPageDirty (page);
@@ -454,7 +455,8 @@ static void prep_new_page(struct page *p 1 << PG_reclaim | 1 << PG_slab | 1 << PG_swapcache | - 1 << PG_writeback ))) + 1 << PG_writeback | + 1 << PG_reserved )))bad_page (__FUNCTION__, page); page->flags &= ~(1 << PG_uptodate | 1 << PG_error |
@@ -1011,7 +1013,7 @@ void __pagevec_free(struct pagevec *pvec fastcall void __free_pages(struct page *page, unsigned int order) { -if (!PageReserved (page) &&put_page_testzero (page)) { +if (put_page_testzero (page)) {if (order ==0 )free_hot_page (page);else
@@ -1654,7 +1656,7 @@ void __init memmap_init_zone(unsigned locontinue ; page =pfn_to_page (pfn);set_page_links (page, zone, nid, pfn); -set_page_count (page,0 ); +set_page_count (page,1 );reset_page_mapcount (page);SetPageReserved (page);INIT_LIST_HEAD (&page->lru);
mm/swap.c +2 -2
@@ -48,7 +48,7 @@ void put_page(struct page *page) }return ; } -if (!PageReserved (page) &&put_page_testzero (page)) +if (put_page_testzero (page))__page_cache_release (page); }EXPORT_SYMBOL (put_page);
@@ -215,7 +215,7 @@ void release_pages(struct page **pages,struct page *page = pages[i];struct zone *pagezone; -if (PageReserved (page) || !put_page_testzero (page)) +if (!put_page_testzero (page))continue ; pagezone =page_zone (page);
mm/fremap.c +16 -9
@@ -29,18 +29,21 @@ static inline void zap_pte(struct mm_strreturn ;if (pte_present (pte)) {unsigned long pfn =pte_pfn (pte); +struct page *page;flush_cache_page (vma, addr, pfn); pte =ptep_clear_flush (vma, addr, ptep); -if (pfn_valid (pfn)) { -struct page *page =pfn_to_page (pfn); -if (!PageReserved (page)) { -if (pte_dirty (pte)) -set_page_dirty (page); -page_remove_rmap (page); -page_cache_release (page); -dec_mm_counter (mm, rss); - } +if (unlikely (!pfn_valid (pfn))) { +invalid_pfn (pte, vma->vm_flags, addr); +return ; + } + page =pfn_to_page (pfn); +if (page !=ZERO_PAGE (addr)) { +if (pte_dirty (pte)) +set_page_dirty (page); +page_remove_rmap (page); +dec_mm_counter (mm, rss); +page_cache_release (page); } }else {if (!pte_file (pte))
@@ -65,6 +68,8 @@ int install_page(struct mm_struct *mm, spgd_t *pgd;pte_t pte_val; +BUG_ON (vma->vm_flags &VM_RESERVED ); + pgd =pgd_offset (mm, addr);spin_lock (&mm->page_table_lock);
@@ -122,6 +127,8 @@ int install_file_pte(struct mm_struct *mpgd_t *pgd;pte_t pte_val; +BUG_ON (vma->vm_flags &VM_RESERVED ); + pgd =pgd_offset (mm, addr);spin_lock (&mm->page_table_lock);
mm/msync.c +6 -3
@@ -37,11 +37,11 @@ static void sync_pte_range(struct vm_areif (!pte_maybe_dirty (*pte))continue ; pfn =pte_pfn (*pte); -if (!pfn_valid (pfn)) +if (unlikely (!pfn_valid (pfn))) { +invalid_pfn (*pte, vma->vm_flags, addr);continue ; + } page =pfn_to_page (pfn); -if (PageReserved (page)) -continue ;if (ptep_clear_flush_dirty (vma, addr, pte) ||page_test_and_clear_dirty (page))
@@ -149,6 +149,9 @@ static int msync_interval(struct vm_areaif ((flags &MS_INVALIDATE ) && (vma->vm_flags &VM_LOCKED ))return -EBUSY ; +if (vma->vm_flags &VM_RESERVED ) +return -EINVAL ; +if (file && (vma->vm_flags &VM_SHARED )) {filemap_sync (vma, addr, end);
mm/rmap.c +4 -10
@@ -442,8 +442,6 @@ int page_referenced(struct page *page, ivoid page_add_anon_rmap (struct page *page,struct vm_area_struct *vma,unsigned long address) { -BUG_ON (PageReserved (page)); -inc_mm_counter (vma->vm_mm, anon_rss);if (atomic_inc_and_test (&page->_mapcount)) {
@@ -469,8 +467,7 @@ void page_add_anon_rmap(struct page *pagvoid page_add_file_rmap (struct page *page) {BUG_ON (PageAnon (page)); -if (!pfn_valid (page_to_pfn (page)) ||PageReserved (page)) -return ; +BUG_ON (!pfn_valid (page_to_pfn (page)));if (atomic_inc_and_test (&page->_mapcount))inc_page_state (nr_mapped);
@@ -484,8 +481,6 @@ void page_add_file_rmap(struct page *pag*/ void page_remove_rmap (struct page *page) { -BUG_ON (PageReserved (page)); -if (atomic_add_negative (-1 , &page->_mapcount)) {BUG_ON (page_mapcount (page) <0 );/*
@@ -643,13 +638,13 @@ static void try_to_unmap_cluster(unsignecontinue ; pfn =pte_pfn (*pte); -if (!pfn_valid (pfn)) +if (unlikely (!pfn_valid (pfn))) { +invalid_pfn (*pte, vma->vm_flags, address);continue ; + } page =pfn_to_page (pfn);BUG_ON (PageAnon (page)); -if (PageReserved (page)) -continue ;if (ptep_clear_flush_young (vma, address, pte))continue ;
@@ -812,7 +807,6 @@ int try_to_unmap(struct page *page) {int ret; -BUG_ON (PageReserved (page));BUG_ON (!PageLocked (page));if (PageAnon (page))
drivers/scsi/sg.c +8 -4
@@ -1887,13 +1887,17 @@ st_unmap_user_pages(struct scatterlist *int i;for (i=0 ; i < nr_pages; i++) { -if (dirtied && !PageReserved (sgl[i].page)) -SetPageDirty (sgl[i].page); -/* unlock_page(sgl[i].page); */ +struct page *page = sgl[i].page; + +/* XXX: just for debug. Remove when PageReserved is removed */ +BUG_ON (PageReserved (page)); +if (dirtied) +SetPageDirty (page); +/* unlock_page(page); */ /* FIXME: cache flush missing for rw==READ * FIXME: call the correct reference counting function */ -page_cache_release (sgl[i].page); +page_cache_release (page); }return 0 ;
drivers/scsi/st.c +7 -3
@@ -4435,12 +4435,16 @@ static int sgl_unmap_user_pages(struct sint i;for (i=0 ; i < nr_pages; i++) { -if (dirtied && !PageReserved (sgl[i].page)) -SetPageDirty (sgl[i].page); +struct page *page = sgl[i].page; + +/* XXX: just for debug. Remove when PageReserved is removed */ +BUG_ON (PageReserved (page)); +if (dirtied) +SetPageDirty (page);/* FIXME: cache flush missing for rw==READ * FIXME: call the correct reference counting function */ -page_cache_release (sgl[i].page); +page_cache_release (page); }return 0 ;
sound/core/pcm_native.c +3 -6
@@ -2944,8 +2944,7 @@ static struct page * snd_pcm_mmap_statusreturn NOPAGE_OOM ; runtime = substream->runtime; page =virt_to_page (runtime->status); -if (!PageReserved (page)) -get_page (page); +get_page (page);if (type) *type =VM_FAULT_MINOR ;return page;
@@ -2987,8 +2986,7 @@ static struct page * snd_pcm_mmap_controreturn NOPAGE_OOM ; runtime = substream->runtime; page =virt_to_page (runtime->control); -if (!PageReserved (page)) -get_page (page); +get_page (page);if (type) *type =VM_FAULT_MINOR ;return page;
@@ -3061,8 +3059,7 @@ static struct page *snd_pcm_mmap_data_no vaddr = runtime->dma_area + offset; page =virt_to_page (vaddr); } -if (!PageReserved (page)) -get_page (page); +get_page (page);if (type) *type =VM_FAULT_MINOR ;return page;
mm/mmap.c +11 -0
@@ -1073,6 +1073,17 @@ munmap_back: error = file->f_op->mmap (file, vma);if (error) goto unmap_and_free_vma; +if ((vma->vm_flags & (VM_SHARED |VM_WRITE |VM_RESERVED )) + == (VM_WRITE |VM_RESERVED )) { +printk (KERN_WARNING "program %s is using MAP_PRIVATE, " +"PROT_WRITE mmap of VM_RESERVED memory, which " +"is deprecated. Please report this to " +"[email protected]\n" ,current->comm); +if (vma->vm_ops && vma->vm_ops->close) + vma->vm_ops->close (vma); + error = -EACCES ; + goto unmap_and_free_vma; + } }else if (vm_flags &VM_SHARED ) { error =shmem_zero_setup (vma);if (error)
mm/mprotect.c +8 -0
@@ -131,6 +131,14 @@ mprotect_fixup(struct vm_area_struct *vmreturn -ENOMEM ; newflags |=VM_ACCOUNT ; } +if (oldflags &VM_RESERVED ) { +BUG_ON (oldflags &VM_WRITE ); +printk (KERN_WARNING "program %s is using MAP_PRIVATE, " +"PROT_WRITE mprotect of VM_RESERVED memory, " +"which is deprecated. Please report this to " +"[email protected]\n" ,current->comm); +return -EACCES ; + } } newprot = protection_map[newflags &0xf ];
mm/bootmem.c +1 -0
@@ -297,6 +297,7 @@ static unsigned long __init free_all_booif (j +16 <BITS_PER_LONG )prefetchw (page + j +16 );__ClearPageReserved (page + j); +set_page_count (page + j,0 ); }__free_pages (page, order); i +=BITS_PER_LONG ;
mm/mempolicy.c +5 -1
@@ -253,8 +253,10 @@ static int check_pte_range(struct mm_strif (!pte_present (*pte))continue ; pfn =pte_pfn (*pte); -if (!pfn_valid (pfn)) +if (unlikely (!pfn_valid (pfn))) { +invalid_pfn (*pte,-1UL , addr);continue ; + } nid =pfn_to_nid (pfn);if (!test_bit (nid, nodes))break ;
@@ -326,6 +328,8 @@ check_range(struct mm_struct *mm, unsign first =find_vma (mm, start);if (!first)return ERR_PTR (-EFAULT ); +if (first->vm_flags &VM_RESERVED ) +return ERR_PTR (-EACCES ); prev =NULL ;for (vma = first; vma && vma->vm_start < end; vma = vma->vm_next) {if (!vma->vm_next && vma->vm_end < end)
arch/ppc64/kernel/vdso.c +6 -4
@@ -176,13 +176,13 @@ static struct page * vdso_vma_nopage(strreturn NOPAGE_SIGBUS ;/* -* Last page is systemcfg, special handling here, no get_page() a -* this is a reserved page +* Last page is systemcfg. */ if ((vma->vm_end - address) <=PAGE_SIZE ) -return virt_to_page (systemcfg); + pg =virt_to_page (systemcfg); +else + pg =virt_to_page (vbase + offset); - pg =virt_to_page (vbase + offset);get_page (pg);DBG (" ->page count: %d\n" ,page_count (pg));
@@ -600,6 +600,8 @@ void __init vdso_init(void)ClearPageReserved (pg);get_page (pg); } + +get_page (virt_to_page (systemcfg)); }int in_gate_area_no_task (unsigned long addr)
kernel/power/swsusp.c +16 -9
@@ -434,15 +434,23 @@ static int save_highmem_zone(struct zonecontinue ; page =pfn_to_page (pfn);/* -* This condition results from rvmalloc() sans vmalloc_32() -* and architectural memory reservations. This should be -* corrected eventually when the cases giving rise to this -* are better understood. +* PageReserved results from rvmalloc() sans vmalloc_32() +* and architectural memory reservations. +* +* rvmalloc should not cause this, because all implementations +* appear to always be using vmalloc_32 on architectures with +* highmem. This is a good thing, because we would like to save +* rvmalloc pages. +* +* It appears to be triggered by pages which do not point to +* valid memory (see arch/i386/mm/init.c:one_highpage_init(), +* which sets PageReserved if the page does not point to valid +* RAM. +* +* XXX: must remove usage of PageReserved! */ -if (PageReserved (page)) { -printk ("highmem reserved page?!\n" ); +if (PageReserved (page))continue ; - }BUG_ON (PageNosave (page));if (PageNosaveFree (page))continue ;
@@ -528,10 +536,9 @@ static int saveable(struct zone * zone,return 0 ; page =pfn_to_page (pfn); -BUG_ON (PageReserved (page) &&PageNosave (page));if (PageNosave (page))return 0 ; -if (PageReserved (page) &&pfn_is_nosave (pfn)) { +if (pfn_is_nosave (pfn)) {pr_debug ("[nosave pfn 0x%lx]" , pfn);return 0 ; }
mm/shmem.c +2 -1
@@ -1523,7 +1523,8 @@ static void do_shmem_file_read(struct fi index += offset >>PAGE_CACHE_SHIFT ; offset &= ~PAGE_CACHE_MASK ; -page_cache_release (page); +if (page !=ZERO_PAGE (0 )) +page_cache_release (page);if (ret != nr || !desc->count)break ;
Re: [patch 2/6] mm: micro-optimise rmap
In reply to Nick Piggin[Nick, your mail bounced while sending this privately so reply-all this time]
Quoted 25 lines
Index:
linux-2.6/mm/rmap.c
===================================================================mm/rmap.c +2
-10@@ -442,22 +442,23 @@ int page_referenced(struct page *page, ivoid page_add_anon_rmap (struct page *page,struct vm_area_struct *vma,unsigned long address) { -struct anon_vma *anon_vma = vma->anon_vma; -pgoff_t index; -BUG_ON (PageReserved (page)); -BUG_ON (!anon_vma);inc_mm_counter (vma->vm_mm, anon_rss); - anon_vma = (void *) anon_vma +PAGE_MAPPING_ANON ; - index = (address - vma->vm_start) >>PAGE_SHIFT ; - index += vma->vm_pgoff; - index >>=PAGE_CACHE_SHIFT -PAGE_SHIFT ; -if (atomic_inc_and_test (&page->_mapcount)) { - page->index = index; +struct anon_vma *anon_vma = vma->anon_vma; +pgoff_t index;
mm/rmap.c int page_referenced(struct page *page, i · line 461
Quoted 10 lines
mm/rmap.c +9
-0+ +BUG_ON (!anon_vma); + anon_vma = (void *) anon_vma +PAGE_MAPPING_ANON ; page->mapping = (struct address_space *) anon_vma; + + index = (address - vma->vm_start) >>PAGE_SHIFT ; + index += vma->vm_pgoff; + index >>=PAGE_CACHE_SHIFT -PAGE_SHIFT ; + page->index = index; +
linear_page_index() here too?
Re: [patch 2/6] mm: micro-optimise rmap
Quoted 5 lines · Alexander Nyberg
Quoted 1 line
void page_add_anon_rmap(struct page *page,
linear_page_index()here too?
Hi Alexander,
Yes, that's what patch 3/6 did :)
Signature · 3 lines
SUSE Labs, Novell Inc. Send instant messages to your online friends http://au.messenger.yahoo.com
Quoted 6 lines · Nick Piggin
Hi Andrew,
If you're feeling like -mm is getting too stable, then you might consider giving these patches a spin? (unless anyone else raises an objection).
Patches are against 2.6.13-rc3-git7
Signature · 3 lines
SUSE Labs, Novell Inc. Send instant messages to your online friends http://au.messenger.yahoo.com
Quoted 12 lines · Nick Piggin
Hi Andrew,
If you're feeling like -mm is getting too stable, then you might consider giving these patches a spin? (unless anyone else raises an objection).
Ben thought I should get moving with them soon.
Not much change from last time. A bit of ppc64 input from Ben, and some
rmap.cinput from Hugh. Boots and runs on a few machines I have lying around here.
Quoted 7 lines
The only remaining places that *test* PageReserved are swsusp, a trivial useage in
drivers/char/agp/amd64-agp.c, andarch/code.Most of the arch code is just reserved memory reporting, which isn't very interesting and could easily be removed. Some arch users are a bit more subtle, however they *should not* break, because all the places that set and clear PageReserved are basically intact.
What is the desired fix look like for arch users?
- kumar
Quoted 9 lines · Kumar Gala
Quoted 5 lines
Most of the arch code is just reserved memory reporting, which isn't very interesting and could easily be removed. Some arch users are a bit more subtle, however they *should not* break, because all the places that set and clear PageReserved are basically intact.
What is the desired fix look like for arch users?
It really depends on how it is used.
Firstly, we want to retain all the places that do SetPageReserved and ClearPageReserved to ensure that remaining places that test PageReserved will continue to work.
So users of PageReserved need to be removed. For example, on i386 this is simply reserved memory accounting - which isn't very meaningful and can probably be simply deleted. i386 ioremap also tests PageReserved to ensure it isn't remapping usable RAM, which is a similar need to swsusp's, so one solution would likely cover that ioremap and swsusp.
For now, the main thing to keep in mind is to not add a new user of PageReserved. We can start looking at how to cut down existing users when the core patch gets into -mm or further upstream.
Nick
Send instant messages to your online friends http://au.messenger.yahoo.com