From: Mike Kravetz <mike.kravetz@oracle.com>
To: linux-mm@kvack.org, linux-kernel@vger.kernel.org
Cc: David Hildenbrand <david@redhat.com>,
Michal Hocko <mhocko@suse.com>,
Oscar Salvador <osalvador@suse.de>, Zi Yan <ziy@nvidia.com>,
David Rientjes <rientjes@google.com>,
Andrew Morton <akpm@linux-foundation.org>,
Mike Kravetz <mike.kravetz@oracle.com>
Subject: [RFC PATCH 3/3] hugetlb: add hugetlb demote page support
Date: Mon, 8 Mar 2021 16:18:55 -0800 [thread overview]
Message-ID: <20210309001855.142453-4-mike.kravetz@oracle.com> (raw)
In-Reply-To: <20210309001855.142453-1-mike.kravetz@oracle.com>
Demote page functionality will split a huge page into a number of huge
pages of a smaller size. For example, on x86 a 1GB huge page can be
demoted into 512 2M huge pages. Demotion is done 'in place' by simply
splitting the huge page.
Signed-off-by: Mike Kravetz <mike.kravetz@oracle.com>
---
mm/hugetlb.c | 61 +++++++++++++++++++++++++++++++++++++++++++++++++---
1 file changed, 58 insertions(+), 3 deletions(-)
diff --git a/mm/hugetlb.c b/mm/hugetlb.c
index 0c29b7d0d469..33b0d8778551 100644
--- a/mm/hugetlb.c
+++ b/mm/hugetlb.c
@@ -2744,17 +2744,72 @@ static int set_max_huge_pages(struct hstate *h, unsigned long count, int nid,
return 0;
}
+static int demote_free_huge_page(struct hstate *h, struct page *page)
+{
+ int i, nid = page_to_nid(page);
+ struct hstate *target_hstate;
+ bool cma_page = HPageCma(page);
+
+ target_hstate = size_to_hstate(PAGE_SIZE << h->demote_order);
+
+ ClearHPageFreed(page);
+ list_del(&page->lru);
+ h->free_huge_pages--;
+ h->free_huge_pages_node[nid]--;
+ h->nr_huge_pages--;
+ h->nr_huge_pages_node[nid]--;
+ set_page_refcounted(page);
+ set_compound_page_dtor(page, NULL_COMPOUND_DTOR);
+ spin_unlock(&hugetlb_lock);
+
+ /*
+ * Note for future:
+ * When support for reducing vmemmap of huge pages is added, we
+ * will need to allocate vmemmap pages here and could fail.
+ */
+ destroy_compound_gigantic_page(page, huge_page_order(h));
+
+ for (i = 0; i < pages_per_huge_page(h);
+ i += pages_per_huge_page(target_hstate)) {
+ /*
+ * Explicitly use prep_compound_gigantic_page if demoting
+ * a page allocated from CMA so that TAIL_MAPPING is not
+ * set in tail pages. The CMA code does not expect this.
+ */
+ if (cma_page)
+ prep_compound_gigantic_page(page + i,
+ target_hstate->order);
+ else
+ prep_compound_huge_page(page + i, target_hstate->order);
+ prep_new_huge_page(target_hstate, page + i, nid);
+ if (cma_page)
+ SetHPageCma(page + i);
+ put_page(page + i);
+ }
+
+ spin_lock(&hugetlb_lock);
+ return 0;
+}
+
static int demote_pool_huge_page(struct hstate *h, nodemask_t *nodes_allowed)
{
+ int nr_nodes, node;
+ struct page *page;
int rc = 0;
/* If no demote order, free to buddy */
if (!h->demote_order)
return free_pool_huge_page(h, nodes_allowed, 0);
- /*
- * TODO - demote fucntionality will be added in subsequent patch
- */
+ for_each_node_mask_to_free(h, nr_nodes, node, nodes_allowed) {
+ if (!list_empty(&h->hugepage_freelists[node])) {
+ page = list_entry(h->hugepage_freelists[node].next,
+ struct page, lru);
+ rc = !demote_free_huge_page(h, page);
+ break;
+ }
+ }
+
return rc;
}
--
2.29.2
next prev parent reply other threads:[~2021-03-09 0:20 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-03-09 0:18 [RFC PATCH 0/3] hugetlb: add demote/split page functionality Mike Kravetz
2021-03-09 0:18 ` [RFC PATCH 1/3] hugetlb: add demote hugetlb page sysfs interfaces Mike Kravetz
2021-03-09 0:18 ` [RFC PATCH 2/3] hugetlb: add HPageCma flag and code to free non-gigantic pages in CMA Mike Kravetz
2021-03-09 0:18 ` Mike Kravetz [this message]
2021-03-09 9:01 ` [RFC PATCH 0/3] hugetlb: add demote/split page functionality David Hildenbrand
2021-03-09 17:11 ` Mike Kravetz
2021-03-09 17:50 ` David Hildenbrand
2021-03-09 18:21 ` Mike Kravetz
2021-03-09 19:01 ` David Hildenbrand
2021-03-10 15:58 ` Oscar Salvador
2021-03-10 16:23 ` Michal Hocko
2021-03-10 16:46 ` Zi Yan
2021-03-10 17:05 ` Michal Hocko
2021-03-10 17:36 ` Zi Yan
2021-03-10 19:56 ` Mike Kravetz
2021-03-10 19:45 ` Mike Kravetz
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=20210309001855.142453-4-mike.kravetz@oracle.com \
--to=mike.kravetz@oracle.com \
--cc=akpm@linux-foundation.org \
--cc=david@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=mhocko@suse.com \
--cc=osalvador@suse.de \
--cc=rientjes@google.com \
--cc=ziy@nvidia.com \
/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).