Re: [PATCH v2 3/4] mm/memory_hotplug: Make register_mem_sect_under_node a cb of walk_memory_range

2018-08-16 Thread Pasha Tatashin
On 18-06-22 13:18:38, osalva...@techadventures.net wrote:
> From: Oscar Salvador 
> 
> link_mem_sections() and walk_memory_range() share most of the code,
> so we can use convert link_mem_sections() into a dummy function that calls
> walk_memory_range() with a callback to register_mem_sect_under_node().
> 
> This patch converts register_mem_sect_under_node() in order to
> match a walk_memory_range's callback, getting rid of the
> check_nid argument and checking instead if the system is still
> boothing, since we only have to check for the nid if the system
> is in such state.
> 
> Signed-off-by: Oscar Salvador 
> Suggested-by: Pavel Tatashin 

Reviewed-by: Pavel Tatashin 

Re: [PATCH v2 3/4] mm/memory_hotplug: Make register_mem_sect_under_node a cb of walk_memory_range

2018-08-16 Thread Pasha Tatashin
On 18-06-22 13:18:38, osalva...@techadventures.net wrote:
> From: Oscar Salvador 
> 
> link_mem_sections() and walk_memory_range() share most of the code,
> so we can use convert link_mem_sections() into a dummy function that calls
> walk_memory_range() with a callback to register_mem_sect_under_node().
> 
> This patch converts register_mem_sect_under_node() in order to
> match a walk_memory_range's callback, getting rid of the
> check_nid argument and checking instead if the system is still
> boothing, since we only have to check for the nid if the system
> is in such state.
> 
> Signed-off-by: Oscar Salvador 
> Suggested-by: Pavel Tatashin 

Reviewed-by: Pavel Tatashin 

Re: [PATCH v2 3/4] mm/memory_hotplug: Make register_mem_sect_under_node a cb of walk_memory_range

2018-08-16 Thread Oscar Salvador
On Wed, Aug 15, 2018 at 03:21:35PM -0700, Andrew Morton wrote:
> On Fri, 22 Jun 2018 13:18:38 +0200 osalva...@techadventures.net wrote:
> 
> > From: Oscar Salvador 
> > 
> > link_mem_sections() and walk_memory_range() share most of the code,
> > so we can use convert link_mem_sections() into a dummy function that calls
> > walk_memory_range() with a callback to register_mem_sect_under_node().
> > 
> > This patch converts register_mem_sect_under_node() in order to
> > match a walk_memory_range's callback, getting rid of the
> > check_nid argument and checking instead if the system is still
> > boothing, since we only have to check for the nid if the system
> > is in such state.
> > 
> > Signed-off-by: Oscar Salvador 
> > Suggested-by: Pavel Tatashin 
> 
> We have two tested-by's bu no reviewers or ackers?
 
Pavel, would you be so kind to review this patch?
It is the only patch from the patchset which did not get a 
review.

Thanks!
-- 
Oscar Salvador
SUSE L3


Re: [PATCH v2 3/4] mm/memory_hotplug: Make register_mem_sect_under_node a cb of walk_memory_range

2018-08-16 Thread Oscar Salvador
On Wed, Aug 15, 2018 at 03:21:35PM -0700, Andrew Morton wrote:
> On Fri, 22 Jun 2018 13:18:38 +0200 osalva...@techadventures.net wrote:
> 
> > From: Oscar Salvador 
> > 
> > link_mem_sections() and walk_memory_range() share most of the code,
> > so we can use convert link_mem_sections() into a dummy function that calls
> > walk_memory_range() with a callback to register_mem_sect_under_node().
> > 
> > This patch converts register_mem_sect_under_node() in order to
> > match a walk_memory_range's callback, getting rid of the
> > check_nid argument and checking instead if the system is still
> > boothing, since we only have to check for the nid if the system
> > is in such state.
> > 
> > Signed-off-by: Oscar Salvador 
> > Suggested-by: Pavel Tatashin 
> 
> We have two tested-by's bu no reviewers or ackers?
 
Pavel, would you be so kind to review this patch?
It is the only patch from the patchset which did not get a 
review.

Thanks!
-- 
Oscar Salvador
SUSE L3


