diff mbox series

[v6] mm/page_owner.c: add llseek for page_owner

Message ID 20220810013218.27416-1-quic_yingangl@quicinc.com (mailing list archive)
State New
Headers show
Series [v6] mm/page_owner.c: add llseek for page_owner | expand

Commit Message

Kassey Li Aug. 10, 2022, 1:32 a.m. UTC
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/page_owner.c                 | 10 +++++++---
 2 files changed, 13 insertions(+), 3 deletions(-)

Comments

kernel test robot Aug. 10, 2022, 9:02 a.m. UTC | #1
Hi Kassey,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on v5.19]
[also build test ERROR on next-20220810]
[cannot apply to akpm-mm/mm-everything linus/master]
[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/20220810-093417
base:    3d7cb6b04c3f3115719235cc6866b10326de34cd
config: parisc-buildonly-randconfig-r004-20220810 (https://download.01.org/0day-ci/archive/20220810/202208101628.o6qUzx50-lkp@intel.com/config)
compiler: hppa-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/d2decd69a8d5756c1706092c805a4c8af14df471
        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/20220810-093417
        git checkout d2decd69a8d5756c1706092c805a4c8af14df471
        # 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=parisc SHELL=/bin/bash

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

All errors (new ones prefixed by >>):

   In file included from mm/page_owner.c:16:
>> mm/../fs/proc/internal.h:51:9: error: unknown type name 'proc_write_t'
      51 |         proc_write_t write;
         |         ^~~~~~~~~~~~


vim +/proc_write_t +51 mm/../fs/proc/internal.h

^1da177e4c3f41 Linus Torvalds    2005-04-16  19  
59d8053f1e1690 David Howells     2013-04-11  20  /*
59d8053f1e1690 David Howells     2013-04-11  21   * This is not completely implemented yet. The idea is to
59d8053f1e1690 David Howells     2013-04-11  22   * create an in-memory tree (like the actual /proc filesystem
59d8053f1e1690 David Howells     2013-04-11  23   * tree) of these proc_dir_entries, so that we can dynamically
59d8053f1e1690 David Howells     2013-04-11  24   * add new files to /proc.
59d8053f1e1690 David Howells     2013-04-11  25   *
710585d4922fd3 Nicolas Dichtel   2014-12-10  26   * parent/subdir are used for the directory structure (every /proc file has a
710585d4922fd3 Nicolas Dichtel   2014-12-10  27   * parent, but "subdir" is empty for all non-directory entries).
710585d4922fd3 Nicolas Dichtel   2014-12-10  28   * subdir_node is used to build the rb tree "subdir" of the parent.
59d8053f1e1690 David Howells     2013-04-11  29   */
59d8053f1e1690 David Howells     2013-04-11  30  struct proc_dir_entry {
163cf548db8887 Alexey Dobriyan   2018-02-06  31  	/*
163cf548db8887 Alexey Dobriyan   2018-02-06  32  	 * number of callers into module in progress;
163cf548db8887 Alexey Dobriyan   2018-02-06  33  	 * negative -> it's going away RSN
163cf548db8887 Alexey Dobriyan   2018-02-06  34  	 */
163cf548db8887 Alexey Dobriyan   2018-02-06  35  	atomic_t in_use;
9cdd83e3100651 Alexey Dobriyan   2018-04-10  36  	refcount_t refcnt;
163cf548db8887 Alexey Dobriyan   2018-02-06  37  	struct list_head pde_openers;	/* who did ->open, but not ->release */
53f63345d893df Alexey Dobriyan   2018-02-06  38  	/* protects ->pde_openers and all struct pde_opener instances */
53f63345d893df Alexey Dobriyan   2018-02-06  39  	spinlock_t pde_unload_lock;
163cf548db8887 Alexey Dobriyan   2018-02-06  40  	struct completion *pde_unload_completion;
163cf548db8887 Alexey Dobriyan   2018-02-06  41  	const struct inode_operations *proc_iops;
d56c0d45f0e27f Alexey Dobriyan   2020-02-03  42  	union {
d56c0d45f0e27f Alexey Dobriyan   2020-02-03  43  		const struct proc_ops *proc_ops;
d56c0d45f0e27f Alexey Dobriyan   2020-02-03  44  		const struct file_operations *proc_dir_ops;
d56c0d45f0e27f Alexey Dobriyan   2020-02-03  45  	};
1fde6f21d90f8b Alexey Dobriyan   2019-02-01  46  	const struct dentry_operations *proc_dops;
3f3942aca6da35 Christoph Hellwig 2018-05-15  47  	union {
fddda2b7b52118 Christoph Hellwig 2018-04-13  48  		const struct seq_operations *seq_ops;
3f3942aca6da35 Christoph Hellwig 2018-05-15  49  		int (*single_show)(struct seq_file *, void *);
3f3942aca6da35 Christoph Hellwig 2018-05-15  50  	};
564def71765caf David Howells     2018-05-18 @51  	proc_write_t write;
163cf548db8887 Alexey Dobriyan   2018-02-06  52  	void *data;
44414d82cfe0f6 Christoph Hellwig 2018-04-24  53  	unsigned int state_size;
59d8053f1e1690 David Howells     2013-04-11  54  	unsigned int low_ino;
59d8053f1e1690 David Howells     2013-04-11  55  	nlink_t nlink;
59d8053f1e1690 David Howells     2013-04-11  56  	kuid_t uid;
59d8053f1e1690 David Howells     2013-04-11  57  	kgid_t gid;
59d8053f1e1690 David Howells     2013-04-11  58  	loff_t size;
710585d4922fd3 Nicolas Dichtel   2014-12-10  59  	struct proc_dir_entry *parent;
4f1134370a29a5 Alexey Dobriyan   2018-04-10  60  	struct rb_root subdir;
710585d4922fd3 Nicolas Dichtel   2014-12-10  61  	struct rb_node subdir_node;
b4884f23331ae3 Alexey Dobriyan   2018-04-10  62  	char *name;
163cf548db8887 Alexey Dobriyan   2018-02-06  63  	umode_t mode;
d919b33dafb3e2 Alexey Dobriyan   2020-04-06  64  	u8 flags;
59d8053f1e1690 David Howells     2013-04-11  65  	u8 namelen;
24074a35c5c975 David Howells     2018-06-13  66  	char inline_name[];
3859a271a003ab Kees Cook         2016-10-28  67  } __randomize_layout;
^1da177e4c3f41 Linus Torvalds    2005-04-16  68
Kassey Li Aug. 11, 2022, 3:02 a.m. UTC | #2
hi, Vlastimil:


On 8/10/2022 5:02 PM, kernel test robot wrote:
> Hi Kassey,
> 
> Thank you for the patch! Yet something to improve:
> 
> [auto build test ERROR on v5.19]
> [also build test ERROR on next-20220810]
> [cannot apply to akpm-mm/mm-everything linus/master]
> [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/20220810-093417
> base:    3d7cb6b04c3f3115719235cc6866b10326de34cd
> config: parisc-buildonly-randconfig-r004-20220810 (https://download.01.org/0day-ci/archive/20220810/202208101628.o6qUzx50-lkp@intel.com/config)
> compiler: hppa-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/d2decd69a8d5756c1706092c805a4c8af14df471
>          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/20220810-093417
>          git checkout d2decd69a8d5756c1706092c805a4c8af14df471
>          # 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=parisc SHELL=/bin/bash
> 
> If you fix the issue, kindly add following tag where applicable
> Reported-by: kernel test robot <lkp@intel.com>
> 
> All errors (new ones prefixed by >>):
> 
>     In file included from mm/page_owner.c:16:
>>> mm/../fs/proc/internal.h:51:9: error: unknown type name 'proc_write_t'
>        51 |         proc_write_t write;
>           |         ^~~~~~~~~~~~

# CONFIG_PROC_FS is not set in some arch, so we can not directly include 
the header file.
+#include "../fs/proc/internal.h"

how about add an extern  ? or do you have other suggest  ?

> 
> 
> vim +/proc_write_t +51 mm/../fs/proc/internal.h
> 
> ^1da177e4c3f41 Linus Torvalds    2005-04-16  19
> 59d8053f1e1690 David Howells     2013-04-11  20  /*
> 59d8053f1e1690 David Howells     2013-04-11  21   * This is not completely implemented yet. The idea is to
> 59d8053f1e1690 David Howells     2013-04-11  22   * create an in-memory tree (like the actual /proc filesystem
> 59d8053f1e1690 David Howells     2013-04-11  23   * tree) of these proc_dir_entries, so that we can dynamically
> 59d8053f1e1690 David Howells     2013-04-11  24   * add new files to /proc.
> 59d8053f1e1690 David Howells     2013-04-11  25   *
> 710585d4922fd3 Nicolas Dichtel   2014-12-10  26   * parent/subdir are used for the directory structure (every /proc file has a
> 710585d4922fd3 Nicolas Dichtel   2014-12-10  27   * parent, but "subdir" is empty for all non-directory entries).
> 710585d4922fd3 Nicolas Dichtel   2014-12-10  28   * subdir_node is used to build the rb tree "subdir" of the parent.
> 59d8053f1e1690 David Howells     2013-04-11  29   */
> 59d8053f1e1690 David Howells     2013-04-11  30  struct proc_dir_entry {
> 163cf548db8887 Alexey Dobriyan   2018-02-06  31  	/*
> 163cf548db8887 Alexey Dobriyan   2018-02-06  32  	 * number of callers into module in progress;
> 163cf548db8887 Alexey Dobriyan   2018-02-06  33  	 * negative -> it's going away RSN
> 163cf548db8887 Alexey Dobriyan   2018-02-06  34  	 */
> 163cf548db8887 Alexey Dobriyan   2018-02-06  35  	atomic_t in_use;
> 9cdd83e3100651 Alexey Dobriyan   2018-04-10  36  	refcount_t refcnt;
> 163cf548db8887 Alexey Dobriyan   2018-02-06  37  	struct list_head pde_openers;	/* who did ->open, but not ->release */
> 53f63345d893df Alexey Dobriyan   2018-02-06  38  	/* protects ->pde_openers and all struct pde_opener instances */
> 53f63345d893df Alexey Dobriyan   2018-02-06  39  	spinlock_t pde_unload_lock;
> 163cf548db8887 Alexey Dobriyan   2018-02-06  40  	struct completion *pde_unload_completion;
> 163cf548db8887 Alexey Dobriyan   2018-02-06  41  	const struct inode_operations *proc_iops;
> d56c0d45f0e27f Alexey Dobriyan   2020-02-03  42  	union {
> d56c0d45f0e27f Alexey Dobriyan   2020-02-03  43  		const struct proc_ops *proc_ops;
> d56c0d45f0e27f Alexey Dobriyan   2020-02-03  44  		const struct file_operations *proc_dir_ops;
> d56c0d45f0e27f Alexey Dobriyan   2020-02-03  45  	};
> 1fde6f21d90f8b Alexey Dobriyan   2019-02-01  46  	const struct dentry_operations *proc_dops;
> 3f3942aca6da35 Christoph Hellwig 2018-05-15  47  	union {
> fddda2b7b52118 Christoph Hellwig 2018-04-13  48  		const struct seq_operations *seq_ops;
> 3f3942aca6da35 Christoph Hellwig 2018-05-15  49  		int (*single_show)(struct seq_file *, void *);
> 3f3942aca6da35 Christoph Hellwig 2018-05-15  50  	};
> 564def71765caf David Howells     2018-05-18 @51  	proc_write_t write;
> 163cf548db8887 Alexey Dobriyan   2018-02-06  52  	void *data;
> 44414d82cfe0f6 Christoph Hellwig 2018-04-24  53  	unsigned int state_size;
> 59d8053f1e1690 David Howells     2013-04-11  54  	unsigned int low_ino;
> 59d8053f1e1690 David Howells     2013-04-11  55  	nlink_t nlink;
> 59d8053f1e1690 David Howells     2013-04-11  56  	kuid_t uid;
> 59d8053f1e1690 David Howells     2013-04-11  57  	kgid_t gid;
> 59d8053f1e1690 David Howells     2013-04-11  58  	loff_t size;
> 710585d4922fd3 Nicolas Dichtel   2014-12-10  59  	struct proc_dir_entry *parent;
> 4f1134370a29a5 Alexey Dobriyan   2018-04-10  60  	struct rb_root subdir;
> 710585d4922fd3 Nicolas Dichtel   2014-12-10  61  	struct rb_node subdir_node;
> b4884f23331ae3 Alexey Dobriyan   2018-04-10  62  	char *name;
> 163cf548db8887 Alexey Dobriyan   2018-02-06  63  	umode_t mode;
> d919b33dafb3e2 Alexey Dobriyan   2020-04-06  64  	u8 flags;
> 59d8053f1e1690 David Howells     2013-04-11  65  	u8 namelen;
> 24074a35c5c975 David Howells     2018-06-13  66  	char inline_name[];
> 3859a271a003ab Kees Cook         2016-10-28  67  } __randomize_layout;
> ^1da177e4c3f41 Linus Torvalds    2005-04-16  68
>
Vlastimil Babka (SUSE) Aug. 11, 2022, 9:40 a.m. UTC | #3
On 8/11/22 05:02, Kassey Li wrote:
> hi, Vlastimil:
> 
> 
> On 8/10/2022 5:02 PM, kernel test robot wrote:
>> Hi Kassey,
>>
>> Thank you for the patch! Yet something to improve:
>>
>> [auto build test ERROR on v5.19]
>> [also build test ERROR on next-20220810]
>> [cannot apply to akpm-mm/mm-everything linus/master]
>> [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/20220810-093417
>> base:    3d7cb6b04c3f3115719235cc6866b10326de34cd
>> config: parisc-buildonly-randconfig-r004-20220810
>> (https://download.01.org/0day-ci/archive/20220810/202208101628.o6qUzx50-lkp@intel.com/config)
>> compiler: hppa-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/d2decd69a8d5756c1706092c805a4c8af14df471
>>          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/20220810-093417
>>          git checkout d2decd69a8d5756c1706092c805a4c8af14df471
>>          # 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=parisc SHELL=/bin/bash
>>
>> If you fix the issue, kindly add following tag where applicable
>> Reported-by: kernel test robot <lkp@intel.com>
>>
>> All errors (new ones prefixed by >>):
>>
>>     In file included from mm/page_owner.c:16:
>>>> mm/../fs/proc/internal.h:51:9: error: unknown type name 'proc_write_t'
>>        51 |         proc_write_t write;
>>           |         ^~~~~~~~~~~~
> 
> # CONFIG_PROC_FS is not set in some arch, so we can not directly include the
> header file.
> +#include "../fs/proc/internal.h"
> 
> how about add an extern  ? or do you have other suggest  ?

Hi, I replied to v5 after the bot reports:

Sorry, my suggestion (to reuse mem_lseek() from proc) was wrong as the
kernel test bot just showed us. mem_lseek() may be unavailable without
CONFIG_PROC_FS.
The easiest way is to add a page_owner specific lseek function back as in
the early version, but make it correct for SEEK_CUR. Thanks.
Kassey Li Aug. 15, 2022, 6:31 a.m. UTC | #4
On 8/11/2022 5:40 PM, Vlastimil Babka (SUSE) wrote:
> On 8/11/22 05:02, Kassey Li wrote:
>> hi, Vlastimil:
>>
>>
>> On 8/10/2022 5:02 PM, kernel test robot wrote:
>>> Hi Kassey,
>>>
>>> Thank you for the patch! Yet something to improve:
>>>
>>> [auto build test ERROR on v5.19]
>>> [also build test ERROR on next-20220810]
>>> [cannot apply to akpm-mm/mm-everything linus/master]
>>> [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/20220810-093417
>>> base:    3d7cb6b04c3f3115719235cc6866b10326de34cd
>>> config: parisc-buildonly-randconfig-r004-20220810
>>> (https://download.01.org/0day-ci/archive/20220810/202208101628.o6qUzx50-lkp@intel.com/config)
>>> compiler: hppa-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/d2decd69a8d5756c1706092c805a4c8af14df471
>>>           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/20220810-093417
>>>           git checkout d2decd69a8d5756c1706092c805a4c8af14df471
>>>           # 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=parisc SHELL=/bin/bash
>>>
>>> If you fix the issue, kindly add following tag where applicable
>>> Reported-by: kernel test robot <lkp@intel.com>
>>>
>>> All errors (new ones prefixed by >>):
>>>
>>>      In file included from mm/page_owner.c:16:
>>>>> mm/../fs/proc/internal.h:51:9: error: unknown type name 'proc_write_t'
>>>         51 |         proc_write_t write;
>>>            |         ^~~~~~~~~~~~
>>
>> # CONFIG_PROC_FS is not set in some arch, so we can not directly include the
>> header file.
>> +#include "../fs/proc/internal.h"
>>
>> how about add an extern  ? or do you have other suggest  ?
> 
> Hi, I replied to v5 after the bot reports:
> 
> Sorry, my suggestion (to reuse mem_lseek() from proc) was wrong as the
> kernel test bot just showed us. mem_lseek() may be unavailable without
> CONFIG_PROC_FS.
> The easiest way is to add a page_owner specific lseek function back as in
> the early version, but make it correct for SEEK_CUR. Thanks.
    OK, got this point.
>
diff mbox series

Patch

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/page_owner.c b/mm/page_owner.c
index e4c6f3f1695b..33832b5908e6 100644
--- a/mm/page_owner.c
+++ b/mm/page_owner.c
@@ -13,6 +13,7 @@ 
 #include <linux/memcontrol.h>
 #include <linux/sched/clock.h>
 
+#include "../fs/proc/internal.h"
 #include "internal.h"
 
 /*
@@ -497,8 +498,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 +564,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 +663,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)