From patchwork Thu Jan 5 10:18:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Houghton X-Patchwork-Id: 13089657 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 0DD83C3DA7D for ; Thu, 5 Jan 2023 10:19:33 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9B8FC940014; Thu, 5 Jan 2023 05:19:31 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 8F43E940008; Thu, 5 Jan 2023 05:19:31 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 682F8940014; Thu, 5 Jan 2023 05:19:31 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 473E8940008 for ; Thu, 5 Jan 2023 05:19:31 -0500 (EST) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 136AAAB26A for ; Thu, 5 Jan 2023 10:19:31 +0000 (UTC) X-FDA: 80320348542.20.4DBB538 Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.202]) by imf12.hostedemail.com (Postfix) with ESMTP id 7B55C40005 for ; Thu, 5 Jan 2023 10:19:29 +0000 (UTC) Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=d8vpxkw4; spf=pass (imf12.hostedemail.com: domain of 3MKS2YwoKCHceocjpbcojibjjbgZ.Xjhgdips-hhfqVXf.jmb@flex--jthoughton.bounces.google.com designates 209.85.128.202 as permitted sender) smtp.mailfrom=3MKS2YwoKCHceocjpbcojibjjbgZ.Xjhgdips-hhfqVXf.jmb@flex--jthoughton.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1672913969; 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: in-reply-to:in-reply-to:references:references:dkim-signature; bh=6PQiqeYYa8WUfPyd+HQWnupwn9/KSP4leVRdHky4yOM=; b=vEPv/3cUslWCzQzOEEZynAGCXXKd/VOjutjr5iYgbVgumq0GIvW00WWZoMHutknj9/I0AT Lzg6gm6DezaXcMzuTSXeIP3x3P51CroPGo3LVk8apcW6seReplzcGL2fcKTon80WKtm8iK 0TFCNGzeLlpjgJad4DTPv83pIRgmGR8= ARC-Authentication-Results: i=1; imf12.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=d8vpxkw4; spf=pass (imf12.hostedemail.com: domain of 3MKS2YwoKCHceocjpbcojibjjbgZ.Xjhgdips-hhfqVXf.jmb@flex--jthoughton.bounces.google.com designates 209.85.128.202 as permitted sender) smtp.mailfrom=3MKS2YwoKCHceocjpbcojibjjbgZ.Xjhgdips-hhfqVXf.jmb@flex--jthoughton.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1672913969; a=rsa-sha256; cv=none; b=kYOii9bfV/mpCT/0d1VlHb1P7cjuetH4xG6SyvYLHQJi/CpzwpSrBrj9HLGd32ChYkifBG xhZYKLsup7kcyMrdtCXK5kXdMAdLEP204nmd1HtijKxNGDRkTLRfy7qgdydDurZG8+FGgh TVgUKPQkXhX7CP31we5TKKghE5SdOVI= Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-4bdeb1bbeafso12321477b3.4 for ; Thu, 05 Jan 2023 02:19:29 -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=6PQiqeYYa8WUfPyd+HQWnupwn9/KSP4leVRdHky4yOM=; b=d8vpxkw4cTLgxinECDNkHM+FwEcUinhdEQd7152gUdKOFJEIQWa1NKtdQXLphkyKcT bpdH2lMDTgH/beB2g0VRtLMbp+YcroXFdVWLsiB6oveY6i22u5iwTllcBXk4KZYEr5Lx jObYGpas5lPGHqnShPWhNo4LAECP+oEcPhuNZUZ42WhflXI8bNSy0hV3UJuJvQz9gAgU aaKzW0AsLx6ESc+6vZVPFmko4ZGS7CpMbtELN0GU2kUY+xSiGVcH6pE6avyLi3c5Nfa7 BUv7WnFzE7GEtpQgVFx2SZ3xKkQNMHAOjJODDJtAiHOnqYYOeN0dJ26YV8xiaDyNelrQ A/ig== 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=6PQiqeYYa8WUfPyd+HQWnupwn9/KSP4leVRdHky4yOM=; b=knHAIc3/ah7+5U5gzNAa+E9f1KrZrE+WgWAK3MvYTrtgajvoDMHLgRlnnL7WaRNZml u6MXMiKOkJ15+YAhpRio2/hlGJgOrcxKfMgVjh3G9kcndprjGHcYW4Ry2yjA1vfQ5Rzw 7QJFJYo/yTxdujbSt3GtD3GmW99fYxGU+aiKvBAcH/eowtnagKXTov1nVSyvOtsuIn/s l5DYI/KvM8LrmDofwLa4jVMd83gNDdJ6iuP3g9ASfx2mxdSY2Hlw0EmJS/DUALMjf814 suR+p9wBie4KveqaACV/65q7LQJzeANSRCs6d8n8Qgq+MxV6XInKtKzP6FaeoCJz8t2D EZOg== X-Gm-Message-State: AFqh2kqyYg6WQQ9OrSE3kumHUgU39g+ox8cXhlJ/8aerzKV8+zcUGypr BS3LYuajGN6sQiFwc6FRvkBzQdGZLo0HNlGS X-Google-Smtp-Source: AMrXdXuHdxtCjAeXg0wpQsCwfeAOcMgREXgzkYqYmxQ5/aPde2G7xFjeSk9hNA3xk1wNawTqTTGKNIYZYTNmO/5v X-Received: from jthoughton.c.googlers.com ([fda3:e722:ac3:cc00:14:4d90:c0a8:2a4f]) (user=jthoughton job=sendgmr) by 2002:a25:ab26:0:b0:703:481:a16b with SMTP id u35-20020a25ab26000000b007030481a16bmr4722307ybi.301.1672913968726; Thu, 05 Jan 2023 02:19:28 -0800 (PST) Date: Thu, 5 Jan 2023 10:18:21 +0000 In-Reply-To: <20230105101844.1893104-1-jthoughton@google.com> Mime-Version: 1.0 References: <20230105101844.1893104-1-jthoughton@google.com> X-Mailer: git-send-email 2.39.0.314.g84b9a713c41-goog Message-ID: <20230105101844.1893104-24-jthoughton@google.com> Subject: [PATCH 23/46] mm: rmap: make page_vma_mapped_walk callers use pte_order From: James Houghton To: Mike Kravetz , Muchun Song , Peter Xu 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 , Andrew Morton , linux-mm@kvack.org, linux-kernel@vger.kernel.org, James Houghton X-Stat-Signature: 5qha84xt3o7r7krzyxhztjpcjowyu1jq X-Rspam-User: X-Rspamd-Queue-Id: 7B55C40005 X-Rspamd-Server: rspam06 X-HE-Tag: 1672913969-206910 X-HE-Meta: U2FsdGVkX1++gMI1Nb60ZmDyhfs9yuxgZ+NaXVBd0TLl60kttXzD9A11yZA7Rwy5wU55q3//eJlxeh8h9+fO7KNWeY9hA8WFFohvxVkpb9Mi50RzrxyIn/GtWnwBmQ+sbCoqgmeasMUs+9+CW6ETGXV/HrG5mDmNbgu70q8OAr+YM/ABNgNaUxHuYayUt38Aj9GZ8FcRYggAN+RpJeH/3LWWfpY/3+zRGk8U98YRY5ab2lwEEPCt5E9PEp29egCzhtR50ti7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htofXkeV+/qsrjFddBGhtcFGJQIzdTOkO3EtT9WFqiq5Eb7WTyJDGCrgLI2rqn/ZyMHX66iJZd1+qQp4Rcee8H6dbLVxPJh 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: This also updates the callers' hugetlb mapcounting code to handle mapcount properly for subpage-mapped hugetlb pages. Signed-off-by: James Houghton --- mm/migrate.c | 2 +- mm/rmap.c | 17 +++++++++++++---- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/mm/migrate.c b/mm/migrate.c index 832f639fc49a..0062689f4878 100644 --- a/mm/migrate.c +++ b/mm/migrate.c @@ -244,7 +244,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 8a24b90d9531..ff7e6c770b0a 100644 --- a/mm/rmap.c +++ b/mm/rmap.c @@ -1608,7 +1608,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)); @@ -1767,7 +1767,11 @@ 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)) + page_remove_rmap(&folio->page, vma, true); + else + page_remove_rmap(subpage, vma, false); + if (vma->vm_flags & VM_LOCKED) mlock_page_drain_local(); folio_put(folio); @@ -2030,7 +2034,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)); @@ -2122,7 +2126,10 @@ 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)) + page_remove_rmap(&folio->page, vma, true); + else + page_remove_rmap(subpage, vma, false); if (vma->vm_flags & VM_LOCKED) mlock_page_drain_local(); folio_put(folio); @@ -2206,6 +2213,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);