diff options
Diffstat (limited to 'mm/rmap.c')
-rw-r--r-- | mm/rmap.c | 25 |
1 files changed, 21 insertions, 4 deletions
@@ -182,7 +182,7 @@ int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src) | |||
182 | { | 182 | { |
183 | struct anon_vma_chain *avc, *pavc; | 183 | struct anon_vma_chain *avc, *pavc; |
184 | 184 | ||
185 | list_for_each_entry(pavc, &src->anon_vma_chain, same_vma) { | 185 | list_for_each_entry_reverse(pavc, &src->anon_vma_chain, same_vma) { |
186 | avc = anon_vma_chain_alloc(); | 186 | avc = anon_vma_chain_alloc(); |
187 | if (!avc) | 187 | if (!avc) |
188 | goto enomem_failure; | 188 | goto enomem_failure; |
@@ -232,6 +232,7 @@ int anon_vma_fork(struct vm_area_struct *vma, struct vm_area_struct *pvma) | |||
232 | out_error_free_anon_vma: | 232 | out_error_free_anon_vma: |
233 | anon_vma_free(anon_vma); | 233 | anon_vma_free(anon_vma); |
234 | out_error: | 234 | out_error: |
235 | unlink_anon_vmas(vma); | ||
235 | return -ENOMEM; | 236 | return -ENOMEM; |
236 | } | 237 | } |
237 | 238 | ||
@@ -729,13 +730,29 @@ void page_move_anon_rmap(struct page *page, | |||
729 | * @page: the page to add the mapping to | 730 | * @page: the page to add the mapping to |
730 | * @vma: the vm area in which the mapping is added | 731 | * @vma: the vm area in which the mapping is added |
731 | * @address: the user virtual address mapped | 732 | * @address: the user virtual address mapped |
733 | * @exclusive: the page is exclusively owned by the current process | ||
732 | */ | 734 | */ |
733 | static void __page_set_anon_rmap(struct page *page, | 735 | static void __page_set_anon_rmap(struct page *page, |
734 | struct vm_area_struct *vma, unsigned long address) | 736 | struct vm_area_struct *vma, unsigned long address, int exclusive) |
735 | { | 737 | { |
736 | struct anon_vma *anon_vma = vma->anon_vma; | 738 | struct anon_vma *anon_vma = vma->anon_vma; |
737 | 739 | ||
738 | BUG_ON(!anon_vma); | 740 | BUG_ON(!anon_vma); |
741 | |||
742 | /* | ||
743 | * If the page isn't exclusively mapped into this vma, | ||
744 | * we must use the _oldest_ possible anon_vma for the | ||
745 | * page mapping! | ||
746 | * | ||
747 | * So take the last AVC chain entry in the vma, which is | ||
748 | * the deepest ancestor, and use the anon_vma from that. | ||
749 | */ | ||
750 | if (!exclusive) { | ||
751 | struct anon_vma_chain *avc; | ||
752 | avc = list_entry(vma->anon_vma_chain.prev, struct anon_vma_chain, same_vma); | ||
753 | anon_vma = avc->anon_vma; | ||
754 | } | ||
755 | |||
739 | anon_vma = (void *) anon_vma + PAGE_MAPPING_ANON; | 756 | anon_vma = (void *) anon_vma + PAGE_MAPPING_ANON; |
740 | page->mapping = (struct address_space *) anon_vma; | 757 | page->mapping = (struct address_space *) anon_vma; |
741 | page->index = linear_page_index(vma, address); | 758 | page->index = linear_page_index(vma, address); |
@@ -790,7 +807,7 @@ void page_add_anon_rmap(struct page *page, | |||
790 | VM_BUG_ON(!PageLocked(page)); | 807 | VM_BUG_ON(!PageLocked(page)); |
791 | VM_BUG_ON(address < vma->vm_start || address >= vma->vm_end); | 808 | VM_BUG_ON(address < vma->vm_start || address >= vma->vm_end); |
792 | if (first) | 809 | if (first) |
793 | __page_set_anon_rmap(page, vma, address); | 810 | __page_set_anon_rmap(page, vma, address, 0); |
794 | else | 811 | else |
795 | __page_check_anon_rmap(page, vma, address); | 812 | __page_check_anon_rmap(page, vma, address); |
796 | } | 813 | } |
@@ -812,7 +829,7 @@ void page_add_new_anon_rmap(struct page *page, | |||
812 | SetPageSwapBacked(page); | 829 | SetPageSwapBacked(page); |
813 | atomic_set(&page->_mapcount, 0); /* increment count (starts at -1) */ | 830 | atomic_set(&page->_mapcount, 0); /* increment count (starts at -1) */ |
814 | __inc_zone_page_state(page, NR_ANON_PAGES); | 831 | __inc_zone_page_state(page, NR_ANON_PAGES); |
815 | __page_set_anon_rmap(page, vma, address); | 832 | __page_set_anon_rmap(page, vma, address, 1); |
816 | if (page_evictable(page, vma)) | 833 | if (page_evictable(page, vma)) |
817 | lru_cache_add_lru(page, LRU_ACTIVE_ANON); | 834 | lru_cache_add_lru(page, LRU_ACTIVE_ANON); |
818 | else | 835 | else |