Re: [RESEND PATCH v2] alpha: switch to NO_BOOTMEM

2018-10-20 Thread Mike Rapoport
On Thu, Oct 18, 2018 at 06:58:34PM -0700, Andrew Morton wrote:
> No reviews or acks for this one yet?

Nope :(
 
> From: Mike Rapoport 
> Subject: alpha: switch to NO_BOOTMEM
> 
> Replace bootmem allocator with memblock and enable use of NO_BOOTMEM like
> on most other architectures.
> 
> Alpha gets the description of the physical memory from the firmware as an
> array of memory clusters.  Each cluster that is not reserved by the
> firmware is added to memblock.memory.
> 
> Once the memblock.memory is set up, we reserve the kernel and initrd pages
> with memblock reserve.
> 
> Since we don't need the bootmem bitmap anymore, the code that finds an
> appropriate place is removed.
> 
> The conversion does not take care of NUMA support which is marked broken
> for more than 10 years now.
> 
> Link: 
> http://lkml.kernel.org/r/1535952894-10967-1-git-send-email-r...@linux.vnet.ibm.com
> Signed-off-by: Mike Rapoport 
> Cc: Richard Henderson 
> Cc: Ivan Kokshaysky 
> Cc: Michal Hocko 
> Signed-off-by: Andrew Morton 
> ---
> 
> 
> --- a/arch/alpha/Kconfig~alpha-switch-to-no_bootmem
> +++ a/arch/alpha/Kconfig
> @@ -31,6 +31,8 @@ config ALPHA
>   select ODD_RT_SIGACTION
>   select OLD_SIGSUSPEND
>   select CPU_NO_EFFICIENT_FFS if !ALPHA_EV67
> + select HAVE_MEMBLOCK
> + select NO_BOOTMEM
>   help
> The Alpha is a 64-bit general-purpose processor designed and
> marketed by the Digital Equipment Corporation of blessed memory,
> --- a/arch/alpha/kernel/core_irongate.c~alpha-switch-to-no_bootmem
> +++ a/arch/alpha/kernel/core_irongate.c
> @@ -21,6 +21,7 @@
>  #include 
>  #include 
>  #include 
> +#include 
> 
>  #include 
>  #include 
> @@ -241,8 +242,7 @@ albacore_init_arch(void)
>  size / 1024);
>   }
>  #endif
> - reserve_bootmem_node(NODE_DATA(0), pci_mem, memtop -
> - pci_mem, BOOTMEM_DEFAULT);
> + memblock_reserve(pci_mem, memtop - pci_mem);
>   printk("irongate_init_arch: temporarily reserving "
>   "region %08lx-%08lx for PCI\n", pci_mem, memtop - 1);
>   }
> --- a/arch/alpha/kernel/setup.c~alpha-switch-to-no_bootmem
> +++ a/arch/alpha/kernel/setup.c
> @@ -30,6 +30,7 @@
>  #include 
>  #include 
>  #include 
> +#include 
>  #include 
>  #include 
>  #include 
> @@ -312,9 +313,7 @@ setup_memory(void *kernel_end)
>  {
>   struct memclust_struct * cluster;
>   struct memdesc_struct * memdesc;
> - unsigned long start_kernel_pfn, end_kernel_pfn;
> - unsigned long bootmap_size, bootmap_pages, bootmap_start;
> - unsigned long start, end;
> + unsigned long kernel_size;
>   unsigned long i;
> 
>   /* Find free clusters, and init and free the bootmem accordingly.  */
> @@ -322,6 +321,8 @@ setup_memory(void *kernel_end)
> (hwrpb->mddt_offset + (unsigned long) hwrpb);
> 
>   for_each_mem_cluster(memdesc, cluster, i) {
> + unsigned long end;
> +
>   printk("memcluster %lu, usage %01lx, start %8lu, end %8lu\n",
>  i, cluster->usage, cluster->start_pfn,
>  cluster->start_pfn + cluster->numpages);
> @@ -335,6 +336,9 @@ setup_memory(void *kernel_end)
>   end = cluster->start_pfn + cluster->numpages;
>   if (end > max_low_pfn)
>   max_low_pfn = end;
> +
> + memblock_add(PFN_PHYS(cluster->start_pfn),
> +  cluster->numpages << PAGE_SHIFT);
>   }
> 
>   /*
> @@ -363,87 +367,9 @@ setup_memory(void *kernel_end)
>   max_low_pfn = mem_size_limit;
>   }
> 
> - /* Find the bounds of kernel memory.  */
> - start_kernel_pfn = PFN_DOWN(KERNEL_START_PHYS);
> - end_kernel_pfn = PFN_UP(virt_to_phys(kernel_end));
> - bootmap_start = -1;
> -
> - try_again:
> - if (max_low_pfn <= end_kernel_pfn)
> - panic("not enough memory to boot");
> -
> - /* We need to know how many physically contiguous pages
> -we'll need for the bootmap.  */
> - bootmap_pages = bootmem_bootmap_pages(max_low_pfn);
> -
> - /* Now find a good region where to allocate the bootmap.  */
> - for_each_mem_cluster(memdesc, cluster, i) {
> - if (cluster->usage & 3)
> - continue;
> -
> - start = cluster->start_pfn;
> - end = start + cluster->numpages;
> - if (start >= max_low_pfn)
> - continue;
> - if (end > max_low_pfn)
> - end = max_low_pfn;
> - if (start < start_kernel_pfn) {
> - if (end > end_kernel_pfn
> - && end - end_kernel_pfn >= bootmap_pages) {
> - bootmap_start = end_kernel_pfn;
> - break;
> - } else if (end > start_kernel_pfn)
> - end = start_kernel_pfn;
> - 

Re: [RESEND PATCH v2] alpha: switch to NO_BOOTMEM

2018-10-18 Thread Andrew Morton
No reviews or acks for this one yet?

From: Mike Rapoport 
Subject: alpha: switch to NO_BOOTMEM

Replace bootmem allocator with memblock and enable use of NO_BOOTMEM like
on most other architectures.

Alpha gets the description of the physical memory from the firmware as an
array of memory clusters.  Each cluster that is not reserved by the
firmware is added to memblock.memory.

Once the memblock.memory is set up, we reserve the kernel and initrd pages
with memblock reserve.

Since we don't need the bootmem bitmap anymore, the code that finds an
appropriate place is removed.

The conversion does not take care of NUMA support which is marked broken
for more than 10 years now.

Link: 
http://lkml.kernel.org/r/1535952894-10967-1-git-send-email-r...@linux.vnet.ibm.com
Signed-off-by: Mike Rapoport 
Cc: Richard Henderson 
Cc: Ivan Kokshaysky 
Cc: Michal Hocko 
Signed-off-by: Andrew Morton 
---


--- a/arch/alpha/Kconfig~alpha-switch-to-no_bootmem
+++ a/arch/alpha/Kconfig
@@ -31,6 +31,8 @@ config ALPHA
select ODD_RT_SIGACTION
select OLD_SIGSUSPEND
select CPU_NO_EFFICIENT_FFS if !ALPHA_EV67
+   select HAVE_MEMBLOCK
+   select NO_BOOTMEM
help
  The Alpha is a 64-bit general-purpose processor designed and
  marketed by the Digital Equipment Corporation of blessed memory,
--- a/arch/alpha/kernel/core_irongate.c~alpha-switch-to-no_bootmem
+++ a/arch/alpha/kernel/core_irongate.c
@@ -21,6 +21,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include 
 #include 
@@ -241,8 +242,7 @@ albacore_init_arch(void)
   size / 1024);
}
 #endif
-   reserve_bootmem_node(NODE_DATA(0), pci_mem, memtop -
-   pci_mem, BOOTMEM_DEFAULT);
+   memblock_reserve(pci_mem, memtop - pci_mem);
printk("irongate_init_arch: temporarily reserving "
"region %08lx-%08lx for PCI\n", pci_mem, memtop - 1);
}
--- a/arch/alpha/kernel/setup.c~alpha-switch-to-no_bootmem
+++ a/arch/alpha/kernel/setup.c
@@ -30,6 +30,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -312,9 +313,7 @@ setup_memory(void *kernel_end)
 {
struct memclust_struct * cluster;
struct memdesc_struct * memdesc;
-   unsigned long start_kernel_pfn, end_kernel_pfn;
-   unsigned long bootmap_size, bootmap_pages, bootmap_start;
-   unsigned long start, end;
+   unsigned long kernel_size;
unsigned long i;
 
/* Find free clusters, and init and free the bootmem accordingly.  */
@@ -322,6 +321,8 @@ setup_memory(void *kernel_end)
  (hwrpb->mddt_offset + (unsigned long) hwrpb);
 
for_each_mem_cluster(memdesc, cluster, i) {
+   unsigned long end;
+
printk("memcluster %lu, usage %01lx, start %8lu, end %8lu\n",
   i, cluster->usage, cluster->start_pfn,
   cluster->start_pfn + cluster->numpages);
@@ -335,6 +336,9 @@ setup_memory(void *kernel_end)
end = cluster->start_pfn + cluster->numpages;
if (end > max_low_pfn)
max_low_pfn = end;
+
+   memblock_add(PFN_PHYS(cluster->start_pfn),
+cluster->numpages << PAGE_SHIFT);
}
 
/*
@@ -363,87 +367,9 @@ setup_memory(void *kernel_end)
max_low_pfn = mem_size_limit;
}
 
-   /* Find the bounds of kernel memory.  */
-   start_kernel_pfn = PFN_DOWN(KERNEL_START_PHYS);
-   end_kernel_pfn = PFN_UP(virt_to_phys(kernel_end));
-   bootmap_start = -1;
-
- try_again:
-   if (max_low_pfn <= end_kernel_pfn)
-   panic("not enough memory to boot");
-
-   /* We need to know how many physically contiguous pages
-  we'll need for the bootmap.  */
-   bootmap_pages = bootmem_bootmap_pages(max_low_pfn);
-
-   /* Now find a good region where to allocate the bootmap.  */
-   for_each_mem_cluster(memdesc, cluster, i) {
-   if (cluster->usage & 3)
-   continue;
-
-   start = cluster->start_pfn;
-   end = start + cluster->numpages;
-   if (start >= max_low_pfn)
-   continue;
-   if (end > max_low_pfn)
-   end = max_low_pfn;
-   if (start < start_kernel_pfn) {
-   if (end > end_kernel_pfn
-   && end - end_kernel_pfn >= bootmap_pages) {
-   bootmap_start = end_kernel_pfn;
-   break;
-   } else if (end > start_kernel_pfn)
-   end = start_kernel_pfn;
-   } else if (start < end_kernel_pfn)
-   start = end_kernel_pfn;
-   if (end - start >= bootmap_pages) {
-   bootmap_start = start;
-   

[RESEND PATCH v2] alpha: switch to NO_BOOTMEM

2018-09-02 Thread Mike Rapoport
Replace bootmem allocator with memblock and enable use of NO_BOOTMEM like
on most other architectures.

Alpha gets the description of the physical memory from the firmware as an
array of memory clusters. Each cluster that is not reserved by the firmware
is added to memblock.memory.

Once the memblock.memory is set up, we reserve the kernel and initrd pages
with memblock reserve.

Since we don't need the bootmem bitmap anymore, the code that finds an
appropriate place is removed.

The conversion does not take care of NUMA support which is marked broken
for more than 10 years now.

Signed-off-by: Mike Rapoport 
---
v2: describe the conversion as per Michal's request

Tested with qemu-system-alpha. I've added some tweaks to sys_dp264 to force
memory split for testing with CONFIG_DISCONTIGMEM=y

 arch/alpha/Kconfig|   2 +
 arch/alpha/kernel/core_irongate.c |   4 +-
 arch/alpha/kernel/setup.c |  98 -
 arch/alpha/mm/numa.c  | 113 +-
 4 files changed, 29 insertions(+), 188 deletions(-)

diff --git a/arch/alpha/Kconfig b/arch/alpha/Kconfig
index 5b4f883..620b0a7 100644
--- a/arch/alpha/Kconfig
+++ b/arch/alpha/Kconfig
@@ -31,6 +31,8 @@ config ALPHA
select ODD_RT_SIGACTION
select OLD_SIGSUSPEND
select CPU_NO_EFFICIENT_FFS if !ALPHA_EV67
+   select HAVE_MEMBLOCK
+   select NO_BOOTMEM
help
  The Alpha is a 64-bit general-purpose processor designed and
  marketed by the Digital Equipment Corporation of blessed memory,
diff --git a/arch/alpha/kernel/core_irongate.c 
b/arch/alpha/kernel/core_irongate.c
index aec7572..f709866 100644
--- a/arch/alpha/kernel/core_irongate.c
+++ b/arch/alpha/kernel/core_irongate.c
@@ -21,6 +21,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include 
 #include 
@@ -241,8 +242,7 @@ albacore_init_arch(void)
   size / 1024);
}
 #endif
-   reserve_bootmem_node(NODE_DATA(0), pci_mem, memtop -
-   pci_mem, BOOTMEM_DEFAULT);
+   memblock_reserve(pci_mem, memtop - pci_mem);
printk("irongate_init_arch: temporarily reserving "
"region %08lx-%08lx for PCI\n", pci_mem, memtop - 1);
}
diff --git a/arch/alpha/kernel/setup.c b/arch/alpha/kernel/setup.c
index 5576f76..4f0d944 100644
--- a/arch/alpha/kernel/setup.c
+++ b/arch/alpha/kernel/setup.c
@@ -30,6 +30,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -312,9 +313,7 @@ setup_memory(void *kernel_end)
 {
struct memclust_struct * cluster;
struct memdesc_struct * memdesc;
-   unsigned long start_kernel_pfn, end_kernel_pfn;
-   unsigned long bootmap_size, bootmap_pages, bootmap_start;
-   unsigned long start, end;
+   unsigned long kernel_size;
unsigned long i;
 
/* Find free clusters, and init and free the bootmem accordingly.  */
@@ -322,6 +321,8 @@ setup_memory(void *kernel_end)
  (hwrpb->mddt_offset + (unsigned long) hwrpb);
 
for_each_mem_cluster(memdesc, cluster, i) {
+   unsigned long end;
+
printk("memcluster %lu, usage %01lx, start %8lu, end %8lu\n",
   i, cluster->usage, cluster->start_pfn,
   cluster->start_pfn + cluster->numpages);
@@ -335,6 +336,9 @@ setup_memory(void *kernel_end)
end = cluster->start_pfn + cluster->numpages;
if (end > max_low_pfn)
max_low_pfn = end;
+
+   memblock_add(PFN_PHYS(cluster->start_pfn),
+cluster->numpages << PAGE_SHIFT);
}
 
/*
@@ -363,87 +367,9 @@ setup_memory(void *kernel_end)
max_low_pfn = mem_size_limit;
}
 
-   /* Find the bounds of kernel memory.  */
-   start_kernel_pfn = PFN_DOWN(KERNEL_START_PHYS);
-   end_kernel_pfn = PFN_UP(virt_to_phys(kernel_end));
-   bootmap_start = -1;
-
- try_again:
-   if (max_low_pfn <= end_kernel_pfn)
-   panic("not enough memory to boot");
-
-   /* We need to know how many physically contiguous pages
-  we'll need for the bootmap.  */
-   bootmap_pages = bootmem_bootmap_pages(max_low_pfn);
-
-   /* Now find a good region where to allocate the bootmap.  */
-   for_each_mem_cluster(memdesc, cluster, i) {
-   if (cluster->usage & 3)
-   continue;
-
-   start = cluster->start_pfn;
-   end = start + cluster->numpages;
-   if (start >= max_low_pfn)
-   continue;
-   if (end > max_low_pfn)
-   end = max_low_pfn;
-   if (start < start_kernel_pfn) {
-   if (end > end_kernel_pfn
-   && end - end_kernel_pfn >= bootmap_pages) {
-  

Re: [PATCH v2] alpha: switch to NO_BOOTMEM

2018-07-12 Thread Mike Rapoport
(added Matt Turner, sorry, should have done it from the beginning)

Any comments on this?
 
> On Sat, Jun 30, 2018 at 06:13:30PM +0300, Mike Rapoport wrote:
> Replace bootmem allocator with memblock and enable use of NO_BOOTMEM like
> on most other architectures.
> 
> Alpha gets the description of the physical memory from the firmware as an
> array of memory clusters. Each cluster that is not reserved by the firmware
> is added to memblock.memory.
> 
> Once the memblock.memory is set up, we reserve the kernel and initrd pages
> with memblock reserve.
> 
> Since we don't need the bootmem bitmap anymore, the code that finds an
> appropriate place is removed.
> 
> The conversion does not take care of NUMA support which is marked broken
> for more than 10 years now.
> 
> Signed-off-by: Mike Rapoport 
> ---
> v2: describe the conversion as per Michal's request
> 
> Tested with qemu-system-alpha. I've added some tweaks to sys_dp264 to force
> memory split for testing with CONFIG_DISCONTIGMEM=y
> 
> The allyesconfig build requires update to DEFERRED_STRUCT_PAGE_INIT
> dependencies [1] which is already in -mm tree.
> 
> [1] https://lkml.org/lkml/2018/6/29/353
> 
>  arch/alpha/Kconfig|   2 +
>  arch/alpha/kernel/core_irongate.c |   4 +-
>  arch/alpha/kernel/setup.c |  98 -
>  arch/alpha/mm/numa.c  | 113 
> +-
>  4 files changed, 29 insertions(+), 188 deletions(-)
> 
> diff --git a/arch/alpha/Kconfig b/arch/alpha/Kconfig
> index 04a4a138ed13..040692a8d433 100644
> --- a/arch/alpha/Kconfig
> +++ b/arch/alpha/Kconfig
> @@ -30,6 +30,8 @@ config ALPHA
>   select ODD_RT_SIGACTION
>   select OLD_SIGSUSPEND
>   select CPU_NO_EFFICIENT_FFS if !ALPHA_EV67
> + select HAVE_MEMBLOCK
> + select NO_BOOTMEM
>   help
> The Alpha is a 64-bit general-purpose processor designed and
> marketed by the Digital Equipment Corporation of blessed memory,
> diff --git a/arch/alpha/kernel/core_irongate.c 
> b/arch/alpha/kernel/core_irongate.c
> index aec757250e07..f70986683fc6 100644
> --- a/arch/alpha/kernel/core_irongate.c
> +++ b/arch/alpha/kernel/core_irongate.c
> @@ -21,6 +21,7 @@
>  #include 
>  #include 
>  #include 
> +#include 
> 
>  #include 
>  #include 
> @@ -241,8 +242,7 @@ albacore_init_arch(void)
>  size / 1024);
>   }
>  #endif
> - reserve_bootmem_node(NODE_DATA(0), pci_mem, memtop -
> - pci_mem, BOOTMEM_DEFAULT);
> + memblock_reserve(pci_mem, memtop - pci_mem);
>   printk("irongate_init_arch: temporarily reserving "
>   "region %08lx-%08lx for PCI\n", pci_mem, memtop - 1);
>   }
> diff --git a/arch/alpha/kernel/setup.c b/arch/alpha/kernel/setup.c
> index 5576f7646fb6..4f0d94471bc9 100644
> --- a/arch/alpha/kernel/setup.c
> +++ b/arch/alpha/kernel/setup.c
> @@ -30,6 +30,7 @@
>  #include 
>  #include 
>  #include 
> +#include 
>  #include 
>  #include 
>  #include 
> @@ -312,9 +313,7 @@ setup_memory(void *kernel_end)
>  {
>   struct memclust_struct * cluster;
>   struct memdesc_struct * memdesc;
> - unsigned long start_kernel_pfn, end_kernel_pfn;
> - unsigned long bootmap_size, bootmap_pages, bootmap_start;
> - unsigned long start, end;
> + unsigned long kernel_size;
>   unsigned long i;
> 
>   /* Find free clusters, and init and free the bootmem accordingly.  */
> @@ -322,6 +321,8 @@ setup_memory(void *kernel_end)
> (hwrpb->mddt_offset + (unsigned long) hwrpb);
> 
>   for_each_mem_cluster(memdesc, cluster, i) {
> + unsigned long end;
> +
>   printk("memcluster %lu, usage %01lx, start %8lu, end %8lu\n",
>  i, cluster->usage, cluster->start_pfn,
>  cluster->start_pfn + cluster->numpages);
> @@ -335,6 +336,9 @@ setup_memory(void *kernel_end)
>   end = cluster->start_pfn + cluster->numpages;
>   if (end > max_low_pfn)
>   max_low_pfn = end;
> +
> + memblock_add(PFN_PHYS(cluster->start_pfn),
> +  cluster->numpages << PAGE_SHIFT);
>   }
> 
>   /*
> @@ -363,87 +367,9 @@ setup_memory(void *kernel_end)
>   max_low_pfn = mem_size_limit;
>   }
> 
> - /* Find the bounds of kernel memory.  */
> - start_kernel_pfn = PFN_DOWN(KERNEL_START_PHYS);
> - end_kernel_pfn = PFN_UP(virt_to_phys(kernel_end));
> - bootmap_start = -1;
> -
> - try_again:
> - if (max_low_pfn <= end_kernel_pfn)
> - panic("not enough memory to boot");
> -
> - /* We need to know how many physically contiguous pages
> -we'll need for the bootmap.  */
> - bootmap_pages = bootmem_bootmap_pages(max_low_pfn);
> -
> - /* Now find a good region where to allocate the bootmap.  */
> - for_each_mem_cluster(memdesc, cluster, i) {
> - if 

Re: [PATCH v2] alpha: switch to NO_BOOTMEM

2018-07-04 Thread Mike Rapoport
Any comments on this?

On Sat, Jun 30, 2018 at 06:13:30PM +0300, Mike Rapoport wrote:
> Replace bootmem allocator with memblock and enable use of NO_BOOTMEM like
> on most other architectures.
> 
> Alpha gets the description of the physical memory from the firmware as an
> array of memory clusters. Each cluster that is not reserved by the firmware
> is added to memblock.memory.
> 
> Once the memblock.memory is set up, we reserve the kernel and initrd pages
> with memblock reserve.
> 
> Since we don't need the bootmem bitmap anymore, the code that finds an
> appropriate place is removed.
> 
> The conversion does not take care of NUMA support which is marked broken
> for more than 10 years now.
> 
> Signed-off-by: Mike Rapoport 
> ---
> v2: describe the conversion as per Michal's request
> 
> Tested with qemu-system-alpha. I've added some tweaks to sys_dp264 to force
> memory split for testing with CONFIG_DISCONTIGMEM=y
> 
> The allyesconfig build requires update to DEFERRED_STRUCT_PAGE_INIT
> dependencies [1] which is already in -mm tree.
> 
> [1] https://lkml.org/lkml/2018/6/29/353
> 
>  arch/alpha/Kconfig|   2 +
>  arch/alpha/kernel/core_irongate.c |   4 +-
>  arch/alpha/kernel/setup.c |  98 -
>  arch/alpha/mm/numa.c  | 113 
> +-
>  4 files changed, 29 insertions(+), 188 deletions(-)
> 
> diff --git a/arch/alpha/Kconfig b/arch/alpha/Kconfig
> index 04a4a138ed13..040692a8d433 100644
> --- a/arch/alpha/Kconfig
> +++ b/arch/alpha/Kconfig
> @@ -30,6 +30,8 @@ config ALPHA
>   select ODD_RT_SIGACTION
>   select OLD_SIGSUSPEND
>   select CPU_NO_EFFICIENT_FFS if !ALPHA_EV67
> + select HAVE_MEMBLOCK
> + select NO_BOOTMEM
>   help
> The Alpha is a 64-bit general-purpose processor designed and
> marketed by the Digital Equipment Corporation of blessed memory,
> diff --git a/arch/alpha/kernel/core_irongate.c 
> b/arch/alpha/kernel/core_irongate.c
> index aec757250e07..f70986683fc6 100644
> --- a/arch/alpha/kernel/core_irongate.c
> +++ b/arch/alpha/kernel/core_irongate.c
> @@ -21,6 +21,7 @@
>  #include 
>  #include 
>  #include 
> +#include 
> 
>  #include 
>  #include 
> @@ -241,8 +242,7 @@ albacore_init_arch(void)
>  size / 1024);
>   }
>  #endif
> - reserve_bootmem_node(NODE_DATA(0), pci_mem, memtop -
> - pci_mem, BOOTMEM_DEFAULT);
> + memblock_reserve(pci_mem, memtop - pci_mem);
>   printk("irongate_init_arch: temporarily reserving "
>   "region %08lx-%08lx for PCI\n", pci_mem, memtop - 1);
>   }
> diff --git a/arch/alpha/kernel/setup.c b/arch/alpha/kernel/setup.c
> index 5576f7646fb6..4f0d94471bc9 100644
> --- a/arch/alpha/kernel/setup.c
> +++ b/arch/alpha/kernel/setup.c
> @@ -30,6 +30,7 @@
>  #include 
>  #include 
>  #include 
> +#include 
>  #include 
>  #include 
>  #include 
> @@ -312,9 +313,7 @@ setup_memory(void *kernel_end)
>  {
>   struct memclust_struct * cluster;
>   struct memdesc_struct * memdesc;
> - unsigned long start_kernel_pfn, end_kernel_pfn;
> - unsigned long bootmap_size, bootmap_pages, bootmap_start;
> - unsigned long start, end;
> + unsigned long kernel_size;
>   unsigned long i;
> 
>   /* Find free clusters, and init and free the bootmem accordingly.  */
> @@ -322,6 +321,8 @@ setup_memory(void *kernel_end)
> (hwrpb->mddt_offset + (unsigned long) hwrpb);
> 
>   for_each_mem_cluster(memdesc, cluster, i) {
> + unsigned long end;
> +
>   printk("memcluster %lu, usage %01lx, start %8lu, end %8lu\n",
>  i, cluster->usage, cluster->start_pfn,
>  cluster->start_pfn + cluster->numpages);
> @@ -335,6 +336,9 @@ setup_memory(void *kernel_end)
>   end = cluster->start_pfn + cluster->numpages;
>   if (end > max_low_pfn)
>   max_low_pfn = end;
> +
> + memblock_add(PFN_PHYS(cluster->start_pfn),
> +  cluster->numpages << PAGE_SHIFT);
>   }
> 
>   /*
> @@ -363,87 +367,9 @@ setup_memory(void *kernel_end)
>   max_low_pfn = mem_size_limit;
>   }
> 
> - /* Find the bounds of kernel memory.  */
> - start_kernel_pfn = PFN_DOWN(KERNEL_START_PHYS);
> - end_kernel_pfn = PFN_UP(virt_to_phys(kernel_end));
> - bootmap_start = -1;
> -
> - try_again:
> - if (max_low_pfn <= end_kernel_pfn)
> - panic("not enough memory to boot");
> -
> - /* We need to know how many physically contiguous pages
> -we'll need for the bootmap.  */
> - bootmap_pages = bootmem_bootmap_pages(max_low_pfn);
> -
> - /* Now find a good region where to allocate the bootmap.  */
> - for_each_mem_cluster(memdesc, cluster, i) {
> - if (cluster->usage & 3)
> - continue;
> -
> - 

[PATCH v2] alpha: switch to NO_BOOTMEM

2018-06-30 Thread Mike Rapoport
Replace bootmem allocator with memblock and enable use of NO_BOOTMEM like
on most other architectures.

Alpha gets the description of the physical memory from the firmware as an
array of memory clusters. Each cluster that is not reserved by the firmware
is added to memblock.memory.

Once the memblock.memory is set up, we reserve the kernel and initrd pages
with memblock reserve.

Since we don't need the bootmem bitmap anymore, the code that finds an
appropriate place is removed.

The conversion does not take care of NUMA support which is marked broken
for more than 10 years now.

Signed-off-by: Mike Rapoport 
---
v2: describe the conversion as per Michal's request

Tested with qemu-system-alpha. I've added some tweaks to sys_dp264 to force
memory split for testing with CONFIG_DISCONTIGMEM=y

The allyesconfig build requires update to DEFERRED_STRUCT_PAGE_INIT
dependencies [1] which is already in -mm tree.

[1] https://lkml.org/lkml/2018/6/29/353

 arch/alpha/Kconfig|   2 +
 arch/alpha/kernel/core_irongate.c |   4 +-
 arch/alpha/kernel/setup.c |  98 -
 arch/alpha/mm/numa.c  | 113 +-
 4 files changed, 29 insertions(+), 188 deletions(-)

diff --git a/arch/alpha/Kconfig b/arch/alpha/Kconfig
index 04a4a138ed13..040692a8d433 100644
--- a/arch/alpha/Kconfig
+++ b/arch/alpha/Kconfig
@@ -30,6 +30,8 @@ config ALPHA
select ODD_RT_SIGACTION
select OLD_SIGSUSPEND
select CPU_NO_EFFICIENT_FFS if !ALPHA_EV67
+   select HAVE_MEMBLOCK
+   select NO_BOOTMEM
help
  The Alpha is a 64-bit general-purpose processor designed and
  marketed by the Digital Equipment Corporation of blessed memory,
diff --git a/arch/alpha/kernel/core_irongate.c 
b/arch/alpha/kernel/core_irongate.c
index aec757250e07..f70986683fc6 100644
--- a/arch/alpha/kernel/core_irongate.c
+++ b/arch/alpha/kernel/core_irongate.c
@@ -21,6 +21,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include 
 #include 
@@ -241,8 +242,7 @@ albacore_init_arch(void)
   size / 1024);
}
 #endif
