lkml.org 
[lkml]   [2022]   [Aug]   [8]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH v5] mm/page_owner.c: add llseek for page_owner
Date
There is usage to dump a given cma region page_owner
instead of all page's.

This change allows to specify a ppos as start_pfn
by fseek.

Any invalid ppos will be skipped, so it did not
broken the origin dump feature.

Suggested-by: Vlastimil Babka <vbabka@suse.cz>
Signed-off-by: Kassey Li <quic_yingangl@quicinc.com>
---
Documentation/vm/page_owner.rst | 6 ++++++
mm/internal.h | 5 +++++
mm/page_owner.c | 9 ++++++---
3 files changed, 17 insertions(+), 3 deletions(-)

diff --git a/Documentation/vm/page_owner.rst b/Documentation/vm/page_owner.rst
index f5c954afe97c..8d33d976da8a 100644
--- a/Documentation/vm/page_owner.rst
+++ b/Documentation/vm/page_owner.rst
@@ -95,6 +95,12 @@ Usage
PFN XXX ...
// Detailed stack

+ By default, it will do full pfn dump, to start with a given pfn,
+ page_owner supports fseek.
+
+ FILE *fp = fopen("/sys/kernel/debug/page_owner", "r");
+ fseek(fp, pfn_start, SEEK_SET);
+
The ``page_owner_sort`` tool ignores ``PFN`` rows, puts the remaining rows
in buf, uses regexp to extract the page order value, counts the times
and pages of buf, and finally sorts them according to the parameter(s).
diff --git a/mm/internal.h b/mm/internal.h
index c0f8fbe0445b..1ad8f86e6e33 100644
--- a/mm/internal.h
+++ b/mm/internal.h
@@ -189,6 +189,11 @@ extern void reclaim_throttle(pg_data_t *pgdat, enum vmscan_throttle_state reason
*/
extern pmd_t *mm_find_pmd(struct mm_struct *mm, unsigned long address);

+/*
+ * in mm/page_owner.c:
+ */
+extern loff_t mem_lseek(struct file *, loff_t, int);
+
/*
* in mm/page_alloc.c
*/
diff --git a/mm/page_owner.c b/mm/page_owner.c
index e4c6f3f1695b..dcbe05e206e1 100644
--- a/mm/page_owner.c
+++ b/mm/page_owner.c
@@ -497,8 +497,10 @@ read_page_owner(struct file *file, char __user *buf, size_t count, loff_t *ppos)
return -EINVAL;

page = NULL;
- pfn = min_low_pfn + *ppos;
-
+ if (*ppos == 0)
+ pfn= min_low_pfn;
+ else
+ pfn = *ppos;
/* Find a valid PFN or the start of a MAX_ORDER_NR_PAGES area */
while (!pfn_valid(pfn) && (pfn & (MAX_ORDER_NR_PAGES - 1)) != 0)
pfn++;
@@ -561,7 +563,7 @@ read_page_owner(struct file *file, char __user *buf, size_t count, loff_t *ppos)
continue;

/* Record the next PFN to read in the file offset */
- *ppos = (pfn - min_low_pfn) + 1;
+ *ppos = pfn + 1;

return print_page_owner(buf, count, pfn, page,
page_owner, handle);
@@ -660,6 +662,7 @@ static void init_early_allocated_pages(void)

static const struct file_operations proc_page_owner_operations = {
.read = read_page_owner,
+ .llseek = mem_lseek,
};

static int __init pageowner_init(void)
--
2.17.1
\
 
 \ /
  Last update: 2022-08-09 04:48    [W:0.077 / U:0.132 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site