2021-04-06 20:29:32

by Oscar Salvador

[permalink] [raw]
Subject: [PATCH v6 3/8] mm,memory_hotplug: Factor out adjusting present pages into adjust_present_page_count()

From: David Hildenbrand <[email protected]>

Let's have a single place (inspired by adjust_managed_page_count()) where
we adjust present pages, to prepare for additional bookkeeping.
In contrast to adjust_managed_page_count(), only memory onlining/offlining
is allowed to modify the number of present pages.

Signed-off-by: David Hildenbrand <[email protected]>
Signed-off-by: Oscar Salvador <[email protected]>
Reviewed-by: Oscar Salvador <[email protected]>
---
mm/memory_hotplug.c | 22 ++++++++++++----------
1 file changed, 12 insertions(+), 10 deletions(-)

diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c
index 5fe3e3942b19..7411f6b5287d 100644
--- a/mm/memory_hotplug.c
+++ b/mm/memory_hotplug.c
@@ -829,6 +829,16 @@ struct zone * zone_for_pfn_range(int online_type, int nid, unsigned start_pfn,
return default_zone_for_pfn(nid, start_pfn, nr_pages);
}

+static void adjust_present_page_count(struct zone *zone, long nr_pages)
+{
+ unsigned long flags;
+
+ zone->present_pages += nr_pages;
+ pgdat_resize_lock(zone->zone_pgdat, &flags);
+ zone->zone_pgdat->node_present_pages += nr_pages;
+ pgdat_resize_unlock(zone->zone_pgdat, &flags);
+}
+
int __ref online_pages(unsigned long pfn, unsigned long nr_pages,
int online_type, int nid)
{
@@ -881,11 +891,7 @@ int __ref online_pages(unsigned long pfn, unsigned long nr_pages,
}

online_pages_range(pfn, nr_pages);
- zone->present_pages += nr_pages;
-
- pgdat_resize_lock(zone->zone_pgdat, &flags);
- zone->zone_pgdat->node_present_pages += nr_pages;
- pgdat_resize_unlock(zone->zone_pgdat, &flags);
+ adjust_present_page_count(zone, nr_pages);

node_states_set_node(nid, &arg);
if (need_zonelists_rebuild)
@@ -1699,11 +1705,7 @@ int __ref offline_pages(unsigned long start_pfn, unsigned long nr_pages)

/* removal success */
adjust_managed_page_count(pfn_to_page(start_pfn), -nr_pages);
- zone->present_pages -= nr_pages;
-
- pgdat_resize_lock(zone->zone_pgdat, &flags);
- zone->zone_pgdat->node_present_pages -= nr_pages;
- pgdat_resize_unlock(zone->zone_pgdat, &flags);
+ adjust_present_page_count(zone, -nr_pages);

init_per_zone_wmark_min();

--
2.16.3


2021-04-07 08:55:50

by David Hildenbrand

[permalink] [raw]
Subject: Re: [PATCH v6 3/8] mm,memory_hotplug: Factor out adjusting present pages into adjust_present_page_count()

On 06.04.21 13:11, Oscar Salvador wrote:
> From: David Hildenbrand <[email protected]>
>
> Let's have a single place (inspired by adjust_managed_page_count()) where
> we adjust present pages, to prepare for additional bookkeeping.

Maybe in the context of this series, remove the "additional bookkeeping"
part.

> In contrast to adjust_managed_page_count(), only memory onlining/offlining
> is allowed to modify the number of present pages.
>
> Signed-off-by: David Hildenbrand <[email protected]>
> Signed-off-by: Oscar Salvador <[email protected]>
> Reviewed-by: Oscar Salvador <[email protected]>
> ---
> mm/memory_hotplug.c | 22 ++++++++++++----------
> 1 file changed, 12 insertions(+), 10 deletions(-)
>
> diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c
> index 5fe3e3942b19..7411f6b5287d 100644
> --- a/mm/memory_hotplug.c
> +++ b/mm/memory_hotplug.c
> @@ -829,6 +829,16 @@ struct zone * zone_for_pfn_range(int online_type, int nid, unsigned start_pfn,
> return default_zone_for_pfn(nid, start_pfn, nr_pages);
> }
>
> +static void adjust_present_page_count(struct zone *zone, long nr_pages)
> +{
> + unsigned long flags;
> +
> + zone->present_pages += nr_pages;
> + pgdat_resize_lock(zone->zone_pgdat, &flags);
> + zone->zone_pgdat->node_present_pages += nr_pages;
> + pgdat_resize_unlock(zone->zone_pgdat, &flags);
> +}
> +
> int __ref online_pages(unsigned long pfn, unsigned long nr_pages,
> int online_type, int nid)
> {
> @@ -881,11 +891,7 @@ int __ref online_pages(unsigned long pfn, unsigned long nr_pages,
> }
>
> online_pages_range(pfn, nr_pages);
> - zone->present_pages += nr_pages;
> -
> - pgdat_resize_lock(zone->zone_pgdat, &flags);
> - zone->zone_pgdat->node_present_pages += nr_pages;
> - pgdat_resize_unlock(zone->zone_pgdat, &flags);
> + adjust_present_page_count(zone, nr_pages);
>
> node_states_set_node(nid, &arg);
> if (need_zonelists_rebuild)
> @@ -1699,11 +1705,7 @@ int __ref offline_pages(unsigned long start_pfn, unsigned long nr_pages)
>
> /* removal success */
> adjust_managed_page_count(pfn_to_page(start_pfn), -nr_pages);
> - zone->present_pages -= nr_pages;
> -
> - pgdat_resize_lock(zone->zone_pgdat, &flags);
> - zone->zone_pgdat->node_present_pages -= nr_pages;
> - pgdat_resize_unlock(zone->zone_pgdat, &flags);
> + adjust_present_page_count(zone, -nr_pages);
>
> init_per_zone_wmark_min();
>
>


--
Thanks,

David / dhildenb

2021-04-07 22:31:01

by Oscar Salvador

[permalink] [raw]
Subject: Re: [PATCH v6 3/8] mm,memory_hotplug: Factor out adjusting present pages into adjust_present_page_count()

On Tue, Apr 06, 2021 at 05:33:46PM +0200, David Hildenbrand wrote:
> On 06.04.21 13:11, Oscar Salvador wrote:
> > From: David Hildenbrand <[email protected]>
> >
> > Let's have a single place (inspired by adjust_managed_page_count()) where
> > we adjust present pages, to prepare for additional bookkeeping.
>
> Maybe in the context of this series, remove the "additional bookkeeping"
> part.

Definitely, it was a slip.

Thanks

--
Oscar Salvador
SUSE L3