linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Vlastimil Babka <vbabka@suse.cz>
To: Kassey Li <quic_yingangl@quicinc.com>,
	akpm@linux-foundation.org, vbabka@kernel.org
Cc: minchan@kernel.org, iamjoonsoo.kim@lge.com,
	linux-kernel@vger.kernel.org, linux-mm@kvack.org
Subject: Re: [PATCH v9] mm/page_owner.c: add llseek for page_owner
Date: Thu, 18 Aug 2022 16:41:28 +0200	[thread overview]
Message-ID: <9ef46ec0-f0fc-3712-b140-53e1471dd5d2@suse.cz> (raw)
In-Reply-To: <20220818022425.31056-1-quic_yingangl@quicinc.com>

On 8/18/22 04:24, Kassey Li wrote:
> It is too slow to dump all the pages, in some usage we just want dump
> a given start pfn, for example: CMA range or a single page.
> 
> To speed up and save time, this change allows specify start pfn
> by add llseek for page_onwer.
> 
> Suggested-by: Vlastimil Babka <vbabka@suse.cz>
> Signed-off-by: Kassey Li <quic_yingangl@quicinc.com>

Acked-by: Vlastimil Babka <vbabka@suse.cz>

> ---
>  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..25720d81bc26 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;
>  }
>  
> +static 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)



      reply	other threads:[~2022-08-18 19:00 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-08-18  2:24 Kassey Li
2022-08-18 14:41 ` Vlastimil Babka [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=9ef46ec0-f0fc-3712-b140-53e1471dd5d2@suse.cz \
    --to=vbabka@suse.cz \
    --cc=akpm@linux-foundation.org \
    --cc=iamjoonsoo.kim@lge.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=minchan@kernel.org \
    --cc=quic_yingangl@quicinc.com \
    --cc=vbabka@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox