Skip to content

Commit 42b2eb6

Browse files
uarif1akpm00
authored andcommitted
mm: convert partially_mapped set/clear operations to be atomic
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]>
1 parent 6309b8c commit 42b2eb6

File tree

2 files changed

+6
-14
lines changed

2 files changed

+6
-14
lines changed

include/linux/page-flags.h

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -862,18 +862,10 @@ static inline void ClearPageCompound(struct page *page)
862862
ClearPageHead(page);
863863
}
864864
FOLIO_FLAG(large_rmappable, FOLIO_SECOND_PAGE)
865-
FOLIO_TEST_FLAG(partially_mapped, FOLIO_SECOND_PAGE)
866-
/*
867-
* PG_partially_mapped is protected by deferred_split split_queue_lock,
868-
* so its safe to use non-atomic set/clear.
869-
*/
870-
__FOLIO_SET_FLAG(partially_mapped, FOLIO_SECOND_PAGE)
871-
__FOLIO_CLEAR_FLAG(partially_mapped, FOLIO_SECOND_PAGE)
865+
FOLIO_FLAG(partially_mapped, FOLIO_SECOND_PAGE)
872866
#else
873867
FOLIO_FLAG_FALSE(large_rmappable)
874-
FOLIO_TEST_FLAG_FALSE(partially_mapped)
875-
__FOLIO_SET_FLAG_NOOP(partially_mapped)
876-
__FOLIO_CLEAR_FLAG_NOOP(partially_mapped)
868+
FOLIO_FLAG_FALSE(partially_mapped)
877869
#endif
878870

879871
#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
@@ -3577,7 +3577,7 @@ int split_huge_page_to_list_to_order(struct page *page, struct list_head *list,
35773577
!list_empty(&folio->_deferred_list)) {
35783578
ds_queue->split_queue_len--;
35793579
if (folio_test_partially_mapped(folio)) {
3580-
__folio_clear_partially_mapped(folio);
3580+
folio_clear_partially_mapped(folio);
35813581
mod_mthp_stat(folio_order(folio),
35823582
MTHP_STAT_NR_ANON_PARTIALLY_MAPPED, -1);
35833583
}
@@ -3689,7 +3689,7 @@ bool __folio_unqueue_deferred_split(struct folio *folio)
36893689
if (!list_empty(&folio->_deferred_list)) {
36903690
ds_queue->split_queue_len--;
36913691
if (folio_test_partially_mapped(folio)) {
3692-
__folio_clear_partially_mapped(folio);
3692+
folio_clear_partially_mapped(folio);
36933693
mod_mthp_stat(folio_order(folio),
36943694
MTHP_STAT_NR_ANON_PARTIALLY_MAPPED, -1);
36953695
}
@@ -3733,7 +3733,7 @@ void deferred_split_folio(struct folio *folio, bool partially_mapped)
37333733
spin_lock_irqsave(&ds_queue->split_queue_lock, flags);
37343734
if (partially_mapped) {
37353735
if (!folio_test_partially_mapped(folio)) {
3736-
__folio_set_partially_mapped(folio);
3736+
folio_set_partially_mapped(folio);
37373737
if (folio_test_pmd_mappable(folio))
37383738
count_vm_event(THP_DEFERRED_SPLIT_PAGE);
37393739
count_mthp_stat(folio_order(folio), MTHP_STAT_SPLIT_DEFERRED);
@@ -3826,7 +3826,7 @@ static unsigned long deferred_split_scan(struct shrinker *shrink,
38263826
} else {
38273827
/* We lost race with folio_put() */
38283828
if (folio_test_partially_mapped(folio)) {
3829-
__folio_clear_partially_mapped(folio);
3829+
folio_clear_partially_mapped(folio);
38303830
mod_mthp_stat(folio_order(folio),
38313831
MTHP_STAT_NR_ANON_PARTIALLY_MAPPED, -1);
38323832
}

0 commit comments

Comments
 (0)