diff options
Diffstat (limited to 'include')
-rw-r--r-- | include/linux/ksm.h | 5 | ||||
-rw-r--r-- | include/linux/mm.h | 17 | ||||
-rw-r--r-- | include/linux/rmap.h | 8 |
3 files changed, 27 insertions, 3 deletions
diff --git a/include/linux/ksm.h b/include/linux/ksm.h index a485c14ecd5..1401a313fa7 100644 --- a/include/linux/ksm.h +++ b/include/linux/ksm.h @@ -38,7 +38,8 @@ static inline void ksm_exit(struct mm_struct *mm) */ static inline int PageKsm(struct page *page) { - return ((unsigned long)page->mapping == PAGE_MAPPING_ANON); + return ((unsigned long)page->mapping & PAGE_MAPPING_FLAGS) == + (PAGE_MAPPING_ANON | PAGE_MAPPING_KSM); } /* @@ -47,7 +48,7 @@ static inline int PageKsm(struct page *page) static inline void page_add_ksm_rmap(struct page *page) { if (atomic_inc_and_test(&page->_mapcount)) { - page->mapping = (void *) PAGE_MAPPING_ANON; + page->mapping = (void *) (PAGE_MAPPING_ANON | PAGE_MAPPING_KSM); __inc_zone_page_state(page, NR_ANON_PAGES); } } diff --git a/include/linux/mm.h b/include/linux/mm.h index 24c395694f4..1202cd3121e 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -620,13 +620,22 @@ void page_address_init(void); /* * On an anonymous page mapped into a user virtual memory area, * page->mapping points to its anon_vma, not to a struct address_space; - * with the PAGE_MAPPING_ANON bit set to distinguish it. + * with the PAGE_MAPPING_ANON bit set to distinguish it. See rmap.h. + * + * On an anonymous page in a VM_MERGEABLE area, if CONFIG_KSM is enabled, + * the PAGE_MAPPING_KSM bit may be set along with the PAGE_MAPPING_ANON bit; + * and then page->mapping points, not to an anon_vma, but to a private + * structure which KSM associates with that merged page. See ksm.h. + * + * PAGE_MAPPING_KSM without PAGE_MAPPING_ANON is currently never used. * * Please note that, confusingly, "page_mapping" refers to the inode * address_space which maps the page from disk; whereas "page_mapped" * refers to user virtual address space into which the page is mapped. */ #define PAGE_MAPPING_ANON 1 +#define PAGE_MAPPING_KSM 2 +#define PAGE_MAPPING_FLAGS (PAGE_MAPPING_ANON | PAGE_MAPPING_KSM) extern struct address_space swapper_space; static inline struct address_space *page_mapping(struct page *page) @@ -644,6 +653,12 @@ static inline struct address_space *page_mapping(struct page *page) return mapping; } +/* Neutral page->mapping pointer to address_space or anon_vma or other */ +static inline void *page_rmapping(struct page *page) +{ + return (void *)((unsigned long)page->mapping & ~PAGE_MAPPING_FLAGS); +} + static inline int PageAnon(struct page *page) { return ((unsigned long)page->mapping & PAGE_MAPPING_ANON) != 0; diff --git a/include/linux/rmap.h b/include/linux/rmap.h index cb0ba703260..1f65af44c6d 100644 --- a/include/linux/rmap.h +++ b/include/linux/rmap.h @@ -39,6 +39,14 @@ struct anon_vma { #ifdef CONFIG_MMU +static inline struct anon_vma *page_anon_vma(struct page *page) +{ + if (((unsigned long)page->mapping & PAGE_MAPPING_FLAGS) != + PAGE_MAPPING_ANON) + return NULL; + return page_rmapping(page); +} + static inline void anon_vma_lock(struct vm_area_struct *vma) { struct anon_vma *anon_vma = vma->anon_vma; |