linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: David Hildenbrand <david@redhat.com>
To: sxwjean@me.com, akpm@linux-foundation.org, mhocko@suse.com,
	dan.j.williams@intel.com, osalvador@suse.de,
	naoya.horiguchi@nec.com, thunder.leizhen@huawei.com
Cc: linux-mm@kvack.org, linux-fsdevel@vger.kernel.org,
	linux-kernel@vger.kernel.org, Xiongwei Song <sxwjean@gmail.com>
Subject: Re: [PATCH 1/2] mm/memremap.c: Add pfn_to_devmap_page() to get page in ZONE_DEVICE
Date: Mon, 10 Jan 2022 09:16:20 +0100	[thread overview]
Message-ID: <93865d07-1cc6-8cad-c14a-7fcded63e954@redhat.com> (raw)
In-Reply-To: <20220109130515.140092-2-sxwjean@me.com>

On 09.01.22 14:05, sxwjean@me.com wrote:
> From: Xiongwei Song <sxwjean@gmail.com>
> 
> when requesting page information by /proc/kpage*, the pages in ZONE_DEVICE
> were missed. We need a function to help on this.
> 
> The pfn_to_devmap_page() function like pfn_to_online_page(), but only
> concerns the pages in ZONE_DEVICE.
> 
> Signed-off-by: Xiongwei Song <sxwjean@gmail.com>
> ---
>  include/linux/memremap.h |  8 ++++++++
>  mm/memremap.c            | 42 ++++++++++++++++++++++++++++++++++++++++
>  2 files changed, 50 insertions(+)
> 
> diff --git a/include/linux/memremap.h b/include/linux/memremap.h
> index c0e9d35889e8..621723e9c4a5 100644
> --- a/include/linux/memremap.h
> +++ b/include/linux/memremap.h
> @@ -137,6 +137,8 @@ void *devm_memremap_pages(struct device *dev, struct dev_pagemap *pgmap);
>  void devm_memunmap_pages(struct device *dev, struct dev_pagemap *pgmap);
>  struct dev_pagemap *get_dev_pagemap(unsigned long pfn,
>  		struct dev_pagemap *pgmap);
> +struct page *pfn_to_devmap_page(unsigned long pfn,
> +		struct dev_pagemap **pgmap);
>  bool pgmap_pfn_valid(struct dev_pagemap *pgmap, unsigned long pfn);
>  
>  unsigned long vmem_altmap_offset(struct vmem_altmap *altmap);
> @@ -166,6 +168,12 @@ static inline struct dev_pagemap *get_dev_pagemap(unsigned long pfn,
>  	return NULL;
>  }
>  
> +static inline struct page *pfn_to_devmap_page(unsigned long pfn,
> +		struct dev_pagemap **pgmap)
> +{
> +	return NULL;
> +}
> +
>  static inline bool pgmap_pfn_valid(struct dev_pagemap *pgmap, unsigned long pfn)
>  {
>  	return false;
> diff --git a/mm/memremap.c b/mm/memremap.c
> index 5a66a71ab591..072dbe6ab81c 100644
> --- a/mm/memremap.c
> +++ b/mm/memremap.c
> @@ -494,6 +494,48 @@ struct dev_pagemap *get_dev_pagemap(unsigned long pfn,
>  }
>  EXPORT_SYMBOL_GPL(get_dev_pagemap);
>  
> +/**
> + * pfn_to_devmap_page - get page pointer which belongs to dev_pagemap by @pfn
> + * @pfn: page frame number to lookup page_map
> + * @pgmap: to save pgmap address which is for putting reference
> + *
> + * If @pgmap is non-NULL, then pfn is on ZONE_DEVICE and return page pointer.
> + */
> +struct page *pfn_to_devmap_page(unsigned long pfn, struct dev_pagemap **pgmap)
> +{
> +	unsigned long nr = pfn_to_section_nr(pfn);
> +	struct mem_section *ms;
> +	struct page *page = NULL;
> +
> +	if (nr >= NR_MEM_SECTIONS)
> +		return NULL;
> +
> +	if (IS_ENABLED(CONFIG_HAVE_ARCH_PFN_VALID) && !pfn_valid(pfn))
> +		return NULL;
> +
> +	ms = __nr_to_section(nr);
> +	if (!valid_section(ms))
> +		return NULL;
> +	if (!pfn_section_valid(ms, pfn))
> +		return NULL;
> +
> +	/*
> +	 * Two types of sections may include valid pfns:
> +	 * - The pfns of section belong to ZONE_DEVICE and ZONE_{NORMAL,MOVABLE}
> +	 *   at the same time.
> +	 * - All pfns in one section are offline but valid.
> +	 */
> +	if (!online_device_section(ms) && online_section(ms))
> +		return NULL;
> +
> +	*pgmap = get_dev_pagemap(pfn, NULL);
> +	if (*pgmap)
> +		page = pfn_to_page(pfn);
> +
> +	return page;
> +}
> +EXPORT_SYMBOL_GPL(pfn_to_devmap_page);

Is this complexity really required?

Take a look at mm/memory-failure.c

p = pfn_to_online_page(pfn);
if (!p) {
	if (pfn_valid(pfn)) {
		pgmap = get_dev_pagemap(pfn, NULL);
		if (pgmap)
			// success
		// error
	}
	// error
}


Also, why do we need the export?

-- 
Thanks,

David / dhildenb


  reply	other threads:[~2022-01-10  8:16 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-09 13:05 [PATCH 0/2] Add support for getting page info of ZONE_DEVICE by /proc/kpage* sxwjean
2022-01-09 13:05 ` [PATCH 1/2] mm/memremap.c: Add pfn_to_devmap_page() to get page in ZONE_DEVICE sxwjean
2022-01-10  8:16   ` David Hildenbrand [this message]
2022-01-10  9:30     ` Xiongwei Song
2022-01-09 13:05 ` [PATCH 2/2] proc: Add getting pages info of ZONE_DEVICE support sxwjean

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=93865d07-1cc6-8cad-c14a-7fcded63e954@redhat.com \
    --to=david@redhat.com \
    --cc=akpm@linux-foundation.org \
    --cc=dan.j.williams@intel.com \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=mhocko@suse.com \
    --cc=naoya.horiguchi@nec.com \
    --cc=osalvador@suse.de \
    --cc=sxwjean@gmail.com \
    --cc=sxwjean@me.com \
    --cc=thunder.leizhen@huawei.com \
    /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;
as well as URLs for NNTP newsgroup(s).