Loading drivers/base/memory.c +29 −0 Original line number Diff line number Diff line Loading @@ -982,3 +982,32 @@ int for_each_memory_block(void *arg, walk_memory_blocks_func_t func) return bus_for_each_dev(&memory_subsys, NULL, &cb_data, for_each_memory_block_cb); } static int check_memblock_offlined(struct memory_block *mem, void *arg) { unsigned long *nr_pages_offlined = (unsigned long *)arg; if (is_memblock_offlined(mem)) *nr_pages_offlined += memory_block_size_bytes() / PAGE_SIZE; return 0; } /** * get_offlined_pages_count - get total pages offlined in the system * * This function walks through all the memory blocks present and gives * the total offlined pages count in the system. * */ unsigned long get_offlined_pages_count(void) { unsigned long nr_pages_offlined = 0; lock_device_hotplug_sysfs(); for_each_memory_block(&nr_pages_offlined, check_memblock_offlined); unlock_device_hotplug(); return nr_pages_offlined; } fs/proc/meminfo.c +2 −0 Original line number Diff line number Diff line Loading @@ -6,6 +6,7 @@ #include <linux/hugetlb.h> #include <linux/mman.h> #include <linux/mmzone.h> #include <linux/memory.h> #include <linux/proc_fs.h> #include <linux/percpu.h> #include <linux/seq_file.h> Loading Loading @@ -53,6 +54,7 @@ static int meminfo_proc_show(struct seq_file *m, void *v) pages[lru] = global_node_page_state(NR_LRU_BASE + lru); available = si_mem_available(); i.totalram += get_offlined_pages_count(); sreclaimable = global_node_page_state(NR_SLAB_RECLAIMABLE); sunreclaim = global_node_page_state(NR_SLAB_UNRECLAIMABLE); Loading include/linux/memory.h +2 −0 Original line number Diff line number Diff line Loading @@ -131,11 +131,13 @@ extern int for_each_memory_block(void *arg, walk_memory_blocks_func_t func); }) #define register_hotmemory_notifier(nb) register_memory_notifier(nb) #define unregister_hotmemory_notifier(nb) unregister_memory_notifier(nb) extern unsigned long get_offlined_pages_count(void); #else #define hotplug_memory_notifier(fn, pri) ({ 0; }) /* These aren't inline functions due to a GCC bug. */ #define register_hotmemory_notifier(nb) ({ (void)(nb); 0; }) #define unregister_hotmemory_notifier(nb) ({ (void)(nb); }) static inline unsigned long get_offlined_pages_count(void) { return 0; } #endif /* Loading Loading
drivers/base/memory.c +29 −0 Original line number Diff line number Diff line Loading @@ -982,3 +982,32 @@ int for_each_memory_block(void *arg, walk_memory_blocks_func_t func) return bus_for_each_dev(&memory_subsys, NULL, &cb_data, for_each_memory_block_cb); } static int check_memblock_offlined(struct memory_block *mem, void *arg) { unsigned long *nr_pages_offlined = (unsigned long *)arg; if (is_memblock_offlined(mem)) *nr_pages_offlined += memory_block_size_bytes() / PAGE_SIZE; return 0; } /** * get_offlined_pages_count - get total pages offlined in the system * * This function walks through all the memory blocks present and gives * the total offlined pages count in the system. * */ unsigned long get_offlined_pages_count(void) { unsigned long nr_pages_offlined = 0; lock_device_hotplug_sysfs(); for_each_memory_block(&nr_pages_offlined, check_memblock_offlined); unlock_device_hotplug(); return nr_pages_offlined; }
fs/proc/meminfo.c +2 −0 Original line number Diff line number Diff line Loading @@ -6,6 +6,7 @@ #include <linux/hugetlb.h> #include <linux/mman.h> #include <linux/mmzone.h> #include <linux/memory.h> #include <linux/proc_fs.h> #include <linux/percpu.h> #include <linux/seq_file.h> Loading Loading @@ -53,6 +54,7 @@ static int meminfo_proc_show(struct seq_file *m, void *v) pages[lru] = global_node_page_state(NR_LRU_BASE + lru); available = si_mem_available(); i.totalram += get_offlined_pages_count(); sreclaimable = global_node_page_state(NR_SLAB_RECLAIMABLE); sunreclaim = global_node_page_state(NR_SLAB_UNRECLAIMABLE); Loading
include/linux/memory.h +2 −0 Original line number Diff line number Diff line Loading @@ -131,11 +131,13 @@ extern int for_each_memory_block(void *arg, walk_memory_blocks_func_t func); }) #define register_hotmemory_notifier(nb) register_memory_notifier(nb) #define unregister_hotmemory_notifier(nb) unregister_memory_notifier(nb) extern unsigned long get_offlined_pages_count(void); #else #define hotplug_memory_notifier(fn, pri) ({ 0; }) /* These aren't inline functions due to a GCC bug. */ #define register_hotmemory_notifier(nb) ({ (void)(nb); 0; }) #define unregister_hotmemory_notifier(nb) ({ (void)(nb); }) static inline unsigned long get_offlined_pages_count(void) { return 0; } #endif /* Loading