[PATCH 1/3] mm: rename alloc_pages_exact_node to __alloc_pages_node

2015-08-20 Thread Vlastimil Babka
The function alloc_pages_exact_node() was introduced in 6484eb3e2a81 (page
allocator: do not check NUMA node ID when the caller knows the node is valid)
as an optimized variant of alloc_pages_node(), that doesn't fallback to current
node for nid == NUMA_NO_NODE. Unfortunately the name of the function can easily
suggest that the allocation is restricted to the given node and fails
otherwise. In truth, the node is only preferred, unless __GFP_THISNODE is
passed among the gfp flags.

The misleading name has lead to mistakes in the past, see 5265047ac301 (mm,
thp: really limit transparent hugepage allocation to local node) and
b360edb43f8e (mm, mempolicy: migrate_to_node should only migrate to node).

Another issue with the name is that there's a family of alloc_pages_exact*()
functions where 'exact' means exact size (instead of page order), which leads
to more confusion.

To prevent further mistakes, this patch effectively renames
alloc_pages_exact_node() to __alloc_pages_node() to better convey that it's
an optimized variant of alloc_pages_node() not intended for general usage.
Both functions get described in comments.

It has been also considered to really provide a convenience function for
allocations restricted to a node, but the major opinion seems to be that
__GFP_THISNODE already provides that functionality and we shouldn't duplicate
the API needlessly. The number of users would be small anyway.

Existing callers of alloc_pages_exact_node() are simply converted to call
__alloc_pages_node(), with the exception of sba_alloc_coherent() which
open-codes the check for NUMA_NO_NODE, so it is converted to use
alloc_pages_node() instead. This means it no longer performs some VM_BUG_ON
checks, and since the current check for nid in alloc_pages_node() uses a 'nid 
0' comparison (which includes NUMA_NO_NODE), it may hide wrong values which
would be previously exposed. Both differences will be rectified by the next
patch.

To sum up, this patch makes no functional changes, except temporarily hiding
potentially buggy callers. Restricting the checks in alloc_pages_node() is
left for the next patch which can in turn expose more existing buggy callers.

Signed-off-by: Vlastimil Babka vba...@suse.cz
Acked-by: Johannes Weiner han...@cmpxchg.org
Cc: Mel Gorman mgor...@suse.de
Cc: David Rientjes rient...@google.com
Cc: Greg Thelen gthe...@google.com
Cc: Aneesh Kumar K.V aneesh.ku...@linux.vnet.ibm.com
Acked-by: Christoph Lameter c...@linux.com
Cc: Pekka Enberg penb...@kernel.org
Cc: Joonsoo Kim iamjoonsoo@lge.com
Cc: Naoya Horiguchi n-horigu...@ah.jp.nec.com
Cc: Tony Luck tony.l...@intel.com
Cc: Fenghua Yu fenghua...@intel.com
Cc: Arnd Bergmann a...@arndb.de
Cc: Benjamin Herrenschmidt b...@kernel.crashing.org
Cc: Paul Mackerras pau...@samba.org
Acked-by: Michael Ellerman m...@ellerman.id.au
Cc: Gleb Natapov g...@kernel.org
Cc: Paolo Bonzini pbonz...@redhat.com
Cc: Thomas Gleixner t...@linutronix.de
Cc: Ingo Molnar mi...@redhat.com
Cc: H. Peter Anvin h...@zytor.com
Cc: Cliff Whickman c...@sgi.com
Acked-by: Robin Holt robinmh...@gmail.com
---
 v3: fixed the slob part (Christoph Lameter), removed forgotten hunk from
 huge_memory.c (DavidR)

 arch/ia64/hp/common/sba_iommu.c   |  6 +-
 arch/ia64/kernel/uncached.c   |  2 +-
 arch/ia64/sn/pci/pci_dma.c|  2 +-
 arch/powerpc/platforms/cell/ras.c |  2 +-
 arch/x86/kvm/vmx.c|  2 +-
 drivers/misc/sgi-xp/xpc_uv.c  |  2 +-
 include/linux/gfp.h   | 23 +++
 kernel/profile.c  |  8 
 mm/filemap.c  |  2 +-
 mm/huge_memory.c  |  2 +-
 mm/hugetlb.c  |  4 ++--
 mm/memory-failure.c   |  2 +-
 mm/mempolicy.c|  4 ++--
 mm/migrate.c  |  4 ++--
 mm/page_alloc.c   |  2 --
 mm/slab.c |  2 +-
 mm/slob.c |  4 ++--
 mm/slub.c |  2 +-
 18 files changed, 38 insertions(+), 37 deletions(-)

