From: "Liam R. Howlett" <Liam.Howlett@Oracle.com>
To: linux-mm@kvack.org
Cc: akpm@linux-foundation.org, mhocko@suse.com,
n-horiguchi@ah.jp.nec.com, mike.kravetz@Oracle.com,
aneesh.kumar@linux.vnet.ibm.com, khandual@linux.vnet.ibm.com,
punit.agrawal@arm.com, arnd@arndb.de, gerald.schaefer@de.ibm.com,
aarcange@redhat.com, oleg@redhat.com,
penguin-kernel@I-love.SAKURA.ne.jp, mingo@kernel.org,
kirill.shutemov@linux.intel.com, vdavydov.dev@gmail.com,
willy@infradead.org
Subject: [RFC PATCH 1/1] mm/hugetlb mm/oom_kill: Add support for reclaiming hugepages on OOM events.
Date: Thu, 27 Jul 2017 14:02:36 -0400 [thread overview]
Message-ID: <20170727180236.6175-2-Liam.Howlett@Oracle.com> (raw)
In-Reply-To: <20170727180236.6175-1-Liam.Howlett@Oracle.com>
When a system runs out of memory it may be desirable to reclaim
unreserved hugepages. This situation arises when a correctly configured
system has a memory failure and takes corrective action of rebooting and
removing the memory from the memory pool results in a system failing to
boot. With this change, the out of memory handler is able to reclaim
any pages that are free and not reserved.
Signed-off-by: Liam R. Howlett <Liam.Howlett@Oracle.com>
---
include/linux/hugetlb.h | 1 +
mm/hugetlb.c | 35 +++++++++++++++++++++++++++++++++++
mm/oom_kill.c | 8 ++++++++
3 files changed, 44 insertions(+)
diff --git a/include/linux/hugetlb.h b/include/linux/hugetlb.h
index 8d9fe131a240..20e5729b9e9a 100644
--- a/include/linux/hugetlb.h
+++ b/include/linux/hugetlb.h
@@ -470,6 +470,7 @@ static inline pgoff_t basepage_index(struct page *page)
}
extern int dissolve_free_huge_page(struct page *page);
+extern unsigned long decrease_free_hugepages(nodemask_t *nodes);
extern int dissolve_free_huge_pages(unsigned long start_pfn,
unsigned long end_pfn);
static inline bool hugepage_migration_supported(struct hstate *h)
diff --git a/mm/hugetlb.c b/mm/hugetlb.c
index bc48ee783dd9..00a0e08b96c5 100644
--- a/mm/hugetlb.c
+++ b/mm/hugetlb.c
@@ -1454,6 +1454,41 @@ static int free_pool_huge_page(struct hstate *h, nodemask_t *nodes_allowed,
}
/*
+ * Decrement free hugepages. Used by oom kill to avoid killing a task if
+ * there is free huge pages that can be used instead.
+ * Returns the number of bytes reclaimed from hugepages
+ */
+#define CONFIG_HUGETLB_PAGE_OOM
+unsigned long decrease_free_hugepages(nodemask_t *nodes)
+{
+#ifdef CONFIG_HUGETLB_PAGE_OOM
+ struct hstate *h;
+ unsigned long ret = 0;
+
+ spin_lock(&hugetlb_lock);
+ for_each_hstate(h) {
+ if (h->free_huge_pages > h->resv_huge_pages) {
+ char buf[32];
+
+ memfmt(buf, huge_page_size(h));
+ ret = free_pool_huge_page(h, nodes ?
+ nodes : &node_online_map, 0);
+ pr_warn("HugeTLB: Reclaiming %lu hugepage(s) of page size %s\n",
+ ret, buf);
+ ret *= huge_page_size(h);
+ goto found;
+ }
+ }
+
+found:
+ spin_unlock(&hugetlb_lock);
+ return ret;
+#else
+ return 0;
+#endif /* CONFIG_HUGETLB_PAGE_OOM */
+}
+
+/*
* Dissolve a given free hugepage into free buddy pages. This function does
* nothing for in-use (including surplus) hugepages. Returns -EBUSY if the
* number of free hugepages would be reduced below the number of reserved
diff --git a/mm/oom_kill.c b/mm/oom_kill.c
index 9e8b4f030c1c..0a42f6d7d253 100644
--- a/mm/oom_kill.c
+++ b/mm/oom_kill.c
@@ -40,6 +40,7 @@
#include <linux/ratelimit.h>
#include <linux/kthread.h>
#include <linux/init.h>
+#include <linux/hugetlb.h>
#include <asm/tlb.h>
#include "internal.h"
@@ -1044,6 +1045,13 @@ bool out_of_memory(struct oom_control *oc)
return true;
}
+ /* Reclaim a free, unreserved hugepage. */
+ freed = decrease_free_hugepages(oc->nodemask);
+ if (freed != 0) {
+ pr_err("Out of memory: Reclaimed %lu from HugeTLB\n", freed);
+ return true;
+ }
+
select_bad_process(oc);
/* Found nothing?!?! Either we hang forever, or we panic. */
if (!oc->chosen && !is_sysrq_oom(oc) && !is_memcg_oom(oc)) {
--
2.13.0.90.g1eb437020
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
next prev parent reply other threads:[~2017-07-27 18:03 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-07-27 18:02 [RFC PATCH 0/1] oom support for reclaiming of hugepages Liam R. Howlett
2017-07-27 18:02 ` Liam R. Howlett [this message]
2017-07-28 6:46 ` [RFC PATCH 1/1] mm/hugetlb mm/oom_kill: Add support for reclaiming hugepages on OOM events Michal Hocko
2017-07-28 11:33 ` Kirill A. Shutemov
2017-07-28 12:23 ` Michal Hocko
2017-07-28 12:44 ` Michal Hocko
2017-07-29 1:56 ` Liam R. Howlett
2017-07-31 9:10 ` Michal Hocko
2017-07-31 13:56 ` Liam R. Howlett
2017-07-31 14:08 ` Michal Hocko
2017-07-31 14:37 ` Matthew Wilcox
2017-07-31 14:49 ` Michal Hocko
2017-08-01 1:25 ` Liam R. Howlett
2017-08-01 8:28 ` Michal Hocko
2017-08-01 1:11 ` Liam R. Howlett
2017-08-01 8:29 ` Michal Hocko
2017-08-01 14:41 ` Liam R. Howlett
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=20170727180236.6175-2-Liam.Howlett@Oracle.com \
--to=liam.howlett@oracle.com \
--cc=aarcange@redhat.com \
--cc=akpm@linux-foundation.org \
--cc=aneesh.kumar@linux.vnet.ibm.com \
--cc=arnd@arndb.de \
--cc=gerald.schaefer@de.ibm.com \
--cc=khandual@linux.vnet.ibm.com \
--cc=kirill.shutemov@linux.intel.com \
--cc=linux-mm@kvack.org \
--cc=mhocko@suse.com \
--cc=mike.kravetz@Oracle.com \
--cc=mingo@kernel.org \
--cc=n-horiguchi@ah.jp.nec.com \
--cc=oleg@redhat.com \
--cc=penguin-kernel@I-love.SAKURA.ne.jp \
--cc=punit.agrawal@arm.com \
--cc=vdavydov.dev@gmail.com \
--cc=willy@infradead.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