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 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id CDE46CDB474 for ; Tue, 17 Oct 2023 20:42:01 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 18B606B0253; Tue, 17 Oct 2023 16:42:01 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 13C276B0254; Tue, 17 Oct 2023 16:42:01 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0033D6B0255; Tue, 17 Oct 2023 16:42:00 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id E3A6F6B0253 for ; Tue, 17 Oct 2023 16:42:00 -0400 (EDT) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id A5846140E57 for ; Tue, 17 Oct 2023 20:42:00 +0000 (UTC) X-FDA: 81356125200.06.ADEF3A6 Received: from mail-pj1-f45.google.com (mail-pj1-f45.google.com [209.85.216.45]) by imf14.hostedemail.com (Postfix) with ESMTP id E220A10002D for ; Tue, 17 Oct 2023 20:41:58 +0000 (UTC) Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=GC9ZgsW4; spf=pass (imf14.hostedemail.com: domain of shy828301@gmail.com designates 209.85.216.45 as permitted sender) smtp.mailfrom=shy828301@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1697575319; a=rsa-sha256; cv=none; b=RmOKMIUpxM4tDkKe6LLgtzHjBW60z2vsFmubp270+7K405f+RYllFM09tk85t9bdn/+NB6 pBl7IY8nCGhjt1ERo6A8Vjmmq0vXnfMW8Tt3QLAbLk/0uUqTxiNFIjI8GGcLYs7fxxw+lQ f/KnIc1DU4T6P1JoRoOAhapiIq9zoco= ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=GC9ZgsW4; spf=pass (imf14.hostedemail.com: domain of shy828301@gmail.com designates 209.85.216.45 as permitted sender) smtp.mailfrom=shy828301@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1697575318; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=EJopoaNgvivmBcLFBdfIDmzr0qztUwvLw+YT1b0SCdk=; b=HDAHzHDdynbzPW/TYlSasxc85zioazAeKxSlG9zul2dcySeTOq9t0vVR09BCCGxoMIjypv IOycL7tMWqLaDfooDyhMvuqJACiTa5EuR3h380b8i9krexa48lo73yhSSZZNuEusZiTvW0 QbcPFH7Yo+f2qjCqwcTzSkNFiyMM8n0= Received: by mail-pj1-f45.google.com with SMTP id 98e67ed59e1d1-27d1b48e20dso3588787a91.0 for ; Tue, 17 Oct 2023 13:41:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1697575318; x=1698180118; darn=kvack.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=EJopoaNgvivmBcLFBdfIDmzr0qztUwvLw+YT1b0SCdk=; b=GC9ZgsW42MboEndUe08QFSCHFroTlGy2A982tSg+UpZMLfG2AwwW+G0mY4GkCct001 DBLsYygfRGK8NR1WGgGwYjOxlgAHh6HvPLSqjqLGVn4bA04Z8bKhqQWmk5vMFxX9ltnH 0nklvbEVrTqxZ8uDPChsl79hIdSsCw4Zqx007z4fDaGLDFOP7TaohFF4qBg8fgQ3E8DS l+r8vFeQAHmSwEtryhxAD9IP2wSc+jwQ6XcZh6evwPmCcykXhOcuon68FV/8Bx5sHW9P uw+tO6K0jAJ12ibsulhnMX+5as8Jr3SDS31r7AYK6xHrFxqwLvGgOazzIFVhWujIr6S3 bF4Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697575318; x=1698180118; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=EJopoaNgvivmBcLFBdfIDmzr0qztUwvLw+YT1b0SCdk=; b=aYr2sS7h/VrKRFf5kzi8+PvDcHiEvcGOSakDzx0Gds/uw/O8oSgo8tz7P6TdNU82Ww t5x9vDRCbuToW3imHERjw9q87rqy/z8D1AZJbMuIW5qGE0skMYv2GWXxZGzVvPnl9CHb psKESAWR4HDnzWc2SI+V1QpHUKXwiR5+0zAwfXRfr1ylx1IjEVSfM+BFqNImmWRivbUs iDln39wRWkKAxaWR3Qv5Yc25SVjSaAUffStGbdAAVaw13THc6Bu3RsA18XsncKnUjABK LFA7M+zrZrK9uRVoWMheQ9FhVwI4cn91BLvwU0Fct8b02e+JsnLxmHdQBN7Zx0qPB5Gj VlkQ== X-Gm-Message-State: AOJu0YwGV8fE5uCnCc55Svy+LeOt0M+bWruz1v59IZN7TJ5+c08u3OON aAB2rkgRgOp5pKWfz7acD197ueeNAFDFPxFNpys= X-Google-Smtp-Source: AGHT+IFD9sjsz/nxhufOudoMvKUywMmy9QHuwrScNCcoGHBewdqoVyQa/kTgSXcBWHcsJBHcwGAPuhHXu7vEDBwPPOA= X-Received: by 2002:a17:90a:656:b0:27d:a5f6:21da with SMTP id q22-20020a17090a065600b0027da5f621damr3065351pje.16.1697575317589; Tue, 17 Oct 2023 13:41:57 -0700 (PDT) MIME-Version: 1.0 References: <20231016200510.7387-1-vishal.moola@gmail.com> <20231016200510.7387-3-vishal.moola@gmail.com> In-Reply-To: <20231016200510.7387-3-vishal.moola@gmail.com> From: Yang Shi Date: Tue, 17 Oct 2023 13:41:46 -0700 Message-ID: Subject: Re: [PATCH 2/5] mm/khugepaged: Convert hpage_collapse_scan_pmd() to use folios To: "Vishal Moola (Oracle)" Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, akpm@linux-foundation.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: E220A10002D X-Stat-Signature: tr5ehsoosijptipgfn4sfhap5ndiinus X-Rspam-User: X-HE-Tag: 1697575318-121230 X-HE-Meta: U2FsdGVkX18ztCH7bTIPt0dh4HZ/eyQ3qWIbDtZQC4UyKkI9l4YRxjvzpDJtmlFaiG27HHMhczJYOSht06iR4qSqTw7qWb7ZU15UhMu2mrtT963PWyJTKqPFDobEzbhZSrsyY+H+LXX31Sy5bJF6Hwobisqy5jN4theerdetm5CUshqCD4O7S6KkZMQPHgfttDs32gVI/sdK34QaqgIwdfK5p/Vyroc3uILSpB1KH/zSRVuQOTc9gVaiP02foVr2lcmXnWseieEsuybLATEHPMMTk3evE69NDwrzcMyS/Ou49bnaFiz4DjmmJa7E73ecibXf7xL0AMu5i2KQfPDCgcZwzIqz6jLCxL4XAa/x6U6FHQ57NFm3g7bwEHD2qoiQ1zajaOGWVb0I/pgtFLjd4B7PBxivu9pRULGj00Tl2R9Rm/gU6sJq/TlO198X9BsiQCX2sh669iPCT7iUUPxgGoHgfzZUcdVq7Rr1da95Jpk/ymabpDHBOZzPFrQFJ4+alf4RLpQoQQ/WWME1SsOEO1WUasCiNuAPiV6ox8+n43iU6upMknh3yVh05yYSmEd1nkqhhJSNMU4/sSdvBT5S+KjjhncWvozkAGRWJL1RpCLgkW069CMetRVfiDb343f5omtog5M3eCZWy6LTCVne8H0mH/CLtuN7J1RKRaNc3tL1wehdobf19NMYSb4KDjyu4b4qmdJvk2UMjeTk8OSXQ9KIrnVS9gI+gP7J9kGkQBiigfzsmT153gcBPnKIQaOiR/Asxs2u+H0WZcb78I/qekLXXutsTVNEgHD3zqkLNMxljlSujHH+D26n2PkRhUhDp7xWx1Cmq+ttXXm8yLG9Iz8DRbAzpqgIx6s6AbesNt65mYz8KYVOHYlOUwvpXityWsjnEi+2c4wKEzo0fQ7xjiJgMVbofCZ+Rs12QFnBEVXMvMiG7/XczuTb2HlVgFPiCmFIVG6ygAXGFliUMdx L5kSLpXe N7OVrTJsF0IClZyEhYQGoYRTeb71mfHrVhaFi6DF0e/d3DEhq0Bx1QDVg15o+rEHEZWkNv7gENdFtJHYF3J199gsSfrDxGTX198EXQQbkiZxCBcKwLMsH/re4oXbTtQg2AHIzWhmhCVgC1P6rKG2XwRaAfuVkPv7dZxEgK1SZkBWHXql+5FtQNXw4h6A5JZj5imCWqV3NJTTRQkmuNlhMyS8E0b1QfQPH+0QgXbOR3r2fLoEzIWaXqGBcHpjQcfS/7oe7UZpaP0M6f91ZQHndksfcSt4Bk5M1pFwPEPjgRRl7B9+dxrzUSzSLXrZA96Ip7eEOsBhBnoxw3aeOIC+gcFkzHsCCGHiCVQNAJiEJrXCJIzhzMdJu14OGXFklbAOovHqAI5g0HM2C1j32OqnNWZVygRumZog1fUYJDFcmx1os2UcIXUg00qwjwrhxSyIjLrWQaA55P5ZBhn/ZMGePvgBFGjQ3RcJQzEiPVJwI5cfptXU= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Mon, Oct 16, 2023 at 1:06=E2=80=AFPM Vishal Moola (Oracle) wrote: > > Replaces 5 calls to compound_head(), and removes 1466 bytes of kernel > text. > > Previously, to determine if any pte was shared, the page mapcount > corresponding exactly to the pte was checked. This gave us a precise > number of shared ptes. Using folio_estimated_sharers() instead uses > the mapcount of the head page, giving us an estimate for tail page ptes. > > This means if a tail page's mapcount is greater than its head page's > mapcount, folio_estimated_sharers() would be underestimating the number o= f > shared ptes, and vice versa. > > Signed-off-by: Vishal Moola (Oracle) > --- > mm/khugepaged.c | 26 ++++++++++++-------------- > 1 file changed, 12 insertions(+), 14 deletions(-) > > diff --git a/mm/khugepaged.c b/mm/khugepaged.c > index 7a552fe16c92..67aac53b31c8 100644 > --- a/mm/khugepaged.c > +++ b/mm/khugepaged.c > @@ -1245,7 +1245,7 @@ static int hpage_collapse_scan_pmd(struct mm_struct= *mm, > pte_t *pte, *_pte; > int result =3D SCAN_FAIL, referenced =3D 0; > int none_or_zero =3D 0, shared =3D 0; > - struct page *page =3D NULL; > + struct folio *folio =3D NULL; > unsigned long _address; > spinlock_t *ptl; > int node =3D NUMA_NO_NODE, unmapped =3D 0; > @@ -1316,13 +1316,13 @@ static int hpage_collapse_scan_pmd(struct mm_stru= ct *mm, > if (pte_write(pteval)) > writable =3D true; > > - page =3D vm_normal_page(vma, _address, pteval); > - if (unlikely(!page) || unlikely(is_zone_device_page(page)= )) { > + folio =3D vm_normal_folio(vma, _address, pteval); > + if (unlikely(!folio) || unlikely(folio_is_zone_device(fol= io))) { > result =3D SCAN_PAGE_NULL; > goto out_unmap; > } > > - if (page_mapcount(page) > 1) { > + if (folio_estimated_sharers(folio) > 1) { This doesn't look correct. The max_ptes_shared is used to control the cap of shared PTEs. IIRC, folio_estimated_sharers() just reads the mapcount of the head page. If we set max_ptes_shared to 256, and just the head page is shared, but "shared" will return 512 and prevent from collapsing the area even though just one PTE is shared. This breaks the semantics of max_ptes_shared. > ++shared; > if (cc->is_khugepaged && > shared > khugepaged_max_ptes_shared) { > @@ -1332,29 +1332,27 @@ static int hpage_collapse_scan_pmd(struct mm_stru= ct *mm, > } > } > > - page =3D compound_head(page); > - > /* > * Record which node the original page is from and save t= his > * information to cc->node_load[]. > * Khugepaged will allocate hugepage from the node has th= e max > * hit record. > */ > - node =3D page_to_nid(page); > + node =3D folio_nid(folio); > if (hpage_collapse_scan_abort(node, cc)) { > result =3D SCAN_SCAN_ABORT; > goto out_unmap; > } > cc->node_load[node]++; > - if (!PageLRU(page)) { > + if (!folio_test_lru(folio)) { > result =3D SCAN_PAGE_LRU; > goto out_unmap; > } > - if (PageLocked(page)) { > + if (folio_test_locked(folio)) { > result =3D SCAN_PAGE_LOCK; > goto out_unmap; > } > - if (!PageAnon(page)) { > + if (!folio_test_anon(folio)) { > result =3D SCAN_PAGE_ANON; > goto out_unmap; > } > @@ -1369,7 +1367,7 @@ static int hpage_collapse_scan_pmd(struct mm_struct= *mm, > * has excessive GUP pins (i.e. 512). Anyway the same ch= eck > * will be done again later the risk seems low. > */ > - if (!is_refcount_suitable(page)) { > + if (!is_refcount_suitable(&folio->page)) { > result =3D SCAN_PAGE_COUNT; > goto out_unmap; > } > @@ -1379,8 +1377,8 @@ static int hpage_collapse_scan_pmd(struct mm_struct= *mm, > * enough young pte to justify collapsing the page > */ > if (cc->is_khugepaged && > - (pte_young(pteval) || page_is_young(page) || > - PageReferenced(page) || mmu_notifier_test_young(vma-= >vm_mm, > + (pte_young(pteval) || folio_test_young(folio) || > + folio_test_referenced(folio) || mmu_notifier_test_yo= ung(vma->vm_mm, > addr= ess))) > referenced++; > } > @@ -1402,7 +1400,7 @@ static int hpage_collapse_scan_pmd(struct mm_struct= *mm, > *mmap_locked =3D false; > } > out: > - trace_mm_khugepaged_scan_pmd(mm, page, writable, referenced, > + trace_mm_khugepaged_scan_pmd(mm, &folio->page, writable, referenc= ed, > none_or_zero, result, unmapped); > return result; > } > -- > 2.40.1 >