Re: [PATCH v2 3/4] mm/memory_hotplug: Make register_mem_sect_under_node a cb of walk_memory_range

2018-08-15 Thread Andrew Morton
On Fri, 22 Jun 2018 13:18:38 +0200 osalva...@techadventures.net wrote:

> From: Oscar Salvador 
> 
> link_mem_sections() and walk_memory_range() share most of the code,
> so we can use convert link_mem_sections() into a dummy function that calls
> walk_memory_range() with a callback to register_mem_sect_under_node().
> 
> This patch converts register_mem_sect_under_node() in order to
> match a walk_memory_range's callback, getting rid of the
> check_nid argument and checking instead if the system is still
> boothing, since we only have to check for the nid if the system
> is in such state.
> 
> Signed-off-by: Oscar Salvador 
> Suggested-by: Pavel Tatashin 

We have two tested-by's bu no reviewers or ackers?

From: Oscar Salvador 
Subject: mm/memory_hotplug.c: make register_mem_sect_under_node() a callback of 
walk_memory_range()

link_mem_sections() and walk_memory_range() share most of the code, so we
can use convert link_mem_sections() into a dummy function that calls
walk_memory_range() with a callback to register_mem_sect_under_node().

This patch converts register_mem_sect_under_node() in order to match a
walk_memory_range's callback, getting rid of the check_nid argument and
checking instead if the system is still boothing, since we only have to
check for the nid if the system is in such state.

Link: 
http://lkml.kernel.org/r/20180622111839.10071-4-osalva...@techadventures.net
Signed-off-by: Oscar Salvador 
Suggested-by: Pavel Tatashin 
Tested-by: Reza Arbab 
Tested-by: Jonathan Cameron 
Cc: Michal Hocko 
Cc: Vlastimil Babka 
Signed-off-by: Andrew Morton 
---

 drivers/base/node.c  |   44 +
 include/linux/node.h |   12 ++-
 mm/memory_hotplug.c  |5 
 3 files changed, 14 insertions(+), 47 deletions(-)

--- 
a/drivers/base/node.c~mm-memory_hotplug-make-register_mem_sect_under_node-a-cb-of-walk_memory_range
+++ a/drivers/base/node.c
@@ -399,10 +399,9 @@ static int __ref get_nid_for_pfn(unsigne
 }
 
 /* register memory section under specified node if it spans that node */
