Received: by 2002:a05:7412:d8a:b0:e2:908c:2ebd with SMTP id b10csp3403192rdg; Tue, 17 Oct 2023 13:42:12 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHS1rFbnSP9J6ZwzMIstWyumvMJcbPvXrFETbJhEf71XnRdvF20WIOPQWUXtfyvjJMhFC9g X-Received: by 2002:a05:6a00:2283:b0:6be:2ace:deb8 with SMTP id f3-20020a056a00228300b006be2acedeb8mr3830562pfe.20.1697575331718; Tue, 17 Oct 2023 13:42:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697575331; cv=none; d=google.com; s=arc-20160816; b=uRtq45weVfa8s/GwZKK5v8Whs8d+MuUtRLn9R64Hn5cmhNFntNXX4mh2WmTHAtV4pz 0ttzFsnvmMVpn3pKLjCXDSmjcj1fmQG6p41G98tnzoyLZSkoaoi4HVE81gw/+yso50ZX Vx2zWos88qV6RRvY3CtQvY4PPu57pIS2UZcLgiQeraApCy0y3EDNrF3+KaZ8ZUOMmiIA +VuhRk1HxiYDz1+cNXKi9IeJfxhmzuljNfYF5lW0oSjDz/jUPUfQjd92PqU1J/naXHBB HITAb2WzS9UeWCMGokf1ifY5uADaYtybRmqFhOUm2mB4IRpmUimUjcU/eBC0hV8e2VIg 8uTQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=EJopoaNgvivmBcLFBdfIDmzr0qztUwvLw+YT1b0SCdk=; fh=LOC492lplOqC4GkaMZEta4CHkilCnlhS9LUDSBPxgEk=; b=hDjqt1fkHzyCnlYG56bkHCsoxhTk+hEq1gejh/yNIlEvp8Ap7X/5cbA6RhtgVdJxLW NNgFDJvbXvnB0HzpDpDQx5RsjxpjekCtbRMxsOOpl0EGTmIVSDOm58BdkhOdxW6L54LS 16gDxm0X7+YEwbDRuTexhNoUofs8Sgheb+3eV009UXAqBFfDIlBJBGOkb5AFxQJjue6v fPUUvNCv8wnEJmuPr5776B6PWAug7O3nQ+RlqIcck0YSfZ7MqcQIV7uW2gCrV+oFYOQF Z5WHMvNdc8DNmqLYYtjxEukd5phK44qB0vNFHrr/BDnAJxerGsS844+5Bp/Z2MgvJXYJ N9fg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=lzTCnrIV; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from howler.vger.email (howler.vger.email. [23.128.96.34]) by mx.google.com with ESMTPS id d3-20020a056a0024c300b006bd66ce21d9si2456956pfv.322.2023.10.17.13.42.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Oct 2023 13:42:11 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) client-ip=23.128.96.34; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=lzTCnrIV; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id 44CB080CBDF0; Tue, 17 Oct 2023 13:42:09 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344254AbjJQUmB (ORCPT + 99 others); Tue, 17 Oct 2023 16:42:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49642 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231149AbjJQUl7 (ORCPT ); Tue, 17 Oct 2023 16:41:59 -0400 Received: from mail-pg1-x534.google.com (mail-pg1-x534.google.com [IPv6:2607:f8b0:4864:20::534]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4085BC4 for ; Tue, 17 Oct 2023 13:41:58 -0700 (PDT) Received: by mail-pg1-x534.google.com with SMTP id 41be03b00d2f7-5aa7172bafdso2966660a12.1 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=vger.kernel.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=lzTCnrIVqnUPlKzDsIYut08kaYCo6zoX+vO+YTCB/g4qLPPcythr4JUfkgtztmB2r5 1aKj44z2iWf7lxby+hDPqBPl74zJaAhRmpFue+OxXqDoYnmCePTxEwRyeR07h3q5HMzM smHxxfjGMaQiV6YW2HPVlLF92Vmp48FNf6pCcZVYPYtwNQmAfrDx7f3PtY9ld/fbOgxm G5/LR3QYE/OeEF6NbOyI7kUDlIw4H3p+0bZWtQWqlRl6CsFz+0LJ2qlmdQ+M3JZMgZ1h /K4QQkGdqk6zvL9X1v9zeej9MENgzUCp4LWH6lqL6tnUhzZwv6nHE8L0pTl7XGjDjcUS J3og== 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=lOFmGOC7TJsZSgFFvnUTLio3yLIiqq4jzDEKhX8niFFrixGjdl2r5SPV5EpAdJxnVJ Kry6WCqcaXAqLv/QDhSY0IA4sX0AhmVtgIlepnTp2mYXikFwOTlMBSTww8g7EQkwNOQ4 g7nY7FOLlhT2iNiRoWgtyjeMzBBLkOlE5zVyJFi8TxxaR5J/GyN5+AfMcYA/iA95Ooy/ uQ978umBE1afSZiIK/LXk2Bp59Jw6yc+GGNyAg2xTeuYFPw83p2SYJKrjH/7uarxsQ+C /BVfT9yzinqOAm5yUAQxWf70WqE9fzTSC5ioaA3uA93SWBykmKeA8wMdR6le2gHIfZIg CXjg== X-Gm-Message-State: AOJu0YwO/O257LHeI7C1ZiMaMkhaUnlVm/U2sUl6b+7y7bXvQx/HJOcV wkqC6MMnS7a5gImQfgefavxnvF16cX9K+7ue7ng13y8y 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-Spam-Status: No, score=-0.6 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on howler.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (howler.vger.email [0.0.0.0]); Tue, 17 Oct 2023 13:42:09 -0700 (PDT) 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 >