From: Dan Williams <dan.j.williams@intel.com>
To: Toshiki Fukasawa <t-fukasawa@vx.jp.nec.com>
Cc: "linux-mm@kvack.org" <linux-mm@kvack.org>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
"akpm@linux-foundation.org" <akpm@linux-foundation.org>,
"mhocko@kernel.org" <mhocko@kernel.org>,
"adobriyan@gmail.com" <adobriyan@gmail.com>,
"hch@lst.de" <hch@lst.de>,
"longman@redhat.com" <longman@redhat.com>,
"sfr@canb.auug.org.au" <sfr@canb.auug.org.au>,
"mst@redhat.com" <mst@redhat.com>, "cai@lca.pw" <cai@lca.pw>,
Naoya Horiguchi <n-horiguchi@ah.jp.nec.com>,
Junichi Nomura <j-nomura@ce.jp.nec.com>
Subject: Re: [PATCH 2/3] mm: Introduce subsection_dev_map
Date: Fri, 8 Nov 2019 11:13:55 -0800 [thread overview]
Message-ID: <CAPcyv4h+++k1VTB2xKWHXjC4LC0N=nvDUMcdbGAsDBmwMob5dw@mail.gmail.com> (raw)
In-Reply-To: <20191108000855.25209-3-t-fukasawa@vx.jp.nec.com>
On Thu, Nov 7, 2019 at 4:15 PM Toshiki Fukasawa
<t-fukasawa@vx.jp.nec.com> wrote:
>
> Currently, there is no way to identify pfn on ZONE_DEVICE.
> Identifying pfn on system memory can be done by using a
> section-level flag. On the other hand, identifying pfn on
> ZONE_DEVICE requires a subsection-level flag since ZONE_DEVICE
> can be created in units of subsections.
>
> This patch introduces a new bitmap subsection_dev_map so that
> we can identify pfn on ZONE_DEVICE.
>
> Also, subsection_dev_map is used to prove that struct pages
> included in the subsection have been initialized since it is
> set after memmap_init_zone_device(). We can avoid accessing
> pages currently being initialized by checking subsection_dev_map.
>
> Signed-off-by: Toshiki Fukasawa <t-fukasawa@vx.jp.nec.com>
> ---
> include/linux/mmzone.h | 19 +++++++++++++++++++
> mm/memremap.c | 2 ++
> mm/sparse.c | 32 ++++++++++++++++++++++++++++++++
> 3 files changed, 53 insertions(+)
>
> diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
> index bda2028..11376c4 100644
> --- a/include/linux/mmzone.h
> +++ b/include/linux/mmzone.h
> @@ -1174,11 +1174,17 @@ static inline unsigned long section_nr_to_pfn(unsigned long sec)
>
> struct mem_section_usage {
> DECLARE_BITMAP(subsection_map, SUBSECTIONS_PER_SECTION);
> +#ifdef CONFIG_ZONE_DEVICE
> + DECLARE_BITMAP(subsection_dev_map, SUBSECTIONS_PER_SECTION);
> +#endif
Hi Toshiki,
There is currently an effort to remove the PageReserved() flag as some
code is using that to detect ZONE_DEVICE. In reviewing those patches
we realized that what many code paths want is to detect online memory.
So instead of a subsection_dev_map add a subsection_online_map. That
way pfn_to_online_page() can reliably avoid ZONE_DEVICE ranges. I
otherwise question the use case for pfn_walkers to return pages for
ZONE_DEVICE pages, I think the skip behavior when pfn_to_online_page()
== false is the right behavior.
> /* See declaration of similar field in struct zone */
> unsigned long pageblock_flags[0];
> };
>
> void subsection_map_init(unsigned long pfn, unsigned long nr_pages);
> +#ifdef CONFIG_ZONE_DEVICE
> +void subsections_mark_device(unsigned long start_pfn, unsigned long size);
> +#endif
>
> struct page;
> struct page_ext;
> @@ -1367,6 +1373,19 @@ static inline int pfn_present(unsigned long pfn)
> return present_section(__nr_to_section(pfn_to_section_nr(pfn)));
> }
>
> +static inline int pfn_zone_device(unsigned long pfn)
> +{
> +#ifdef CONFIG_ZONE_DEVICE
> + if (pfn_valid(pfn)) {
> + struct mem_section *ms = __pfn_to_section(pfn);
> + int idx = subsection_map_index(pfn);
> +
> + return test_bit(idx, ms->usage->subsection_dev_map);
> + }
> +#endif
> + return 0;
> +}
> +
> /*
> * These are _only_ used during initialisation, therefore they
> * can use __initdata ... They could have names to indicate
> diff --git a/mm/memremap.c b/mm/memremap.c
> index 03ccbdf..8a97fd4 100644
> --- a/mm/memremap.c
> +++ b/mm/memremap.c
> @@ -303,6 +303,8 @@ void *memremap_pages(struct dev_pagemap *pgmap, int nid)
> memmap_init_zone_device(&NODE_DATA(nid)->node_zones[ZONE_DEVICE],
> PHYS_PFN(res->start),
> PHYS_PFN(resource_size(res)), pgmap);
> + subsections_mark_device(PHYS_PFN(res->start),
> + PHYS_PFN(resource_size(res)));
> percpu_ref_get_many(pgmap->ref, pfn_end(pgmap) - pfn_first(pgmap));
> return __va(res->start);
>
> diff --git a/mm/sparse.c b/mm/sparse.c
> index f6891c1..a3fc9e0a 100644
> --- a/mm/sparse.c
> +++ b/mm/sparse.c
> @@ -603,6 +603,31 @@ void __init sparse_init(void)
> vmemmap_populate_print_last();
> }
>
> +#ifdef CONFIG_ZONE_DEVICE
> +void subsections_mark_device(unsigned long start_pfn, unsigned long size)
> +{
> + struct mem_section *ms;
> + unsigned long *dev_map;
> + unsigned long sec, start_sec, end_sec, pfns;
> +
> + start_sec = pfn_to_section_nr(start_pfn);
> + end_sec = pfn_to_section_nr(start_pfn + size - 1);
> + for (sec = start_sec; sec <= end_sec;
> + sec++, start_pfn += pfns, size -= pfns) {
> + pfns = min(size, PAGES_PER_SECTION
> + - (start_pfn & ~PAGE_SECTION_MASK));
> + if (WARN_ON(!valid_section_nr(sec)))
> + continue;
> + ms = __pfn_to_section(start_pfn);
> + if (!ms->usage)
> + continue;
> +
> + dev_map = &ms->usage->subsection_dev_map[0];
> + subsection_mask_set(dev_map, start_pfn, pfns);
> + }
> +}
> +#endif
> +
> #ifdef CONFIG_MEMORY_HOTPLUG
>
> /* Mark all memory sections within the pfn range as online */
> @@ -782,7 +807,14 @@ static void section_deactivate(unsigned long pfn, unsigned long nr_pages,
> memmap = sparse_decode_mem_map(ms->section_mem_map, section_nr);
> ms->section_mem_map = sparse_encode_mem_map(NULL, section_nr);
> }
> +#ifdef CONFIG_ZONE_DEVICE
> + /* deactivation of a partial section on ZONE_DEVICE */
> + if (ms->usage) {
> + unsigned long *dev_map = &ms->usage->subsection_dev_map[0];
>
> + bitmap_andnot(dev_map, dev_map, map, SUBSECTIONS_PER_SECTION);
> + }
> +#endif
> if (section_is_early && memmap)
> free_map_bootmem(memmap);
> else
> --
> 1.8.3.1
>
next prev parent reply other threads:[~2019-11-08 19:14 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-11-08 0:08 [PATCH 0/3] make pfn walker support ZONE_DEVICE Toshiki Fukasawa
2019-11-08 0:08 ` [PATCH 1/3] procfs: refactor kpage_*_read() in fs/proc/page.c Toshiki Fukasawa
2019-11-08 0:08 ` [PATCH 2/3] mm: Introduce subsection_dev_map Toshiki Fukasawa
2019-11-08 19:13 ` Dan Williams [this message]
2019-11-13 18:51 ` David Hildenbrand
2019-11-13 19:06 ` Dan Williams
2019-11-13 19:53 ` David Hildenbrand
2019-11-13 20:10 ` Dan Williams
2019-11-13 20:23 ` David Hildenbrand
2019-11-13 20:40 ` David Hildenbrand
2019-11-13 21:11 ` Dan Williams
2019-11-13 21:22 ` David Hildenbrand
2019-11-13 21:26 ` Dan Williams
2019-11-14 23:36 ` Toshiki Fukasawa
2019-11-15 0:46 ` David Hildenbrand
2019-11-15 2:57 ` Toshiki Fukasawa
2019-11-08 0:08 ` [PATCH 3/3] mm: make pfn walker support ZONE_DEVICE Toshiki Fukasawa
2019-11-09 17:08 ` kbuild test robot
2019-11-09 19:14 ` kbuild test robot
2019-11-08 9:18 ` [PATCH 0/3] " Michal Hocko
2019-11-11 8:00 ` Toshiki Fukasawa
2019-11-11 16:23 ` Dan Williams
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='CAPcyv4h+++k1VTB2xKWHXjC4LC0N=nvDUMcdbGAsDBmwMob5dw@mail.gmail.com' \
--to=dan.j.williams@intel.com \
--cc=adobriyan@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=cai@lca.pw \
--cc=hch@lst.de \
--cc=j-nomura@ce.jp.nec.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=longman@redhat.com \
--cc=mhocko@kernel.org \
--cc=mst@redhat.com \
--cc=n-horiguchi@ah.jp.nec.com \
--cc=sfr@canb.auug.org.au \
--cc=t-fukasawa@vx.jp.nec.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).