Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753086AbcKYM1v (ORCPT ); Fri, 25 Nov 2016 07:27:51 -0500 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:37595 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1753974AbcKYM1f (ORCPT ); Fri, 25 Nov 2016 07:27:35 -0500 Subject: Re: [PATCH v2 10/12] mm: mempolicy: mbind and migrate_pages support thp migration To: Naoya Horiguchi , linux-mm@kvack.org References: <1478561517-4317-1-git-send-email-n-horiguchi@ah.jp.nec.com> <1478561517-4317-11-git-send-email-n-horiguchi@ah.jp.nec.com> Cc: "Kirill A. Shutemov" , Hugh Dickins , Andrew Morton , Dave Hansen , Andrea Arcangeli , Mel Gorman , Michal Hocko , Vlastimil Babka , Pavel Emelyanov , Zi Yan , Balbir Singh , linux-kernel@vger.kernel.org, Naoya Horiguchi From: Anshuman Khandual Date: Fri, 25 Nov 2016 17:57:20 +0530 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.1.0 MIME-Version: 1.0 In-Reply-To: <1478561517-4317-11-git-send-email-n-horiguchi@ah.jp.nec.com> Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit X-TM-AS-MML: disable X-Content-Scanned: Fidelis XPS MAILER x-cbid: 16112512-0048-0000-0000-000001E3EF5C X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 16112512-0049-0000-0000-0000470E86DC Message-Id: <58382E28.9060706@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:,, definitions=2016-11-25_04:,, signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 suspectscore=0 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1609300000 definitions=main-1611250218 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 3308 Lines: 112 On 11/08/2016 05:01 AM, Naoya Horiguchi wrote: > This patch enables thp migration for mbind(2) and migrate_pages(2). > > Signed-off-by: Naoya Horiguchi > --- > ChangeLog v1 -> v2: > - support pte-mapped and doubly-mapped thp > --- > mm/mempolicy.c | 108 +++++++++++++++++++++++++++++++++++++++++---------------- > 1 file changed, 79 insertions(+), 29 deletions(-) > > diff --git v4.9-rc2-mmotm-2016-10-27-18-27/mm/mempolicy.c v4.9-rc2-mmotm-2016-10-27-18-27_patched/mm/mempolicy.c > index 77d0668..96507ee 100644 > --- v4.9-rc2-mmotm-2016-10-27-18-27/mm/mempolicy.c > +++ v4.9-rc2-mmotm-2016-10-27-18-27_patched/mm/mempolicy.c > @@ -94,6 +94,7 @@ > #include > #include > #include > +#include > > #include > #include > @@ -486,6 +487,49 @@ static inline bool queue_pages_node_check(struct page *page, > return node_isset(nid, *qp->nmask) == !!(flags & MPOL_MF_INVERT); > } > > +static int queue_pages_pmd(pmd_t *pmd, spinlock_t *ptl, unsigned long addr, > + unsigned long end, struct mm_walk *walk) > +{ > + int ret = 0; > + struct page *page; > + struct queue_pages *qp = walk->private; > + unsigned long flags; > + > + if (unlikely(is_pmd_migration_entry(*pmd))) { > + ret = 1; > + goto unlock; > + } > + page = pmd_page(*pmd); > + if (is_huge_zero_page(page)) { > + spin_unlock(ptl); > + __split_huge_pmd(walk->vma, pmd, addr, false, NULL); > + goto out; > + } > + if (!thp_migration_supported()) { > + get_page(page); > + spin_unlock(ptl); > + lock_page(page); > + ret = split_huge_page(page); > + unlock_page(page); > + put_page(page); > + goto out; > + } > + if (queue_pages_node_check(page, qp)) { > + ret = 1; > + goto unlock; > + } > + > + ret = 1; > + flags = qp->flags; > + /* go to thp migration */ > + if (flags & (MPOL_MF_MOVE | MPOL_MF_MOVE_ALL)) > + migrate_page_add(page, qp->pagelist, flags); > +unlock: > + spin_unlock(ptl); > +out: > + return ret; > +} > + > /* > * Scan through pages checking if pages follow certain conditions, > * and move them to the pagelist if they do. > @@ -497,30 +541,15 @@ static int queue_pages_pte_range(pmd_t *pmd, unsigned long addr, > struct page *page; > struct queue_pages *qp = walk->private; > unsigned long flags = qp->flags; > - int nid, ret; > + int ret; > pte_t *pte; > spinlock_t *ptl; > > - if (pmd_trans_huge(*pmd)) { > - ptl = pmd_lock(walk->mm, pmd); > - if (pmd_trans_huge(*pmd)) { > - page = pmd_page(*pmd); > - if (is_huge_zero_page(page)) { > - spin_unlock(ptl); > - __split_huge_pmd(vma, pmd, addr, false, NULL); > - } else { > - get_page(page); > - spin_unlock(ptl); > - lock_page(page); > - ret = split_huge_page(page); > - unlock_page(page); > - put_page(page); > - if (ret) > - return 0; > - } > - } else { > - spin_unlock(ptl); > - } > + ptl = pmd_trans_huge_lock(pmd, vma); > + if (ptl) { > + ret = queue_pages_pmd(pmd, ptl, addr, end, walk); > + if (ret) > + return 0; > } I wonder if we should introduce pte_entry function along with pmd_entry function as we are first looking for trans huge PMDs either for direct addition into the migration list or splitting it before looking for PTEs.