Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S947641AbdDTVCc (ORCPT ); Thu, 20 Apr 2017 17:02:32 -0400 Received: from out3-smtp.messagingengine.com ([66.111.4.27]:35489 "EHLO out3-smtp.messagingengine.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S947559AbdDTVAK (ORCPT ); Thu, 20 Apr 2017 17:00:10 -0400 X-ME-Sender: X-Sasl-enc: fGEseLhiJFKRcMG92opaMD8wh+INcofd6VbMguII3JRU 1492721279 From: Zi Yan To: n-horiguchi@ah.jp.nec.com, kirill.shutemov@linux.intel.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org Cc: akpm@linux-foundation.org, minchan@kernel.org, vbabka@suse.cz, mgorman@techsingularity.net, mhocko@kernel.org, khandual@linux.vnet.ibm.com, zi.yan@cs.rutgers.edu, dnellans@nvidia.com Subject: [PATCH v5 10/11] mm: migrate: move_pages() supports thp migration Date: Thu, 20 Apr 2017 16:47:51 -0400 Message-Id: <20170420204752.79703-11-zi.yan@sent.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170420204752.79703-1-zi.yan@sent.com> References: <20170420204752.79703-1-zi.yan@sent.com> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 3756 Lines: 128 From: Naoya Horiguchi This patch enables thp migration for move_pages(2). Signed-off-by: Naoya Horiguchi ChangeLog: v1 -> v5: - fix page counting Signed-off-by: Zi Yan --- mm/migrate.c | 47 +++++++++++++++++++++++++++++++++-------------- 1 file changed, 33 insertions(+), 14 deletions(-) diff --git a/mm/migrate.c b/mm/migrate.c index bbc856264b69..f7c1a1999c8e 100644 --- a/mm/migrate.c +++ b/mm/migrate.c @@ -184,8 +184,8 @@ void putback_movable_pages(struct list_head *l) put_page(page); } else { putback_lru_page(page); - dec_node_page_state(page, NR_ISOLATED_ANON + - page_is_file_cache(page)); + mod_node_page_state(page_pgdat(page), NR_ISOLATED_ANON + + page_is_file_cache(page), -hpage_nr_pages(page)); } } } @@ -1141,8 +1141,8 @@ static ICE_noinline int unmap_and_move(new_page_t get_new_page, * as __PageMovable */ if (likely(!__PageMovable(page))) - dec_node_page_state(page, NR_ISOLATED_ANON + - page_is_file_cache(page)); + mod_node_page_state(page_pgdat(page), NR_ISOLATED_ANON + + page_is_file_cache(page), -hpage_nr_pages(page)); } /* @@ -1159,7 +1159,7 @@ static ICE_noinline int unmap_and_move(new_page_t get_new_page, * it's how HWPoison flag works at the moment. */ if (!test_set_page_hwpoison(page)) - num_poisoned_pages_inc(); + num_poisoned_pages_add(hpage_nr_pages(page)); } } else { if (rc != -EAGAIN) { @@ -1414,7 +1414,17 @@ static struct page *new_page_node(struct page *p, unsigned long private, if (PageHuge(p)) return alloc_huge_page_node(page_hstate(compound_head(p)), pm->node); - else + else if (thp_migration_supported() && PageTransHuge(p)) { + struct page *thp; + + thp = alloc_pages_node(pm->node, + (GFP_TRANSHUGE | __GFP_THISNODE) & ~__GFP_RECLAIM, + HPAGE_PMD_ORDER); + if (!thp) + return NULL; + prep_transhuge_page(thp); + return thp; + } else return __alloc_pages_node(pm->node, GFP_HIGHUSER_MOVABLE | __GFP_THISNODE, 0); } @@ -1441,6 +1451,8 @@ static int do_move_page_to_node_array(struct mm_struct *mm, for (pp = pm; pp->node != MAX_NUMNODES; pp++) { struct vm_area_struct *vma; struct page *page; + struct page *head; + unsigned int follflags; err = -EFAULT; vma = find_vma(mm, pp->addr); @@ -1448,8 +1460,10 @@ static int do_move_page_to_node_array(struct mm_struct *mm, goto set_status; /* FOLL_DUMP to ignore special (like zero) pages */ - page = follow_page(vma, pp->addr, - FOLL_GET | FOLL_SPLIT | FOLL_DUMP); + follflags = FOLL_GET | FOLL_DUMP; + if (!thp_migration_supported()) + follflags |= FOLL_SPLIT; + page = follow_page(vma, pp->addr, follflags); err = PTR_ERR(page); if (IS_ERR(page)) @@ -1459,7 +1473,6 @@ static int do_move_page_to_node_array(struct mm_struct *mm, if (!page) goto set_status; - pp->page = page; err = page_to_nid(page); if (err == pp->node) @@ -1474,16 +1487,22 @@ static int do_move_page_to_node_array(struct mm_struct *mm, goto put_and_set; if (PageHuge(page)) { - if (PageHead(page)) + if (PageHead(page)) { isolate_huge_page(page, &pagelist); + err = 0; + pp->page = page; + } goto put_and_set; } - err = isolate_lru_page(page); + pp->page = compound_head(page); + head = compound_head(page); + err = isolate_lru_page(head); if (!err) { - list_add_tail(&page->lru, &pagelist); - inc_node_page_state(page, NR_ISOLATED_ANON + - page_is_file_cache(page)); + list_add_tail(&head->lru, &pagelist); + mod_node_page_state(page_pgdat(head), + NR_ISOLATED_ANON + page_is_file_cache(head), + hpage_nr_pages(head)); } put_and_set: /* -- 2.11.0