From: Ma Wupeng mawupeng1@huawei.com
hulk inclusion category: feature bugzilla: https://gitee.com/openeuler/kernel/issues/I8USBA CVE: NA
--------------------------------
Add reliable memory info in /proc/meminfo:
- ReliableTotal: total reliable memory size - ReliableUsed: used reliable memory size - ReliableShmem: reliable memory used by shmem - FileCache: memory usage of page cache - ReliableFileCache: reliable memory usage of page cache
Signed-off-by: Ma Wupeng mawupeng1@huawei.com --- Documentation/filesystems/proc.rst | 22 +++++++++++++++++ fs/proc/meminfo.c | 2 ++ include/linux/mem_reliable.h | 2 ++ mm/mem_reliable.c | 38 ++++++++++++++++++++++++++++++ 4 files changed, 64 insertions(+)
diff --git a/Documentation/filesystems/proc.rst b/Documentation/filesystems/proc.rst index d7c614e3be67..3bbae7b35bb0 100644 --- a/Documentation/filesystems/proc.rst +++ b/Documentation/filesystems/proc.rst @@ -1027,6 +1027,13 @@ Example output. You may not have all of these fields. DirectMap4k: 401152 kB DirectMap2M: 10008576 kB DirectMap1G: 24117248 kB + ReliableTotal: 8190696 kB + ReliableUsed: 252912 kB + ReliableTaskUsed: 108136 kB + ReliableBuddyMem: 7937784 kB + ReliableShmem: 840 kB + FileCache: 104944 kB + ReliableFileCache: 102688 kB
MemTotal Total usable RAM (i.e. physical RAM minus a few reserved @@ -1191,6 +1198,21 @@ HugePages_Total, HugePages_Free, HugePages_Rsvd, HugePages_Surp, Hugepagesize, H DirectMap4k, DirectMap2M, DirectMap1G Breakdown of page table sizes used in the kernel's identity mapping of RAM +ReliableTotal + Total reliable memory size +ReliableUsed + The used amount of reliable memory +ReliableTaskUsed + Size of mirrored memory used by user task +ReliableBuddyMem + Size of unused mirrored memory in buddy system +ReliableShmem + Total reliable memory used by share memory +FileCache + Memory usage of page cache +ReliableFileCache + Reliable memory usage of page cache +
vmallocinfo ~~~~~~~~~~~ diff --git a/fs/proc/meminfo.c b/fs/proc/meminfo.c index 45af9a989d40..8f8cd1c60e04 100644 --- a/fs/proc/meminfo.c +++ b/fs/proc/meminfo.c @@ -168,6 +168,8 @@ static int meminfo_proc_show(struct seq_file *m, void *v)
arch_report_meminfo(m);
+ reliable_report_meminfo(m); + return 0; }
diff --git a/include/linux/mem_reliable.h b/include/linux/mem_reliable.h index b2be7010c520..8dba07dc6983 100644 --- a/include/linux/mem_reliable.h +++ b/include/linux/mem_reliable.h @@ -27,6 +27,7 @@ void shmem_reliable_init(void); void reliable_lru_add(enum lru_list lru, struct folio *folio, int val); void reliable_lru_add_batch(int zid, enum lru_list lru, int val); bool mem_reliable_counter_initialized(void); +void reliable_report_meminfo(struct seq_file *m);
static inline bool mem_reliable_is_enabled(void) { @@ -146,6 +147,7 @@ static inline void reliable_lru_add_batch(int zid, enum lru_list lru, static inline bool mem_reliable_counter_initialized(void) { return false; } static inline void shmem_reliable_folio_add(struct folio *folio, int nr_page) {} +static inline void reliable_report_meminfo(struct seq_file *m) {} #endif
#endif diff --git a/mm/mem_reliable.c b/mm/mem_reliable.c index 9251f82255db..c046d8016228 100644 --- a/mm/mem_reliable.c +++ b/mm/mem_reliable.c @@ -129,6 +129,44 @@ static int __init reliable_sysctl_init(void) } arch_initcall(reliable_sysctl_init);
+#define PAGES_TO_KB(n_pages) ((n_pages) << (PAGE_SHIFT - 10)) + +void reliable_report_meminfo(struct seq_file *m) +{ + if (!mem_reliable_is_enabled()) + return; + + seq_printf(m, "ReliableTotal: %8lu kB\n", + PAGES_TO_KB(total_reliable_pages())); + seq_printf(m, "ReliableUsed: %8lu kB\n", + PAGES_TO_KB(used_reliable_pages())); + seq_printf(m, "ReliableTaskUsed: %8lu kB\n", + PAGES_TO_KB(task_reliable_used_pages())); + seq_printf(m, "ReliableBuddyMem: %8lu kB\n", + PAGES_TO_KB(free_reliable_pages())); + + if (shmem_reliable_is_enabled()) { + unsigned long shmem_pages = (unsigned long)percpu_counter_sum( + &shmem_reliable_pages); + seq_printf(m, "ReliableShmem: %8lu kB\n", + PAGES_TO_KB(shmem_pages)); + } + + if (filemap_reliable_is_enabled()) { + unsigned long nr_reliable_pages = 0; + unsigned long num = 0; + + num += global_node_page_state(NR_LRU_BASE + LRU_ACTIVE_FILE); + num += global_node_page_state(NR_LRU_BASE + LRU_INACTIVE_FILE); + seq_printf(m, "FileCache: %8lu kB\n", PAGES_TO_KB(num)); + + nr_reliable_pages = + percpu_counter_sum_positive(&pagecache_reliable_pages); + seq_printf(m, "ReliableFileCache: %8lu kB\n", + PAGES_TO_KB(nr_reliable_pages)); + } +} + static int __init setup_reliable_debug(char *str) { if (*str++ != '=' || !*str)