2022-08-09 02:52:20

by Kassey Li

[permalink] [raw]
Subject: [PATCH v5] mm/page_owner.c: add llseek for page_owner

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 <[email protected]>
Signed-off-by: Kassey Li <[email protected]>
---
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


2022-08-09 09:44:19

by Vlastimil Babka (SUSE)

[permalink] [raw]
Subject: Re: [PATCH v5] mm/page_owner.c: add llseek for page_owner

On 8/9/22 04:47, Kassey Li wrote:
> 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 <[email protected]>
> Signed-off-by: Kassey Li <[email protected]>
> ---
> 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:

This should say where it's defined, not used from, and that's
fs/proc/base.c. But it's already declared in fs/proc/internal.h so maybe
page_owner.c could just include that header (although it's a bit meh).

> + */
> +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;

missing space before '='

> + 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)

2022-08-10 01:51:26

by kernel test robot

[permalink] [raw]
Subject: Re: [PATCH v5] mm/page_owner.c: add llseek for page_owner

Hi Kassey,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on v5.19]
[also build test ERROR on next-20220809]
[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/20220809-104956
base: 3d7cb6b04c3f3115719235cc6866b10326de34cd
config: arm-buildonly-randconfig-r003-20220808 (https://download.01.org/0day-ci/archive/20220810/[email protected]/config)
compiler: arm-linux-gnueabi-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/2c71629233aa8742e2a6ce7341287c02bc1aa9fd
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/20220809-104956
git checkout 2c71629233aa8742e2a6ce7341287c02bc1aa9fd
# 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=arm SHELL=/bin/bash

If you fix the issue, kindly add following tag where applicable
Reported-by: kernel test robot <[email protected]>

All errors (new ones prefixed by >>):

arm-linux-gnueabi-ld: mm/page_owner.o: in function `.LANCHOR4':
>> page_owner.c:(.rodata+0x4): undefined reference to `mem_lseek'

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

2022-08-10 02:32:12

by Kassey Li

[permalink] [raw]
Subject: Re: [PATCH v5] mm/page_owner.c: add llseek for page_owner



On 8/9/2022 5:30 PM, Vlastimil Babka (SUSE) wrote:
> On 8/9/22 04:47, Kassey Li wrote:
>> 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 <[email protected]>
>> Signed-off-by: Kassey Li <[email protected]>
>> ---
>> 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:
>
> This should say where it's defined, not used from, and that's
> fs/proc/base.c. But it's already declared in fs/proc/internal.h so maybe
> page_owner.c could just include that header (although it's a bit meh).
ok, let's do it.
>
>> + */
>> +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;
>
> missing space before '='

my bad, for v6

./scripts/checkpatch.pl
v6-0001-mm-page_owner.c-add-llseek-for-page_owner.patch
total: 0 errors, 0 warnings, 46 lines checked

v6-0001-mm-page_owner.c-add-llseek-for-page_owner.patch has no obvious
style problems and is ready for submission.
>
>> + 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)
>

2022-08-10 09:17:35

by Vlastimil Babka

[permalink] [raw]
Subject: Re: [PATCH v5] mm/page_owner.c: add llseek for page_owner

On 8/10/22 03:33, Kassey Li wrote:
>
>
> On 8/9/2022 5:30 PM, Vlastimil Babka (SUSE) wrote:
>> On 8/9/22 04:47, Kassey Li wrote:
>>> 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 <[email protected]>
>>> Signed-off-by: Kassey Li <[email protected]>
>>> ---
>>> 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:
>>
>> This should say where it's defined, not used from, and that's
>> fs/proc/base.c. But it's already declared in fs/proc/internal.h so maybe
>> page_owner.c could just include that header (although it's a bit meh).
> ok, let's do it.

Sorry, my suggestion was wrong as the kernel test bot just showed us.
mem_lseek() may be unavailable without CONFIG_PROC_FS.
The easiest way is you add a page_owner specific one back, but make it
correct for SEEK_CUR. Thanks.

>>
>>> + */
>>> +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;
>>
>> missing space before '='
>
> my bad, for v6
>
> ./scripts/checkpatch.pl
> v6-0001-mm-page_owner.c-add-llseek-for-page_owner.patch
> total: 0 errors, 0 warnings, 46 lines checked
>
> v6-0001-mm-page_owner.c-add-llseek-for-page_owner.patch has no obvious
> style problems and is ready for submission.
>>
>>> + 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)
>>