diff --git a/arch/ia64/hp/common/sba_iommu.c b/arch/ia64/hp/common/sba_iommu.c
index 344387a..a6d6190 100644
--- a/arch/ia64/hp/common/sba_iommu.c
+++ b/arch/ia64/hp/common/sba_iommu.c
@@ -1140,13 +1140,9 @@ sba_alloc_coherent(struct device *dev, size_t size, 
dma_addr_t *dma_handle,
 
 #ifdef CONFIG_NUMA
{
-   int node = ioc-node;
struct page *page;
 
-   if (node == NUMA_NO_NODE)
-   node = numa_node_id();
-
-   page = alloc_pages_exact_node(node, flags, get_order(size));
+   page = alloc_pages_node(ioc-node, flags, get_order(size));
if (unlikely(!page))
return NULL;
 
diff --git a/arch/ia64/kernel/uncached.c b/arch/ia64/kernel/uncached.c
index 20e8a9b..f3976da 100644
--- a/arch/ia64/kernel/uncached.c
+++ b/arch/ia64/kernel/uncached.c
@@ -97,7 +97,7 @@ static int uncached_add_chunk(struct 

Re: [PATCH 1/3] mm: rename alloc_pages_exact_node to __alloc_pages_node

2015-08-20 Thread Michal Hocko
On Thu 20-08-15 13:43:20, Vlastimil Babka wrote:
 The function alloc_pages_exact_node() was introduced in 6484eb3e2a81 (page
 allocator: do not check NUMA node ID when the caller knows the node is valid)
 as an optimized variant of alloc_pages_node(), that doesn't fallback to 
 current
 node for nid == NUMA_NO_NODE. Unfortunately the name of the function can 
 easily
 suggest that the allocation is restricted to the given node and fails
 otherwise. In truth, the node is only preferred, unless __GFP_THISNODE is
 passed among the gfp flags.
 
 The misleading name has lead to mistakes in the past, see 5265047ac301 (mm,
 thp: really limit transparent hugepage allocation to local node) and
 b360edb43f8e (mm, mempolicy: migrate_to_node should only migrate to node).
 
 Another issue with the name is that there's a family of alloc_pages_exact*()
 functions where 'exact' means exact size (instead of page order), which leads
 to more confusion.
 
 To prevent further mistakes, this patch effectively renames
 alloc_pages_exact_node() to __alloc_pages_node() to better convey that it's
 an optimized variant of alloc_pages_node() not intended for general usage.
 Both functions get described in comments.
 
 It has been also considered to really provide a convenience function for
 allocations restricted to a node, but the major opinion seems to be that
 __GFP_THISNODE already provides that functionality and we shouldn't duplicate
 the API needlessly. The number of users would be small anyway.
 
 Existing callers of alloc_pages_exact_node() are simply converted to call
 __alloc_pages_node(), with the exception of sba_alloc_coherent() which
 open-codes the check for NUMA_NO_NODE, so it is converted to use
 alloc_pages_node() instead. This means it no longer performs some VM_BUG_ON
 checks, and since the current check for nid in alloc_pages_node() uses a 'nid 
 
 0' comparison (which includes NUMA_NO_NODE), it may hide wrong values which
 would be previously exposed. Both differences will be rectified by the next
 patch.
 
 To sum up, this patch makes no functional changes, except temporarily hiding
 potentially buggy callers. Restricting the checks in alloc_pages_node() is
 left for the next patch which can in turn expose more existing buggy callers.

Nice cleanup!

 Signed-off-by: Vlastimil Babka vba...@suse.cz
 Acked-by: Johannes Weiner han...@cmpxchg.org
 Cc: Mel Gorman mgor...@suse.de
 Cc: David Rientjes rient...@google.com
 Cc: Greg Thelen gthe...@google.com
 Cc: Aneesh Kumar K.V aneesh.ku...@linux.vnet.ibm.com
 Acked-by: Christoph Lameter c...@linux.com
 Cc: Pekka Enberg penb...@kernel.org
 Cc: Joonsoo Kim iamjoonsoo@lge.com
 Cc: Naoya Horiguchi n-horigu...@ah.jp.nec.com
 Cc: Tony Luck tony.l...@intel.com
 Cc: Fenghua Yu fenghua...@intel.com
 Cc: Arnd Bergmann a...@arndb.de
 Cc: Benjamin Herrenschmidt b...@kernel.crashing.org
 Cc: Paul Mackerras pau...@samba.org
 Acked-by: Michael Ellerman m...@ellerman.id.au
 Cc: Gleb Natapov g...@kernel.org
 Cc: Paolo Bonzini pbonz...@redhat.com
 Cc: Thomas Gleixner t...@linutronix.de
 Cc: Ingo Molnar mi...@redhat.com
 Cc: H. Peter Anvin h...@zytor.com
 Cc: Cliff Whickman c...@sgi.com
 Acked-by: Robin Holt robinmh...@gmail.com

Acked-by: Michal Hocko mho...@suse.com

 ---
  v3: fixed the slob part (Christoph Lameter), removed forgotten hunk from
  huge_memory.c (DavidR)
 
  arch/ia64/hp/common/sba_iommu.c   |  6 +-
  arch/ia64/kernel/uncached.c   |  2 +-
  arch/ia64/sn/pci/pci_dma.c|  2 +-
  arch/powerpc/platforms/cell/ras.c |  2 +-
  arch/x86/kvm/vmx.c|  2 +-
  drivers/misc/sgi-xp/xpc_uv.c  |  2 +-
  include/linux/gfp.h   | 23 +++
  kernel/profile.c  |  8 
  mm/filemap.c  |  2 +-
  mm/huge_memory.c  |  2 +-
  mm/hugetlb.c  |  4 ++--
  mm/memory-failure.c   |  2 +-
  mm/mempolicy.c|  4 ++--
  mm/migrate.c  |  4 ++--
  mm/page_alloc.c   |  2 --
  mm/slab.c |  2 +-
  mm/slob.c |  4 ++--
  mm/slub.c |  2 +-
  18 files changed, 38 insertions(+), 37 deletions(-)
 
 diff --git a/arch/ia64/hp/common/sba_iommu.c b/arch/ia64/hp/common/sba_iommu.c
 index 344387a..a6d6190 100644
 --- a/arch/ia64/hp/common/sba_iommu.c
 +++ b/arch/ia64/hp/common/sba_iommu.c
 @@ -1140,13 +1140,9 @@ sba_alloc_coherent(struct device *dev, size_t size, 
 dma_addr_t *dma_handle,
  
  #ifdef CONFIG_NUMA
   {
 - int node = ioc-node;
   struct page *page;
  
 - if (node == NUMA_NO_NODE)
 - node = numa_node_id();
 -
 - page = alloc_pages_exact_node(node, flags, get_order(size));
 + page = alloc_pages_node(ioc-node, flags, get_order(size));
   if (unlikely(!page))
   return NULL;
  
 diff --git