Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp2377613ybv; Fri, 21 Feb 2020 14:31:29 -0800 (PST) X-Google-Smtp-Source: APXvYqyREKqjFN6f2g8sT3SB4qP62Xx1wlBWaCMIwwIZQODFsSdSZoQdf/8bXx2urbTksCs8DWgN X-Received: by 2002:a9d:65da:: with SMTP id z26mr30742866oth.197.1582324288849; Fri, 21 Feb 2020 14:31:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1582324288; cv=none; d=google.com; s=arc-20160816; b=VnZemizIIOTNKHyqzzfM0jMyP8GS3F0N5Uo5aaTidr/XiE3ui9Ngu8QMhuJJax4ZYB aHkt6MVrixgzwc3MaFSk9/D51AB7FYTnqwY0oRtMFAn+rzXMJgyob2Hnfmp6+St42gLx hz/jQH2BAInydUgZVeeqlFt+1xJIykY8+m9QQ8Xm+PQebyNOnTYbsPgtcw/7vRT2Wcwh XViKaT8DJnvclfzi7lVlmeiDb0PdxJWdixUYX4+/dccNNi3e1bY3QHZ8do9smOAHYvB4 4ufmDVxbAqYCG+OZsZsjxkWuuQrhPEKtbycfWDhhXEXExy+pCqfDtubQqzZvJhKElVnb CskQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:dkim-signature:mime-version:references :in-reply-to:message-id:date:subject:cc:to:from; bh=XywVQ4NavmYoVd2KPSSlq8wuG2qzt2sd/INsB7AlKo4=; b=y+MZiVJlB8RAtV5UK9XBC8VlaMgH+psbMUJVD5XeqEYbdMfxp7L4uP8n17XbLWTv6p 8fHGyLOOb2wQwIBgtszYU8VN+7wZfyihdeRbfHk3aV3QdG+yQbB7Dqvtip3im7d+/O0/ Zbq5OU1g78T9ruCQysnaJ8leTWn/0xgQpgldNpTi4FIW2vJ8pLRjvf/hRiz8VC7ufvEq aLSDgShBLeMBPR78s3kOQUJgvl0iQst577glU0l2E0MtydtlNk56mxk4KZOqH3eaTiZo LZctrugXR3dqt4H/o8jKXKdGXIWvuJHyc5yRwPi42ggVilhHo/PTl3jPWjDYule+g4jN E0UQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nvidia.com header.s=n1 header.b=K8OJxhnB; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=nvidia.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i2si2038171otc.130.2020.02.21.14.31.16; Fri, 21 Feb 2020 14:31:28 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@nvidia.com header.s=n1 header.b=K8OJxhnB; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=nvidia.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728722AbgBUWbK (ORCPT + 99 others); Fri, 21 Feb 2020 17:31:10 -0500 Received: from hqnvemgate26.nvidia.com ([216.228.121.65]:6143 "EHLO hqnvemgate26.nvidia.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726802AbgBUWbK (ORCPT ); Fri, 21 Feb 2020 17:31:10 -0500 Received: from hqpgpgate101.nvidia.com (Not Verified[216.228.121.13]) by hqnvemgate26.nvidia.com (using TLS: TLSv1.2, DES-CBC3-SHA) id ; Fri, 21 Feb 2020 14:30:55 -0800 Received: from hqmail.nvidia.com ([172.20.161.6]) by hqpgpgate101.nvidia.com (PGP Universal service); Fri, 21 Feb 2020 14:31:08 -0800 X-PGP-Universal: processed; by hqpgpgate101.nvidia.com on Fri, 21 Feb 2020 14:31:08 -0800 Received: from [10.2.168.89] (10.124.1.5) by HQMAIL107.nvidia.com (172.20.187.13) with Microsoft SMTP Server (TLS) id 15.0.1473.3; Fri, 21 Feb 2020 22:31:07 +0000 From: Zi Yan To: Rik van Riel CC: , , , , , , , , , Subject: Re: [PATCH 2/2] mm,thp,compaction,cma: allow THP migration for CMA allocations Date: Fri, 21 Feb 2020 17:31:05 -0500 X-Mailer: MailMate (1.13.1r5678) Message-ID: In-Reply-To: <3289dc5e6c4c3174999598d8293adf8ed3e93b57.1582321645.git.riel@surriel.com> References: <3289dc5e6c4c3174999598d8293adf8ed3e93b57.1582321645.git.riel@surriel.com> MIME-Version: 1.0 X-Originating-IP: [10.124.1.5] X-ClientProxiedBy: HQMAIL111.nvidia.com (172.20.187.18) To HQMAIL107.nvidia.com (172.20.187.13) Content-Type: multipart/signed; boundary="=_MailMate_134D27D2-AE58-44F8-8819-BA451892FA30_="; micalg=pgp-sha1; protocol="application/pgp-signature" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nvidia.com; s=n1; t=1582324255; bh=XywVQ4NavmYoVd2KPSSlq8wuG2qzt2sd/INsB7AlKo4=; h=X-PGP-Universal:From:To:CC:Subject:Date:X-Mailer:Message-ID: In-Reply-To:References:MIME-Version:X-Originating-IP: X-ClientProxiedBy:Content-Type; b=K8OJxhnB509QELljcqib6w6+KncRpl3YDU9YNgS6YSplMBoRLwrFE6Dl/1uViHxDQ dh+RdvSXlZMhsS2YBPO5IobNpfxVaXLLlcqoDgs/g/o3fNSecL079nCThtsNMkIdLP Gc0T/RhX63Zsd8zQ/HgL6gyY+TBc9znnZ/QE1LIo5x1M8IJ7ZzlNa9V5EHINnqI7of N/tkokZOp+v2+c4nQsJi8xoehJvcYuPVmPbNjxfhEMLrJxFGeyhnAohGQsonz/WRrn 8Vq2Gv9lq5+IJDUznd7XNjVxl1i3rawyc6AsMOhLtWzH/Ww6p4D7fo9kmdbyNQuC91 g7snC8Fg0DrkQ== Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org --=_MailMate_134D27D2-AE58-44F8-8819-BA451892FA30_= Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On 21 Feb 2020, at 16:53, Rik van Riel wrote: > The code to implement THP migrations already exists, and the code > for CMA to clear out a region of memory already exists. > > Only a few small tweaks are needed to allow CMA to move THP memory > when attempting an allocation from alloc_contig_range. > > With these changes, migrating THPs from a CMA area works when > allocating a 1GB hugepage from CMA memory. > > Signed-off-by: Rik van Riel > --- > mm/compaction.c | 16 +++++++++------- > mm/page_alloc.c | 6 ++++-- > 2 files changed, 13 insertions(+), 9 deletions(-) > > diff --git a/mm/compaction.c b/mm/compaction.c > index 672d3c78c6ab..f3e05c91df62 100644 > --- a/mm/compaction.c > +++ b/mm/compaction.c > @@ -894,12 +894,12 @@ isolate_migratepages_block(struct compact_control= *cc, unsigned long low_pfn, > > /* > * Regardless of being on LRU, compound pages such as THP and > - * hugetlbfs are not to be compacted. We can potentially save > - * a lot of iterations if we skip them at once. The check is > - * racy, but we can consider only valid values and the only > - * danger is skipping too much. > + * hugetlbfs are not to be compacted most of the time. We can > + * potentially save a lot of iterations if we skip them at > + * once. The check is racy, but we can consider only valid > + * values and the only danger is skipping too much. > */ Maybe add =E2=80=9Cwe do want to move them when allocating contiguous mem= ory using CMA=E2=80=9D to help people understand the context of using cc->alloc_contig? > - if (PageCompound(page)) { > + if (PageCompound(page) && !cc->alloc_contig) { > const unsigned int order =3D compound_order(page); > > if (likely(order < MAX_ORDER)) > @@ -969,7 +969,7 @@ isolate_migratepages_block(struct compact_control *= cc, unsigned long low_pfn, > * and it's on LRU. It can only be a THP so the order > * is safe to read and it's 0 for tail pages. > */ > - if (unlikely(PageCompound(page))) { > + if (unlikely(PageCompound(page) && !cc->alloc_contig)) { > low_pfn +=3D compound_nr(page) - 1; > goto isolate_fail; > } > @@ -981,7 +981,9 @@ isolate_migratepages_block(struct compact_control *= cc, unsigned long low_pfn, > if (__isolate_lru_page(page, isolate_mode) !=3D 0) > goto isolate_fail; > > - VM_BUG_ON_PAGE(PageCompound(page), page); > + /* The whole page is taken off the LRU; skip the tail pages. */ > + if (PageCompound(page)) > + low_pfn +=3D compound_nr(page) - 1; > > /* Successfully isolated */ > del_page_from_lru_list(page, lruvec, page_lru(page)); > diff --git a/mm/page_alloc.c b/mm/page_alloc.c > index a36736812596..38c8ddfcecc8 100644 > --- a/mm/page_alloc.c > +++ b/mm/page_alloc.c > @@ -8253,14 +8253,16 @@ struct page *has_unmovable_pages(struct zone *z= one, struct page *page, > > /* > * Hugepages are not in LRU lists, but they're movable. > + * THPs are on the LRU, but need to be counted as #small pages. > * We need not scan over tail pages because we don't > * handle each tail page individually in migration. > */ > - if (PageHuge(page)) { > + if (PageTransHuge(page)) { > struct page *head =3D compound_head(page); > unsigned int skip_pages; > > - if (!hugepage_migration_supported(page_hstate(head))) > + if (PageHuge(page) && > + !hugepage_migration_supported(page_hstate(head))) > return page; > > skip_pages =3D compound_nr(head) - (page - head); > -- = > 2.24.1 Everything else looks good to me. Reviewed-by: Zi Yan -- Best Regards, Yan Zi --=_MailMate_134D27D2-AE58-44F8-8819-BA451892FA30_= Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQJDBAEBAgAtFiEEh7yFAW3gwjwQ4C9anbJR82th+ooFAl5QWikPHHppeUBudmlk aWEuY29tAAoJEJ2yUfNrYfqKvl4QAKngAI1velwcxFzzNgTUWA2r0Ay1hH8O0whc ydr/RrC3tj17BZFy9E9VEmngnytvpv9f4VmIWfN5AVcebkjI6MNogqmDcPuyj1VN mss9VdlPYyTkmFQ3xUchlyUV3lBg4xNzmtKCzllLTcXxcNDEB0GGbQBuvVFvcuwQ cl9DNWGQ5ay9spOEX43KGOU2xQQrxeDuALicdRhaD5GYCRHw4uMx5mHZbtefVNNt hUnYRu0p8KrP+1zjDlqxDg5QaSUIQcWDaYKKZ9ViarhrOa9wycntCxbhTamdPjmR kBPY40QXx3t4DWGiuMXGOAsd5UKGAZpuZS1cs/B8At/KDFQXuFJI12TixpbO/xxI /qcw8fKKqvrWO4Up5h2CnpdsM+xp2nLmVxa7ppsXNAHO0IkZ3cLIj23kEgQJzWxU UxkizkhYYD/LwAwqfpOcMjv+tZPZpyv+UQ6nDf8dEVP1TBm0DMrKwSQDCdieLsNM uBC8JZxqjmF2M35q1gb1kPLVGYG5fsnjTYIltXZM2ZtlNIBBZoHzxY3eTL0n09/S tlCDLCJESTjN2fpqcDjrxObgsoyoTerxLqaecOFppG6M/hcJAJrCdRVmKkFsQe8H OPy+QtN0S+IGou0c/2SNfctbV2hCWTYQ8BD438JeiOwF/DRhJZh8r4Zy8riuPQa2 lrFvaQYm =qzsY -----END PGP SIGNATURE----- --=_MailMate_134D27D2-AE58-44F8-8819-BA451892FA30_=--