From patchwork Sat Feb 18 00:27:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Houghton X-Patchwork-Id: 13145371 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 06AD3C05027 for ; Sat, 18 Feb 2023 00:28:56 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 45BE2280001; Fri, 17 Feb 2023 19:28:51 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 3E50C6B007D; Fri, 17 Feb 2023 19:28:51 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 285BC280001; Fri, 17 Feb 2023 19:28:51 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 1748E6B007B for ; Fri, 17 Feb 2023 19:28:51 -0500 (EST) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id DDE3B80723 for ; Sat, 18 Feb 2023 00:28:50 +0000 (UTC) X-FDA: 80478527220.18.C96F4E3 Received: from mail-yb1-f202.google.com (mail-yb1-f202.google.com [209.85.219.202]) by imf21.hostedemail.com (Postfix) with ESMTP id 244231C0014 for ; Sat, 18 Feb 2023 00:28:48 +0000 (UTC) Authentication-Results: imf21.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=UvLBkxS6; spf=pass (imf21.hostedemail.com: domain of 3wBvwYwoKCN0ISGNTFGSNMFNNFKD.BNLKHMTW-LLJU9BJ.NQF@flex--jthoughton.bounces.google.com designates 209.85.219.202 as permitted sender) smtp.mailfrom=3wBvwYwoKCN0ISGNTFGSNMFNNFKD.BNLKHMTW-LLJU9BJ.NQF@flex--jthoughton.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1676680129; a=rsa-sha256; cv=none; b=jGZyC7tSv2YEoCvfQTkk28tsuPdQ7FoqgDMP5l7FVeFajIFVFwtbhtkP0mCnoehBvnleQd FYUeVBJ0jL0xOf7S0xwp3c3UbCymKxlsPn6YE5E/Hl7ZYTz4PEed26jk1dTdq4DP7zLPE4 rP2Oe/qfE5Q7mN50F92+7P0cNz5YFx4= ARC-Authentication-Results: i=1; imf21.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=UvLBkxS6; spf=pass (imf21.hostedemail.com: domain of 3wBvwYwoKCN0ISGNTFGSNMFNNFKD.BNLKHMTW-LLJU9BJ.NQF@flex--jthoughton.bounces.google.com designates 209.85.219.202 as permitted sender) smtp.mailfrom=3wBvwYwoKCN0ISGNTFGSNMFNNFKD.BNLKHMTW-LLJU9BJ.NQF@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=1676680129; 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=nelWhEWWDb3ok6PYl3fRG2FGkHP98SSg6vQYnhj1QJk=; b=M+oMrrEY1VaT352SCL9L0eB578ey+hW5qzbrI0VzEEfEi2uX2cZQkE6jb52qTGZbRqD/4g yqXDpYAH3Ew+Cwh4jXraAVK+2SYpKBYnznExs8/aqurhLJrqXOx234pXanXfNuYVHTJkWP 5HhEmkPWfHU1oPOeeQoG11KZByKId1c= Received: by mail-yb1-f202.google.com with SMTP id e83-20020a25e756000000b0086349255277so2436361ybh.8 for ; Fri, 17 Feb 2023 16:28:48 -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=nelWhEWWDb3ok6PYl3fRG2FGkHP98SSg6vQYnhj1QJk=; b=UvLBkxS6HWSvm6F/1ZojF9oUJKGMsoR6TJYUH52tIUGTUnHPSS4OjC8ZKXvwZwASAV tHFCfrP/r3B6sftGO2ROO6qyp0hWV5ssCNe8BVzZ/8UYiB4V6Kh8RSM5cqHAivyWBXpO lalg+riEaU3qUCklp3VFoj3s+ykjm2m5yzWRFdOAwMvlFIaPzMq9C6wMUYVDqXxeAYN4 ydi5/oNHHp4Z8bFgiq0SG1+hakJtq3Bas6/hdi8e26/G9KknLRZXzrhTcc3TXa9yzpwQ m8r8Qx+aRsi+iePo4b0oOe0PRXw52ZFZExKevE8Zt1tK+nMw9eyeE3g+fji1JRRzlVBM Sb3g== 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=nelWhEWWDb3ok6PYl3fRG2FGkHP98SSg6vQYnhj1QJk=; b=HGyOSn3cRUjQX4GB5alsLleuWp344A0AHkIytIcGo2j8cFBci54HRGZ7bvDmvu/7Wp OJfqH7IQ2hF6zL2UJojKZegzv9MCHExpxnyWT8DqYH50vsBg1wUZIfC8Poa+ndmo6sTy P1xuW8EbHznSREsY//n7h2HGJnS6cMVSM3f/3Lkby5QpyvUsQ26acD6Hzc8cZ5vc9FFw HzFNoGL1HN+UsibYGWcMshezpWSAhSE/k1kbpkOvD/qTRLRbcl52+ZYJH5Orkssn8Ah1 ppVUrumdeU0eAwE45o4AieuGQxgm4RRJoZPnU20aNg6eArZPDIc8Qjl8FjrHhj+xooKL PbQg== X-Gm-Message-State: AO0yUKVbiUBH2nvQNHvkRx1J+2D/oMdHgfARUOHc+fuCpeX+w3tJZl/F PNGd5Drc8Y7fHMc1VJAOGY/uBcv5FXakfr7d X-Google-Smtp-Source: AK7set/Hqt7/tFdWTqNQyJko4/eRErfrIERd8YtMlK8cdL7HORy0LZ2CmPBJNFYLl26tfN06LjHCnVCVpHyEbeAH X-Received: from jthoughton.c.googlers.com ([fda3:e722:ac3:cc00:14:4d90:c0a8:2a4f]) (user=jthoughton job=sendgmr) by 2002:a81:b705:0:b0:534:d71f:14e6 with SMTP id v5-20020a81b705000000b00534d71f14e6mr53479ywh.9.1676680128284; Fri, 17 Feb 2023 16:28:48 -0800 (PST) Date: Sat, 18 Feb 2023 00:27:38 +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-6-jthoughton@google.com> Subject: [PATCH v2 05/46] rmap: hugetlb: switch from page_dup_file_rmap to page_add_file_rmap 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-Rspam-User: X-Rspamd-Queue-Id: 244231C0014 X-Rspamd-Server: rspam01 X-Stat-Signature: 9jwxuzy6en139ictjx7yafcp59n4d945 X-HE-Tag: 1676680128-893459 X-HE-Meta: U2FsdGVkX196r4F17fUkOM8EG8z70pwb1tcZ1zEOvALRU2MY8smocz4K62iHb1CZJC9CtZPJ4nOo9xzAzDVb9B+dImxMzk+7qUZlDd1kY3LQt+ql22IfcTIQGFJSNx7WjOGRn5kGHizSC80qi+GycZhQ1Djvi8BDC+Cxr6R+DBuJDy8q7TSm+xP6tg74IUA3/03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aaIM+G+Dms5JsIIxafkd15D5/bGVDsGURRAwOJ1xF7s7SDCdLxqK4A/GZ53ucQ7zvkS4y06k5X7O5uXOXnL/B7YwkIwpi247uQu4LruJ4Ew2b6ngHOzBylPmeC3Q2p9w7RanL/W1EG7ahLQqwxOPESNryuoXdxz/L5KS2ypI2ykxH6UBKojt/lIv/io0NfcYHRaLMMhNoFVRISfj7OGnBN9wK/MGdKcCmrI4/j4jmC+0igtCSHYjbQcoEznKX5WJsB01/0GQeT8hwJFHmWbYsr6IgoD5P2sbXrgw9Zcn1u2BkSXEZRHiRC91MwktvU0e8M2rLfXotmrNKvKd9tfo+veqJ1gQ= 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 only applies to file-backed HugeTLB, and it should be a no-op until high-granularity mapping is possible. Also update page_remove_rmap to support the eventual case where !compound && folio_test_hugetlb(). HugeTLB doesn't use LRU or mlock, so we avoid those bits. This also means we don't need to use subpage_mapcount; if we did, it would overflow with only a few mappings. There is still one caller of page_dup_file_rmap left: copy_present_pte, and it is always called with compound=false in this case. Signed-off-by: James Houghton diff --git a/mm/hugetlb.c b/mm/hugetlb.c index 08004371cfed..6c008c9de80e 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -5077,7 +5077,7 @@ int copy_hugetlb_page_range(struct mm_struct *dst, struct mm_struct *src, * sleep during the process. */ if (!PageAnon(ptepage)) { - page_dup_file_rmap(ptepage, true); + page_add_file_rmap(ptepage, src_vma, true); } else if (page_try_dup_anon_rmap(ptepage, true, src_vma)) { pte_t src_pte_old = entry; @@ -5910,7 +5910,7 @@ static vm_fault_t hugetlb_no_page(struct mm_struct *mm, if (anon_rmap) hugepage_add_new_anon_rmap(folio, vma, haddr); else - page_dup_file_rmap(&folio->page, true); + page_add_file_rmap(&folio->page, vma, true); new_pte = make_huge_pte(vma, &folio->page, ((vma->vm_flags & VM_WRITE) && (vma->vm_flags & VM_SHARED))); /* @@ -6301,7 +6301,7 @@ int hugetlb_mcopy_atomic_pte(struct mm_struct *dst_mm, goto out_release_unlock; if (folio_in_pagecache) - page_dup_file_rmap(&folio->page, true); + page_add_file_rmap(&folio->page, dst_vma, true); else hugepage_add_new_anon_rmap(folio, dst_vma, dst_addr); diff --git a/mm/migrate.c b/mm/migrate.c index d3964c414010..b0f87f19b536 100644 --- a/mm/migrate.c +++ b/mm/migrate.c @@ -254,7 +254,7 @@ static bool remove_migration_pte(struct folio *folio, hugepage_add_anon_rmap(new, vma, pvmw.address, rmap_flags); else - page_dup_file_rmap(new, true); + page_add_file_rmap(new, vma, true); set_huge_pte_at(vma->vm_mm, pvmw.address, pvmw.pte, pte); } else #endif diff --git a/mm/rmap.c b/mm/rmap.c index 15ae24585fc4..c010d0af3a82 100644 --- a/mm/rmap.c +++ b/mm/rmap.c @@ -1318,21 +1318,21 @@ void page_add_file_rmap(struct page *page, struct vm_area_struct *vma, int nr = 0, nr_pmdmapped = 0; bool first; - VM_BUG_ON_PAGE(compound && !PageTransHuge(page), page); + VM_BUG_ON_PAGE(compound && !PageTransHuge(page) + && !folio_test_hugetlb(folio), page); /* Is page being mapped by PTE? Is this its first map to be added? */ if (likely(!compound)) { first = atomic_inc_and_test(&page->_mapcount); nr = first; - if (first && folio_test_large(folio)) { + if (first && folio_test_large(folio) + && !folio_test_hugetlb(folio)) { nr = atomic_inc_return_relaxed(mapped); nr = (nr < COMPOUND_MAPPED); } - } else if (folio_test_pmd_mappable(folio)) { - /* That test is redundant: it's for safety or to optimize out */ - + } else { first = atomic_inc_and_test(&folio->_entire_mapcount); - if (first) { + if (first && !folio_test_hugetlb(folio)) { nr = atomic_add_return_relaxed(COMPOUND_MAPPED, mapped); if (likely(nr < COMPOUND_MAPPED + COMPOUND_MAPPED)) { nr_pmdmapped = folio_nr_pages(folio); @@ -1347,6 +1347,9 @@ void page_add_file_rmap(struct page *page, struct vm_area_struct *vma, } } + if (folio_test_hugetlb(folio)) + return; + if (nr_pmdmapped) __lruvec_stat_mod_folio(folio, folio_test_swapbacked(folio) ? NR_SHMEM_PMDMAPPED : NR_FILE_PMDMAPPED, nr_pmdmapped); @@ -1376,8 +1379,7 @@ void page_remove_rmap(struct page *page, struct vm_area_struct *vma, VM_BUG_ON_PAGE(compound && !PageHead(page), page); /* Hugetlb pages are not counted in NR_*MAPPED */ - if (unlikely(folio_test_hugetlb(folio))) { - /* hugetlb pages are always mapped with pmds */ + if (unlikely(folio_test_hugetlb(folio)) && compound) { atomic_dec(&folio->_entire_mapcount); return; } @@ -1386,15 +1388,14 @@ void page_remove_rmap(struct page *page, struct vm_area_struct *vma, if (likely(!compound)) { last = atomic_add_negative(-1, &page->_mapcount); nr = last; - if (last && folio_test_large(folio)) { + if (last && folio_test_large(folio) + && !folio_test_hugetlb(folio)) { nr = atomic_dec_return_relaxed(mapped); nr = (nr < COMPOUND_MAPPED); } - } else if (folio_test_pmd_mappable(folio)) { - /* That test is redundant: it's for safety or to optimize out */ - + } else { last = atomic_add_negative(-1, &folio->_entire_mapcount); - if (last) { + if (last && !folio_test_hugetlb(folio)) { nr = atomic_sub_return_relaxed(COMPOUND_MAPPED, mapped); if (likely(nr < COMPOUND_MAPPED)) { nr_pmdmapped = folio_nr_pages(folio); @@ -1409,6 +1410,9 @@ void page_remove_rmap(struct page *page, struct vm_area_struct *vma, } } + if (folio_test_hugetlb(folio)) + return; + if (nr_pmdmapped) { if (folio_test_anon(folio)) idx = NR_ANON_THPS;