From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.9 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7F188C4742C for ; Thu, 29 Oct 2020 21:37:37 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 133BF20731 for ; Thu, 29 Oct 2020 21:37:37 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=nvidia.com header.i=@nvidia.com header.b="q+Z29RwP" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725852AbgJ2Vhg (ORCPT ); Thu, 29 Oct 2020 17:37:36 -0400 Received: from hqnvemgate25.nvidia.com ([216.228.121.64]:16359 "EHLO hqnvemgate25.nvidia.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725768AbgJ2Vhe (ORCPT ); Thu, 29 Oct 2020 17:37:34 -0400 Received: from hqmail.nvidia.com (Not Verified[216.228.121.13]) by hqnvemgate25.nvidia.com (using TLS: TLSv1.2, AES256-SHA) id ; Thu, 29 Oct 2020 14:31:35 -0700 Received: from [10.2.173.19] (10.124.1.5) by HQMAIL107.nvidia.com (172.20.187.13) with Microsoft SMTP Server (TLS) id 15.0.1473.3; Thu, 29 Oct 2020 21:31:31 +0000 From: Zi Yan To: Yang Shi CC: Andrew Morton , Linux MM , Rik van Riel , Linux Kernel Mailing List , Subject: Re: [PATCH] mm/compaction: count pages and stop correctly during page isolation. Date: Thu, 29 Oct 2020 17:31:28 -0400 X-Mailer: MailMate (1.13.2r5673) Message-ID: In-Reply-To: References: <20201029200435.3386066-1-zi.yan@sent.com> MIME-Version: 1.0 Content-Type: multipart/signed; boundary="=_MailMate_E48FB94F-D7BB-40CF-84AB-4F00F503E0BA_="; micalg=pgp-sha512; protocol="application/pgp-signature" X-Originating-IP: [10.124.1.5] X-ClientProxiedBy: HQMAIL111.nvidia.com (172.20.187.18) To HQMAIL107.nvidia.com (172.20.187.13) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nvidia.com; s=n1; t=1604007095; bh=9ht2UsSGdwrtZKmu61CDCt2PzcmL0GB/I1gfIJxoux8=; h=From:To:CC:Subject:Date:X-Mailer:Message-ID:In-Reply-To: References:MIME-Version:Content-Type:X-Originating-IP: X-ClientProxiedBy; b=q+Z29RwPkHJ+CN5iOQM7wLYO7vggClhrRlOXbl6MDqZve1cOR7f/HIJxJ+QqCatJL boe76OnzwhB/VJeTYtFRrk5Tyo/Qaev+eKGPEr7CX1SUdSXbvPWIRLJOXHCFgPArR9 0pRKWPcgKW9In3OSj5ZfBLiLzlRbs9Y8ql7teYv3E03ZNGo9gJi8b/fKtS6fZiWotS i/ZUoUtr9AK2/9994uwZgsGzgHK/h6iyHDmeFmU/tjItwdbmsNLtXiyOFNqdUdXgU0 FJmL6vRaxlkYCtg6tVTsm4HxGBvo3b1Fr/9Dn1zrGlSQkKS6cTaqjaehfhPyD+WJEn N9UsTnJ8qrkXw== Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org --=_MailMate_E48FB94F-D7BB-40CF-84AB-4F00F503E0BA_= Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On 29 Oct 2020, at 17:14, Yang Shi wrote: > On Thu, Oct 29, 2020 at 1:04 PM Zi Yan wrote: >> >> From: Zi Yan >> >> In isolate_migratepages_block, when cc->alloc_contig is true, we are >> able to isolate compound pages, nr_migratepages and nr_isolated did no= t >> count compound pages correctly, causing us to isolate more pages than = we >> thought. Use thp_nr_pages to count pages. Otherwise, we might be trapp= ed >> in too_many_isolated while loop, since the actual isolated pages can g= o >> up to COMPACT_CLUSTER_MAX*512=3D16384, where COMPACT_CLUSTER_MAX is 32= , > > Is it that easy to run into? 16384 doesn't seem like too many pages, ju= st 64MB. I hit this when I was running oom01 from ltp to test my PUD THP patchset,= which allocates PUD THPs from CMA regions and splits them into PMD THPs due to = memory pressure. I am not sure if it is common that in the upstream kernel PMD T= HPs will be allocated in CMA regions due to allocation fallback. > >> since we stop isolation after cc->nr_migratepages reaches to >> COMPACT_CLUSTER_MAX. >> >> In addition, after we fix the issue above, cc->nr_migratepages could >> never be equal to COMPACT_CLUSTER_MAX if compound pages are isolated, >> thus page isolation could not stop as we intended. Change the isolatio= n >> stop condition to >=3D. > > The fix looks sane to me. Reviewed-by: Yang Shi Thanks. > > Shall you add Fixes tag to commit > 1da2f328fa643bd72197dfed0c655148af31e4eb? And may cc stable. Sure. Fixes: 1da2f328fa64 (=E2=80=9Cmm,thp,compaction,cma: allow THP migration = for CMA allocations=E2=80=9D) stable cc=E2=80=99ed. > >> >> Signed-off-by: Zi Yan >> --- >> mm/compaction.c | 8 ++++---- >> 1 file changed, 4 insertions(+), 4 deletions(-) >> >> diff --git a/mm/compaction.c b/mm/compaction.c >> index ee1f8439369e..0683a4999581 100644 >> --- a/mm/compaction.c >> +++ b/mm/compaction.c >> @@ -1012,8 +1012,8 @@ isolate_migratepages_block(struct compact_contro= l *cc, unsigned long low_pfn, >> >> isolate_success: >> list_add(&page->lru, &cc->migratepages); >> - cc->nr_migratepages++; >> - nr_isolated++; >> + cc->nr_migratepages +=3D thp_nr_pages(page); >> + nr_isolated +=3D thp_nr_pages(page); >> >> /* >> * Avoid isolating too much unless this block is being= >> @@ -1021,7 +1021,7 @@ isolate_migratepages_block(struct compact_contro= l *cc, unsigned long low_pfn, >> * or a lock is contended. For contention, isolate qui= ckly to >> * potentially remove one source of contention. >> */ >> - if (cc->nr_migratepages =3D=3D COMPACT_CLUSTER_MAX && >> + if (cc->nr_migratepages >=3D COMPACT_CLUSTER_MAX && >> !cc->rescan && !cc->contended) { >> ++low_pfn; >> break; >> @@ -1132,7 +1132,7 @@ isolate_migratepages_range(struct compact_contro= l *cc, unsigned long start_pfn, >> if (!pfn) >> break; >> >> - if (cc->nr_migratepages =3D=3D COMPACT_CLUSTER_MAX) >> + if (cc->nr_migratepages >=3D COMPACT_CLUSTER_MAX) >> break; >> } >> >> -- >> 2.28.0 >> >> =E2=80=94 Best Regards, Yan Zi --=_MailMate_E48FB94F-D7BB-40CF-84AB-4F00F503E0BA_= Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQJDBAEBCgAtFiEEh7yFAW3gwjwQ4C9anbJR82th+ooFAl+bNLAPHHppeUBudmlk aWEuY29tAAoJEJ2yUfNrYfqK7rgP/Rz8YR87KeF/sohMCmYD5ok6r7PE4SoNR+OX 88McrpVRKKHfF5LXSHijoSP2/N+lRT+WcPqcU71sfNKl6nSrN+W0fxL473q2WDv0 MvMBbYAL64ZtyIVQRmehjbmn6CCk0wnE5Ni/c+Ba5p4TOURJn+02weYXAHeFUZ55 1peRto9RkYlD0RiefuhDdn5c3WywXdnu3fwNVq3apkBClggZV1OkvVYyFMaaGsp0 YoMGURsqocZ0dClzDHTfqyXLC9OMbLRdMOfNrf8CBZl4hLlw1KXToX8M89kawl1o dLQ4GKS1VkhcqmPjcx/Y2lw/qR2+Kk9/5c4X6tdD8XMrEo7QF/oHW3KoPCCMO4s7 Iur1SD/fMWr5MiTRgMu9nMy3GqCo7uL6KYKY/JvzdheQ+qVGY1aSuiBBErdUpn37 JwJLC2RHfi0v+lCIvsorp/ljemo8GkGy1A6jxCc2lUzOHnpQQpHfuxn+ISTTlQE5 +5QlXO/D8oBTTeopCdsBzCAzuaFgnaWU9MlCh8MFplMVPaGDoY7f7PlB1mPBRHV4 MSGzHLgeWC8MbISJEBYS/ALv2rSiLkf4EM5lDwOkqY8C/EKxfgiZn12PgbTRWOC/ GgL3miQ05yKieD6SZOP5EA/tZaS2Loz7amO7+7fbzVLlzh6Qx5TLRnZBXNDkoudL 4QLPIh4P =E2j7 -----END PGP SIGNATURE----- --=_MailMate_E48FB94F-D7BB-40CF-84AB-4F00F503E0BA_=--