linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v7] mm/page_owner.c: add llseek for page_owner
@ 2022-08-15  6:30 Kassey Li
  2022-08-15 12:40 ` kernel test robot
  2022-08-15 13:53 ` kernel test robot
  0 siblings, 2 replies; 3+ messages in thread
From: Kassey Li @ 2022-08-15  6:30 UTC (permalink / raw)
  To: akpm, vbabka
  Cc: Kassey Li, minchan, vbabka, iamjoonsoo.kim, linux-kernel, linux-mm

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/mm/page_owner.rst |  5 +++++
 mm/page_owner.c                 | 24 +++++++++++++++++++++---
 2 files changed, 26 insertions(+), 3 deletions(-)

diff --git a/Documentation/mm/page_owner.rst b/Documentation/mm/page_owner.rst
index f5c954afe97c..f18fd8907049 100644
--- a/Documentation/mm/page_owner.rst
+++ b/Documentation/mm/page_owner.rst
@@ -94,6 +94,11 @@ Usage
 	Page allocated via order XXX, ...
 	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
diff --git a/mm/page_owner.c b/mm/page_owner.c
index e4c6f3f1695b..c1a54e0e07dc 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);
@@ -570,6 +572,21 @@ read_page_owner(struct file *file, char __user *buf, size_t count, loff_t *ppos)
 	return 0;
 }
 
+loff_t lseek_page_owner(struct file *file, loff_t offset, int orig)
+{
+	switch (orig) {
+	case SEEK_SET:
+		file->f_pos = offset;
+		break;
+	case SEEK_CUR:
+		file->f_pos += offset;
+		break;
+	default:
+		return -EINVAL;
+	}
+	return file->f_pos;
+}
+
 static void init_pages_in_zone(pg_data_t *pgdat, struct zone *zone)
 {
 	unsigned long pfn = zone->zone_start_pfn;
@@ -660,6 +677,7 @@ static void init_early_allocated_pages(void)
 
 static const struct file_operations proc_page_owner_operations = {
 	.read		= read_page_owner,
+	.llseek		= lseek_page_owner,
 };
 
 static int __init pageowner_init(void)
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH v7] mm/page_owner.c: add llseek for page_owner
  2022-08-15  6:30 [PATCH v7] mm/page_owner.c: add llseek for page_owner Kassey Li
@ 2022-08-15 12:40 ` kernel test robot
  2022-08-15 13:53 ` kernel test robot
  1 sibling, 0 replies; 3+ messages in thread
From: kernel test robot @ 2022-08-15 12:40 UTC (permalink / raw)
  To: Kassey Li, akpm, vbabka
  Cc: llvm, kbuild-all, Kassey Li, minchan, vbabka, iamjoonsoo.kim,
	linux-kernel, linux-mm

