From: Ryan Roberts <ryan.roberts@arm.com>
To: Andrew Morton <akpm@linux-foundation.org>,
Matthew Wilcox <willy@infradead.org>,
Yin Fengwei <fengwei.yin@intel.com>,
David Hildenbrand <david@redhat.com>, Yu Zhao <yuzhao@google.com>,
Catalin Marinas <catalin.marinas@arm.com>,
Will Deacon <will@kernel.org>,
Anshuman Khandual <anshuman.khandual@arm.com>,
Yang Shi <shy828301@gmail.com>,
"Huang, Ying" <ying.huang@intel.com>, Zi Yan <ziy@nvidia.com>,
Luis Chamberlain <mcgrof@kernel.org>,
Itaru Kitayama <itaru.kitayama@gmail.com>
Cc: Ryan Roberts <ryan.roberts@arm.com>,
linux-mm@kvack.org, linux-kernel@vger.kernel.org,
linux-arm-kernel@lists.infradead.org
Subject: [PATCH v4 1/5] mm: Non-pmd-mappable, large folios for folio_add_new_anon_rmap()
Date: Wed, 26 Jul 2023 10:51:42 +0100 [thread overview]
Message-ID: <20230726095146.2826796-2-ryan.roberts@arm.com> (raw)
In-Reply-To: <20230726095146.2826796-1-ryan.roberts@arm.com>
In preparation for LARGE_ANON_FOLIO support, improve
folio_add_new_anon_rmap() to allow a non-pmd-mappable, large folio to be
passed to it. In this case, all contained pages are accounted using the
order-0 folio (or base page) scheme.
Reviewed-by: Yu Zhao <yuzhao@google.com>
Reviewed-by: Yin Fengwei <fengwei.yin@intel.com>
Signed-off-by: Ryan Roberts <ryan.roberts@arm.com>
---
mm/rmap.c | 27 ++++++++++++++++++++-------
1 file changed, 20 insertions(+), 7 deletions(-)
diff --git a/mm/rmap.c b/mm/rmap.c
index 0c0d8857dfce..b3e3006738e4 100644
--- a/mm/rmap.c
+++ b/mm/rmap.c
@@ -1278,31 +1278,44 @@ void page_add_anon_rmap(struct page *page, struct vm_area_struct *vma,
* This means the inc-and-test can be bypassed.
* The folio does not have to be locked.
*
- * If the folio is large, it is accounted as a THP. As the folio
+ * 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.
*/
void folio_add_new_anon_rmap(struct folio *folio, struct vm_area_struct *vma,
unsigned long address)
{
- int nr;
+ int nr = folio_nr_pages(folio);
- VM_BUG_ON_VMA(address < vma->vm_start || address >= vma->vm_end, vma);
+ VM_BUG_ON_VMA(address < vma->vm_start ||
+ address + (nr << PAGE_SHIFT) > vma->vm_end, vma);
__folio_set_swapbacked(folio);
- if (likely(!folio_test_pmd_mappable(folio))) {
+ if (likely(!folio_test_large(folio))) {
/* increment count (starts at -1) */
atomic_set(&folio->_mapcount, 0);
- nr = 1;
+ __page_set_anon_rmap(folio, &folio->page, vma, address, 1);
+ } else if (!folio_test_pmd_mappable(folio)) {
+ int i;
+
+ for (i = 0; i < nr; i++) {
+ struct page *page = folio_page(folio, i);
+
+ /* increment count (starts at -1) */
+ atomic_set(&page->_mapcount, 0);
+ __page_set_anon_rmap(folio, page, vma,
+ address + (i << PAGE_SHIFT), 1);
+ }
+
+ atomic_set(&folio->_nr_pages_mapped, nr);
} else {
/* increment count (starts at -1) */
atomic_set(&folio->_entire_mapcount, 0);
atomic_set(&folio->_nr_pages_mapped, COMPOUND_MAPPED);
- nr = folio_nr_pages(folio);
+ __page_set_anon_rmap(folio, &folio->page, vma, address, 1);
__lruvec_stat_mod_folio(folio, NR_ANON_THPS, nr);
}
__lruvec_stat_mod_folio(folio, NR_ANON_MAPPED, nr);
- __page_set_anon_rmap(folio, &folio->page, vma, address, 1);
}
/**
--
2.25.1
next prev parent reply other threads:[~2023-07-26 9:52 UTC|newest]
Thread overview: 53+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-07-26 9:51 [PATCH v4 0/5] variable-order, large folios for anonymous memory Ryan Roberts
2023-07-26 9:51 ` Ryan Roberts [this message]
2023-07-26 9:51 ` [PATCH v4 2/5] mm: LARGE_ANON_FOLIO for improved performance Ryan Roberts
2023-07-26 16:41 ` Yu Zhao
2023-07-27 4:31 ` Yu Zhao
2023-07-28 10:13 ` Ryan Roberts
2023-08-01 6:36 ` Yu Zhao
2023-08-01 23:30 ` Yin Fengwei
2023-08-02 8:02 ` Ryan Roberts
2023-08-02 9:04 ` Ryan Roberts
2023-08-02 13:51 ` Yin, Fengwei
2023-08-03 8:05 ` Yin Fengwei
2023-08-03 8:21 ` Ryan Roberts
2023-08-03 8:37 ` Yin Fengwei
2023-08-03 9:32 ` Ryan Roberts
2023-08-03 9:58 ` Yin Fengwei
2023-08-03 10:27 ` Ryan Roberts
2023-08-03 10:54 ` Yin Fengwei
2023-08-04 0:28 ` Yu Zhao
2023-08-01 6:18 ` Yu Zhao
2023-08-02 9:33 ` Ryan Roberts
2023-08-02 21:05 ` Yu Zhao
2023-08-03 10:24 ` Ryan Roberts
2023-08-03 12:43 ` Ryan Roberts
2023-08-03 14:21 ` Kirill A. Shutemov
2023-08-04 0:19 ` Yu Zhao
2023-08-04 2:16 ` Zi Yan
2023-08-04 3:35 ` Yu Zhao
2023-08-04 9:06 ` Ryan Roberts
2023-08-04 18:53 ` Yu Zhao
2023-08-07 19:00 ` Ryan Roberts
2023-08-03 23:50 ` Yu Zhao
2023-08-04 8:27 ` Ryan Roberts
2023-08-04 20:23 ` David Hildenbrand
2023-08-04 21:00 ` Yu Zhao
2023-08-04 21:13 ` David Hildenbrand
2023-08-04 21:26 ` Yu Zhao
2023-08-04 21:30 ` David Hildenbrand
2023-08-04 21:58 ` Zi Yan
2023-08-05 2:50 ` Yin, Fengwei
2023-08-07 17:45 ` Ryan Roberts
2023-08-07 18:10 ` Zi Yan
2023-08-08 9:58 ` Ryan Roberts
2023-08-07 5:24 ` Yu Zhao
2023-08-07 19:07 ` Ryan Roberts
2023-08-07 23:21 ` Yu Zhao
2023-08-08 9:37 ` Ryan Roberts
2023-08-08 17:57 ` Yu Zhao
2023-08-08 18:12 ` Yu Zhao
2023-08-09 16:08 ` Ryan Roberts
2023-07-26 9:51 ` [PATCH v4 3/5] arm64: mm: Override arch_wants_pte_order() Ryan Roberts
2023-07-26 9:51 ` [PATCH v4 4/5] selftests/mm/cow: Generalize do_run_with_thp() helper Ryan Roberts
2023-07-26 9:51 ` [PATCH v4 5/5] selftests/mm/cow: Add large anon folio tests Ryan Roberts
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230726095146.2826796-2-ryan.roberts@arm.com \
--to=ryan.roberts@arm.com \
--cc=akpm@linux-foundation.org \
--cc=anshuman.khandual@arm.com \
--cc=catalin.marinas@arm.com \
--cc=david@redhat.com \
--cc=fengwei.yin@intel.com \
--cc=itaru.kitayama@gmail.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=mcgrof@kernel.org \
--cc=shy828301@gmail.com \
--cc=will@kernel.org \
--cc=willy@infradead.org \
--cc=ying.huang@intel.com \
--cc=yuzhao@google.com \
--cc=ziy@nvidia.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox