Commit 9e47d0cc authored by Ma Wupeng's avatar Ma Wupeng Committed by Zheng Zengkai
Browse files

meminfo: Show reliable memory info

hulk inclusion
category: feature
bugzilla: https://gitee.com/openeuler/kernel/issues/I4PM01


CVE: NA

--------------------------------

Add ReliMemTotal & ReliMemUsed in /proc/meminfo to show memory info about
reliable memory.

- ReliableTotal: total reliable RAM

- ReliableUsed: thei used amount of reliable memory kernel

Signed-off-by: default avatarMa Wupeng <mawupeng1@huawei.com>
Reviewed-by: default avatarKefeng Wang <wangkefeng.wang@huawei.com>
Signed-off-by: default avatarZheng Zengkai <zhengzengkai@huawei.com>
parent 6c59ddf2
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -963,6 +963,8 @@ varies by architecture and compile options. The following is from a
    AnonHugePages:   49152 kB
    ShmemHugePages:      0 kB
    ShmemPmdMapped:      0 kB
    ReliableTotal: 7340032 kB
    ReliableUsed:   418824 kB

MemTotal
              Total usable RAM (i.e. physical RAM minus a few reserved
@@ -1092,6 +1094,10 @@ VmallocChunk
Percpu
              Memory allocated to the percpu allocator used to back percpu
              allocations. This stat excludes the cost of metadata.
ReliableTotal
              Total reliable memory size
ReliableUsed
              The used amount of reliable memory

vmallocinfo
~~~~~~~~~~~
+2 −0
Original line number Diff line number Diff line
@@ -150,6 +150,8 @@ static int meminfo_proc_show(struct seq_file *m, void *v)

	arch_report_meminfo(m);

	reliable_report_meminfo(m);

	return 0;
}

+2 −0
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@ extern bool reliable_enabled;
extern void add_reliable_mem_size(long sz);
extern void mem_reliable_init(bool has_unmirrored_mem,
			      unsigned long *zone_movable_pfn);
extern void reliable_report_meminfo(struct seq_file *m);

static inline bool mem_reliable_is_enabled(void)
{
@@ -57,6 +58,7 @@ static inline bool skip_none_movable_zone(gfp_t gfp, struct zoneref *z)
{
	return false;
}
static inline void reliable_report_meminfo(struct seq_file *m) {}
#endif

#endif
+25 −0
Original line number Diff line number Diff line
@@ -5,6 +5,8 @@
#include <linux/mm.h>
#include <linux/memory.h>
#include <linux/memory_hotplug.h>
#include <linux/seq_file.h>
#include <linux/mmzone.h>

DEFINE_STATIC_KEY_FALSE(mem_reliable);

@@ -22,6 +24,18 @@ static unsigned long total_reliable_mem_sz(void)
	return atomic_long_read(&total_reliable_mem);
}

static unsigned long used_reliable_mem_sz(void)
{
	unsigned long nr_page = 0;
	struct zone *z;

	for_each_populated_zone(z)
		if (zone_idx(z) < ZONE_MOVABLE)
			nr_page += zone_page_state(z, NR_FREE_PAGES);

	return total_reliable_mem_sz() - nr_page * PAGE_SIZE;
}

static int reliable_mem_notifier(struct notifier_block *nb,
				 unsigned long action, void *arg)
{
@@ -77,3 +91,14 @@ void mem_reliable_init(bool has_unmirrored_mem, unsigned long *zone_movable_pfn)
	pr_info("init succeed, mirrored memory size(%lu)\n",
		total_reliable_mem_sz());
}

void reliable_report_meminfo(struct seq_file *m)
{
	if (!mem_reliable_is_enabled())
		return;

	seq_printf(m, "ReliableTotal:    %8lu kB\n",
		   total_reliable_mem_sz() >> 10);
	seq_printf(m, "ReliableUsed:     %8lu kB\n",
		   used_reliable_mem_sz() >> 10);
}