Skip to content

Commit 86cdb46

Browse files
Naoya Horiguchitorvalds
authored andcommitted
mm: prepare to remove /proc/sys/vm/hugepages_treat_as_movable
Now hugepage migration is enabled, although restricted on pmd-based hugepages for now (due to lack of testing.) So we should allocate migratable hugepages from ZONE_MOVABLE if possible. This patch makes GFP flags in hugepage allocation dependent on migration support, not only the value of hugepages_treat_as_movable. It provides no change on the behavior for architectures which do not support hugepage migration, Signed-off-by: Naoya Horiguchi <n-horiguchi@ah.jp.nec.com> Acked-by: Andi Kleen <ak@linux.intel.com> Reviewed-by: Wanpeng Li <liwanp@linux.vnet.ibm.com> Cc: Hillf Danton <dhillf@gmail.com> Cc: Mel Gorman <mgorman@suse.de> Cc: Hugh Dickins <hughd@google.com> Cc: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com> Cc: Michal Hocko <mhocko@suse.cz> Cc: Rik van Riel <riel@redhat.com> Cc: "Aneesh Kumar K.V" <aneesh.kumar@linux.vnet.ibm.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 83467ef commit 86cdb46

3 files changed

Lines changed: 34 additions & 30 deletions

File tree

‎Documentation/sysctl/vm.txt‎

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -200,17 +200,25 @@ fragmentation index is <= extfrag_threshold. The default value is 500.
200200

201201
hugepages_treat_as_movable
202202

203-
This parameter is only useful when kernelcore= is specified at boot time to
204-
create ZONE_MOVABLE for pages that may be reclaimed or migrated. Huge pages
205-
are not movable so are not normally allocated from ZONE_MOVABLE. A non-zero
206-
value written to hugepages_treat_as_movable allows huge pages to be allocated
207-
from ZONE_MOVABLE.
208-
209-
Once enabled, the ZONE_MOVABLE is treated as an area of memory the huge
210-
pages pool can easily grow or shrink within. Assuming that applications are
211-
not running that mlock() a lot of memory, it is likely the huge pages pool
212-
can grow to the size of ZONE_MOVABLE by repeatedly entering the desired value
213-
into nr_hugepages and triggering page reclaim.
203+
This parameter controls whether we can allocate hugepages from ZONE_MOVABLE
204+
or not. If set to non-zero, hugepages can be allocated from ZONE_MOVABLE.
205+
ZONE_MOVABLE is created when kernel boot parameter kernelcore= is specified,
206+
so this parameter has no effect if used without kernelcore=.
207+
208+
Hugepage migration is now available in some situations which depend on the
209+
architecture and/or the hugepage size. If a hugepage supports migration,
210+
allocation from ZONE_MOVABLE is always enabled for the hugepage regardless
211+
of the value of this parameter.
212+
IOW, this parameter affects only non-migratable hugepages.
213+
214+
Assuming that hugepages are not migratable in your system, one usecase of
215+
this parameter is that users can make hugepage pool more extensible by
216+
enabling the allocation from ZONE_MOVABLE. This is because on ZONE_MOVABLE
217+
page reclaim/migration/compaction work more and you can get contiguous
218+
memory more likely. Note that using ZONE_MOVABLE for non-migratable
219+
hugepages can do harm to other features like memory hotremove (because
220+
memory hotremove expects that memory blocks on ZONE_MOVABLE are always
221+
removable,) so it's a trade-off responsible for the users.
214222

215223
==============================================================
216224

‎kernel/sysctl.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1225,7 +1225,7 @@ static struct ctl_table vm_table[] = {
12251225
.data = &hugepages_treat_as_movable,
12261226
.maxlen = sizeof(int),
12271227
.mode = 0644,
1228-
.proc_handler = hugetlb_treat_movable_handler,
1228+
.proc_handler = proc_dointvec,
12291229
},
12301230
{
12311231
.procname = "nr_overcommit_hugepages",

‎mm/hugetlb.c‎

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
#include "internal.h"
3535

3636
const unsigned long hugetlb_zero = 0, hugetlb_infinity = ~0UL;
37-
static gfp_t htlb_alloc_mask = GFP_HIGHUSER;
3837
unsigned long hugepages_treat_as_movable;
3938

4039
int hugetlb_max_hstate __read_mostly;
@@ -539,6 +538,15 @@ static struct page *dequeue_huge_page_node(struct hstate *h, int nid)
539538
return page;
540539
}
541540

