Skip to content

Commit a086c8d

Browse files
uarif1gregkh
authored andcommitted
mm: convert partially_mapped set/clear operations to be atomic
commit 42b2eb6 upstream. Other page flags in the 2nd page, like PG_hwpoison and PG_anon_exclusive can get modified concurrently. Changes to other page flags might be lost if they are happening at the same time as non-atomic partially_mapped operations. Hence, make partially_mapped operations atomic. Link: https://lkml.kernel.org/r/[email protected] Fixes: 8422acd ("mm: introduce a pageflag for partially mapped folios") Reported-by: David Hildenbrand <[email protected]> Link: https://lore.kernel.org/all/[email protected]/ Signed-off-by: Usama Arif <[email protected]> Acked-by: David Hildenbrand <[email protected]> Acked-by: Johannes Weiner <[email protected]> Acked-by: Roman Gushchin <[email protected]> Cc: Barry Song <[email protected]> Cc: Domenico Cerasuolo <[email protected]> Cc: Jonathan Corbet <[email protected]> Cc: Matthew Wilcox <[email protected]> Cc: Mike Rapoport (Microsoft) <[email protected]> Cc: Nico Pache <[email protected]> Cc: Rik van Riel <[email protected]> Cc: Ryan Roberts <[email protected]> Cc: Shakeel Butt <[email protected]> Cc: Yu Zhao <[email protected]> Cc: <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent a095090 commit a086c8d

2 files changed

Lines changed: 6 additions & 14 deletions

File tree

include/linux/page-flags.h

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -860,18 +860,10 @@ static inline void ClearPageCompound(struct page *page)
860860
ClearPageHead(page);
861861
}
862862
FOLIO_FLAG(large_rmappable, FOLIO_SECOND_PAGE)
863-
FOLIO_TEST_FLAG(partially_mapped, FOLIO_SECOND_PAGE)
864-
/*
865-
* PG_partially_mapped is protected by deferred_split split_queue_lock,
866-
* so its safe to use non-atomic set/clear.
867-
*/
868-
__FOLIO_SET_FLAG(partially_mapped, FOLIO_SECOND_PAGE)
869-
__FOLIO_CLEAR_FLAG(partially_mapped, FOLIO_SECOND_PAGE)
863+
FOLIO_FLAG(partially_mapped, FOLIO_SECOND_PAGE)
870864
#else
871865
FOLIO_FLAG_FALSE(large_rmappable)
872-
FOLIO_TEST_FLAG_FALSE(partially_mapped)
873-
__FOLIO_SET_FLAG_NOOP(partially_mapped)
874-
__FOLIO_CLEAR_FLAG_NOOP(partially_mapped)
866+
FOLIO_FLAG_FALSE(partially_mapped)
875867
#endif
876868

877869
#define PG_head_mask ((1UL << PG_head))

mm/huge_memory.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3503,7 +3503,7 @@ int split_huge_page_to_list_to_order(struct page *page, struct list_head *list,
35033503
!list_empty(&folio->_deferred_list)) {
35043504
ds_queue->split_queue_len--;
35053505
if (folio_test_partially_mapped(folio)) {
3506-
__folio_clear_partially_mapped(folio);
3506+
folio_clear_partially_mapped(folio);
35073507
mod_mthp_stat(folio_order(folio),
35083508
MTHP_STAT_NR_ANON_PARTIALLY_MAPPED, -1);
35093509
}
@@ -3615,7 +3615,7 @@ bool __folio_unqueue_deferred_split(struct folio *folio)
36153615
if (!list_empty(&folio->_deferred_list)) {
36163616
ds_queue->split_queue_len--;
36173617
if (folio_test_partially_mapped(folio)) {
3618-
__folio_clear_partially_mapped(folio);
3618+
folio_clear_partially_mapped(folio);
36193619
mod_mthp_stat(folio_order(folio),
36203620
MTHP_STAT_NR_ANON_PARTIALLY_MAPPED, -1);
36213621
}
@@ -3659,7 +3659,7 @@ void deferred_split_folio(struct folio *folio, bool partially_mapped)
36593659
spin_lock_irqsave(&ds_queue->split_queue_lock, flags);
36603660
if (partially_mapped) {
36613661
if (!folio_test_partially_mapped(folio)) {
3662-
__folio_set_partially_mapped(folio);
3662+
folio_set_partially_mapped(folio);
36633663
if (folio_test_pmd_mappable(folio))
36643664
count_vm_event(THP_DEFERRED_SPLIT_PAGE);
36653665
count_mthp_stat(folio_order(folio), MTHP_STAT_SPLIT_DEFERRED);
@@ -3752,7 +3752,7 @@ static unsigned long deferred_split_scan(struct shrinker *shrink,
37523752
} else {
37533753
/* We lost race with folio_put() */
37543754
if (folio_test_partially_mapped(folio)) {
3755-
__folio_clear_partially_mapped(folio);
3755+
folio_clear_partially_mapped(folio);
37563756
mod_mthp_stat(folio_order(folio),
37573757
MTHP_STAT_NR_ANON_PARTIALLY_MAPPED, -1);
37583758
}

0 commit comments

Comments
 (0)