[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20220109130515.140092-3-sxwjean@me.com>
Date: Sun, 9 Jan 2022 21:05:15 +0800
From: sxwjean@...com
To: akpm@...ux-foundation.org, david@...hat.com, mhocko@...e.com,
dan.j.williams@...el.com, osalvador@...e.de,
naoya.horiguchi@....com, thunder.leizhen@...wei.com
Cc: linux-mm@...ck.org, linux-fsdevel@...r.kernel.org,
linux-kernel@...r.kernel.org, Xiongwei Song <sxwjean@...il.com>
Subject: [PATCH 2/2] proc: Add getting pages info of ZONE_DEVICE support
From: Xiongwei Song <sxwjean@...il.com>
When requesting pages info by /proc/kpage*, the pages in ZONE_DEVICE were
missed.
The pfn_to_devmap_page() function can help to get page that belongs to
ZONE_DEVICE.
Signed-off-by: Xiongwei Song <sxwjean@...il.com>
---
fs/proc/page.c | 35 ++++++++++++++++++++++-------------
1 file changed, 22 insertions(+), 13 deletions(-)
diff --git a/fs/proc/page.c b/fs/proc/page.c
index 9f1077d94cde..2cdc2b315ff8 100644
--- a/fs/proc/page.c
+++ b/fs/proc/page.c
@@ -15,6 +15,7 @@
#include <linux/page_idle.h>
#include <linux/kernel-page-flags.h>
#include <linux/uaccess.h>
+#include <linux/memremap.h>
#include "internal.h"
#define KPMSIZE sizeof(u64)
@@ -46,6 +47,7 @@ static ssize_t kpagecount_read(struct file *file, char __user *buf,
{
const unsigned long max_dump_pfn = get_max_dump_pfn();
u64 __user *out = (u64 __user *)buf;
+ struct dev_pagemap *pgmap = NULL;
struct page *ppage;
unsigned long src = *ppos;
unsigned long pfn;
@@ -60,17 +62,18 @@ static ssize_t kpagecount_read(struct file *file, char __user *buf,
count = min_t(unsigned long, count, (max_dump_pfn * KPMSIZE) - src);
while (count > 0) {
- /*
- * TODO: ZONE_DEVICE support requires to identify
- * memmaps that were actually initialized.
- */
ppage = pfn_to_online_page(pfn);
+ if (!ppage)
+ ppage = pfn_to_devmap_page(pfn, &pgmap);
if (!ppage || PageSlab(ppage) || page_has_type(ppage))
pcount = 0;
else
pcount = page_mapcount(ppage);
+ if (pgmap)
+ put_dev_pagemap(pgmap);
+
if (put_user(pcount, out)) {
ret = -EFAULT;
break;
@@ -229,10 +232,12 @@ static ssize_t kpageflags_read(struct file *file, char __user *buf,
{
const unsigned long max_dump_pfn = get_max_dump_pfn();
u64 __user *out = (u64 __user *)buf;
+ struct dev_pagemap *pgmap = NULL;
struct page *ppage;
unsigned long src = *ppos;
unsigned long pfn;
ssize_t ret = 0;
+ u64 flags;
pfn = src / KPMSIZE;
if (src & KPMMASK || count & KPMMASK)
@@ -242,13 +247,15 @@ static ssize_t kpageflags_read(struct file *file, char __user *buf,
count = min_t(unsigned long, count, (max_dump_pfn * KPMSIZE) - src);
while (count > 0) {
- /*
- * TODO: ZONE_DEVICE support requires to identify
- * memmaps that were actually initialized.
- */
ppage = pfn_to_online_page(pfn);
+ if (!ppage)
+ ppage = pfn_to_devmap_page(pfn, &pgmap);
+
+ flags = stable_page_flags(ppage);
+ if (pgmap)
+ put_dev_pagemap(pgmap);
- if (put_user(stable_page_flags(ppage), out)) {
+ if (put_user(flags, out)) {
ret = -EFAULT;
break;
}
@@ -277,6 +284,7 @@ static ssize_t kpagecgroup_read(struct file *file, char __user *buf,
{
const unsigned long max_dump_pfn = get_max_dump_pfn();
u64 __user *out = (u64 __user *)buf;
+ struct dev_pagemap *pgmap = NULL;
struct page *ppage;
unsigned long src = *ppos;
unsigned long pfn;
@@ -291,17 +299,18 @@ static ssize_t kpagecgroup_read(struct file *file, char __user *buf,
count = min_t(unsigned long, count, (max_dump_pfn * KPMSIZE) - src);
while (count > 0) {
- /*
- * TODO: ZONE_DEVICE support requires to identify
- * memmaps that were actually initialized.
- */
ppage = pfn_to_online_page(pfn);
+ if (!ppage)
+ ppage = pfn_to_devmap_page(pfn, &pgmap);
if (ppage)
ino = page_cgroup_ino(ppage);
else
ino = 0;
+ if (pgmap)
+ put_dev_pagemap(pgmap);
+
if (put_user(ino, out)) {
ret = -EFAULT;
break;
--
2.30.2
Powered by blists - more mailing lists