541+
/* Movability of hugepages depends on migration support. */
542+
static inline gfp_t htlb_alloc_mask(struct hstate *h)
543+
{
544+
if (hugepages_treat_as_movable || hugepage_migration_support(h))
545+
return GFP_HIGHUSER_MOVABLE;
546+
else
547+
return GFP_HIGHUSER;
548+
}
549+
542550
static struct page *dequeue_huge_page_vma(struct hstate *h,
543551
struct vm_area_struct *vma,
544552
unsigned long address, int avoid_reserve,
@@ -568,11 +576,11 @@ static struct page *dequeue_huge_page_vma(struct hstate *h,
568576
retry_cpuset:
569577
cpuset_mems_cookie = get_mems_allowed();
570578
zonelist = huge_zonelist(vma, address,
571-
htlb_alloc_mask, &mpol, &nodemask);
579+
htlb_alloc_mask(h), &mpol, &nodemask);
572580

573581
for_each_zone_zonelist_nodemask(zone, z, zonelist,
574582
MAX_NR_ZONES - 1, nodemask) {
575-
if (cpuset_zone_allowed_softwall(zone, htlb_alloc_mask)) {
583+
if (cpuset_zone_allowed_softwall(zone, htlb_alloc_mask(h))) {
576584
page = dequeue_huge_page_node(h, zone_to_nid(zone));
577585
if (page) {
578586
if (avoid_reserve)
@@ -738,7 +746,7 @@ static struct page *alloc_fresh_huge_page_node(struct hstate *h, int nid)
738746
return NULL;
739747

740748
page = alloc_pages_exact_node(nid,
741-
htlb_alloc_mask|__GFP_COMP|__GFP_THISNODE|
749+
htlb_alloc_mask(h)|__GFP_COMP|__GFP_THISNODE|
742750
__GFP_REPEAT|__GFP_NOWARN,
743751
huge_page_order(h));
744752
if (page) {
@@ -965,12 +973,12 @@ static struct page *alloc_buddy_huge_page(struct hstate *h, int nid)
965973
spin_unlock(&hugetlb_lock);
966974

967975
if (nid == NUMA_NO_NODE)
968-
page = alloc_pages(htlb_alloc_mask|__GFP_COMP|
976+
page = alloc_pages(htlb_alloc_mask(h)|__GFP_COMP|
969977
__GFP_REPEAT|__GFP_NOWARN,
970978
huge_page_order(h));
971979
else
972980
page = alloc_pages_exact_node(nid,
973-
htlb_alloc_mask|__GFP_COMP|__GFP_THISNODE|
981+
htlb_alloc_mask(h)|__GFP_COMP|__GFP_THISNODE|
974982
__GFP_REPEAT|__GFP_NOWARN, huge_page_order(h));
975983

976984
if (page && arch_prepare_hugepage(page)) {
@@ -2117,18 +2125,6 @@ int hugetlb_mempolicy_sysctl_handler(struct ctl_table *table, int write,
21172125
}
21182126
#endif /* CONFIG_NUMA */
21192127

2120-
int hugetlb_treat_movable_handler(struct ctl_table *table, int write,
2121-
void __user *buffer,
2122-
size_t *length, loff_t *ppos)
2123-
{
2124-
proc_dointvec(table, write, buffer, length, ppos);
2125-
if (hugepages_treat_as_movable)
2126-
htlb_alloc_mask = GFP_HIGHUSER_MOVABLE;
2127-
else
2128-
htlb_alloc_mask = GFP_HIGHUSER;
2129-
return 0;
2130-
}
2131-
21322128
int hugetlb_overcommit_handler(struct ctl_table *table, int write,
21332129
void __user *buffer,
21342130
size_t *length, loff_t *ppos)

0 commit comments

Comments
 (0)