-int register_mem_sect_under_node(struct memory_block *mem_blk, int nid,
-bool check_nid)
+int register_mem_sect_under_node(struct memory_block *mem_blk, void *arg)
 {
-   int ret;
+   int ret, nid = *(int *)arg;
unsigned long pfn, sect_start_pfn, sect_end_pfn;
 
if (!mem_blk)
@@ -433,7 +432,7 @@ int register_mem_sect_under_node(struct
 * case, during hotplug we know that all pages in the memory
 * block belong to the same node.
 */
-   if (check_nid) {
+   if (system_state == SYSTEM_BOOTING) {
page_nid = get_nid_for_pfn(pfn);
if (page_nid < 0)
continue;
@@ -490,41 +489,10 @@ int unregister_mem_sect_under_nodes(stru
return 0;
 }
 
-int link_mem_sections(int nid, unsigned long start_pfn, unsigned long nr_pages,
- bool check_nid)
+int link_mem_sections(int nid, unsigned long start_pfn, unsigned long end_pfn)
 {
-   unsigned long end_pfn = start_pfn + nr_pages;
-   unsigned long pfn;
-   struct memory_block *mem_blk = NULL;
-   int err = 0;
-
-   for (pfn = start_pfn; pfn < end_pfn; pfn += PAGES_PER_SECTION) {
-   unsigned long section_nr = pfn_to_section_nr(pfn);
-   struct mem_section *mem_sect;
-   int ret;
-
-   if (!present_section_nr(section_nr))
-   continue;
-   mem_sect = __nr_to_section(section_nr);
-
-   /* same memblock ? */
-   if (mem_blk)
-   if ((section_nr >= mem_blk->start_section_nr) &&
-   (section_nr <= mem_blk->end_section_nr))
-   continue;
-
-   mem_blk = find_memory_block_hinted(mem_sect, mem_blk);
-
-   ret = register_mem_sect_under_node(mem_blk, nid, check_nid);
-   if (!err)
-   err = ret;
-
-   /* discard ref obtained in find_memory_block() */
-   }
-
-   if (mem_blk)
-   kobject_put(_blk->dev.kobj);
-   return err;
+   return walk_memory_range(start_pfn, end_pfn, (void *),
+   register_mem_sect_under_node);
 }
 
 #ifdef CONFIG_HUGETLBFS
--- 
a/include/linux/node.h~mm-memory_hotplug-make-register_mem_sect_under_node-a-cb-of-walk_memory_range
+++ a/include/linux/node.h
@@ -33,10 +33,10 @@ typedef  void (*node_registration_func_t
 
 #if defined(CONFIG_MEMORY_HOTPLUG_SPARSE) && defined(CONFIG_NUMA)
 extern int link_mem_sections(int nid, unsigned long start_pfn,
-unsigned long nr_pages, bool check_nid);
+unsigned long end_pfn);
 #else
 static inline int link_mem_sections(int nid, unsigned long start_pfn,
-   unsigned 

Re: [PATCH v2 3/4] mm/memory_hotplug: Make register_mem_sect_under_node a cb of walk_memory_range

2018-08-15 Thread Andrew Morton
On Fri, 22 Jun 2018 13:18:38 +0200 osalva...@techadventures.net wrote:

> From: Oscar Salvador 
> 
> link_mem_sections() and walk_memory_range() share most of the code,
> so we can use convert link_mem_sections() into a dummy function that calls
> walk_memory_range() with a callback to register_mem_sect_under_node().
> 
> This patch converts register_mem_sect_under_node() in order to
> match a walk_memory_range's callback, getting rid of the
> check_nid argument and checking instead if the system is still
> boothing, since we only have to check for the nid if the system
> is in such state.
> 
> Signed-off-by: Oscar Salvador 
> Suggested-by: Pavel Tatashin 

We have two tested-by's bu no reviewers or ackers?

From: Oscar Salvador 
Subject: mm/memory_hotplug.c: make register_mem_sect_under_node() a callback of 
walk_memory_range()

link_mem_sections() and walk_memory_range() share most of the code, so we
can use convert link_mem_sections() into a dummy function that calls
walk_memory_range() with a callback to register_mem_sect_under_node().

This patch converts register_mem_sect_under_node() in order to match a
walk_memory_range's callback, getting rid of the check_nid argument and
checking instead if the system is still boothing, since we only have to
check for the nid if the system is in such state.

Link: 
http://lkml.kernel.org/r/20180622111839.10071-4-osalva...@techadventures.net
Signed-off-by: Oscar Salvador 
Suggested-by: Pavel Tatashin 
Tested-by: Reza Arbab 
Tested-by: Jonathan Cameron 
Cc: Michal Hocko 
Cc: Vlastimil Babka 
Signed-off-by: Andrew Morton 
---

 drivers/base/node.c  |   44 +
 include/linux/node.h |   12 ++-
 mm/memory_hotplug.c  |5 
 3 files changed, 14 insertions(+), 47 deletions(-)

--- 
a/drivers/base/node.c~mm-memory_hotplug-make-register_mem_sect_under_node-a-cb-of-walk_memory_range
+++ a/drivers/base/node.c
@@ -399,10 +399,9 @@ static int __ref get_nid_for_pfn(unsigne
 }
 
 /* register memory section under specified node if it spans that node */
-int register_mem_sect_under_node(struct memory_block *mem_blk, int nid,
-bool check_nid)
+int register_mem_sect_under_node(struct memory_block *mem_blk, void *arg)
 {
-   int ret;
+   int ret, nid = *(int *)arg;
unsigned long pfn, sect_start_pfn, sect_end_pfn;
 
if (!mem_blk)
@@ -433,7 +432,7 @@ int register_mem_sect_under_node(struct
 * case, during hotplug we know that all pages in the memory
 * block belong to the same node.
 */
-   if (check_nid) {
+   if (system_state == SYSTEM_BOOTING) {
page_nid = get_nid_for_pfn(pfn);
if (page_nid < 0)
continue;
@@ -490,41 +489,10 @@ int unregister_mem_sect_under_nodes(stru
return 0;
 }
 
-int link_mem_sections(int nid, unsigned long start_pfn, unsigned long nr_pages,
- bool check_nid)
+int link_mem_sections(int nid, unsigned long start_pfn, unsigned long end_pfn)
 {
-   unsigned long end_pfn = start_pfn + nr_pages;
-   unsigned long pfn;
-   struct memory_block *mem_blk = NULL;
-   int err = 0;
-
-   for (pfn = start_pfn; pfn < end_pfn; pfn += PAGES_PER_SECTION) {
-   unsigned long section_nr = pfn_to_section_nr(pfn);
-   struct mem_section *mem_sect;
-   int ret;
-
-   if (!present_section_nr(section_nr))
-   continue;
-   mem_sect = __nr_to_section(section_nr);
-
-   /* same memblock ? */
-   if (mem_blk)
-   if ((section_nr >= mem_blk->start_section_nr) &&
-   (section_nr <= mem_blk->end_section_nr))
-   continue;
-
-   mem_blk = find_memory_block_hinted(mem_sect, mem_blk);
-
-   ret = register_mem_sect_under_node(mem_blk, nid, check_nid);
-   if (!err)
-   err = ret;
-
-   /* discard ref obtained in find_memory_block() */
-   }
-
-   if (mem_blk)
-   kobject_put(_blk->dev.kobj);
-   return err;
+   return walk_memory_range(start_pfn, end_pfn, (void *),
+   register_mem_sect_under_node);
 }
 
 #ifdef CONFIG_HUGETLBFS
--- 
a/include/linux/node.h~mm-memory_hotplug-make-register_mem_sect_under_node-a-cb-of-walk_memory_range
+++ a/include/linux/node.h
@@ -33,10 +33,10 @@ typedef  void (*node_registration_func_t
 
 #if defined(CONFIG_MEMORY_HOTPLUG_SPARSE) && defined(CONFIG_NUMA)
 extern int link_mem_sections(int nid, unsigned long start_pfn,
-unsigned long nr_pages, bool check_nid);
+unsigned long end_pfn);
 #else
 static inline int link_mem_sections(int nid, unsigned long start_pfn,
-   unsigned 

[PATCH v2 3/4] mm/memory_hotplug: Make register_mem_sect_under_node a cb of walk_memory_range

2018-06-22 Thread osalvador
From: Oscar Salvador 

link_mem_sections() and walk_memory_range() share most of the code,
so we can use convert link_mem_sections() into a dummy function that calls
walk_memory_range() with a callback to register_mem_sect_under_node().

This patch converts register_mem_sect_under_node() in order to
match a walk_memory_range's callback, getting rid of the
check_nid argument and checking instead if the system is still
boothing, since we only have to check for the nid if the system
is in such state.

Signed-off-by: Oscar Salvador 
Suggested-by: Pavel Tatashin 
---
 drivers/base/node.c  | 44 ++--
 include/linux/node.h | 12 +++-
 mm/memory_hotplug.c  |  5 +
 3 files changed, 14 insertions(+), 47 deletions(-)

diff --git a/drivers/base/node.c b/drivers/base/node.c
index a5e821d09656..845d5523812b 100644
--- a/drivers/base/node.c
+++ b/drivers/base/node.c
@@ -399,10 +399,9 @@ static int __ref get_nid_for_pfn(unsigned long pfn)
 }
 
 /* register memory section under specified node if it spans that node */
-int register_mem_sect_under_node(struct memory_block *mem_blk, int nid,
-bool check_nid)
+int register_mem_sect_under_node(struct memory_block *mem_blk, void *arg)
 {
-   int ret;
+   int ret, nid = *(int *)arg;
unsigned long pfn, sect_start_pfn, sect_end_pfn;
 
if (!mem_blk)
@@ -433,7 +432,7 @@ int register_mem_sect_under_node(struct memory_block 
*mem_blk, int nid,
 * case, during hotplug we know that all pages in the memory
 * block belong to the same node.
 */
-   if (check_nid) {
+   if (system_state == SYSTEM_BOOTING) {
page_nid = get_nid_for_pfn(pfn);
if (page_nid < 0)
continue;
@@ -490,41 +489,10 @@ int unregister_mem_sect_under_nodes(struct memory_block 
*mem_blk,
return 0;
 }
 
-int link_mem_sections(int nid, unsigned long start_pfn, unsigned long nr_pages,
- bool check_nid)
+int link_mem_sections(int nid, unsigned long start_pfn, unsigned long end_pfn)
 {
-   unsigned long end_pfn = start_pfn + nr_pages;
-   unsigned long pfn;
-   struct memory_block *mem_blk = NULL;
-   int err = 0;
-
-   for (pfn = start_pfn; pfn < end_pfn; pfn += PAGES_PER_SECTION) {
-   unsigned long section_nr = pfn_to_section_nr(pfn);
-   struct mem_section *mem_sect;
-   int ret;
-
-   if (!present_section_nr(section_nr))
-   continue;
-   mem_sect = __nr_to_section(section_nr);
-
-   /* same memblock ? */
-   if (mem_blk)
-   if ((section_nr >= mem_blk->start_section_nr) &&
-   (section_nr <= mem_blk->end_section_nr))
-   continue;
-
-   mem_blk = find_memory_block_hinted(mem_sect, mem_blk);
-
-   ret = register_mem_sect_under_node(mem_blk, nid, check_nid);
-   if (!err)
-   err = ret;
-
-   /* discard ref obtained in find_memory_block() */
-   }
-
-   if (mem_blk)
-   kobject_put(_blk->dev.kobj);
-   return err;
+   return walk_memory_range(start_pfn, end_pfn, (void *),
+   register_mem_sect_under_node);
 }
 
 #ifdef CONFIG_HUGETLBFS
diff --git a/include/linux/node.h b/include/linux/node.h
index 6d336e38d155..257bb3d6d014 100644
--- a/include/linux/node.h
+++ b/include/linux/node.h
@@ -33,10 +33,10 @@ typedef  void (*node_registration_func_t)(struct node *);
 
 #if defined(CONFIG_MEMORY_HOTPLUG_SPARSE) && defined(CONFIG_NUMA)
 extern int link_mem_sections(int nid, unsigned long start_pfn,
-unsigned long nr_pages, bool check_nid);
+unsigned long end_pfn);
 #else
 static inline int link_mem_sections(int nid, unsigned long start_pfn,
-   unsigned long nr_pages, bool check_nid)
+   unsigned long end_pfn)
 {
return 0;
 }
@@ -54,12 +54,14 @@ static inline int register_one_node(int nid)
 
if (node_online(nid)) {
struct pglist_data *pgdat = NODE_DATA(nid);
+   unsigned long start_pfn = pgdat->node_start_pfn;
+   unsigned long end_pfn = start_pfn + pgdat->node_spanned_pages;
 
error = __register_one_node(nid);
if (error)
return error;
/* link memory sections under this node */
-   error = link_mem_sections(nid, pgdat->node_start_pfn, 
pgdat->node_spanned_pages, true);
+   error = link_mem_sections(nid, start_pfn, end_pfn);
}
 
return error;
@@ -69,7 +71,7 @@ extern void unregister_one_node(int nid);
 extern int register_cpu_under_node(unsigned 

[PATCH v2 3/4] mm/memory_hotplug: Make register_mem_sect_under_node a cb of walk_memory_range

2018-06-22 Thread osalvador
From: Oscar Salvador 

link_mem_sections() and walk_memory_range() share most of the code,
so we can use convert link_mem_sections() into a dummy function that calls
walk_memory_range() with a callback to register_mem_sect_under_node().

This patch converts register_mem_sect_under_node() in order to
match a walk_memory_range's callback, getting rid of the
check_nid argument and checking instead if the system is still
boothing, since we only have to check for the nid if the system
is in such state.

Signed-off-by: Oscar Salvador 
Suggested-by: Pavel Tatashin 
---
 drivers/base/node.c  | 44 ++--
 include/linux/node.h | 12 +++-
 mm/memory_hotplug.c  |  5 +
 3 files changed, 14 insertions(+), 47 deletions(-)

diff --git a/drivers/base/node.c b/drivers/base/node.c
index a5e821d09656..845d5523812b 100644
--- a/drivers/base/node.c
+++ b/drivers/base/node.c
@@ -399,10 +399,9 @@ static int __ref get_nid_for_pfn(unsigned long pfn)
 }
 
 /* register memory section under specified node if it spans that node */
-int register_mem_sect_under_node(struct memory_block *mem_blk, int nid,
-bool check_nid)
+int register_mem_sect_under_node(struct memory_block *mem_blk, void *arg)
 {
-   int ret;
+   int ret, nid = *(int *)arg;
unsigned long pfn, sect_start_pfn, sect_end_pfn;
 
if (!mem_blk)
@@ -433,7 +432,7 @@ int register_mem_sect_under_node(struct memory_block 
*mem_blk, int nid,
 * case, during hotplug we know that all pages in the memory
 * block belong to the same node.
 */
-   if (check_nid) {
+   if (system_state == SYSTEM_BOOTING) {
page_nid = get_nid_for_pfn(pfn);
if (page_nid < 0)
continue;
@@ -490,41 +489,10 @@ int unregister_mem_sect_under_nodes(struct memory_block 
*mem_blk,
return 0;
 }
 
-int link_mem_sections(int nid, unsigned long start_pfn, unsigned long nr_pages,
- bool check_nid)
+int link_mem_sections(int nid, unsigned long start_pfn, unsigned long end_pfn)
 {
-   unsigned long end_pfn = start_pfn + nr_pages;
-   unsigned long pfn;
-   struct memory_block *mem_blk = NULL;
-   int err = 0;
-
-   for (pfn = start_pfn; pfn < end_pfn; pfn += PAGES_PER_SECTION) {
-   unsigned long section_nr = pfn_to_section_nr(pfn);
-   struct mem_section *mem_sect;
-   int ret;
-
-   if (!present_section_nr(section_nr))
-   continue;
-   mem_sect = __nr_to_section(section_nr);
-
-   /* same memblock ? */
-   if (mem_blk)
-   if ((section_nr >= mem_blk->start_section_nr) &&
-   (section_nr <= mem_blk->end_section_nr))
-   continue;
-
-   mem_blk = find_memory_block_hinted(mem_sect, mem_blk);
-
-   ret = register_mem_sect_under_node(mem_blk, nid, check_nid);
-   if (!err)
-   err = ret;
-
-   /* discard ref obtained in find_memory_block() */
-   }
-
-   if (mem_blk)
-   kobject_put(_blk->dev.kobj);
-   return err;
+   return walk_memory_range(start_pfn, end_pfn, (void *),
+   register_mem_sect_under_node);
 }
 
 #ifdef CONFIG_HUGETLBFS
diff --git a/include/linux/node.h b/include/linux/node.h
index 6d336e38d155..257bb3d6d014 100644
--- a/include/linux/node.h
+++ b/include/linux/node.h
@@ -33,10 +33,10 @@ typedef  void (*node_registration_func_t)(struct node *);
 
 #if defined(CONFIG_MEMORY_HOTPLUG_SPARSE) && defined(CONFIG_NUMA)
 extern int link_mem_sections(int nid, unsigned long start_pfn,
-unsigned long nr_pages, bool check_nid);
+unsigned long end_pfn);
 #else
 static inline int link_mem_sections(int nid, unsigned long start_pfn,
-   unsigned long nr_pages, bool check_nid)
+   unsigned long end_pfn)
 {
return 0;
 }
@@ -54,12 +54,14 @@ static inline int register_one_node(int nid)
 
if (node_online(nid)) {
struct pglist_data *pgdat = NODE_DATA(nid);
+   unsigned long start_pfn = pgdat->node_start_pfn;
+   unsigned long end_pfn = start_pfn + pgdat->node_spanned_pages;
 
error = __register_one_node(nid);
if (error)
return error;
/* link memory sections under this node */
-   error = link_mem_sections(nid, pgdat->node_start_pfn, 
pgdat->node_spanned_pages, true);
+   error = link_mem_sections(nid, start_pfn, end_pfn);
}
 
return error;
@@ -69,7 +71,7 @@ extern void unregister_one_node(int nid);
 extern int register_cpu_under_node(unsigned