From patchwork Thu Jun 13 00:07:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Barry Song <21cnbao@gmail.com> X-Patchwork-Id: 13695692 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 BB37CC27C53 for ; Thu, 13 Jun 2024 00:07:59 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 54AEA6B0095; Wed, 12 Jun 2024 20:07:59 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 4F9786B0096; Wed, 12 Jun 2024 20:07:59 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 373796B0098; Wed, 12 Jun 2024 20:07:59 -0400 (EDT) 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 1A4AC6B0095 for ; Wed, 12 Jun 2024 20:07:59 -0400 (EDT) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 8E3E58172A for ; Thu, 13 Jun 2024 00:07:58 +0000 (UTC) X-FDA: 82223927436.16.2322EF4 Received: from mail-pl1-f174.google.com (mail-pl1-f174.google.com [209.85.214.174]) by imf20.hostedemail.com (Postfix) with ESMTP id A78411C000B for ; Thu, 13 Jun 2024 00:07:55 +0000 (UTC) Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=JVXa7B6e; spf=pass (imf20.hostedemail.com: domain of 21cnbao@gmail.com designates 209.85.214.174 as permitted sender) smtp.mailfrom=21cnbao@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=1718237275; 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=6NpqziHdDLqAIiqSY8F5xKMZFmANNGDCABcj+bnMA4Y=; b=qp+GOBYmyg9alzxnHw8R7YAEVvDA9oeY+GN96g26kQxeSNyXssZ2roshFNOhE6nFuANlv5 cZ+WN/63ZOF2ZAHEvdFbCGcOVneTHTYlyfLsgXuoXA1va43ZtZHSg0242j4burmRty+JYY mCyFCYUgMoaYyYKs47Oh5IGT5fRsCbo= ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=JVXa7B6e; spf=pass (imf20.hostedemail.com: domain of 21cnbao@gmail.com designates 209.85.214.174 as permitted sender) smtp.mailfrom=21cnbao@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1718237275; a=rsa-sha256; cv=none; b=v7hMKePm4zeAwnpgI8JeapkmFyzz3YRqApSw43wrEKdNlYqyVBg3o+c+b63oHf9xvAzfRR Gerddd2hA09+0A9IZQuwO9Pe0XQc5+7qCRpXuxw0wThGOLfb+awa4QExzHlAnTH93ItD11 6HY6jBXOPRhYYhkIZe2VMNjjJCxLl80= Received: by mail-pl1-f174.google.com with SMTP id d9443c01a7336-1f6b0a40721so3494075ad.2 for ; Wed, 12 Jun 2024 17:07:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718237274; x=1718842074; darn=kvack.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=6NpqziHdDLqAIiqSY8F5xKMZFmANNGDCABcj+bnMA4Y=; b=JVXa7B6eUFKNxTl99gOkosgr/ajOLp3WWaR2kL+FAzL/NJHDvpg1OnQO4i0xIcfQ1B 3CI+LU4e+lOWokixJXDg4tkDeHwjHpy3QpcJrhfdgoVhBFKyOTkxLfW+Jvd2gJimtnAf lpZWd0e/gqe/bOv7Pf9Ur1refNWtxaf6xbGOHr0FtP7A6GCN5jFrXDieIwQ5SD5i7ZhC 1QTztDPGEbCuHUKtWBXxYeLZMBCJVidBXKSX2jVecZMT9MYPMo/1pvBuUYlfDdbKicth FBfQBMSg/Ca3GP6CSRgkKN67rzcHWhBm/WETeUyYhORsyL5E20SppsuSvy98Ur9CAL0H 1n2Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718237274; x=1718842074; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=6NpqziHdDLqAIiqSY8F5xKMZFmANNGDCABcj+bnMA4Y=; b=QppQ+6+WD7f0hig1R111qnm5sObkOUTsHZJv5MPv0Ynm9UJqVApMRtutpq7hVrEwwy zMLXn63gPfAlTij/M9NY60B69RdRXhX1zjO4CdWQ3jg+COOZvQqWEPs4/k5uShDcSBhY 3AxlXJK1bm0d03Z6ewG1SBQZCTy1Y/oon9EU01iqsstQg8NNCPl94Kt9k/e/dYCNT89v NLt4ood58JTKtKAddHXDhJYrUx1HEtONbWLTuwd+W9FEoR09E1Sx3Q2v3or//hNlJdn1 Gu2dHmiTUZygsxKexOpNr9Xi3i7FkoxpsPQIh/YX9TntnNep6hU+OyW/OmF/3xQnxwiw 9Iww== X-Forwarded-Encrypted: i=1; AJvYcCVPdA6D1zB3EkJLDnVZdpK8EcrBFIWYv6UliSmdyXxXvSHQ2m44CtMxXA16oyqmBB7Yqn9XzaGLlCc98PfFLGKev4Q= X-Gm-Message-State: AOJu0Yz1VCphRAafde7tKQAHTSrnk0KnfETq62jwBX6nf37Mx4ZZ4fjx 0NAlPzhxy1qsxUjZ1lcgxedYmQO6lPzMPklG1HBBTmaOja8YLHAI X-Google-Smtp-Source: AGHT+IFqnSJUmDgIo8AipknzKgGcCL0uU9MekGnVAVXd4ZlmgCCLwGt5Rq6fxNTCV4HDqJOXsCvfbw== X-Received: by 2002:a17:902:d482:b0:1f6:7815:2325 with SMTP id d9443c01a7336-1f83b71a137mr39747405ad.56.1718237274424; Wed, 12 Jun 2024 17:07:54 -0700 (PDT) Received: from localhost.localdomain ([2407:7000:8942:5500:aaa1:59ff:fe57:eb97]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1f855f1af16sm525515ad.246.2024.06.12.17.07.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Jun 2024 17:07:53 -0700 (PDT) From: Barry Song <21cnbao@gmail.com> To: david@redhat.com, akpm@linux-foundation.org, linux-mm@kvack.org Cc: chrisl@kernel.org, linux-kernel@vger.kernel.org, mhocko@suse.com, ryan.roberts@arm.com, baolin.wang@linux.alibaba.com, yosryahmed@google.com, shy828301@gmail.com, surenb@google.com, v-songbaohua@oppo.com, willy@infradead.org, ying.huang@intel.com, yuzhao@google.com Subject: [PATCH RFC 1/3] mm: extend rmap flags arguments for folio_add_new_anon_rmap Date: Thu, 13 Jun 2024 12:07:19 +1200 Message-Id: <20240613000721.23093-2-21cnbao@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240613000721.23093-1-21cnbao@gmail.com> References: <20240613000721.23093-1-21cnbao@gmail.com> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: A78411C000B X-Stat-Signature: dh3yc3mp9ffyuqsjq7wstd7hcas3759f X-HE-Tag: 1718237275-373285 X-HE-Meta: U2FsdGVkX1+BKC5LhiJOftlHpMXg+CVCblGz/+e5dhO7xNOaDaL0rSmYYO0bIZXS4n1Skfmw25rUCdsKuivtDM21KfLRMd/hbJue8yR53R/qMBHPxDV4Y7RSFkIC62bIrJ/DE0LIXRVnwkLphhwuPJvDHvfbafHkon+1DuTAJ1DFFFPlujENAKB3TPt1wCfidL+20lcGlO98KdAshhE/IpB/xcFgyP3WumIMy335UbpLVZcGgAXQeivQ1lGyoz+KDl09ds3IPRn7V/ScAnis49bHdEycEeVvbXYi6iyqEUvXI6wm5LFlw1Dq8GYwdA4j7NmTqoprn+YX7t6u23p5Lf2XjjGx2q69h3MqzhJWuoGsJZd+fxmwafTjzVrHBN8y04zXTc4hqAf5mRLRC6pNCQYZdk24X5cYf3AgWzh0sW2U+CnOmRsDibZI+gZBvjB7WS/api19Ee/UoOvRPG5tzPkChFq8RinNonkDwCMUKlFYOnzj20ahgbp0bcTFgaNkTqj+LBaoNEfZe5yEYsgUvqwzlMdmimxEYZyyEtylTsTpDzDXTaZHz+C6RY3MVb6XeYNdLQJBLZH6aQgy1MjyojwOkLoPYYaQKxFCtcxmiYsOV5tO9GzAk/n1w6LRtODAFIYq63rcJLW9E0/ZkMAaUHN8cqCL1YeSW2DJUVz41UI/TG3MuWC6hV4IqLuK9njsPbohLe2pWosnh9Sx6KCwhjg1NVIbCA1WaWbgkVGJXUNTWbJnrV2zcGgo5JRatCDd9eQUW3pEDvdENrymnYjAvWj8z9wFPBoHZ5qN9aKVXFXd5mN/jEltjaZTjMxuJc2wAMFBMIhr4AL77UyhybF4tCOdnJx4c5/2TsrtAkD3zfn/ngwSteicDgrJUnVKPu0f2/UcD2GhxAQJwsjbffCbU5FNirKPfNrbO7dVG5/EVYJYdYU+jzGgcWQSDnPzAUhhCAKyGcd56KyqoYZrKhh x2ym36/U quTp8qUUMOuzW489crbYiKg/JLYcpTURPJ+F27O5wp9Z3KAYuk56Ypw0uOtQKtWKRPLDZ0odMYtSrCYqn21orfVPZzhYFxuvft3i61hxRzeOEYM0STUa/ehgNG5v2RoGc88i9CN1KhxzXXoxvSKUX2t7cGn2/o9nEYIzvsh1E0kEesj3QA6QqIaxDsI+qKlAubgict5PLxaY/T/U4r+EE6QPM1PDHbwsJOQsvM9cB44VHsbsUsbwVUULqiQeTEuTD2uRRjmUUMdhVeWAVjBAKMC7/yqxc0IaaayYuR14RCcjCug97hklO52NSxcJWWpe6WuDGAh9+8tIwEZ7kXfxwi/jZ30frxkW5X1KEyQHDw7Y1XLh0/tgRLipdlRZNIy28MggJpnPPpxzXTMUzOl3kGp2yZ6Qp075bs7OL1CPL0/Unv9BsxGBk/4uWDOJzu7fVLOuWgfz+8eGlM8xeP44zH9VkzYQQR/C25hJbPN6D8Ca7/Kt1CPC/9fv/h48+UlGQMcUuym4O5MvR9ikrFw8g4grNAzAXaiDKXY7Q 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: List-Subscribe: List-Unsubscribe: From: Barry Song In the case of do_swap_page(), a new anonymous folio isn’t necessarily exclusive. This patch extends the rmap flags to allow treating a new anon folio as either exclusive or non-exclusive. To maintain the current behavior, we always use EXCLUSIVE as arguments. Suggested-by: David Hildenbrand Signed-off-by: Barry Song --- include/linux/rmap.h | 2 +- kernel/events/uprobes.c | 2 +- mm/huge_memory.c | 2 +- mm/khugepaged.c | 2 +- mm/memory.c | 10 +++++----- mm/migrate_device.c | 2 +- mm/rmap.c | 15 +++++++++------ mm/swapfile.c | 2 +- mm/userfaultfd.c | 2 +- 9 files changed, 21 insertions(+), 18 deletions(-) diff --git a/include/linux/rmap.h b/include/linux/rmap.h index cae38a2a643d..01a64e7e72b9 100644 --- a/include/linux/rmap.h +++ b/include/linux/rmap.h @@ -244,7 +244,7 @@ void folio_add_anon_rmap_ptes(struct folio *, struct page *, int nr_pages, void folio_add_anon_rmap_pmd(struct folio *, struct page *, struct vm_area_struct *, unsigned long address, rmap_t flags); void folio_add_new_anon_rmap(struct folio *, struct vm_area_struct *, - unsigned long address); + unsigned long address, rmap_t flags); void folio_add_file_rmap_ptes(struct folio *, struct page *, int nr_pages, struct vm_area_struct *); #define folio_add_file_rmap_pte(folio, page, vma) \ diff --git a/kernel/events/uprobes.c b/kernel/events/uprobes.c index 2c83ba776fc7..c20368aa33dd 100644 --- a/kernel/events/uprobes.c +++ b/kernel/events/uprobes.c @@ -181,7 +181,7 @@ static int __replace_page(struct vm_area_struct *vma, unsigned long addr, if (new_page) { folio_get(new_folio); - folio_add_new_anon_rmap(new_folio, vma, addr); + folio_add_new_anon_rmap(new_folio, vma, addr, RMAP_EXCLUSIVE); folio_add_lru_vma(new_folio, vma); } else /* no new page, just dec_mm_counter for old_page */ diff --git a/mm/huge_memory.c b/mm/huge_memory.c index f409ea9fcc18..09a83e43c71a 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -973,7 +973,7 @@ static vm_fault_t __do_huge_pmd_anonymous_page(struct vm_fault *vmf, entry = mk_huge_pmd(page, vma->vm_page_prot); entry = maybe_pmd_mkwrite(pmd_mkdirty(entry), vma); - folio_add_new_anon_rmap(folio, vma, haddr); + folio_add_new_anon_rmap(folio, vma, haddr, RMAP_EXCLUSIVE); folio_add_lru_vma(folio, vma); pgtable_trans_huge_deposit(vma->vm_mm, vmf->pmd, pgtable); set_pmd_at(vma->vm_mm, haddr, vmf->pmd, entry); diff --git a/mm/khugepaged.c b/mm/khugepaged.c index 774a97e6e2da..4d759a7487d0 100644 --- a/mm/khugepaged.c +++ b/mm/khugepaged.c @@ -1213,7 +1213,7 @@ static int collapse_huge_page(struct mm_struct *mm, unsigned long address, spin_lock(pmd_ptl); BUG_ON(!pmd_none(*pmd)); - folio_add_new_anon_rmap(folio, vma, address); + folio_add_new_anon_rmap(folio, vma, address, RMAP_EXCLUSIVE); folio_add_lru_vma(folio, vma); pgtable_trans_huge_deposit(mm, pmd, pgtable); set_pmd_at(mm, address, pmd, _pmd); diff --git a/mm/memory.c b/mm/memory.c index 54d7d2acdf39..2f94921091fb 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -930,7 +930,7 @@ copy_present_page(struct vm_area_struct *dst_vma, struct vm_area_struct *src_vma *prealloc = NULL; copy_user_highpage(&new_folio->page, page, addr, src_vma); __folio_mark_uptodate(new_folio); - folio_add_new_anon_rmap(new_folio, dst_vma, addr); + folio_add_new_anon_rmap(new_folio, dst_vma, addr, RMAP_EXCLUSIVE); folio_add_lru_vma(new_folio, dst_vma); rss[MM_ANONPAGES]++; @@ -3400,7 +3400,7 @@ static vm_fault_t wp_page_copy(struct vm_fault *vmf) * some TLBs while the old PTE remains in others. */ ptep_clear_flush(vma, vmf->address, vmf->pte); - folio_add_new_anon_rmap(new_folio, vma, vmf->address); + folio_add_new_anon_rmap(new_folio, vma, vmf->address, RMAP_EXCLUSIVE); folio_add_lru_vma(new_folio, vma); BUG_ON(unshare && pte_write(entry)); set_pte_at(mm, vmf->address, vmf->pte, entry); @@ -4337,7 +4337,7 @@ vm_fault_t do_swap_page(struct vm_fault *vmf) /* ksm created a completely new copy */ if (unlikely(folio != swapcache && swapcache)) { - folio_add_new_anon_rmap(folio, vma, address); + folio_add_new_anon_rmap(folio, vma, address, RMAP_EXCLUSIVE); folio_add_lru_vma(folio, vma); } else { folio_add_anon_rmap_ptes(folio, page, nr_pages, vma, address, @@ -4592,7 +4592,7 @@ static vm_fault_t do_anonymous_page(struct vm_fault *vmf) #ifdef CONFIG_TRANSPARENT_HUGEPAGE count_mthp_stat(folio_order(folio), MTHP_STAT_ANON_FAULT_ALLOC); #endif - folio_add_new_anon_rmap(folio, vma, addr); + folio_add_new_anon_rmap(folio, vma, addr, RMAP_EXCLUSIVE); folio_add_lru_vma(folio, vma); setpte: if (vmf_orig_pte_uffd_wp(vmf)) @@ -4790,7 +4790,7 @@ void set_pte_range(struct vm_fault *vmf, struct folio *folio, /* copy-on-write page */ if (write && !(vma->vm_flags & VM_SHARED)) { VM_BUG_ON_FOLIO(nr != 1, folio); - folio_add_new_anon_rmap(folio, vma, addr); + folio_add_new_anon_rmap(folio, vma, addr, RMAP_EXCLUSIVE); folio_add_lru_vma(folio, vma); } else { folio_add_file_rmap_ptes(folio, page, nr, vma); diff --git a/mm/migrate_device.c b/mm/migrate_device.c index 051d0a3ccbee..6d66dc1c6ffa 100644 --- a/mm/migrate_device.c +++ b/mm/migrate_device.c @@ -658,7 +658,7 @@ static void migrate_vma_insert_page(struct migrate_vma *migrate, goto unlock_abort; inc_mm_counter(mm, MM_ANONPAGES); - folio_add_new_anon_rmap(folio, vma, addr); + folio_add_new_anon_rmap(folio, vma, addr, RMAP_EXCLUSIVE); if (!folio_is_zone_device(folio)) folio_add_lru_vma(folio, vma); folio_get(folio); diff --git a/mm/rmap.c b/mm/rmap.c index b9e5943c8349..e612d999811a 100644 --- a/mm/rmap.c +++ b/mm/rmap.c @@ -1406,14 +1406,14 @@ void folio_add_anon_rmap_pmd(struct folio *folio, struct page *page, * This means the inc-and-test can be bypassed. * The folio does not have to be locked. * - * If the folio is pmd-mappable, it is accounted as a THP. As the folio - * is new, it's assumed to be mapped exclusively by a single process. + * If the folio is pmd-mappable, it is accounted as a THP. */ void folio_add_new_anon_rmap(struct folio *folio, struct vm_area_struct *vma, - unsigned long address) + unsigned long address, rmap_t flags) { int nr = folio_nr_pages(folio); int nr_pmdmapped = 0; + bool exclusive = flags & RMAP_EXCLUSIVE; VM_WARN_ON_FOLIO(folio_test_hugetlb(folio), folio); VM_BUG_ON_VMA(address < vma->vm_start || @@ -1424,7 +1424,8 @@ void folio_add_new_anon_rmap(struct folio *folio, struct vm_area_struct *vma, if (likely(!folio_test_large(folio))) { /* increment count (starts at -1) */ atomic_set(&folio->_mapcount, 0); - SetPageAnonExclusive(&folio->page); + if (exclusive) + SetPageAnonExclusive(&folio->page); } else if (!folio_test_pmd_mappable(folio)) { int i; @@ -1433,7 +1434,8 @@ void folio_add_new_anon_rmap(struct folio *folio, struct vm_area_struct *vma, /* increment count (starts at -1) */ atomic_set(&page->_mapcount, 0); - SetPageAnonExclusive(page); + if (exclusive) + SetPageAnonExclusive(page); } /* increment count (starts at -1) */ @@ -1445,7 +1447,8 @@ void folio_add_new_anon_rmap(struct folio *folio, struct vm_area_struct *vma, /* increment count (starts at -1) */ atomic_set(&folio->_large_mapcount, 0); atomic_set(&folio->_nr_pages_mapped, ENTIRELY_MAPPED); - SetPageAnonExclusive(&folio->page); + if (exclusive) + SetPageAnonExclusive(&folio->page); nr_pmdmapped = nr; } diff --git a/mm/swapfile.c b/mm/swapfile.c index 9c6d8e557c0f..ae1d2700f6a3 100644 --- a/mm/swapfile.c +++ b/mm/swapfile.c @@ -1911,7 +1911,7 @@ static int unuse_pte(struct vm_area_struct *vma, pmd_t *pmd, folio_add_anon_rmap_pte(folio, page, vma, addr, rmap_flags); } else { /* ksm created a completely new copy */ - folio_add_new_anon_rmap(folio, vma, addr); + folio_add_new_anon_rmap(folio, vma, addr, RMAP_EXCLUSIVE); folio_add_lru_vma(folio, vma); } new_pte = pte_mkold(mk_pte(page, vma->vm_page_prot)); diff --git a/mm/userfaultfd.c b/mm/userfaultfd.c index 5e7f2801698a..8dedaec00486 100644 --- a/mm/userfaultfd.c +++ b/mm/userfaultfd.c @@ -216,7 +216,7 @@ int mfill_atomic_install_pte(pmd_t *dst_pmd, folio_add_lru(folio); folio_add_file_rmap_pte(folio, page, dst_vma); } else { - folio_add_new_anon_rmap(folio, dst_vma, dst_addr); + folio_add_new_anon_rmap(folio, dst_vma, dst_addr, RMAP_EXCLUSIVE); folio_add_lru_vma(folio, dst_vma); } From patchwork Thu Jun 13 00:07:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Barry Song <21cnbao@gmail.com> X-Patchwork-Id: 13695693 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 427CFC27C53 for ; Thu, 13 Jun 2024 00:08:04 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C9D076B0098; Wed, 12 Jun 2024 20:08:03 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C4D376B0099; Wed, 12 Jun 2024 20:08:03 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id AC6BE6B009A; Wed, 12 Jun 2024 20:08:03 -0400 (EDT) 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 8C99D6B0098 for ; Wed, 12 Jun 2024 20:08:03 -0400 (EDT) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 4C8651A09BE for ; Thu, 13 Jun 2024 00:08:03 +0000 (UTC) X-FDA: 82223927646.16.D5A8FD7 Received: from mail-pl1-f182.google.com (mail-pl1-f182.google.com [209.85.214.182]) by imf04.hostedemail.com (Postfix) with ESMTP id 74F5A40008 for ; Thu, 13 Jun 2024 00:08:01 +0000 (UTC) Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=XuqLNeCM; spf=pass (imf04.hostedemail.com: domain of 21cnbao@gmail.com designates 209.85.214.182 as permitted sender) smtp.mailfrom=21cnbao@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1718237280; a=rsa-sha256; cv=none; b=u9bXKcgejXqYdPYMWYyxvlMSZjV2yV8CvRfnvA6/7duL8d0vQvvOb6XtT0An0xY5qZ25Bi s0NrGZD2j2aRvVze5SmFqPN5kxEYm8FnSdUEV5AUH2K3gtl4ZCx4HHDyRKzL63FB30rJWX YMIC2HWwPuIkHCcdF2EsrXic81oWI5s= ARC-Authentication-Results: i=1; imf04.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=XuqLNeCM; spf=pass (imf04.hostedemail.com: domain of 21cnbao@gmail.com designates 209.85.214.182 as permitted sender) smtp.mailfrom=21cnbao@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=1718237280; 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=oOir94itApCcnCYgLiAuZL5MLif6sFkW68CX2FRT/Do=; b=dCOTt639gJT+aN6wLzfHX8nwVgIHadV2W1T2bLufY68MRyPiw3AbOdP8c7fqE1dbT8wvbW FeiTNKzo6svr2SQbkQ27esUNjX9lNu5+KxJXhJ1oYtX1dfK0Tw7xVRAb5IP+D38TqNdNA/ 8ytmKSW7TpujBZGteraJ+gOORcXb84s= Received: by mail-pl1-f182.google.com with SMTP id d9443c01a7336-1f7274a453bso4117565ad.2 for ; Wed, 12 Jun 2024 17:08:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718237280; x=1718842080; darn=kvack.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=oOir94itApCcnCYgLiAuZL5MLif6sFkW68CX2FRT/Do=; b=XuqLNeCMZGzxm2RR4g/SiiqhJ8L/BdWH02gdGobGjS0hQme6GauXra6c8XCBIykkpv PiDcPaVsgjRYQ9ZcyYeo0Hw+2puAPVYmj6uK5wrar8ZWOIQPVLI7uxL8xkO1KkKFNbaR SOOcj4gDpiU4+ucywHYXlaschjExHUYFHwpijgveEQEcjV8xileWNWZueL72QhVFrU70 A1NcqK94bmzu7M+1/txoot9PsdU+xF5nT2zh2ihFbtknM4e+GoB6/eM1EX+gzC7P3i+O mQMPvT5APGmDTbYOrcM/09CCIg9y0en0uS6iMPLXIBcV1oXEd+a74qepYS8RH16tyTue uLYg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718237280; x=1718842080; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=oOir94itApCcnCYgLiAuZL5MLif6sFkW68CX2FRT/Do=; b=EokNyQpJenXea7DNnw1dca4PoIyDiqDCYsehxfJKH6s5bOMAqnDvdkh+B1+/PR44Et 0e78dxRer2BUIW1TQLqqlaryZIlg7NhEi+K4pOvCl8zRpYlWBJMRvPvSHevteC9HhUpP DML0pcRDfyoKBwNl/DdTISfONHfmTXHSOArfwvmkYilicFEAnm1iOvq0UXrh9lAZHSU/ MSU0mLZjyM4HAEGiQpuIU1kcD0CilVWAyssUn4GEMUBa2tdkDWT9reukOPJL8YR4lxI8 vxEtneIO3mkfsM8l9/HjE2rwq51Ma8SLaUakvsjLbdntv9HlhEnEZ/27Oncy8iyU79vn tjuw== X-Forwarded-Encrypted: i=1; AJvYcCWSntu16F/IMLOEpFmggXGtmVNztHJRhELy5RoTtQHVjSJ0jF/iRqePUPZuByI1eieWApwwmhh1hSx/iZxnkFrBFzc= X-Gm-Message-State: AOJu0YxtKbYCuF52l71tnRiR0b8F9SkPUHa1L0eh3UGA4syf6Thsd1Ba YfQCQdkIZDhcfnGIYE1jB+qoScc6WoQYChIioMjtqszpSb9h0Tyo X-Google-Smtp-Source: AGHT+IF6Dwth/q4utPM0FRywSk8vwXXsQspGeBZ4bBzg0jTpx0YsRNhvhNn2CVgfUyqsr9q7gfvTsQ== X-Received: by 2002:a17:902:db11:b0:1f7:3042:9727 with SMTP id d9443c01a7336-1f83b522f7emr36687645ad.4.1718237280269; Wed, 12 Jun 2024 17:08:00 -0700 (PDT) Received: from localhost.localdomain ([2407:7000:8942:5500:aaa1:59ff:fe57:eb97]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1f855f1af16sm525515ad.246.2024.06.12.17.07.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Jun 2024 17:07:59 -0700 (PDT) From: Barry Song <21cnbao@gmail.com> To: david@redhat.com, akpm@linux-foundation.org, linux-mm@kvack.org Cc: chrisl@kernel.org, linux-kernel@vger.kernel.org, mhocko@suse.com, ryan.roberts@arm.com, baolin.wang@linux.alibaba.com, yosryahmed@google.com, shy828301@gmail.com, surenb@google.com, v-songbaohua@oppo.com, willy@infradead.org, ying.huang@intel.com, yuzhao@google.com Subject: [PATCH RFC 2/3] mm: do_swap_page: use folio_add_new_anon_rmap() if folio_test_anon(folio)==false Date: Thu, 13 Jun 2024 12:07:20 +1200 Message-Id: <20240613000721.23093-3-21cnbao@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240613000721.23093-1-21cnbao@gmail.com> References: <20240613000721.23093-1-21cnbao@gmail.com> MIME-Version: 1.0 X-Stat-Signature: o7ommx19eugudxiayxrsewd34uaw6pf7 X-Rspamd-Queue-Id: 74F5A40008 X-Rspam-User: X-Rspamd-Server: rspam10 X-HE-Tag: 1718237281-189405 X-HE-Meta: U2FsdGVkX19lKVIvRyFK1yKTGmpaeVNwGK6BLJdaDL7H64bHtYxn/2863kMwSeohJh+SfaldBFU62QcrZ8FUE5CXVKqcCBwdLGpyyO/INlcWNukGmUjknb2RJmBqnWUxQTE5cKL43gY4mBftYoZkHx/7Ke6N7mUW4k6/FSRFJAacNS5YYsJRcnvw35TA7OBMylIhSIgfmO1/bjPyu5rzHa7XeouFoIEfhJJRjriUKMYke8PfG73KW+koidYxCfEEjJzJ01WVLey3HUHQTpPFYDNlSt6Ggr1RHExScVMNm5nkZwUaEytWg9XelQaafVPClVgeH6jiMHcaAZiijZ5s0QMh1qTe3gDcmBESEi0QV/Q9NNi8wXW4xa8JRXePQhiBHb0ibmKSq/uwySbQKpXSRw2DbK1BmI1VhipJgaRPSXkTGwsWSFV4Xs55R+uYRVT+gvEhtw6Q7BA/LmUM3te8ADSgL6l7TsPE8iENM4KVISO4WOhZpXw+oJKkOX0KWeh4plOIYLBSl/TY2aVbOgrmNcvWc8VoM9vU2h9Xsw0GkZyxXVfzfR8lWVVhHAUbM8TAdi0I1pqpGU3NEniEwcsl0zPA728KnbkF3FvUdLRtlgkfnDlPjvRFCK7fxiN0s4MC9kEazu4/dJquIS605eqYDukjB/0CZiDx8vxdJPcwDUcAHhdo10JD4tasLMmb9VYfKJpTjqVJT/NO9tExCNrzRKemiRWY/u/slSh/Ol2rWI/9wju6zGkvFVf0CSO/Ib7cFH7yY6HIBvyArOmUT1anq+2Q7wIdQmTxd2DsFwGAez/x4MjKPJ6XIQPhKJHOvrHvhV6Y2U9LxWVVbW8EeWki92OVM2IfxJxJTjNDMxsVuEOXzWrnnkr3d3mf0NkKBfN/i63MD+WhJI5I/ANXlSYqJ1y8BjiUcfgpABtv2bxhLV2E9NDHum0NppZ3VelqhYi7NrU2FqghcJPFxmPCg/T CjYtmkRm 1bkdH87usgQLwA0vQtdGElDaQkSUSdNSok2CM+Bwog5NdtrPoCekn6eA1Erk0jJAXoAWf0ZepUnrL396iHbPAcZ8JLjRz2xG+pySITRKFFwQRgKembtxlzbfF2WVS5cM/ik1h+qVKOFEuOCc2RdDjnii/iEVhmobwlFPYM6mgN4rRrYzl5Stiz1oWuAP/BQtX+rZbhyXNlXZO3KAmjJjlbjTRfhCaHFrOd/EyjCXgz6Zi2KovxuWoL8BDQrY9QxlwUivve00l36MVpS6xxGPo1XujdRFmQuXuQr6ccHwqjbEe2LDTH/rmyCQlUeUA7m2kO9UfrpZpB3OPxKbV9mvkfmA0DbZ+ieRsAVC37RSlQyAomRps1fy15x74skzo1hTxqdcYhSTeGygOgGCwrKa09Nhr2lwmIWmtWBCWbatC5bZQC4Lm+NvrpuACw4IqqsjoMMrLevGFmdCh05DpvsC0jXKhnj5rPssC8hb4P/UV0JLGGydCo+vVLy+S8zNWEydi6XsbW+N+apmgryC4eECOWD36FPuJNnKUvmcv 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: List-Subscribe: List-Unsubscribe: From: Barry Song For the !folio_test_anon(folio) case, we can now invoke folio_add_new_anon_rmap() with the rmap flags set to either EXCLUSIVE or non-EXCLUSIVE. This action will suppress the VM_WARN_ON_FOLIO check within __folio_add_anon_rmap() while initiating the process of bringing up mTHP swapin. static __always_inline void __folio_add_anon_rmap(struct folio *folio, struct page *page, int nr_pages, struct vm_area_struct *vma, unsigned long address, rmap_t flags, enum rmap_level level) { ... if (unlikely(!folio_test_anon(folio))) { VM_WARN_ON_FOLIO(folio_test_large(folio) && level != RMAP_LEVEL_PMD, folio); } ... } It also enhances the code’s readability. Suggested-by: David Hildenbrand Signed-off-by: Barry Song --- mm/memory.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/mm/memory.c b/mm/memory.c index 2f94921091fb..9c962f62f928 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -4339,6 +4339,8 @@ vm_fault_t do_swap_page(struct vm_fault *vmf) if (unlikely(folio != swapcache && swapcache)) { folio_add_new_anon_rmap(folio, vma, address, RMAP_EXCLUSIVE); folio_add_lru_vma(folio, vma); + } else if (!folio_test_anon(folio)) { + folio_add_new_anon_rmap(folio, vma, address, rmap_flags); } else { folio_add_anon_rmap_ptes(folio, page, nr_pages, vma, address, rmap_flags); From patchwork Thu Jun 13 00:07:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Barry Song <21cnbao@gmail.com> X-Patchwork-Id: 13695694 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 896EDC27C6E for ; Thu, 13 Jun 2024 00:08:10 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1A10F6B009A; Wed, 12 Jun 2024 20:08:10 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 1517D6B009B; Wed, 12 Jun 2024 20:08:10 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id F34446B009C; Wed, 12 Jun 2024 20:08:09 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id D29916B009A for ; Wed, 12 Jun 2024 20:08:09 -0400 (EDT) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 4DCB7120E95 for ; Thu, 13 Jun 2024 00:08:09 +0000 (UTC) X-FDA: 82223927898.27.B2111E4 Received: from mail-pl1-f169.google.com (mail-pl1-f169.google.com [209.85.214.169]) by imf18.hostedemail.com (Postfix) with ESMTP id 7AE3A1C0028 for ; Thu, 13 Jun 2024 00:08:07 +0000 (UTC) Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=DdddpP9Q; spf=pass (imf18.hostedemail.com: domain of 21cnbao@gmail.com designates 209.85.214.169 as permitted sender) smtp.mailfrom=21cnbao@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=1718237287; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=bCCgBtm4kYdnlOxW6KC7ddfNlNkcCijSw9u/7Ny6adI=; b=F+BveROGBSOptEJXrQY1qfgN/rNpYV+ahRNMoC6qemMXrw09mJeIspkv83/x94bhZXsI/8 ZtJuZtcvarjuZIffmxrSSCYHDGXJqfJmxACackiyMAqLwhd68qgAmJE9Jqttshl1S0rzYm B2ZO9cFlMDduNtpbRX/poPhsNHNWpZY= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=DdddpP9Q; spf=pass (imf18.hostedemail.com: domain of 21cnbao@gmail.com designates 209.85.214.169 as permitted sender) smtp.mailfrom=21cnbao@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1718237287; a=rsa-sha256; cv=none; b=o3GvL0KOKoiG4a2ptacfqgBjJpXb0Ux1sm1d8ojEqRPRoUXj6h7DzP8eFl97JZD/DBQSkk iMc5yXOlMVX1+UJ/de2Vr0jkTF1VLMq1ilfwivTg6uvOR5bLIo/hwnmBp+sQfMzU70P3l0 aVSh5ipsGCXpgS/YUbJF5Jso1fkLlAA= Received: by mail-pl1-f169.google.com with SMTP id d9443c01a7336-1f44b594deeso4360215ad.2 for ; Wed, 12 Jun 2024 17:08:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718237286; x=1718842086; darn=kvack.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=bCCgBtm4kYdnlOxW6KC7ddfNlNkcCijSw9u/7Ny6adI=; b=DdddpP9Q//Gk3iHzLI0/U2TngoiOoR+ogYU3fMSxPF1fahWDgDMbB+3tmQ+oDecFfI bKyI1LPsfWepMGZfNdCypZAzaklg3syGm8BKxhiLLOD/M9q+AcRL+kj4BAd1Z8kJ4pyb kNjyzoouN46sR1YxuyWh7jAE69Qvas6xg1V97RudkkNmo/goSi4gk7ehz3/YQtK0uFXg 6AbulxVNwV51lbA5UGEzw7ctSqaOMfW27s4PznBy3k3tTw6N/igmVPlch1DOhRPAfmwa brNlsn2jmiC61G4yFYWipVgeg5Oo/9/gurA195aIiWI34PftcFMhaDbSaOX1GQPXM1V2 iuOQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718237286; x=1718842086; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=bCCgBtm4kYdnlOxW6KC7ddfNlNkcCijSw9u/7Ny6adI=; b=bcX4Nz61ZXiLFoSRfDZp4pleGr3+Yk6PEucgNmK0xQRzhqGPJXmVKal0/CjLPgOeC1 +odWsE9nSycR/WQiJP6KDbbyOWemjQBk0IG5o96PcR5UpnKuEhWwsYxTQu58MyL81Kpi ORtCF04TB6auIGA3Yk9sqpX4taD0nSBDuZ1wCENTe9vZBjui1AUONKdw6r4+rmzVM5jy xuojzxXmTN+MFztWlIb0M4xUiSJP6lKGo2ljslM0tO2Wfy2u1yZwXo7OR7LeZJcFji7k 2XdZgPopK8szww27AMC2O+IYQX+6F77ScVVNA4HR5xfSmqJWUice1GCV6uKv7HBI3U1H 13kQ== X-Forwarded-Encrypted: i=1; AJvYcCXttbTTTZoU3ygQh5XtlvBR3zN7w9gobXgXXpWbX1AnvV3t2cCUcnj3NBjGgTIud96l+Makq839Ykf1VJyhI8562Pk= X-Gm-Message-State: AOJu0Yzx7SGoa6NcyDYkLXWVcAAXPRwp9T/cU9ADG8eeeZW5zG/fQcl9 YUXo+15p0R/XfN3tVyFbwY/PcUrMLE0tUqzQ1OBx8ObEb2dSrklV X-Google-Smtp-Source: AGHT+IF3arrhaKJraeaVPGonKcs+bjSohtVRGhBzdoUWTP+KTk/DXUJQQ7qlrLIgRjj+zyClZOrwPA== X-Received: by 2002:a17:903:188:b0:1f7:1c84:13cc with SMTP id d9443c01a7336-1f83b713848mr38288865ad.42.1718237286072; Wed, 12 Jun 2024 17:08:06 -0700 (PDT) Received: from localhost.localdomain ([2407:7000:8942:5500:aaa1:59ff:fe57:eb97]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1f855f1af16sm525515ad.246.2024.06.12.17.08.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Jun 2024 17:08:05 -0700 (PDT) From: Barry Song <21cnbao@gmail.com> To: david@redhat.com, akpm@linux-foundation.org, linux-mm@kvack.org Cc: chrisl@kernel.org, linux-kernel@vger.kernel.org, mhocko@suse.com, ryan.roberts@arm.com, baolin.wang@linux.alibaba.com, yosryahmed@google.com, shy828301@gmail.com, surenb@google.com, v-songbaohua@oppo.com, willy@infradead.org, ying.huang@intel.com, yuzhao@google.com Subject: [PATCH RFC 3/3] mm: remove folio_test_anon(folio)==false path in __folio_add_anon_rmap() Date: Thu, 13 Jun 2024 12:07:21 +1200 Message-Id: <20240613000721.23093-4-21cnbao@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240613000721.23093-1-21cnbao@gmail.com> References: <20240613000721.23093-1-21cnbao@gmail.com> MIME-Version: 1.0 X-Stat-Signature: bc95oww67unjqi7zxueyjfbp7qc1ojzy X-Rspam-User: X-Rspamd-Queue-Id: 7AE3A1C0028 X-Rspamd-Server: rspam02 X-HE-Tag: 1718237287-388138 X-HE-Meta: U2FsdGVkX19Oh74bPgfPnBUH6ZAy2qC+WmLq0DRVIvmxsKfoZHRYgyVoHEIEqZ3KfrRR9dnTBPxgI35aWo8OFEsf6UFgj8AeISy46FLv5ZaQDOTbZDr9YZita9XJkzxsxF7RZx0zUxXtludk7tLLCMQovUooCYUwbeeey2Au956PRXKea5FB09WxBNEVJnOMBFr9Rd9AxFVYeygTmDmPUFqRJOIT75MEuz6ycl9jyBwmpidp+u+NxrlJUeuT9dBf8jzlkbeCCJZhghpcEiKfJJTQ1gOdS5/+zbDE13U4xAiB+yosUo7z5DsPEEbaRCChcKSWKBVv++YZ1qMTyv9P4ec1QjIBgCTnqXM1bpfMX7EMad+TncE6YIR0CcTXKAqG32DXDZVzdZLCOPcCarTHw8VcVTdnTCo+RTsIGZg0RAfddYQJqHyc/z/+L3QGIu55OKPjJmJsLFu1zQ953agt8UR7EJotzdkvXMw0RMAFnbZmpl8REPsFkcoyvvrwxbLsTQ/Z1yyTd5j9BcaklALQj/i8YsrdaTqlYdvLO0rJvXCQqSeHEkZj33SC2bdCIa2x1zCzZycwZiF7XqoTycRZzE/sJuIUMiBL+iaeMomHPcsB29UQzjMJ+m8SSpM/R5mqLWoyKISGsaRNpUXUMapWfc1JKpE6F6E2DnrO3ij+zTQ/5AIHd6MOj9P5JF3SrUhAlc8ANvfvOTBTB2Uu86S9bTviBxNWGeShcQf2iJRJdawq+CJJ+fBu3SY0JLIrni9aTHKd3gWAVH8LuZA3Bc3l4rXgZamFG4plr/oAQmQXB3rBSX0oJ+OZBAMSBRwZvYKZrYfF9hkN1nOa+vf0abTxMC3GvwkZF6zSiLcEbsMJyQ2rpEct9MB7GBYXd/Q5nFEWLBS7MhQJss9a2P3yB0RqoR3RcNtOXcgxajYYPDiZbNJiRm6rftr2zC1RqfMwvmKkuLi3fdXlFZFLJVsDXNZ eCoq3VNz 6ACujqptEeqFDl317uIbg/h/PXlX89ifnQZV89itxdCh5tB/J4wupLXjeUrWd5+TRPujPjV7SJQtYd/A4tHO/ovrqB+m+P8mJ2PVYKGtAFc5Tp7GvpQCXLk1xZ0U68z4Go4v1ZoqUbBoz7sNZIxmhLXNtpn+fzkUJe50Wkfc/RW1R7todidftQJju/NzZJg0KLjShDYZUxJ5Rlt0y9GrKHSianTHhNgeHEKLQ9LZ2ydAJ97xrxCbPy4j8C0CKZ8qx2f+v0qI6xyZmvzrc+atHY/31exkXjBuwtjOUb5SknfCdO4FZPdsnxbbPcVgxOYdLR+jE8MlV1qkABvQ5sz1MCvdLgvSJKrUGUMV104/GmnmMk7OmDnfb59pgkeVhBxmVe7+KBqCaY9SLlkmpqd+c0MyJWunc7uaNR69PIdImvOhYrWmUi/fkfym7IXT1Z9xFl7oApWI81SeRhgc5g9icQkIunqSdPqLziirTlk1sAWTSBstZNeZA9ECwng== 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: List-Subscribe: List-Unsubscribe: From: Barry Song The folio_test_anon(folio)==false case within do_swap_page() has been relocated to folio_add_new_anon_rmap(). Additionally, two other callers consistently pass anonymous folios. stack 1: remove_migration_pmd -> folio_add_anon_rmap_pmd -> __folio_add_anon_rmap stack 2: __split_huge_pmd_locked -> folio_add_anon_rmap_ptes -> __folio_add_anon_rmap __folio_add_anon_rmap() only needs to handle the cases folio_test_anon(folio)==true now. Suggested-by: David Hildenbrand Signed-off-by: Barry Song --- mm/rmap.c | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) diff --git a/mm/rmap.c b/mm/rmap.c index e612d999811a..e84c706c8241 100644 --- a/mm/rmap.c +++ b/mm/rmap.c @@ -1299,21 +1299,10 @@ static __always_inline void __folio_add_anon_rmap(struct folio *folio, nr = __folio_add_rmap(folio, page, nr_pages, level, &nr_pmdmapped); - if (unlikely(!folio_test_anon(folio))) { - VM_WARN_ON_FOLIO(!folio_test_locked(folio), folio); - /* - * For a PTE-mapped large folio, we only know that the single - * PTE is exclusive. Further, __folio_set_anon() might not get - * folio->index right when not given the address of the head - * page. - */ - VM_WARN_ON_FOLIO(folio_test_large(folio) && - level != RMAP_LEVEL_PMD, folio); - __folio_set_anon(folio, vma, address, - !!(flags & RMAP_EXCLUSIVE)); - } else if (likely(!folio_test_ksm(folio))) { + VM_WARN_ON_FOLIO(!folio_test_anon(folio), folio); + + if (likely(!folio_test_ksm(folio))) __page_check_anon_rmap(folio, page, vma, address); - } __folio_mod_stat(folio, nr, nr_pmdmapped);