Hi Kassey,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on linus/master]
[also build test WARNING on v6.0-rc1 next-20220815]
[cannot apply to akpm-mm/mm-everything]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Kassey-Li/mm-page_owner-c-add-llseek-for-page_owner/20220815-143155
base:   https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git 568035b01cfb107af8d2e4bd2fb9aea22cf5b868
config: hexagon-randconfig-r041-20220814 (https://download.01.org/0day-ci/archive/20220815/202208152007.a6QeCOGK-lkp@intel.com/config)
compiler: clang version 16.0.0 (https://github.com/llvm/llvm-project 6afcc4a459ead8809a0d6d9b4bf7b64bcc13582b)
reproduce (this is a W=1 build):
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # https://github.com/intel-lab-lkp/linux/commit/f9ef28f8ab55cdd176ab5ce7ad606ca45b4dbcc0
        git remote add linux-review https://github.com/intel-lab-lkp/linux
        git fetch --no-tags linux-review Kassey-Li/mm-page_owner-c-add-llseek-for-page_owner/20220815-143155
        git checkout f9ef28f8ab55cdd176ab5ce7ad606ca45b4dbcc0
        # save the config file
        mkdir build_dir && cp config build_dir/.config
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=hexagon SHELL=/bin/bash

If you fix the issue, kindly add following tag where applicable
Reported-by: kernel test robot <lkp@intel.com>

All warnings (new ones prefixed by >>):

>> mm/page_owner.c:575:8: warning: no previous prototype for function 'lseek_page_owner' [-Wmissing-prototypes]
   loff_t lseek_page_owner(struct file *file, loff_t offset, int orig)
          ^
   mm/page_owner.c:575:1: note: declare 'static' if the function is not intended to be used outside of this translation unit
   loff_t lseek_page_owner(struct file *file, loff_t offset, int orig)
   ^
   static 
   1 warning generated.


vim +/lseek_page_owner +575 mm/page_owner.c

   574	
 > 575	loff_t lseek_page_owner(struct file *file, loff_t offset, int orig)
   576	{
   577		switch (orig) {
   578		case SEEK_SET:
   579			file->f_pos = offset;
   580			break;
   581		case SEEK_CUR:
   582			file->f_pos += offset;
   583			break;
   584		default:
   585			return -EINVAL;
   586		}
   587		return file->f_pos;
   588	}
   589	

-- 
0-DAY CI Kernel Test Service
https://01.org/lkp

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH v7] mm/page_owner.c: add llseek for page_owner
  2022-08-15  6:30 [PATCH v7] mm/page_owner.c: add llseek for page_owner Kassey Li
  2022-08-15 12:40 ` kernel test robot
@ 2022-08-15 13:53 ` kernel test robot
  1 sibling, 0 replies; 3+ messages in thread
From: kernel test robot @ 2022-08-15 13:53 UTC (permalink / raw)
  To: Kassey Li, akpm, vbabka
  Cc: kbuild-all, Kassey Li, minchan, vbabka, iamjoonsoo.kim,
	linux-kernel, linux-mm

Hi Kassey,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on linus/master]
[also build test WARNING on v6.0-rc1 next-20220815]
[cannot apply to akpm-mm/mm-everything]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Kassey-Li/mm-page_owner-c-add-llseek-for-page_owner/20220815-143155
base:   https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git 568035b01cfb107af8d2e4bd2fb9aea22cf5b868
config: sh-allmodconfig (https://download.01.org/0day-ci/archive/20220815/202208152108.7XytfeP8-lkp@intel.com/config)
compiler: sh4-linux-gcc (GCC) 12.1.0
reproduce (this is a W=1 build):
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # https://github.com/intel-lab-lkp/linux/commit/f9ef28f8ab55cdd176ab5ce7ad606ca45b4dbcc0
        git remote add linux-review https://github.com/intel-lab-lkp/linux
        git fetch --no-tags linux-review Kassey-Li/mm-page_owner-c-add-llseek-for-page_owner/20220815-143155
        git checkout f9ef28f8ab55cdd176ab5ce7ad606ca45b4dbcc0
        # save the config file
        mkdir build_dir && cp config build_dir/.config
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-12.1.0 make.cross W=1 O=build_dir ARCH=sh SHELL=/bin/bash

If you fix the issue, kindly add following tag where applicable
Reported-by: kernel test robot <lkp@intel.com>

All warnings (new ones prefixed by >>):

>> mm/page_owner.c:575:8: warning: no previous prototype for 'lseek_page_owner' [-Wmissing-prototypes]
     575 | loff_t lseek_page_owner(struct file *file, loff_t offset, int orig)
         |        ^~~~~~~~~~~~~~~~


vim +/lseek_page_owner +575 mm/page_owner.c

   574	
 > 575	loff_t lseek_page_owner(struct file *file, loff_t offset, int orig)
   576	{
   577		switch (orig) {
   578		case SEEK_SET:
   579			file->f_pos = offset;
   580			break;
   581		case SEEK_CUR:
   582			file->f_pos += offset;
   583			break;
   584		default:
   585			return -EINVAL;
   586		}
   587		return file->f_pos;
   588	}
   589	

-- 
0-DAY CI Kernel Test Service
https://01.org/lkp

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-08-15 13:53 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-08-15  6:30 [PATCH v7] mm/page_owner.c: add llseek for page_owner Kassey Li
2022-08-15 12:40 ` kernel test robot
2022-08-15 13:53 ` kernel test robot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).