From patchwork Mon Jun 17 23:11:35 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: 13701542 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 7A54EC27C79 for ; Mon, 17 Jun 2024 23:12:05 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id F14738D0007; Mon, 17 Jun 2024 19:12:04 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E9CAA8D0001; Mon, 17 Jun 2024 19:12:04 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CEFAC8D0007; Mon, 17 Jun 2024 19:12:04 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id ACD158D0001 for ; Mon, 17 Jun 2024 19:12:04 -0400 (EDT) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 6278D1201C0 for ; Mon, 17 Jun 2024 23:12:04 +0000 (UTC) X-FDA: 82241930568.24.BEF9433 Received: from mail-pl1-f176.google.com (mail-pl1-f176.google.com [209.85.214.176]) by imf10.hostedemail.com (Postfix) with ESMTP id 7F693C000B for ; Mon, 17 Jun 2024 23:12:02 +0000 (UTC) Authentication-Results: imf10.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=WSlGpQwc; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf10.hostedemail.com: domain of 21cnbao@gmail.com designates 209.85.214.176 as permitted sender) smtp.mailfrom=21cnbao@gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1718665915; 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=wvhtOkp6Hw1ojSxAohAyFTdYS+FS6nTiQQWXEJjk460=; b=2gFzwdMONAumVLI1iMSJ2JturtZPS8YEPhyNvV1vHRVyX3oIlM6SXT3am9FwKgjts7rQk5 i0x+N5PGXW5X0dDmWLaI7BAWKepBZG2S1QIzHtwy4C3XN13yruBnqLFPBfzXHY++0SjbKR qcn9ZuVSEbg77/b+kYJvvN3KFUkJDpw= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1718665915; a=rsa-sha256; cv=none; b=eB+xUEtl6U1zuGizOOAtJTTqyduYck0bhsrVbu6QSh7eNm9S6d5VWFCxO7rehrsMI5UEId c2oXTDK1Z34SiCoOIOvIrD7/Aj3YcxgxYIr5jEMcLW9SM9hBr0VQwUbu0Sy83/OzaKLJdj emH7lTpVIObMcHYyDY7zYMN7H+8TLVU= ARC-Authentication-Results: i=1; imf10.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=WSlGpQwc; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf10.hostedemail.com: domain of 21cnbao@gmail.com designates 209.85.214.176 as permitted sender) smtp.mailfrom=21cnbao@gmail.com Received: by mail-pl1-f176.google.com with SMTP id d9443c01a7336-1f717b3f2d8so41391435ad.1 for ; Mon, 17 Jun 2024 16:12:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718665921; x=1719270721; 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=wvhtOkp6Hw1ojSxAohAyFTdYS+FS6nTiQQWXEJjk460=; b=WSlGpQwcvelkRzIqon83k2+8EorLXx9FhsP9HJ6aYpVCiyH9m++/m1r7wVcO70ZWOz VSJnZ5Rqkz/xO3n3XaLyv2r6YGngmPSBJ3yWjQ7vSCypm7sgZVFRZ7e19KgWAq+51jjT uj8uAvBZcdzm0jCWG57xzzCs34apL2YfRDXYRe9tBmxWQAYRSE/4vZ2pn8Nu0A+9XQG4 tn4pPXoz6s7pp/7pKUP3GaerlYo1zHu5yuWTOllAAUb4IZIwS98dkCULl5XeH/+Ws6Jm VPd/o4StXEwBzG9JWR4z6/rNr+SYtUcbUcNJJbU/i78eRvFCdqJzb2WS6HCk+SW6G+Ko 95Ug== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718665921; x=1719270721; 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=wvhtOkp6Hw1ojSxAohAyFTdYS+FS6nTiQQWXEJjk460=; b=NIpjHqYHibhjbLflt5b+ZHGCyfBkKBsbA04x79ijWC+BqFOQFp2VUNNVX++vPUGP40 ikbGZ0iOsvNQMWB0rObUCHOio2X/4N9L+rJZhl+MU90VxlvA52b6vOHBy8uxUfhqCPkn iW96Wk9dOtl0Q2UObp0yJvV4/pysm8CuIm+ipKk+LCUVGcTXOoepZEmAqz9ryPS2x2X8 L33GJ+p0ukv9L7vyMWCSlbnFrV6et3VTC3ohaAZFuTXOWwIhWOc+3DrYsxVkJJnr1nF4 VVIwKcuQOZt4BjmdvK2DR+i6KBosNMO49QeX5S7Ufa/Yuy37ecxRS5Xeg5YV7c6HWqwT PZuw== X-Forwarded-Encrypted: i=1; AJvYcCUhiFtWlJHHetj+pMy/v3tUvBgstNf+hJIHPE2wfKKkZmohA/7/hpVCO/BDJbUA9FnOROGMgmYugulgapBzsugLSAY= X-Gm-Message-State: AOJu0Ywo7NIBjXbGoeZCrSTfkObmqoZjOc8M+DG7XWDQGaAQrWBEnZ7L nOggo2xADK/x3aWhYsIKVw+Zqc/Ei5sllliyCqeDISmvX7wftgOC X-Google-Smtp-Source: AGHT+IEqogOoRViu3dOHOoOaWtAQ5vCl8sRMCFCuC7Yuj7hzSrXBJwI06s26PAHRuB+06AGttKgb1A== X-Received: by 2002:a17:902:e546:b0:1f7:3a70:9e71 with SMTP id d9443c01a7336-1f98b22ddd8mr13264205ad.13.1718665921157; Mon, 17 Jun 2024 16:12:01 -0700 (PDT) Received: from localhost.localdomain ([2407:7000:8942:5500:aaa1:59ff:fe57:eb97]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1f855e5a0d5sm84658605ad.43.2024.06.17.16.11.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Jun 2024 16:12:00 -0700 (PDT) From: Barry Song <21cnbao@gmail.com> To: akpm@linux-foundation.org, david@redhat.com, linux-mm@kvack.org Cc: baolin.wang@linux.alibaba.com, chrisl@kernel.org, linux-kernel@vger.kernel.org, mhocko@suse.com, ryan.roberts@arm.com, shy828301@gmail.com, surenb@google.com, v-songbaohua@oppo.com, willy@infradead.org, ying.huang@intel.com, yosryahmed@google.com, yuzhao@google.com, Shuai Yuan Subject: [PATCH v2 1/3] mm: extend rmap flags arguments for folio_add_new_anon_rmap Date: Tue, 18 Jun 2024 11:11:35 +1200 Message-Id: <20240617231137.80726-2-21cnbao@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240617231137.80726-1-21cnbao@gmail.com> References: <20240617231137.80726-1-21cnbao@gmail.com> MIME-Version: 1.0 X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 7F693C000B X-Stat-Signature: wjr19tgdjqpq75hqkz5g69cz1n6azgga X-Rspam-User: X-HE-Tag: 1718665922-134235 X-HE-Meta: U2FsdGVkX1++vnB3HInLo1dyz/hUxVxQfsERz5QkRvj+TOvkTZKxd7W6C9CDckwtuJULoINHjWvxIJGXGXW4UJZprN5MnengG2JrcBYrcyQx7ewJRu3rQfiWxC6Blei87U6QpZT/OCd8bIuq5jjCb8USY9GYpQ70cbTb/Nnuhkz0EdTunRDipsZivshlYdcfL3StIkAd8xGxqvalxCFQH4Aq8zSUspQfuteyJcmFQvGBjHju2ehezPqAfDhoJHK512cNok1TvN4wKCy+L5KpQDLH7tRYuaQphOrnvXWY04nQDuG8xntDn6hdj3AFCmfFyuIMbJVRzfA4gseB38AJzDnYZQh9zB9yPLaX0uqyTsAP6bcTthqJK22/3+/vINQDHFlxxTJCy643z1alMl5I/1AwLikfKjo7rtzTTiAipFCe7nYGYf7slOtPcvTPZKpfzCKGXNPkgE/tdkY6IjgSrTziR6T2gblkGfQWna3a+Ckx5TiOMXLtwzGaKt/pEJW7fbuph969B2nBKu0/0yQLmgZcPkbbsaTrLl0zSvf5+7rop6Uu3oavE5PPPZRZTxSevkZMoZwQhakk0TomTmPwW/mBt/zhagBQgXnZB3oUMc6x36o43awoWlALojsrCSUpJlN3G/bo3uydtd1Pu69WL3VQ89iufxo1DcsyN/kOlPu+iJ/1dJEMzIYsedIIN61UHhFpBrsm57pvS9/hCkfitiB9yJPjc/e6cZN/s+o+Yi6hVXV9PyLSkGlCgjxutsp9nuN23oE6JrrHH/nWvK2shB+l9o56XT0PdmZS4KMpeYYAoFwx/xtc5/SIq93ATEUBHEPFsN3DVWVWf9mEfx9RCS3VZrTCEztw8uBxGIYb72vfs0qJNWs7aNeM6SsqTfI0xsQ1CcnF9kIHNvtGySJzwm9qMWU+JMu1xEdXCKECCJQQdLe9Sf2LzRK64w+4VRpEzrkubHjGOhddhTElmjy zcjDVP41 AYLMgbQD6YmzqmLPJp/s+lxmc7t2Jhbc6bETZ0CaLXM3RZBbdFBT+D5H2+AL299X3uZ8nofgGY89i+0huZKHvg/sF6REt9X3SA1osBJBABpwl/0B/0F0wSrmQPFS26XrRLf2iJAPDsbpNrf4vZ2RH/DsJiKjizcG1taDgy/qEVXq6R9BVAXnMWmt8ep7d1EJeRf95yhYhKAN7zpxd3D+9Yyi5kmEd/sV0aa5xv2qXd8DneXygESJx7195FNn9gelvBkrLXeYedQWENrvrtjYUkTZX8YAWPYwNTZwS6fnBh9OBmbIwkWL1wIrKHOazt5l7XWJQWTp60Adc4MQ5M7YPoy/v3Q8p+pTwShndWAtwepYFebwg1sCx1xLJM84q4u343zYORs4Ixy4+XezY5MGHqMoI+1igNEX6q7yJYczYo2XdL15OP24PSA97chgDCco2b+7JumrQLXWITatby0yLtGq4GHizhGT3UuFxhEaXwAVy6EV3AJBxHRCnHg== 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 a swap-in, a new anonymous folio is not necessarily exclusive. This patch updates the rmap flags to allow a new anonymous folio to be treated as either exclusive or non-exclusive. To maintain the existing behavior, we always use EXCLUSIVE as the default setting. Suggested-by: David Hildenbrand Signed-off-by: Barry Song Tested-by: Shuai Yuan 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 | 17 ++++++++++------- mm/swapfile.c | 2 +- mm/userfaultfd.c | 2 +- 9 files changed, 22 insertions(+), 19 deletions(-) diff --git a/include/linux/rmap.h b/include/linux/rmap.h index b1bbe237ea4c..23d336e5d502 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 425374ae06ed..9e2357ab9b9a 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 b7137d9c99a9..1f24ecdafe05 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 a3c99ac63155..2b19bb92eda5 100644 --- a/mm/rmap.c +++ b/mm/rmap.c @@ -1406,25 +1406,26 @@ 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 || address + (nr << PAGE_SHIFT) > vma->vm_end, vma); __folio_set_swapbacked(folio); - __folio_set_anon(folio, vma, address, true); + __folio_set_anon(folio, vma, address, exclusive); 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 Mon Jun 17 23:11:36 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: 13701543 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 12482C2BA15 for ; Mon, 17 Jun 2024 23:12:12 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 772028D0008; Mon, 17 Jun 2024 19:12:11 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 4FF8A8D0001; Mon, 17 Jun 2024 19:12:11 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 21AB98D0008; Mon, 17 Jun 2024 19:12:11 -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 DD7068D0001 for ; Mon, 17 Jun 2024 19:12:10 -0400 (EDT) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 59C08C015E for ; Mon, 17 Jun 2024 23:12:10 +0000 (UTC) X-FDA: 82241930820.14.049AF03 Received: from mail-pl1-f172.google.com (mail-pl1-f172.google.com [209.85.214.172]) by imf11.hostedemail.com (Postfix) with ESMTP id 7000240011 for ; Mon, 17 Jun 2024 23:12:08 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=RRMcu7ve; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf11.hostedemail.com: domain of 21cnbao@gmail.com designates 209.85.214.172 as permitted sender) smtp.mailfrom=21cnbao@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1718665923; a=rsa-sha256; cv=none; b=N/gjDe2WwEl5yuxekH/V8Uoo0fLGCerPMnxsgUtJmKlaEGxLKcpKkA6SbIuMlXRpmbe+y0 8W5flqXMQudKpYLfEU6/TyKAW+OmuL15KTTZ3IKOmb3HxPengBGswxSwse4gnbWosXemtc 28t32RP/bzF6ogjc3IE9CnUqp3lY7D0= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=RRMcu7ve; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf11.hostedemail.com: domain of 21cnbao@gmail.com designates 209.85.214.172 as permitted sender) smtp.mailfrom=21cnbao@gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1718665923; 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=nnwDyt6wGwOClIOvqiBxhppNdg8blfjOHv9/ogWAFm0=; b=5vObuOkptTNtnkxHRmTshylxl/PmSkByNJkGZFZnCGmM65SCKX4nmMZhQqS4vpOdpO4eti 03bepZ5Mdm9OAw1SD2/3B0ILlhw4BmlzZ5vLlwxB50TCWVt+f+bRyEqiUA1kEMhML0yypU HDYHUo0FKCb7ES1L3GdNspx2JFg2VdI= Received: by mail-pl1-f172.google.com with SMTP id d9443c01a7336-1f64ecb1766so34717655ad.1 for ; Mon, 17 Jun 2024 16:12:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718665927; x=1719270727; 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=nnwDyt6wGwOClIOvqiBxhppNdg8blfjOHv9/ogWAFm0=; b=RRMcu7veTnByEKSfDYO570W683xtTTQNgSSaAvuL8KW4T8Mk62DoDMeY/zi0gacRgm iawz/q7QdMJzCnjYpz3f4HY3IySkl83N00U8oAiqmBkyIPGyAByOfziThhFGh8fiBJcO hfurc6zXwfgf8dX+Y1OK8scDBquKrMmuNkOUV9CW7x2P0inZuqpnwT/l6TKAEAb6E1bh nv4FPXIS4MTTXCr9fVsdGG9M8CrGHDDdhLcCDcdEh9WzP5BsY0j6UDTa/2gbe7r54yHr TYuBTN4Q5VbGcMqrguFJNRm+MGLDgun5yX+VBhnb6ZBw/tj0OZJIb7alDz5yCGNN2LMv JaTg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718665927; x=1719270727; 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=nnwDyt6wGwOClIOvqiBxhppNdg8blfjOHv9/ogWAFm0=; b=COyvRV813Bv9Pr0Szgi46BlhhnXKYGZwdq/af/xSynSBAgX+GpQ2oChIdsno3TBqEI oo8FLMrWQTG2qu327VWkJRYnTtrQQ8eb0l1fkxYMjo/S1HXrlE3HaVXXYmQPq4SOePRM IZcq4W5d+VdqhCTCwg18yTu8+1arrWMHkzGsrnQjwrI6YnD6F64swFvf2CB6luPc20cR la24cdQFz4YgWtejVOETBtvyj469Z7e98mb2BwV4zU4BLBJ71b5A7VFZv2NwtDlsWxQ5 Ot35friSn2YDcYDca15nSdV3e6usDixCfXoyT4GezLRK5/sxrDRSEY2GPNP05lqMHQRp CfqQ== X-Forwarded-Encrypted: i=1; AJvYcCWRWfZU6dGSv2q/c/l+2Mud03CeZK19C25Mjv1F1g/pPLNLdSUYHa0qP0NZQxmw5FzWWTDYJ3XBXLvo2c6L3MU2oOE= X-Gm-Message-State: AOJu0YxaxSylMBCcpPVbwkbGLGMVL+SKZiMEvErccCjrRR3lFz0waqMP I3tdEAoZaFL+oygfIqUBDJnMz2+Pns2Os511LQ0U5bQUG/7+cJsq X-Google-Smtp-Source: AGHT+IHq7JHs/BU8iswnoca29J8kwvvCjAMVVEyjUdJyYgosbrLVDRGHuiSVkNgDJ8EmnZbLmCegbw== X-Received: by 2002:a17:902:c086:b0:1f8:3f13:196a with SMTP id d9443c01a7336-1f8628062b0mr84791845ad.45.1718665927204; Mon, 17 Jun 2024 16:12:07 -0700 (PDT) Received: from localhost.localdomain ([2407:7000:8942:5500:aaa1:59ff:fe57:eb97]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1f855e5a0d5sm84658605ad.43.2024.06.17.16.12.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Jun 2024 16:12:06 -0700 (PDT) From: Barry Song <21cnbao@gmail.com> To: akpm@linux-foundation.org, david@redhat.com, linux-mm@kvack.org Cc: baolin.wang@linux.alibaba.com, chrisl@kernel.org, linux-kernel@vger.kernel.org, mhocko@suse.com, ryan.roberts@arm.com, shy828301@gmail.com, surenb@google.com, v-songbaohua@oppo.com, willy@infradead.org, ying.huang@intel.com, yosryahmed@google.com, yuzhao@google.com, Shuai Yuan Subject: [PATCH v2 2/3] mm: use folio_add_new_anon_rmap() if folio_test_anon(folio)==false Date: Tue, 18 Jun 2024 11:11:36 +1200 Message-Id: <20240617231137.80726-3-21cnbao@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240617231137.80726-1-21cnbao@gmail.com> References: <20240617231137.80726-1-21cnbao@gmail.com> MIME-Version: 1.0 X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 7000240011 X-Stat-Signature: xmuueybpetuamozq9tg43an1uhk84oq9 X-Rspam-User: X-HE-Tag: 1718665928-234476 X-HE-Meta: U2FsdGVkX19JJcrWKh+F7cN6AMJKVF92LhGseODLzYlAw/yxO+KD93YRvxMuXpw0hZb0YdZ97oSJqMKYnLJWmfuLgVTOQdpsePeCV3erA6DWb6XTI6b02gsJuQyN3DQ9CVKT+6tjI/M/RZowSb6S6O6jumo9DlFtf0fMzszdEIUzhXTscjQalZYHbatOCVQacSTwA4BEZROawyx5h4w6QG4ve8JXeZTIxaLXHASymaI1U9Y9vkS8q97CWyc00iD5qfZuwJJRJdYWz+bHUk0Qdl4tDX1inp8oCqmEcSzvw/y6QVfuCEib8w/dOR2Pd+RwDN5aMNg6sRv64gSDatSNQP7tBC4s7Mcu/nbsEG2fmcoIMEF3SrPKNNyDvPJwkRB9e36naC01C2bJbItiOA8PfQima7KbDZf+gBnSBzo2AfvGnDIx+UyDjrPATsbtdkBPaWPVwXYY9F5fZPqTR3yQRq3jT4uLy0tgmzqVGr+9NH0TUBuxOeqyEBYXN6HnkvNdLGxGLXX7Bo+X/9qAnry9jSzWfD9OQdurrRq6lOgfeViq7MaF28SzuaVOgVGBXDWfCPbFKj+jCsGu8YBn4mOC6KkcaLmlu+nXOv0kzDm42Vx83ZCjv7QsHBn+0nmYVV4HBy4i2SB4r0Zf4RAO0k7Fkl8RhEaFvZgCgVKQOVKiTT0uT0JO9gncYfQkEFZ+2L1uu7IcjCeft/Fg4hwQWhQsYOvw4QfMQv2HpDx+uy9zP2o7Te6VsEYaqq5J0g+4yTwhxYW/gj52xJ6cLyPEwy79hx1oTMcs0Ajo2C2XWdrLOVnzAVX1zsFkLgOzv/LsEhWAFjyMEmOR0XnDzwCYnJzjBJzUh8iNX2VZhUvuYDW960uqXGsI0WwrQLMme8t8if9ZlgfAoTcI7INAE+yvKZBPyfygewZDcUvKERGz0PHBdYMl7EnEJV0X9qTWCAbckQG5x9422fGlHIHSjccrtWY w/hnm6Un fOJc7FYUvHdWTwP384w3chp+p5tDPtwv+bNw2uQHYIQj2ivIPXJFXYyKmsT3yE8D2NgOeRygvO755ZIUUX7zftcCEFS3OdErK6Hh1tOIQMx1JHmYUTAdBMfZ/A3VEx2T/XP7JkSpq82cZWc6HkzSFNiVeKWj7mDHLkGkEPmXyv+91tOrjx6GNbUWVZOOAkW2tzvvKVjw2rpRlgSvJSn+ANeMOAWLKUR1Ew4v6jgeOM2N4PhehqyPlWIkgNTD42BEerBmZ38IiyG7kb3IC/7tDRNCYgHACO4zGCEnNFWaPulaA3PwnQXwftg/6mUTSqH2O3tq2Aj1htamOfhh5uLd4nxoQklyzhgJWLh2vxeB/OFeAoh45QmJdQJCtle+dMuf+39JOiT47cYNnEhWPijQ0ud5bMC+1aAdFgamUObrRnDwDYIJHmQcWMjWsdCTBMddjmCF8hMby+raaU4+hf/b/qXexdZFZMbJ8pZ+6fiAZyLEhDLjh2V5eq0Ue2Lz5DOs2a++aF/T7prC2rXeuRzJgMQ0oq2j4G3/vOl6D 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 improves the code’s readability. Currently, all new anonymous folios calling folio_add_anon_rmap_ptes() are order-0. This ensures that new folios cannot be partially exclusive; they are either entirely exclusive or entirely shared. Suggested-by: David Hildenbrand Signed-off-by: Barry Song Tested-by: Shuai Yuan Acked-by: David Hildenbrand Signed-off-by: Barry Song --- mm/memory.c | 8 ++++++++ mm/swapfile.c | 13 +++++++++++-- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/mm/memory.c b/mm/memory.c index 1f24ecdafe05..620654c13b2f 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -4339,6 +4339,14 @@ 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)) { + /* + * We currently only expect small !anon folios, for which we now + * that they are either fully exclusive or fully shared. If we + * ever get large folios here, we have to be careful. + */ + VM_WARN_ON_ONCE(folio_test_large(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); diff --git a/mm/swapfile.c b/mm/swapfile.c index ae1d2700f6a3..69efa1a57087 100644 --- a/mm/swapfile.c +++ b/mm/swapfile.c @@ -1908,8 +1908,17 @@ static int unuse_pte(struct vm_area_struct *vma, pmd_t *pmd, VM_BUG_ON_FOLIO(folio_test_writeback(folio), folio); if (pte_swp_exclusive(old_pte)) rmap_flags |= RMAP_EXCLUSIVE; - - folio_add_anon_rmap_pte(folio, page, vma, addr, rmap_flags); + /* + * We currently only expect small !anon folios, for which we now that + * they are either fully exclusive or fully shared. If we ever get + * large folios here, we have to be careful. + */ + if (!folio_test_anon(folio)) { + VM_WARN_ON_ONCE(folio_test_large(folio)); + folio_add_new_anon_rmap(folio, vma, addr, rmap_flags); + } else { + 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, RMAP_EXCLUSIVE); folio_add_lru_vma(folio, vma); From patchwork Mon Jun 17 23:11:37 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: 13701544 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 75FECC27C79 for ; Mon, 17 Jun 2024 23:12:18 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 502026B00B8; Mon, 17 Jun 2024 19:12:17 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 3C7306B00B2; Mon, 17 Jun 2024 19:12:17 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0E0CC6B0136; Mon, 17 Jun 2024 19:12:17 -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 C14536B00A2 for ; Mon, 17 Jun 2024 19:12:16 -0400 (EDT) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 41724A1941 for ; Mon, 17 Jun 2024 23:12:16 +0000 (UTC) X-FDA: 82241931072.23.EBE4D6A Received: from mail-pl1-f169.google.com (mail-pl1-f169.google.com [209.85.214.169]) by imf20.hostedemail.com (Postfix) with ESMTP id 5D6151C000B for ; Mon, 17 Jun 2024 23:12:14 +0000 (UTC) Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b="K5c/tBJK"; spf=pass (imf20.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=1718665931; 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=QGQ6SzdfrQSO5xjCxNwiBFuEcECCL6Ck79QRnw+gZuY=; b=a/6IvNPq7zBKKnaxHPBCi1/tR/zzV0S3hLEc92Majycbtn02uHhCp+mz7jeBDvqiwoD9wq BSZBEdGJoj/kBIS0ohrDyxj/XNPicvdzZo9RtNrdwfbMR/l/RrGODo9i2nwkNvyaPk8Ahf lxy3qxpn3L5tghpcWssSDNFI3Rz27wA= ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b="K5c/tBJK"; spf=pass (imf20.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=1718665931; a=rsa-sha256; cv=none; b=cPqHie3V3qO4SAJPTp6oteYjpB9hGZSMd4ibQu1S1j/oczVI3MzoHV0TcztUQ2ia2B91/I KeRlDWniWEr1tS+C0uISmL/oig6Fv9lRUtG/fFwh4DZMn6wLkBfRokft69MFEk3QQ56MtQ uV0dCboK0HjemweGcLcYRvIJCG1NYNA= Received: by mail-pl1-f169.google.com with SMTP id d9443c01a7336-1f7028196f2so39745685ad.2 for ; Mon, 17 Jun 2024 16:12:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718665933; x=1719270733; 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=QGQ6SzdfrQSO5xjCxNwiBFuEcECCL6Ck79QRnw+gZuY=; b=K5c/tBJKDcUi9UdkqM3dhUgdNQ0cEEx+4khRzsP34FiEtzGew+o4ki7gxCoqvZ421C Os7O5snXqHKZbQXr0/vpSenP7gi6PwnETqmmnJT5LxsAvGJ9SV+NbHx0pEWQZ51Qz5Yo clwuvcut1mUo+zGLsag7+FFp8rliCsedTXMJBvStwEs9XlWsJ/PnM/IcWbDXDnjPXc7R xF+mV/y9TJTxuQ+H0pjA2oDej82vAI6MbvGq34iaPki11E2GwI5F9949MYZdaUIqb5Q6 zjjhRSAm+RDsx/1XKeNl4esKa7+/cIvxVJEz4RaZTrR4lCudPaCv5mjglJ+HqSH0Mg9D 12Zw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718665933; x=1719270733; 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=QGQ6SzdfrQSO5xjCxNwiBFuEcECCL6Ck79QRnw+gZuY=; b=d7NUYb24ZR3FLa4o1iFzLwJkcM8b2vZvTiqELo7oo4IpncxqZTDz8wrjOe8p551kZF wCYGFv0AjHtD1nMhhKdBAoz51vOYTxs2sLxnM3twYpb8rp3sI+WHlRz/yXikbob1Nw1T LvZ/GS5UjAPi9jN31qzN3HpGALgfkQv6Y+NI2GKFA1wPiMDEwLNcRhjFHqCqMji8QsVY r0BVSFnZI4/KL/PSDeSwraEn6a4zzclt8DkNBREtPHK+L76cRLCFIUDf/g+7XuMjr8kF Xzb83uOCpBGy/L6Iopoe9Ps0Yf59uKgbpFVKiAGNuN8prt9iu8/J18YsbTYLcIOa7/7a D8gg== X-Forwarded-Encrypted: i=1; AJvYcCVkfz900GPvtWfHMjBJ1XrUKMg5Hreroqgk3c5laZ5Aetizea+UVLYd/qPu1+Zd/NRP2Sb5QfYntzaiP+nrDoc/cYc= X-Gm-Message-State: AOJu0YwP9oTzWVeNOYSHZijzCFGGIwIU3aWrP5BfL2ERqsgg4BIWxnaJ qvkvOlN9mlMCNmJXEdfar7IFrXIpUeSxb6Qfts/zO9uX8SrQ7W1BH8k/oa9I X-Google-Smtp-Source: AGHT+IGdavghqDun57MXIuOzQguy6J6tZOKWjsQvvQ/r2qtBVtLUA3Gz519TstrQYTx82XqkXwmIAw== X-Received: by 2002:a17:903:2305:b0:1f7:eb9:945a with SMTP id d9443c01a7336-1f862806364mr90512405ad.44.1718665933275; Mon, 17 Jun 2024 16:12:13 -0700 (PDT) Received: from localhost.localdomain ([2407:7000:8942:5500:aaa1:59ff:fe57:eb97]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1f855e5a0d5sm84658605ad.43.2024.06.17.16.12.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Jun 2024 16:12:12 -0700 (PDT) From: Barry Song <21cnbao@gmail.com> To: akpm@linux-foundation.org, david@redhat.com, linux-mm@kvack.org Cc: baolin.wang@linux.alibaba.com, chrisl@kernel.org, linux-kernel@vger.kernel.org, mhocko@suse.com, ryan.roberts@arm.com, shy828301@gmail.com, surenb@google.com, v-songbaohua@oppo.com, willy@infradead.org, ying.huang@intel.com, yosryahmed@google.com, yuzhao@google.com, Shuai Yuan Subject: [PATCH v2 3/3] mm: remove folio_test_anon(folio)==false path in __folio_add_anon_rmap() Date: Tue, 18 Jun 2024 11:11:37 +1200 Message-Id: <20240617231137.80726-4-21cnbao@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240617231137.80726-1-21cnbao@gmail.com> References: <20240617231137.80726-1-21cnbao@gmail.com> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: 5D6151C000B X-Stat-Signature: gahqyi9k4ug1qaaabiu8wdy1gsyd9arq X-HE-Tag: 1718665934-617875 X-HE-Meta: U2FsdGVkX1++jvbiIGSRrfI3T8HUbxD8r5KAvJBCBsZOfnK41YtFwYG0AOrd37NP7VtXVeddXqOXAeSm3wPlfgVgkFqvPdiouxvS6Bex05nwXlN42mE5tSnyhP4xc438WkGRG3dllkuO5wP0oBW8FivotSTePcau0QIDCYYozQQialkuU8yL8Bz0NXGBPxLOhF34jSZ7SjhKGmWqANdtPbNz6hBiagtclGT5UVE1aGWLpwY6T9o1LBKpxX+NEJ6PH9eKW1SwuP7d2W4Ato20gcN3g2PtnwuJ20C2SMpjDuiOQnOOyUoG1rZapy5UqN5m7uH5RAloKqycyZQIbaDYGuZj2T+ALGZKyXF39GCFpT8w14VzQILsGV63dmMvXvjZ0b8yGjMtlxx8oL80bGQVAPHbrAazfAeZLIx1+uYsRGL8YkwLTqBC+8PzExZTtgzERCfKzySuqxHYb1ilpG2DIxNMSSE5omJG/2qfDSjpwZ5NI5E6ZYyJVvSQrE61B3rneAz+H99t/MlADVz+mnFm5VeSuZOtYlJ/Px31bFOMojE2smIZABOvAneSaRcTV8aD5rbzpOJz9YCoAKKvQjqSkhvrnu1TqWnA7komHFgpYt1EXj95aVaBbaOKGuJo8EsVrgITDiNyqoNTq9RTgF1bbSQaaxB8dQ9zkUalRBDvHhYcoyC+iUGWsms/6LnLBmOMHAQWGZmt2HyRz113W1YQhkTillVrOTPrQDXfMZRFpIMANonDCha6bC/xw4fc9yuPZd5o++w3lT0rpCenM8J1rdyde28IJnZqfqMZITbUXVaeY2FPRfBYkZHmxFEUku2ACRtxjaeChHy77rQjeksqtBcRtCRoloLgMngczcIHYjO4uKibPVOOhbfWkAbRMpOr7Z/3c/Yi2fl2pMZS2yDpJchBHpTuzraQNHjG2dM8blh59uFstB0KmXKyubKgdruq6d8N0TljUXnho5jrS8F ImnWpBHF mRP8slB57c+Y0VV43f2CjLXO/GF6yynNoiiaOBbb8tzZOlGIcuHVUMYj7dS6zBis2JE5EkvhC3YPt6CJLAcRR1Y+CeevB3zt4D8Z8ejK2IvdaZnVnnrnhwqlZaiYlnXFICzCkeC4AXE4YEl60CjNjASHeD0A3W+0sRQrfRxQgRHTFDtSQGvmrVeVD3TWmetI9/6r9OsAn/YCxvQZf2qKMh8skKtUn8O82jymebUUnIAKcpf2S/tQejYGWJbx7aUHCkehWw9eFE+EtloNshXfY9j69F1xesnt0Z84WUMet3c/lFFs/EwedF9aSyL48jZnVPBmXDFDVYb4k65S7lOWjBwusBVt7Y1eipiT9Ag3pR8J/F/qRc97c+T7PK7AArqvyvDDmfLTUZ4TbcmgSq7UW1C08zDOvEvZmHtKNXMODFYwsGCS+TBYMu6SmUGS2bNzslQNgUdxlAc/46LQO2hJuHGGtVylgFdcwW5g3QJqO37Zd2LHFj/s76Dn/tQ== 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 cases has been relocated to folio_add_new_anon_rmap(). Additionally, four 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 stack 3: remove_migration_pmd -> folio_add_anon_rmap_pmd -> __folio_add_anon_rmap (RMAP_LEVEL_PMD) stack 4: try_to_merge_one_page -> replace_page -> folio_add_anon_rmap_pte -> __folio_add_anon_rmap __folio_add_anon_rmap() only needs to handle the cases folio_test_anon(folio)==true now. We can remove the !folio_test_anon(folio)) path within __folio_add_anon_rmap() now. Suggested-by: David Hildenbrand Signed-off-by: Barry Song Tested-by: Shuai Yuan Acked-by: David Hildenbrand --- mm/rmap.c | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) diff --git a/mm/rmap.c b/mm/rmap.c index 2b19bb92eda5..ddcdda752982 100644 --- a/mm/rmap.c +++ b/mm/rmap.c @@ -1297,23 +1297,12 @@ static __always_inline void __folio_add_anon_rmap(struct folio *folio, { int i, nr, nr_pmdmapped = 0; + VM_WARN_ON_FOLIO(!folio_test_anon(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))) { + if (likely(!folio_test_ksm(folio))) __page_check_anon_rmap(folio, page, vma, address); - } __folio_mod_stat(folio, nr, nr_pmdmapped);