Skip to content

Commit 372cbd4

Browse files
ryanhrobakpm00
authored andcommitted
mm: non-pmd-mappable, large folios for folio_add_new_anon_rmap()
In preparation for supporting anonymous multi-size THP, 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. Link: https://lkml.kernel.org/r/20231207161211.2374093-3-ryan.roberts@arm.com Signed-off-by: Ryan Roberts <ryan.roberts@arm.com> Reviewed-by: Yu Zhao <yuzhao@google.com> Reviewed-by: Yin Fengwei <fengwei.yin@intel.com> Reviewed-by: David Hildenbrand <david@redhat.com> Reviewed-by: Barry Song <v-songbaohua@oppo.com> Tested-by: Kefeng Wang <wangkefeng.wang@huawei.com> Tested-by: John Hubbard <jhubbard@nvidia.com> Cc: Alistair Popple <apopple@nvidia.com> Cc: Anshuman Khandual <anshuman.khandual@arm.com> Cc: Catalin Marinas <catalin.marinas@arm.com> Cc: David Rientjes <rientjes@google.com> Cc: "Huang, Ying" <ying.huang@intel.com> Cc: Hugh Dickins <hughd@google.com> Cc: Itaru Kitayama <itaru.kitayama@gmail.com> Cc: Kirill A. Shutemov <kirill.shutemov@linux.intel.com> Cc: Luis Chamberlain <mcgrof@kernel.org> Cc: Matthew Wilcox (Oracle) <willy@infradead.org> Cc: Vlastimil Babka <vbabka@suse.cz> Cc: Yang Shi <shy828301@gmail.com> Cc: Zi Yan <ziy@nvidia.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
1 parent 7dc7c5e commit 372cbd4

File tree

1 file changed

+20
-8
lines changed

1 file changed

+20
-8
lines changed

mm/rmap.c

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1305,32 +1305,44 @@ void page_add_anon_rmap(struct page *page, struct vm_area_struct *vma,
13051305
* This means the inc-and-test can be bypassed.
13061306
* The folio does not have to be locked.
13071307
*
1308-
* If the folio is large, it is accounted as a THP. As the folio
1308+
* If the folio is pmd-mappable, it is accounted as a THP. As the folio
13091309
* is new, it's assumed to be mapped exclusively by a single process.
13101310
*/
13111311
void folio_add_new_anon_rmap(struct folio *folio, struct vm_area_struct *vma,
13121312
unsigned long address)
13131313
{
1314-
int nr;
1314+
int nr = folio_nr_pages(folio);
13151315

1316-
VM_BUG_ON_VMA(address < vma->vm_start || address >= vma->vm_end, vma);
1316+
VM_BUG_ON_VMA(address < vma->vm_start ||
1317+
address + (nr << PAGE_SHIFT) > vma->vm_end, vma);
13171318
__folio_set_swapbacked(folio);
1319+
__folio_set_anon(folio, vma, address, true);
13181320

1319-
if (likely(!folio_test_pmd_mappable(folio))) {
1321+
if (likely(!folio_test_large(folio))) {
13201322
/* increment count (starts at -1) */
13211323
atomic_set(&folio->_mapcount, 0);
1322-
nr = 1;
1324+
SetPageAnonExclusive(&folio->page);
1325+
} else if (!folio_test_pmd_mappable(folio)) {
1326+
int i;
1327+
1328+
for (i = 0; i < nr; i++) {
1329+
struct page *page = folio_page(folio, i);
1330+
1331+
/* increment count (starts at -1) */
1332+
atomic_set(&page->_mapcount, 0);
1333+
SetPageAnonExclusive(page);
1334+
}
1335+
1336+
atomic_set(&folio->_nr_pages_mapped, nr);
13231337
} else {
13241338
/* increment count (starts at -1) */
13251339
atomic_set(&folio->_entire_mapcount, 0);
13261340
atomic_set(&folio->_nr_pages_mapped, COMPOUND_MAPPED);
1327-
nr = folio_nr_pages(folio);
1341+
SetPageAnonExclusive(&folio->page);
13281342
__lruvec_stat_mod_folio(folio, NR_ANON_THPS, nr);
13291343
}
13301344

13311345
__lruvec_stat_mod_folio(folio, NR_ANON_MAPPED, nr);
1332-
__folio_set_anon(folio, vma, address, true);
1333-
SetPageAnonExclusive(&folio->page);
13341346
}
13351347

13361348
/**

0 commit comments

Comments
 (0)