ksm.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. #ifndef __LINUX_KSM_H
  2. #define __LINUX_KSM_H
  3. /*
  4. * Memory merging support.
  5. *
  6. * This code enables dynamic sharing of identical pages found in different
  7. * memory areas, even if they are not shared by fork().
  8. */
  9. #include <linux/bitops.h>
  10. #include <linux/mm.h>
  11. #include <linux/pagemap.h>
  12. #include <linux/rmap.h>
  13. #include <linux/sched.h>
  14. struct stable_node;
  15. struct mem_cgroup;
  16. #ifdef CONFIG_KSM
  17. int ksm_madvise(struct vm_area_struct *vma, unsigned long start,
  18. unsigned long end, int advice, unsigned long *vm_flags);
  19. int __ksm_enter(struct mm_struct *mm);
  20. void __ksm_exit(struct mm_struct *mm);
  21. static inline int ksm_fork(struct mm_struct *mm, struct mm_struct *oldmm)
  22. {
  23. if (test_bit(MMF_VM_MERGEABLE, &oldmm->flags))
  24. return __ksm_enter(mm);
  25. return 0;
  26. }
  27. static inline void ksm_exit(struct mm_struct *mm)
  28. {
  29. if (test_bit(MMF_VM_MERGEABLE, &mm->flags))
  30. __ksm_exit(mm);
  31. }
  32. static inline struct stable_node *page_stable_node(struct page *page)
  33. {
  34. return PageKsm(page) ? page_rmapping(page) : NULL;
  35. }
  36. static inline void set_page_stable_node(struct page *page,
  37. struct stable_node *stable_node)
  38. {
  39. page->mapping = (void *)((unsigned long)stable_node | PAGE_MAPPING_KSM);
  40. }
  41. /*
  42. * When do_swap_page() first faults in from swap what used to be a KSM page,
  43. * no problem, it will be assigned to this vma's anon_vma; but thereafter,
  44. * it might be faulted into a different anon_vma (or perhaps to a different
  45. * offset in the same anon_vma). do_swap_page() cannot do all the locking
  46. * needed to reconstitute a cross-anon_vma KSM page: for now it has to make
  47. * a copy, and leave remerging the pages to a later pass of ksmd.
  48. *
  49. * We'd like to make this conditional on vma->vm_flags & VM_MERGEABLE,
  50. * but what if the vma was unmerged while the page was swapped out?
  51. */
  52. struct page *ksm_might_need_to_copy(struct page *page,
  53. struct vm_area_struct *vma, unsigned long address);
  54. int rmap_walk_ksm(struct page *page, struct rmap_walk_control *rwc);
  55. void ksm_migrate_page(struct page *newpage, struct page *oldpage);
  56. #else /* !CONFIG_KSM */
  57. static inline int ksm_fork(struct mm_struct *mm, struct mm_struct *oldmm)
  58. {
  59. return 0;
  60. }
  61. static inline void ksm_exit(struct mm_struct *mm)
  62. {
  63. }
  64. #ifdef CONFIG_MMU
  65. static inline int ksm_madvise(struct vm_area_struct *vma, unsigned long start,
  66. unsigned long end, int advice, unsigned long *vm_flags)
  67. {
  68. return 0;
  69. }
  70. static inline struct page *ksm_might_need_to_copy(struct page *page,
  71. struct vm_area_struct *vma, unsigned long address)
  72. {
  73. return page;
  74. }
  75. static inline int page_referenced_ksm(struct page *page,
  76. struct mem_cgroup *memcg, unsigned long *vm_flags)
  77. {
  78. return 0;
  79. }
  80. static inline int rmap_walk_ksm(struct page *page,
  81. struct rmap_walk_control *rwc)
  82. {
  83. return 0;
  84. }
  85. static inline void ksm_migrate_page(struct page *newpage, struct page *oldpage)
  86. {
  87. }
  88. #endif /* CONFIG_MMU */
  89. #endif /* !CONFIG_KSM */
  90. #endif /* __LINUX_KSM_H */