Skip to content

Commit 593a10d

Browse files
Kefeng Wangakpm00
authored andcommitted
mm: refactor folio_undo_large_rmappable()
Folios of order <= 1 are not in deferred list, the check of order is added into folio_undo_large_rmappable() from commit 8897277 ("mm: support order-1 folios in the page cache"), but there is a repeated check for small folio (order 0) during each call of the folio_undo_large_rmappable(), so only keep folio_order() check inside the function. In addition, move all the checks into header file to save a function call for non-large-rmappable or empty deferred_list folio. Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: Kefeng Wang <[email protected]> Reviewed-by: David Hildenbrand <[email protected]> Reviewed-by: Vishal Moola (Oracle) <[email protected]> Cc: Johannes Weiner <[email protected]> Cc: Lance Yang <[email protected]> Cc: Matthew Wilcox (Oracle) <[email protected]> Cc: Michal Hocko <[email protected]> Cc: Muchun Song <[email protected]> Cc: Roman Gushchin <[email protected]> Cc: Shakeel Butt <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent 8bf890c commit 593a10d

File tree

5 files changed

+22
-27
lines changed

5 files changed

+22
-27
lines changed

mm/huge_memory.c

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3258,22 +3258,11 @@ int split_huge_page_to_list_to_order(struct page *page, struct list_head *list,
32583258
return ret;
32593259
}
32603260

3261-
void folio_undo_large_rmappable(struct folio *folio)
3261+
void __folio_undo_large_rmappable(struct folio *folio)
32623262
{
32633263
struct deferred_split *ds_queue;
32643264
unsigned long flags;
32653265

3266-
if (folio_order(folio) <= 1)
3267-
return;
3268-
3269-
/*
3270-
* At this point, there is no one trying to add the folio to
3271-
* deferred_list. If folio is not in deferred_list, it's safe
3272-
* to check without acquiring the split_queue_lock.
3273-
*/
3274-
if (data_race(list_empty(&folio->_deferred_list)))
3275-
return;
3276-
32773266
ds_queue = get_deferred_split_queue(folio);
32783267
spin_lock_irqsave(&ds_queue->split_queue_lock, flags);
32793268
if (!list_empty(&folio->_deferred_list)) {

mm/internal.h

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -622,7 +622,22 @@ static inline void folio_set_order(struct folio *folio, unsigned int order)
622622
#endif
623623
}
624624

625-
void folio_undo_large_rmappable(struct folio *folio);
625+
void __folio_undo_large_rmappable(struct folio *folio);
626+
static inline void folio_undo_large_rmappable(struct folio *folio)
627+
{
628+
if (folio_order(folio) <= 1 || !folio_test_large_rmappable(folio))
629+
return;
630+
631+
/*
632+
* At this point, there is no one trying to add the folio to
633+
* deferred_list. If folio is not in deferred_list, it's safe
634+
* to check without acquiring the split_queue_lock.
635+
*/
636+
if (data_race(list_empty(&folio->_deferred_list)))
637+
return;
638+
639+
__folio_undo_large_rmappable(folio);
640+
}
626641

627642
static inline struct folio *page_rmappable_folio(struct page *page)
628643
{

mm/page_alloc.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2661,8 +2661,7 @@ void free_unref_folios(struct folio_batch *folios)
26612661
unsigned long pfn = folio_pfn(folio);
26622662
unsigned int order = folio_order(folio);
26632663

2664-
if (order > 0 && folio_test_large_rmappable(folio))
2665-
folio_undo_large_rmappable(folio);
2664+
folio_undo_large_rmappable(folio);
26662665
if (!free_pages_prepare(&folio->page, order))
26672666
continue;
26682667
/*

mm/swap.c

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,7 @@ void __folio_put(struct folio *folio)
123123
}
124124

125125
page_cache_release(folio);
126-
if (folio_test_large(folio) && folio_test_large_rmappable(folio))
127-
folio_undo_large_rmappable(folio);
126+
folio_undo_large_rmappable(folio);
128127
mem_cgroup_uncharge(folio);
129128
free_unref_page(&folio->page, folio_order(folio));
130129
}
@@ -1002,10 +1001,7 @@ void folios_put_refs(struct folio_batch *folios, unsigned int *refs)
10021001
free_huge_folio(folio);
10031002
continue;
10041003
}
1005-
if (folio_test_large(folio) &&
1006-
folio_test_large_rmappable(folio))
1007-
folio_undo_large_rmappable(folio);
1008-
1004+
folio_undo_large_rmappable(folio);
10091005
__page_cache_release(folio, &lruvec, &flags);
10101006

10111007
if (j != i)

mm/vmscan.c

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1439,9 +1439,7 @@ static unsigned int shrink_folio_list(struct list_head *folio_list,
14391439
*/
14401440
nr_reclaimed += nr_pages;
14411441

1442-
if (folio_test_large(folio) &&
1443-
folio_test_large_rmappable(folio))
1444-
folio_undo_large_rmappable(folio);
1442+
folio_undo_large_rmappable(folio);
14451443
if (folio_batch_add(&free_folios, folio) == 0) {
14461444
mem_cgroup_uncharge_folios(&free_folios);
14471445
try_to_unmap_flush();
@@ -1848,9 +1846,7 @@ static unsigned int move_folios_to_lru(struct lruvec *lruvec,
18481846
if (unlikely(folio_put_testzero(folio))) {
18491847
__folio_clear_lru_flags(folio);
18501848

1851-
if (folio_test_large(folio) &&
1852-
folio_test_large_rmappable(folio))
1853-
folio_undo_large_rmappable(folio);
1849+
folio_undo_large_rmappable(folio);
18541850
if (folio_batch_add(&free_folios, folio) == 0) {
18551851
spin_unlock_irq(&lruvec->lru_lock);
18561852
mem_cgroup_uncharge_folios(&free_folios);

0 commit comments

Comments
 (0)