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 *)stable_node +
  40. (PAGE_MAPPING_ANON | PAGE_MAPPING_KSM);
  41. }
  42. /*
  43. * When do_swap_page() first faults in from swap what used to be a KSM page,
  44. * no problem, it will be assigned to this vma's anon_vma; but thereafter,
  45. * it might be faulted into a different anon_vma (or perhaps to a different
  46. * offset in the same anon_vma). do_swap_page() cannot do all the locking
  47. * needed to reconstitute a cross-anon_vma KSM page: for now it has to make
  48. * a copy, and leave remerging the pages to a later pass of ksmd.
  49. *
  50. * We'd like to make this conditional on vma->vm_flags & VM_MERGEABLE,
  51. * but what if the vma was unmerged while the page was swapped out?
  52. */
  53. struct page *ksm_might_need_to_copy(struct page *page,
  54. struct vm_area_struct *vma, unsigned long address);
  55. int rmap_walk_ksm(struct page *page, struct rmap_walk_control *rwc);
  56. void ksm_migrate_page(struct page *newpage, struct page *oldpage);
  57. #else /* !CONFIG_KSM */
  58. static inline int ksm_fork(struct mm_struct *mm, struct mm_struct *oldmm)
  59. {
  60. return 0;
  61. }
  62. static inline void ksm_exit(struct mm_struct *mm)
  63. {
  64. }
  65. #ifdef CONFIG_MMU
  66. static inline int ksm_madvise(struct vm_area_struct *vma, unsigned long start,
  67. unsigned long end, int advice, unsigned long *vm_flags)
  68. {
  69. return 0;
  70. }
  71. static inline struct page *ksm_might_need_to_copy(struct page *page,
  72. struct vm_area_struct *vma, unsigned long address)
  73. {
  74. return page;
  75. }
  76. static inline int page_referenced_ksm(struct page *page,
  77. struct mem_cgroup *memcg, unsigned long *vm_flags)
  78. {
  79. return 0;
  80. }
  81. static inline int rmap_walk_ksm(struct page *page,
  82. struct rmap_walk_control *rwc)
  83. {
  84. return 0;
  85. }
  86. static inline void ksm_migrate_page(struct page *newpage, struct page *oldpage)
  87. {
  88. }
  89. #endif /* CONFIG_MMU */
  90. #endif /* !CONFIG_KSM */
  91. #endif /* __LINUX_KSM_H */