From patchwork Sat Feb 18 00:28:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Houghton X-Patchwork-Id: 58837 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp142998wrn; Fri, 17 Feb 2023 16:31:54 -0800 (PST) X-Google-Smtp-Source: AK7set+OLO93edzgexdcHcBO47tpkxRLHTf71vvP3RDkZnDS9sdF+RhG6/ynyEGmoM1VMXOF1ewB X-Received: by 2002:a17:906:44b:b0:839:74cf:7c4f with SMTP id e11-20020a170906044b00b0083974cf7c4fmr477426eja.8.1676680314828; Fri, 17 Feb 2023 16:31:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676680314; cv=none; d=google.com; s=arc-20160816; b=ebjc9sCmwuvPnPSwKn8LSuiGT3kCe/KcgOWbC91IyiQ0+xq/q/W98NU0xbyV6d1UAw O4puUl2FkYy+nPWwcmXdUcBFIzeVfZJ847H8we7vDcuIqa2286w9x6uCHqnleLPd1fGI NhcjoYntRjoZvGr9vvucjVgXtbavRF31cplSYlt9ZeLo8Nygsw5nSPf3Ng5NFMKPn/Tt isfpSabkfxiUjytD/1Fr247HbHUCV0U0TGZWmw7UoIhFL/HFiuyRfCc3Vbi4AWF0m10f XnUyovTPdP6xGn3S6jx5nZqUyG/gwSwp7gggCqL/h/QkBoEaLzyMWOQL7Qh90HHO3665 uU6g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:dkim-signature; bh=C4SpvvUSe/+H51r29czUV8oyanUNWvkyfpCFhzIRnLk=; b=TWlqDvTPcAoUfLXSvtQT9kG05Fasls4fEWKU/Dc9MrRGrySrw6VbxSuq/JVJCQ+Xj8 LfCqX6GcWD8s8Xo/lPP/GLqmZStu0AHIFj4id8y9P8m26Hqpt6uwQBz0HV1vF0/QFz06 jga83eNBU8b3r0t6f1cXIxKTwi+8VYOiY5cwQQ02jCTQONqokPhl/PnvWNMYa35uo27z Cq3AEam3rLPBuEF8RF+2Otbc5y3X2SlQMeRPNID1682+St48xZloAsCv6EZ0qmH2iSN+ yEajp8v7RGVct7TtWeSvZVUC4h4vQpm52iXhOljyY7pH4aFjRUePzi0a4ypRPl9G0rzv 9nAA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=URp4YrNR; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id v14-20020a17090610ce00b008bd8270048dsi468116ejv.371.2023.02.17.16.31.31; Fri, 17 Feb 2023 16:31:54 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=URp4YrNR; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230246AbjBRAa5 (ORCPT + 99 others); Fri, 17 Feb 2023 19:30:57 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43524 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230124AbjBRA36 (ORCPT ); Fri, 17 Feb 2023 19:29:58 -0500 Received: from mail-yb1-xb49.google.com (mail-yb1-xb49.google.com [IPv6:2607:f8b0:4864:20::b49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A7D6268E64 for ; Fri, 17 Feb 2023 16:29:19 -0800 (PST) Received: by mail-yb1-xb49.google.com with SMTP id 84-20020a251457000000b0091231592671so2246930ybu.1 for ; Fri, 17 Feb 2023 16:29:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=C4SpvvUSe/+H51r29czUV8oyanUNWvkyfpCFhzIRnLk=; b=URp4YrNRsXrEMcz5vF68rwrPTWL0r/1PsOn0iwRwzUv8fGWjA2Zj3WsCDtOHnnEOXI 9xQcdgSYjiC0L8FMkrysuWd8Z4rTcFfESiyb98ZDWB3Rpv8/7b3sLIWRQtcVzhoZSCmY 1q2oSqG9SQQKP9k9222Pkp5CKnK0J5shuyy4KwIs9snSVsRw3F9uu39yYj2MkyXE/1KV b/75TnZWsolWJ9o2Dg5OQzts7dH32JqEhtpz0u50LcpTAXPOuZwDBizDHafxqGuZbm79 w0zdlsUS9tlTAwK9A8se/3bTurakeHRO+WC3ta4JwV799mBHwIfC4VY+Lrp2ra7exXyR sdeQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=C4SpvvUSe/+H51r29czUV8oyanUNWvkyfpCFhzIRnLk=; b=l4nyNGIA82EOLkVfVbGmyZ9oYoEjpM40IK7WRIpknJNFsF/FP9w7aE+RyFdITyxf5H IDuSHPscFo9kfhk9KotlF3KUwEJp2tASZiuxALhCMli0w3MHqpNRrOQyD+ZWkCrQl+32 Bz80GmRAutjWPpyOYFXC/EuWGbWcs4LuEXF8pWq8d/H5XJa1YaOG3KlC0sGZ9ZGXk3ZV qV6OftL5xkUykX+OOCnRryY9EAHXo8eO1IfTf2Crnse9JG1RuhLTCOxOZ71LXjd74sSf ruPZl3aFAOKpDNimYzkPfDkMkZImrgekpJdCx5H9xwcSghzT3qLQKdMtT0bDAWz1+7Oc 5ziA== X-Gm-Message-State: AO0yUKWVmX4X6bypioKQk/qtPd2LB6a34+Q3PaW1GdTUBP56Se3qLf1w 1MR8nUk3Yel4xrM5wNoGvU7rfWnLQcPfv5gn X-Received: from jthoughton.c.googlers.com ([fda3:e722:ac3:cc00:14:4d90:c0a8:2a4f]) (user=jthoughton job=sendgmr) by 2002:a81:ac66:0:b0:52e:ed7f:6e82 with SMTP id z38-20020a81ac66000000b0052eed7f6e82mr257319ywj.9.1676680150801; Fri, 17 Feb 2023 16:29:10 -0800 (PST) Date: Sat, 18 Feb 2023 00:28:00 +0000 In-Reply-To: <20230218002819.1486479-1-jthoughton@google.com> Mime-Version: 1.0 References: <20230218002819.1486479-1-jthoughton@google.com> X-Mailer: git-send-email 2.39.2.637.g21b0678d19-goog Message-ID: <20230218002819.1486479-28-jthoughton@google.com> Subject: [PATCH v2 27/46] mm: rmap: update try_to_{migrate,unmap} to handle mapcount for HGM From: James Houghton To: Mike Kravetz , Muchun Song , Peter Xu , Andrew Morton Cc: David Hildenbrand , David Rientjes , Axel Rasmussen , Mina Almasry , "Zach O'Keefe" , Manish Mishra , Naoya Horiguchi , "Dr . David Alan Gilbert" , "Matthew Wilcox (Oracle)" , Vlastimil Babka , Baolin Wang , Miaohe Lin , Yang Shi , Frank van der Linden , Jiaqi Yan , linux-mm@kvack.org, linux-kernel@vger.kernel.org, James Houghton X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1758126737763579556?= X-GMAIL-MSGID: =?utf-8?q?1758126737763579556?= Make use of the new pvmw->pte_order field to determine the size of the PTE we're unmapping/migrating. Signed-off-by: James Houghton diff --git a/mm/migrate.c b/mm/migrate.c index 9b4a7e75f6e6..616afcc40fdc 100644 --- a/mm/migrate.c +++ b/mm/migrate.c @@ -247,7 +247,7 @@ static bool remove_migration_pte(struct folio *folio, #ifdef CONFIG_HUGETLB_PAGE if (folio_test_hugetlb(folio)) { - unsigned int shift = huge_page_shift(hstate_vma(vma)); + unsigned int shift = pvmw.pte_order + PAGE_SHIFT; pte = arch_make_huge_pte(pte, shift, vma->vm_flags); if (folio_test_anon(folio)) diff --git a/mm/rmap.c b/mm/rmap.c index c010d0af3a82..0a019ae32f04 100644 --- a/mm/rmap.c +++ b/mm/rmap.c @@ -1609,7 +1609,7 @@ static bool try_to_unmap_one(struct folio *folio, struct vm_area_struct *vma, if (PageHWPoison(subpage) && !(flags & TTU_IGNORE_HWPOISON)) { pteval = swp_entry_to_pte(make_hwpoison_entry(subpage)); if (folio_test_hugetlb(folio)) { - hugetlb_count_sub(folio_nr_pages(folio), mm); + hugetlb_count_sub(1UL << pvmw.pte_order, mm); set_huge_pte_at(mm, address, pvmw.pte, pteval); } else { dec_mm_counter(mm, mm_counter(&folio->page)); @@ -1757,7 +1757,13 @@ static bool try_to_unmap_one(struct folio *folio, struct vm_area_struct *vma, * * See Documentation/mm/mmu_notifier.rst */ - page_remove_rmap(subpage, vma, folio_test_hugetlb(folio)); + if (folio_test_hugetlb(folio)) + hugetlb_remove_rmap(subpage, + pvmw.pte_order + PAGE_SHIFT, + hstate_vma(vma), vma); + else + page_remove_rmap(subpage, vma, false); + if (vma->vm_flags & VM_LOCKED) mlock_drain_local(); folio_put(folio); @@ -2020,7 +2026,7 @@ static bool try_to_migrate_one(struct folio *folio, struct vm_area_struct *vma, } else if (PageHWPoison(subpage)) { pteval = swp_entry_to_pte(make_hwpoison_entry(subpage)); if (folio_test_hugetlb(folio)) { - hugetlb_count_sub(folio_nr_pages(folio), mm); + hugetlb_count_sub(1L << pvmw.pte_order, mm); set_huge_pte_at(mm, address, pvmw.pte, pteval); } else { dec_mm_counter(mm, mm_counter(&folio->page)); @@ -2112,7 +2118,12 @@ static bool try_to_migrate_one(struct folio *folio, struct vm_area_struct *vma, * * See Documentation/mm/mmu_notifier.rst */ - page_remove_rmap(subpage, vma, folio_test_hugetlb(folio)); + if (folio_test_hugetlb(folio)) + hugetlb_remove_rmap(subpage, + pvmw.pte_order + PAGE_SHIFT, + hstate_vma(vma), vma); + else + page_remove_rmap(subpage, vma, false); if (vma->vm_flags & VM_LOCKED) mlock_drain_local(); folio_put(folio); @@ -2196,6 +2207,8 @@ static bool page_make_device_exclusive_one(struct folio *folio, args->owner); mmu_notifier_invalidate_range_start(&range); + VM_BUG_ON_FOLIO(folio_test_hugetlb(folio), folio); + while (page_vma_mapped_walk(&pvmw)) { /* Unexpected PMD-mapped THP? */ VM_BUG_ON_FOLIO(!pvmw.pte, folio);