stable.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Andrew Morton <akpm@linux-foundation.org>
To: akpm@linux-foundation.org, andreas.schaufler@gmx.de,
	aslan@fb.com, guro@fb.com, Jonathan.Cameron@huawei.com,
	js1304@gmail.com, linux-mm@kvack.org, mhocko@kernel.org,
	mike.kravetz@oracle.com, mm-commits@vger.kernel.org,
	riel@surriel.com, robin.murphy@arm.com,
	song.bao.hua@hisilicon.com, stable@vger.kernel.org,
	torvalds@linux-foundation.org
Subject: [patch 3/5] mm/cma.c: use exact_nid true to fix possible per-numa cma leak
Date: Fri, 03 Jul 2020 15:15:24 -0700	[thread overview]
Message-ID: <20200703221524.H3lijT4I2%akpm@linux-foundation.org> (raw)
In-Reply-To: <20200703151445.b6a0cfee402c7c5c4651f1b1@linux-foundation.org>

From: Barry Song <song.bao.hua@hisilicon.com>
Subject: mm/cma.c: use exact_nid true to fix possible per-numa cma leak

Calling cma_declare_contiguous_nid() with false exact_nid for per-numa
reservation can easily cause cma leak and various confusion.  For example,
mm/hugetlb.c is trying to reserve per-numa cma for gigantic pages.  But it
can easily leak cma and make users confused when system has memoryless
nodes.

In case the system has 4 numa nodes, and only numa node0 has memory.  if
we set hugetlb_cma=4G in bootargs, mm/hugetlb.c will get 4 cma areas for 4
different numa nodes.  since exact_nid=false in current code, all 4 numa
nodes will get cma successfully from node0, but hugetlb_cma[1 to 3] will
never be available to hugepage will only allocate memory from
hugetlb_cma[0].

In case the system has 4 numa nodes, both numa node0&2 has memory, other
nodes have no memory.  if we set hugetlb_cma=4G in bootargs, mm/hugetlb.c
will get 4 cma areas for 4 different numa nodes.  since exact_nid=false in
current code, all 4 numa nodes will get cma successfully from node0 or 2,
but hugetlb_cma[1] and [3] will never be available to hugepage as
mm/hugetlb.c will only allocate memory from hugetlb_cma[0] and
hugetlb_cma[2].  This causes permanent leak of the cma areas which are
supposed to be used by memoryless node.

Of cource we can workaround the issue by letting mm/hugetlb.c scan all cma
areas in alloc_gigantic_page() even node_mask includes node0 only.  that
means when node_mask includes node0 only, we can get page from
hugetlb_cma[1] to hugetlb_cma[3].  But this will cause kernel crash in
free_gigantic_page() while it wants to free page by:
cma_release(hugetlb_cma[page_to_nid(page)], page, 1 << order)

On the other hand, exact_nid=false won't consider numa distance, it might
be not that useful to leverage cma areas on remote nodes.  I feel it is
much simpler to make exact_nid true to make everything clear.  After that,
memoryless nodes won't be able to reserve per-numa CMA from other nodes
which have memory.

Link: http://lkml.kernel.org/r/20200628074345.27228-1-song.bao.hua@hisilicon.com
Fixes: cf11e85fc08c ("mm: hugetlb: optionally allocate gigantic hugepages using cma")
Signed-off-by: Barry Song <song.bao.hua@hisilicon.com>
Acked-by: Roman Gushchin <guro@fb.com>
Cc: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Cc: Aslan Bakirov <aslan@fb.com>
Cc: Michal Hocko <mhocko@kernel.org>
Cc: Andreas Schaufler <andreas.schaufler@gmx.de>
Cc: Mike Kravetz <mike.kravetz@oracle.com>
Cc: Rik van Riel <riel@surriel.com>
Cc: Joonsoo Kim <js1304@gmail.com>
Cc: Robin Murphy <robin.murphy@arm.com>
Cc: <stable@vger.kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
---

 mm/cma.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

--- a/mm/cma.c~mm-cmac-use-exact_nid-true-to-fix-possible-per-numa-cma-leak
+++ a/mm/cma.c
@@ -339,13 +339,13 @@ int __init cma_declare_contiguous_nid(ph
 		 */
 		if (base < highmem_start && limit > highmem_start) {
 			addr = memblock_alloc_range_nid(size, alignment,
-					highmem_start, limit, nid, false);
+					highmem_start, limit, nid, true);
 			limit = highmem_start;
 		}
 
 		if (!addr) {
 			addr = memblock_alloc_range_nid(size, alignment, base,
-					limit, nid, false);
+					limit, nid, true);
 			if (!addr) {
 				ret = -ENOMEM;
 				goto err;
_

  parent reply	other threads:[~2020-07-03 22:15 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20200703151445.b6a0cfee402c7c5c4651f1b1@linux-foundation.org>
2020-07-03 22:15 ` [patch 1/5] mm/hugetlb.c: fix pages per hugetlb calculation Andrew Morton
2020-07-03 22:15 ` Andrew Morton [this message]
2020-07-06 23:50 ` + vfs-xattr-mm-shmem-kernfs-release-simple-xattr-entry-in-a-right-way.patch added to -mm tree Andrew Morton
2020-07-07 19:25 ` + fs-minix-check-return-value-of-sb_getblk.patch " Andrew Morton
2020-07-07 19:25 ` + fs-minix-dont-allow-getting-deleted-inodes.patch " Andrew Morton
2020-07-07 19:25 ` + fs-minix-reject-too-large-maximum-file-size.patch " Andrew Morton
2020-07-07 22:18 ` + mm-memcg-fix-refcount-error-while-moving-and-swapping.patch " Andrew Morton
2020-07-10  0:23 ` + mm-close-race-between-munmap-and-expand_upwards-downwards.patch " Andrew Morton
2020-07-10 23:27 ` [to-be-updated] mm-hugetlb-avoid-hardcoding-while-checking-if-cma-is-enable.patch removed from " Andrew Morton
2020-07-10 23:29 ` + mm-hugetlb-avoid-hardcoding-while-checking-if-cma-is-enabled.patch added to " Andrew Morton
2020-07-16 21:28 ` + mm-memcg-slab-fix-memory-leak-at-non-root-kmem_cache-destroy.patch " Andrew Morton
2020-07-21 20:49 ` + fork-silence-a-false-postive-warning-in-__mmdrop.patch " Andrew Morton
2020-07-21 20:57 ` + io-mapping-indicate-mapping-failure.patch " Andrew Morton
2020-07-21 21:06 ` + mm-fix-kthread_use_mm-vs-tlb-invalidate.patch " Andrew Morton
2020-07-24  1:09 ` + mm-page_alloc-fix-memalloc_nocma_save-restore-apis.patch " Andrew Morton
2020-07-24  2:53 ` + khugepaged-fix-null-pointer-dereference-due-to-race.patch " Andrew Morton

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=20200703221524.H3lijT4I2%akpm@linux-foundation.org \
    --to=akpm@linux-foundation.org \
    --cc=Jonathan.Cameron@huawei.com \
    --cc=andreas.schaufler@gmx.de \
    --cc=aslan@fb.com \
    --cc=guro@fb.com \
    --cc=js1304@gmail.com \
    --cc=linux-mm@kvack.org \
    --cc=mhocko@kernel.org \
    --cc=mike.kravetz@oracle.com \
    --cc=mm-commits@vger.kernel.org \
    --cc=riel@surriel.com \
    --cc=robin.murphy@arm.com \
    --cc=song.bao.hua@hisilicon.com \
    --cc=stable@vger.kernel.org \
    --cc=torvalds@linux-foundation.org \
    /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).