All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v4] mm/page_owner.c: add llseek for page_owner
@ 2022-08-08  7:36 Kassey Li
  2022-08-08 15:33 ` Vlastimil Babka (SUSE)
  0 siblings, 1 reply; 3+ messages in thread
From: Kassey Li @ 2022-08-08  7:36 UTC (permalink / raw)
  To: akpm, vbabka; +Cc: Kassey Li, minchan, 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 (SUSE) <vbabka@kernel.org>
Signed-off-by: Kassey Li <quic_yingangl@quicinc.com>
---
 mm/page_owner.c | 20 ++++++++++++++++++--
 1 file changed, 18 insertions(+), 2 deletions(-)

diff --git a/mm/page_owner.c b/mm/page_owner.c
index e4c6f3f1695b..231b1877af99 100644
--- a/mm/page_owner.c
+++ b/mm/page_owner.c
@@ -497,8 +497,8 @@ read_page_owner(struct file *file, char __user *buf, size_t count, loff_t *ppos)
 		return -EINVAL;
 
 	page = NULL;
-	pfn = min_low_pfn + *ppos;
 
+	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 +561,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 +570,21 @@ read_page_owner(struct file *file, char __user *buf, size_t count, loff_t *ppos)
 	return 0;
 }
 
+static loff_t llseek_page_owner(struct file *file, loff_t offset, int whence)
+{
+	loff_t retval = 0;
+	switch (whence) {
+		case SEEK_CUR:
+		case SEEK_SET:
+			file->f_pos = offset;
+			break;
+		default:
+			retval = -ENXIO;
+	}
+
+	return retval;
+}
+
 static void init_pages_in_zone(pg_data_t *pgdat, struct zone *zone)
 {
 	unsigned long pfn = zone->zone_start_pfn;
@@ -660,6 +675,7 @@ static void init_early_allocated_pages(void)
 
 static const struct file_operations proc_page_owner_operations = {
 	.read		= read_page_owner,
+	.llseek 	= llseek_page_owner,
 };
 
 static int __init pageowner_init(void)
-- 
2.17.1


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

* Re: [PATCH v4] mm/page_owner.c: add llseek for page_owner
  2022-08-08  7:36 [PATCH v4] mm/page_owner.c: add llseek for page_owner Kassey Li
@ 2022-08-08 15:33 ` Vlastimil Babka (SUSE)
  2022-08-09  2:48   ` Kassey Li
  0 siblings, 1 reply; 3+ messages in thread
From: Vlastimil Babka (SUSE) @ 2022-08-08 15:33 UTC (permalink / raw)
  To: Kassey Li, akpm; +Cc: minchan, iamjoonsoo.kim, linux-kernel, linux-mm

On 8/8/22 09:36, 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 (SUSE) <vbabka@kernel.org>

Thanks, but please change it to Vlastimil Babka <vbabka@suse.cz>
It was some mistake between me and thunderbird that it was sent from @k.o.

> Signed-off-by: Kassey Li <quic_yingangl@quicinc.com>
> ---
>  mm/page_owner.c | 20 ++++++++++++++++++--
>  1 file changed, 18 insertions(+), 2 deletions(-)
> 
> diff --git a/mm/page_owner.c b/mm/page_owner.c
> index e4c6f3f1695b..231b1877af99 100644
> --- a/mm/page_owner.c
> +++ b/mm/page_owner.c
> @@ -497,8 +497,8 @@ read_page_owner(struct file *file, char __user *buf, size_t count, loff_t *ppos)
>  		return -EINVAL;
>  
>  	page = NULL;
> -	pfn = min_low_pfn + *ppos;
>  
> +	pfn = *ppos;

Maybe we could still optimize the typical case a bit such that when it's 0,
we skip to min_low_pfn immediately.

>  	/* 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 +561,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 +570,21 @@ read_page_owner(struct file *file, char __user *buf, size_t count, loff_t *ppos)
>  	return 0;
>  }
>  
> +static loff_t llseek_page_owner(struct file *file, loff_t offset, int whence)
> +{
> +	loff_t retval = 0;
> +	switch (whence) {
> +		case SEEK_CUR:

It's not correct for SEEK_CUR to behave like this, no?
Can we perhaps reuse the existing mem_lseek() ?

Also we should update Documentation/mm/page_owner.rst to document the lseek
support and that it works with a pfn.

Thanks!

> +		case SEEK_SET:
> +			file->f_pos = offset;
> +			break;
> +		default:
> +			retval = -ENXIO;
> +	}
> +
> +	return retval;
> +}
> +
>  static void init_pages_in_zone(pg_data_t *pgdat, struct zone *zone)
>  {
>  	unsigned long pfn = zone->zone_start_pfn;
> @@ -660,6 +675,7 @@ static void init_early_allocated_pages(void)
>  
>  static const struct file_operations proc_page_owner_operations = {
>  	.read		= read_page_owner,
> +	.llseek 	= llseek_page_owner,
>  };
>  
>  static int __init pageowner_init(void)


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

* Re: [PATCH v4] mm/page_owner.c: add llseek for page_owner
  2022-08-08 15:33 ` Vlastimil Babka (SUSE)
