ksm.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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. /*
  33. * A KSM page is one of those write-protected "shared pages" or "merged pages"
  34. * which KSM maps into multiple mms, wherever identical anonymous page content
  35. * is found in VM_MERGEABLE vmas. It's a PageAnon page, pointing not to any
  36. * anon_vma, but to that page's node of the stable tree.
  37. */
  38. static inline int PageKsm(struct page *page)
  39. {
  40. return ((unsigned long)page->mapping & PAGE_MAPPING_FLAGS) ==
  41. (PAGE_MAPPING_ANON | PAGE_MAPPING_KSM);
  42. }
  43. static inline struct stable_node *page_stable_node(struct page *page)
  44. {
  45. return PageKsm(page) ? page_rmapping(page) : NULL;
  46. }
  47. static inline void set_page_stable_node(struct page *page,
  48. struct stable_node *stable_node)
  49. {
  50. page->mapping = (void *)stable_node +
  51. (PAGE_MAPPING_ANON | PAGE_MAPPING_KSM);
  52. }
  53. /*
  54. * When do_swap_page() first faults in from swap what used to be a KSM page,
  55. * no problem, it will be assigned to this vma's anon_vma; but thereafter,
  56. * it might be faulted into a different anon_vma (or perhaps to a different
  57. * offset in the same anon_vma). do_swap_page() cannot do all the locking
  58. * needed to reconstitute a cross-anon_vma KSM page: for now it has to make
  59. * a copy, and leave remerging the pages to a later pass of ksmd.
  60. *
  61. * We'd like to make this conditional on vma->vm_flags & VM_MERGEABLE,
  62. * but what if the vma was unmerged while the page was swapped out?
  63. */
  64. struct page *ksm_might_need_to_copy(struct page *page,
  65. struct vm_area_struct *vma, unsigned long address);
  66. int rmap_walk_ksm(struct page *page, struct rmap_walk_control *rwc);
  67. void ksm_migrate_page(struct page *newpage, struct page *oldpage);
  68. /*add for charing detect*/
  69. typedef enum {
  70. KAL_FALSE = 0,
  71. KAL_TRUE = 1,
  72. } kal_bool;
  73. kal_bool bat_is_charger_exist(void);
  74. #else /* !CONFIG_KSM */
  75. static inline int ksm_fork(struct mm_struct *mm, struct mm_struct *oldmm)
  76. {
  77. return 0;
  78. }
  79. static inline void ksm_exit(struct mm_struct *mm)
  80. {
  81. }
  82. static inline int PageKsm(struct page *page)
  83. {
  84. return 0;
  85. }
  86. #ifdef CONFIG_MMU
  87. static inline int ksm_madvise(struct vm_area_struct *vma, unsigned long start,
  88. unsigned long end, int advice, unsigned long *vm_flags)
  89. {
  90. return 0;
  91. }
  92. static inline struct page *ksm_might_need_to_copy(struct page *page,
  93. struct vm_area_struct *vma, unsigned long address)
  94. {
  95. return page;
  96. }
  97. static inline int page_referenced_ksm(struct page *page,
  98. struct mem_cgroup *memcg, unsigned long *vm_flags)
  99. {
  100. return 0;
  101. }
  102. static inline int rmap_walk_ksm(struct page *page,
  103. struct rmap_walk_control *rwc)
  104. {
  105. return 0;
  106. }
  107. static inline void ksm_migrate_page(struct page *newpage, struct page *oldpage)
  108. {
  109. }
  110. #endif /* CONFIG_MMU */
  111. #endif /* !CONFIG_KSM */
  112. #endif /* __LINUX_KSM_H */