memory_hotplug.h 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  1. #ifndef __LINUX_MEMORY_HOTPLUG_H
  2. #define __LINUX_MEMORY_HOTPLUG_H
  3. #include <linux/mmzone.h>
  4. #include <linux/spinlock.h>
  5. #include <linux/notifier.h>
  6. #include <linux/bug.h>
  7. struct page;
  8. struct zone;
  9. struct pglist_data;
  10. struct mem_section;
  11. extern unsigned long movable_reserved_start, movable_reserved_size;
  12. extern unsigned long low_power_memory_start, low_power_memory_size;
  13. #ifdef CONFIG_MEMORY_HOTPLUG
  14. /*
  15. * Types for free bootmem stored in page->lru.next. These have to be in
  16. * some random range in unsigned long space for debugging purposes.
  17. */
  18. enum {
  19. MEMORY_HOTPLUG_MIN_BOOTMEM_TYPE = 12,
  20. SECTION_INFO = MEMORY_HOTPLUG_MIN_BOOTMEM_TYPE,
  21. MIX_SECTION_INFO,
  22. NODE_INFO,
  23. MEMORY_HOTPLUG_MAX_BOOTMEM_TYPE = NODE_INFO,
  24. };
  25. /*
  26. * pgdat resizing functions
  27. */
  28. static inline
  29. void pgdat_resize_lock(struct pglist_data *pgdat, unsigned long *flags)
  30. {
  31. spin_lock_irqsave(&pgdat->node_size_lock, *flags);
  32. }
  33. static inline
  34. void pgdat_resize_unlock(struct pglist_data *pgdat, unsigned long *flags)
  35. {
  36. spin_unlock_irqrestore(&pgdat->node_size_lock, *flags);
  37. }
  38. static inline
  39. void pgdat_resize_init(struct pglist_data *pgdat)
  40. {
  41. spin_lock_init(&pgdat->node_size_lock);
  42. }
  43. /*
  44. * Zone resizing functions
  45. */
  46. static inline unsigned zone_span_seqbegin(struct zone *zone)
  47. {
  48. return read_seqbegin(&zone->span_seqlock);
  49. }
  50. static inline int zone_span_seqretry(struct zone *zone, unsigned iv)
  51. {
  52. return read_seqretry(&zone->span_seqlock, iv);
  53. }
  54. static inline void zone_span_writelock(struct zone *zone)
  55. {
  56. write_seqlock(&zone->span_seqlock);
  57. }
  58. static inline void zone_span_writeunlock(struct zone *zone)
  59. {
  60. write_sequnlock(&zone->span_seqlock);
  61. }
  62. static inline void zone_seqlock_init(struct zone *zone)
  63. {
  64. seqlock_init(&zone->span_seqlock);
  65. }
  66. extern int zone_grow_free_lists(struct zone *zone, unsigned long new_nr_pages);
  67. extern int zone_grow_waitqueues(struct zone *zone, unsigned long nr_pages);
  68. extern int add_one_highpage(struct page *page, int pfn, int bad_ppro);
  69. /* VM interface that may be used by firmware interface */
  70. extern int online_pages(unsigned long, unsigned long);
  71. extern void __offline_isolated_pages(unsigned long, unsigned long);
  72. typedef void (*online_page_callback_t)(struct page *page);
  73. extern int set_online_page_callback(online_page_callback_t callback);
  74. extern int restore_online_page_callback(online_page_callback_t callback);
  75. extern void __online_page_set_limits(struct page *page);
  76. extern void __online_page_increment_counters(struct page *page);
  77. extern void __online_page_free(struct page *page);
  78. #ifdef CONFIG_MEMORY_HOTREMOVE
  79. extern bool is_pageblock_removable_nolock(struct page *page);
  80. #endif /* CONFIG_MEMORY_HOTREMOVE */
  81. /* reasonably generic interface to expand the physical pages in a zone */
  82. extern int __add_pages(int nid, struct zone *zone, unsigned long start_pfn,
  83. unsigned long nr_pages);
  84. extern int __remove_pages(struct zone *zone, unsigned long start_pfn,
  85. unsigned long nr_pages);
  86. #ifdef CONFIG_NUMA
  87. extern int memory_add_physaddr_to_nid(u64 start);
  88. #else
  89. static inline int memory_add_physaddr_to_nid(u64 start)
  90. {
  91. return 0;
  92. }
  93. #endif
  94. #ifdef CONFIG_HAVE_ARCH_NODEDATA_EXTENSION
  95. /*
  96. * For supporting node-hotadd, we have to allocate a new pgdat.
  97. *
  98. * If an arch has generic style NODE_DATA(),
  99. * node_data[nid] = kzalloc() works well. But it depends on the architecture.
  100. *
  101. * In general, generic_alloc_nodedata() is used.
  102. * Now, arch_free_nodedata() is just defined for error path of node_hot_add.
  103. *
  104. */
  105. extern pg_data_t *arch_alloc_nodedata(int nid);
  106. extern void arch_free_nodedata(pg_data_t *pgdat);
  107. extern void arch_refresh_nodedata(int nid, pg_data_t *pgdat);
  108. #else /* CONFIG_HAVE_ARCH_NODEDATA_EXTENSION */
  109. #define arch_alloc_nodedata(nid) generic_alloc_nodedata(nid)
  110. #define arch_free_nodedata(pgdat) generic_free_nodedata(pgdat)
  111. #ifdef CONFIG_NUMA
  112. /*
  113. * If ARCH_HAS_NODEDATA_EXTENSION=n, this func is used to allocate pgdat.
  114. * XXX: kmalloc_node() can't work well to get new node's memory at this time.
  115. * Because, pgdat for the new node is not allocated/initialized yet itself.
  116. * To use new node's memory, more consideration will be necessary.
  117. */
  118. #define generic_alloc_nodedata(nid) \
  119. ({ \
  120. kzalloc(sizeof(pg_data_t), GFP_KERNEL); \
  121. })
  122. /*
  123. * This definition is just for error path in node hotadd.
  124. * For node hotremove, we have to replace this.
  125. */
  126. #define generic_free_nodedata(pgdat) kfree(pgdat)
  127. extern pg_data_t *node_data[];
  128. static inline void arch_refresh_nodedata(int nid, pg_data_t *pgdat)
  129. {
  130. node_data[nid] = pgdat;
  131. }
  132. #else /* !CONFIG_NUMA */
  133. /* never called */
  134. static inline pg_data_t *generic_alloc_nodedata(int nid)
  135. {
  136. BUG();
  137. return NULL;
  138. }
  139. static inline void generic_free_nodedata(pg_data_t *pgdat)
  140. {
  141. }
  142. static inline void arch_refresh_nodedata(int nid, pg_data_t *pgdat)
  143. {
  144. }
  145. #endif /* CONFIG_NUMA */
  146. #endif /* CONFIG_HAVE_ARCH_NODEDATA_EXTENSION */
  147. #ifdef CONFIG_SPARSEMEM_VMEMMAP
  148. static inline void register_page_bootmem_info_node(struct pglist_data *pgdat)
  149. {
  150. }
  151. static inline void put_page_bootmem(struct page *page)
  152. {
  153. }
  154. #else
  155. extern void register_page_bootmem_info_node(struct pglist_data *pgdat);
  156. extern void put_page_bootmem(struct page *page);
  157. #endif
  158. /*
  159. * Lock for memory hotplug guarantees 1) all callbacks for memory hotplug
  160. * notifier will be called under this. 2) offline/online/add/remove memory
  161. * will not run simultaneously.
  162. */
  163. void lock_memory_hotplug(void);
  164. void unlock_memory_hotplug(void);
  165. #else /* ! CONFIG_MEMORY_HOTPLUG */
  166. /*
  167. * Stub functions for when hotplug is off
  168. */
  169. static inline void pgdat_resize_lock(struct pglist_data *p, unsigned long *f) {}
  170. static inline void pgdat_resize_unlock(struct pglist_data *p, unsigned long *f) {}
  171. static inline void pgdat_resize_init(struct pglist_data *pgdat) {}
  172. static inline unsigned zone_span_seqbegin(struct zone *zone)
  173. {
  174. return 0;
  175. }
  176. static inline int zone_span_seqretry(struct zone *zone, unsigned iv)
  177. {
  178. return 0;
  179. }
  180. static inline void zone_span_writelock(struct zone *zone) {}
  181. static inline void zone_span_writeunlock(struct zone *zone) {}
  182. static inline void zone_seqlock_init(struct zone *zone) {}
  183. static inline int mhp_notimplemented(const char *func)
  184. {
  185. printk(KERN_WARNING "%s() called, with CONFIG_MEMORY_HOTPLUG disabled\n", func);
  186. dump_stack();
  187. return -ENOSYS;
  188. }
  189. static inline void register_page_bootmem_info_node(struct pglist_data *pgdat)
  190. {
  191. }
  192. static inline void lock_memory_hotplug(void) {}
  193. static inline void unlock_memory_hotplug(void) {}
  194. #endif /* ! CONFIG_MEMORY_HOTPLUG */
  195. #ifdef CONFIG_MEMORY_HOTREMOVE
  196. extern int is_mem_section_removable(unsigned long pfn, unsigned long nr_pages);
  197. #else
  198. static inline int is_mem_section_removable(unsigned long pfn,
  199. unsigned long nr_pages)
  200. {
  201. return 0;
  202. }
  203. #endif /* CONFIG_MEMORY_HOTREMOVE */
  204. extern int mem_online_node(int nid);
  205. extern int add_memory(int nid, u64 start, u64 size);
  206. extern int arch_add_memory(int nid, u64 start, u64 size);
  207. extern int remove_memory(u64 start, u64 size);
  208. extern int sparse_add_one_section(struct zone *zone, unsigned long start_pfn,
  209. int nr_pages);
  210. extern void sparse_remove_one_section(struct zone *zone, struct mem_section *ms);
  211. extern struct page *sparse_decode_mem_map(unsigned long coded_mem_map,
  212. unsigned long pnum);
  213. #endif /* __LINUX_MEMORY_HOTPLUG_H */
  214. extern int physical_remove_memory(u64 start, u64 size);
  215. extern int arch_physical_remove_memory(u64 start, u64 size);
  216. extern int physical_low_power_memory(u64 start, u64 size);
  217. extern int arch_physical_low_power_memory(u64 start, u64 size);
  218. extern int physical_active_memory(u64 start, u64 size);
  219. extern int arch_physical_active_memory(u64 start, u64 size);