@ 2022-08-09  2:48   ` Kassey Li
  0 siblings, 0 replies; 3+ messages in thread
From: Kassey Li @ 2022-08-09  2:48 UTC (permalink / raw)
  To: Vlastimil Babka (SUSE), akpm
  Cc: minchan, iamjoonsoo.kim, linux-kernel, linux-mm



On 8/8/2022 11:33 PM, Vlastimil Babka (SUSE) wrote:
> On 8/8/22 09:36, 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 (SUSE) <vbabka@kernel.org>
> 
> Thanks, but please change it to Vlastimil Babka <vbabka@suse.cz>
> It was some mistake between me and thunderbird that it was sent from @k.o.
   Ok, will change it.
> 
>> Signed-off-by: Kassey Li <quic_yingangl@quicinc.com>
>> ---
>>   mm/page_owner.c | 20 ++++++++++++++++++--
>>   1 file changed, 18 insertions(+), 2 deletions(-)
>>
>> diff --git a/mm/page_owner.c b/mm/page_owner.c
>> index e4c6f3f1695b..231b1877af99 100644
>> --- a/mm/page_owner.c
>> +++ b/mm/page_owner.c
>> @@ -497,8 +497,8 @@ read_page_owner(struct file *file, char __user *buf, size_t count, loff_t *ppos)
>>   		return -EINVAL;
>>   
>>   	page = NULL;
>> -	pfn = min_low_pfn + *ppos;
>>   
>> +	pfn = *ppos;
> 
> Maybe we could still optimize the typical case a bit such that when it's 0,
> we skip to min_low_pfn immediately.
> 
>>   	/* 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 +561,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 +570,21 @@ read_page_owner(struct file *file, char __user *buf, size_t count, loff_t *ppos)
>>   	return 0;
>>   }
>>   
>> +static loff_t llseek_page_owner(struct file *file, loff_t offset, int whence)
>> +{
>> +	loff_t retval = 0;
>> +	switch (whence) {
>> +		case SEEK_CUR:
> 
> It's not correct for SEEK_CUR to behave like this, no?
> Can we perhaps reuse the existing mem_lseek() ?  
   agree.
> 
> Also we should update Documentation/mm/page_owner.rst to document the lseek
> support and that it works with a pfn.
   will do this in v5 patch set.
> 
> Thanks!
> 
>> +		case SEEK_SET:
>> +			file->f_pos = offset;
>> +			break;
>> +		default:
>> +			retval = -ENXIO;
>> +	}
>> +
>> +	return retval;
>> +}
>> +
>>   static void init_pages_in_zone(pg_data_t *pgdat, struct zone *zone)
>>   {
>>   	unsigned long pfn = zone->zone_start_pfn;
>> @@ -660,6 +675,7 @@ static void init_early_allocated_pages(void)
>>   
>>   static const struct file_operations proc_page_owner_operations = {
>>   	.read		= read_page_owner,
>> +	.llseek 	= llseek_page_owner,
>>   };
>>   
>>   static int __init pageowner_init(void)
> 

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

end of thread, other threads:[~2022-08-09  2:48 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-08-08  7:36 [PATCH v4] mm/page_owner.c: add llseek for page_owner Kassey Li
2022-08-08 15:33 ` Vlastimil Babka (SUSE)
2022-08-09  2:48   ` Kassey Li

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.