-   reserve_bootmem_node(NODE_DATA(0), pci_mem, memtop -
-   pci_mem, BOOTMEM_DEFAULT);
+   memblock_reserve(pci_mem, memtop - pci_mem);
printk("irongate_init_arch: temporarily reserving "
"region %08lx-%08lx for PCI\n", pci_mem, memtop - 1);
}
diff --git a/arch/alpha/kernel/setup.c b/arch/alpha/kernel/setup.c
index 5576f7646fb6..4f0d94471bc9 100644
--- a/arch/alpha/kernel/setup.c
+++ b/arch/alpha/kernel/setup.c
@@ -30,6 +30,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -312,9 +313,7 @@ setup_memory(void *kernel_end)
 {
struct memclust_struct * cluster;
struct memdesc_struct * memdesc;
-   unsigned long start_kernel_pfn, end_kernel_pfn;
-   unsigned long bootmap_size, bootmap_pages, bootmap_start;
-   unsigned long start, end;
+   unsigned long kernel_size;
unsigned long i;
 
/* Find free clusters, and init and free the bootmem accordingly.  */
@@ -322,6 +321,8 @@ setup_memory(void *kernel_end)
  (hwrpb->mddt_offset + (unsigned long) hwrpb);
 
for_each_mem_cluster(memdesc, cluster, i) {
+   unsigned long end;
+
printk("memcluster %lu, usage %01lx, start %8lu, end %8lu\n",
   i, cluster->usage, cluster->start_pfn,
   cluster->start_pfn + cluster->numpages);
@@ -335,6 +336,9 @@ setup_memory(void *kernel_end)
end = cluster->start_pfn + cluster->numpages;
if (end > max_low_pfn)
max_low_pfn = end;
+
+   memblock_add(PFN_PHYS(cluster->start_pfn),
+cluster->numpages << PAGE_SHIFT);
}
 
/*
@@ -363,87 +367,9 @@ setup_memory(void *kernel_end)
max_low_pfn = mem_size_limit;
}
 
-   /* Find the bounds of kernel memory.  */
-   start_kernel_pfn = PFN_DOWN(KERNEL_START_PHYS);
-   end_kernel_pfn = PFN_UP(virt_to_phys(kernel_end));
-   bootmap_start = -1;
-
- try_again:
-   if (max_low_pfn <= end_kernel_pfn)
-   panic("not enough memory to boot");
-
-   /* We need to know how many physically contiguous pages
-  we'll need for the bootmap.  */
-   bootmap_pages = bootmem_bootmap_pages(max_low_pfn);
-
-   /* Now find a good region where to allocate the bootmap.  */
-   for_each_mem_cluster(memdesc, cluster, i) {
-   if (cluster->usage & 3)
-   continue;
-
-   start = cluster->start_pfn;
-   end = start + cluster->numpages;
-   if (start >= max_low_pfn)
-   continue;
-   if (end > max_low_pfn)
-   end = max_low_pfn;
-