* [RFC PATCH 0/2] mm/gup: move pinned pages to unevictable list to avoid meaningless scan
@ 2023-08-26 9:22 Jinjiang Tu
2023-08-26 9:22 ` [RFC PATCH 1/2] " Jinjiang Tu
2023-08-26 9:22 ` [RFC PATCH 2/2] mm/gup: remove folio_maybe_dma_pinned() calls in shrink_page_list() Jinjiang Tu
0 siblings, 2 replies; 3+ messages in thread
From: Jinjiang Tu @ 2023-08-26 9:22 UTC (permalink / raw)
To: linux-mm, akpm, wangkefeng.wang; +Cc: tujinjiang
The pages pinned by GUP interfaces are unable to be swapped out. Currently,
these pages are put into active/inactive list, leading to meaningless scan
when reclaiming memory.
Even worse, when we try to pin memory more than free memory, the system
fails to response for long time, all tasks are reclaiming memory. However,
the process takes long time to scan too much pinned pages, but only reclaim
few pages. Because each scan takes too much time, during this time, some
pages are swapped out again, some pages can be reclaimed again during next
scan. As a result, the OOM condition is not easy to meet.
I reproduce this problem by gup_test utility (CONFIG_GUP_TEST is needed).
The system has 3.3G free memory, and I pins 4G memory by command
'./gup_test -b -m 4096'. The system will fail to response for 10+ minutes
before triggering OOM.
To solve this problem, this patchset moves pinned pages to unevictable list
to avoid meaningless scanning during memory reclaim.
Jinjiang Tu (2):
mm/gup: move pinned pages to unevictable list to avoid meaningless
scan
mm/gup: remove folio_maybe_dma_pinned() calls in shrink_page_list()
mm/gup.c | 13 +++++++++++++
mm/internal.h | 2 +-
mm/vmscan.c | 12 ------------
3 files changed, 14 insertions(+), 13 deletions(-)
--
2.25.1
^ permalink raw reply [flat|nested] 3+ messages in thread* [RFC PATCH 1/2] mm/gup: move pinned pages to unevictable list to avoid meaningless scan
2023-08-26 9:22 [RFC PATCH 0/2] mm/gup: move pinned pages to unevictable list to avoid meaningless scan Jinjiang Tu
@ 2023-08-26 9:22 ` Jinjiang Tu
2023-08-26 9:22 ` [RFC PATCH 2/2] mm/gup: remove folio_maybe_dma_pinned() calls in shrink_page_list() Jinjiang Tu
1 sibling, 0 replies; 3+ messages in thread
From: Jinjiang Tu @ 2023-08-26 9:22 UTC (permalink / raw)
To: linux-mm, akpm, wangkefeng.wang; +Cc: tujinjiang
To avoid meaningless scan during memory reclaim, this patch moves pinned
pages to unevictable list to avoid meaningless scan during memory reclaim.
Update folio_evictable() to check if the folio is pinned. If the folio is
pinned, the function returns false. The vmscan code will put the folio to
inevictable list when scanning the folio, so each pinned page will be
scanned at most once. When the folio is unpinned, check if the folio can
be put back to inactive/active list by calling folio_evictable().
Signed-off-by: Jinjiang Tu <tujinjiang@huawei.com>
---
mm/gup.c | 13 +++++++++++++
mm/internal.h | 2 +-
2 files changed, 14 insertions(+), 1 deletion(-)
diff --git a/mm/gup.c b/mm/gup.c
index 6e2f9e9d6537..ca82e1bc6826 100644
--- a/mm/gup.c
+++ b/mm/gup.c
@@ -200,6 +200,19 @@ static void gup_put_folio(struct folio *folio, int refs, unsigned int flags)
if (!put_devmap_managed_page_refs(&folio->page, refs))
folio_put_refs(folio, refs);
+
+ if (folio_test_unevictable(folio) && folio_evictable(folio)) {
+ struct lruvec *lruvec = folio_lruvec_lock_irq(folio);
+
+ lruvec_del_folio(lruvec, folio);
+ folio_clear_unevictable(folio);
+ lruvec_add_folio(lruvec, folio);
+ folio_set_lru(folio);
+ __count_vm_events(UNEVICTABLE_PGRESCUED,
+ folio_nr_pages(folio));
+
+ unlock_page_lruvec_irq(lruvec);
+ }
}
/**
diff --git a/mm/internal.h b/mm/internal.h
index 8ed127c1c808..9ce158de40cf 100644
--- a/mm/internal.h
+++ b/mm/internal.h
@@ -154,7 +154,7 @@ static inline bool folio_evictable(struct folio *folio)
/* Prevent address_space of inode and swap cache from being freed */
rcu_read_lock();
ret = !mapping_unevictable(folio_mapping(folio)) &&
- !folio_test_mlocked(folio);
+ !folio_test_mlocked(folio) && !folio_maybe_dma_pinned(folio);
rcu_read_unlock();
return ret;
}
--
2.25.1
^ permalink raw reply [flat|nested] 3+ messages in thread* [RFC PATCH 2/2] mm/gup: remove folio_maybe_dma_pinned() calls in shrink_page_list()
2023-08-26 9:22 [RFC PATCH 0/2] mm/gup: move pinned pages to unevictable list to avoid meaningless scan Jinjiang Tu
2023-08-26 9:22 ` [RFC PATCH 1/2] " Jinjiang Tu
@ 2023-08-26 9:22 ` Jinjiang Tu
1 sibling, 0 replies; 3+ messages in thread
From: Jinjiang Tu @ 2023-08-26 9:22 UTC (permalink / raw)
To: linux-mm, akpm, wangkefeng.wang; +Cc: tujinjiang
Since the pinned pages have been put into inevictable list,
folio_maybe_dma_pinned() calls in shrink_page_list() could
be removed.
Signed-off-by: Jinjiang Tu <tujinjiang@huawei.com>
---
mm/vmscan.c | 12 ------------
1 file changed, 12 deletions(-)
diff --git a/mm/vmscan.c b/mm/vmscan.c
index 2fe4a11d63f4..590833c1fdbe 100644
--- a/mm/vmscan.c
+++ b/mm/vmscan.c
@@ -1891,8 +1891,6 @@ static unsigned int shrink_folio_list(struct list_head *folio_list,
if (!folio_test_swapcache(folio)) {
if (!(sc->gfp_mask & __GFP_IO))
goto keep_locked;
- if (folio_maybe_dma_pinned(folio))
- goto keep_locked;
if (folio_test_large(folio)) {
/* cannot split folio, skip it */
if (!can_split_folio(folio, NULL))
@@ -1959,16 +1957,6 @@ static unsigned int shrink_folio_list(struct list_head *folio_list,
}
}
- /*
- * Folio is unmapped now so it cannot be newly pinned anymore.
- * No point in trying to reclaim folio if it is pinned.
- * Furthermore we don't want to reclaim underlying fs metadata
- * if the folio is pinned and thus potentially modified by the
- * pinning process as that may upset the filesystem.
- */
- if (folio_maybe_dma_pinned(folio))
- goto activate_locked;
-
mapping = folio_mapping(folio);
if (folio_test_dirty(folio)) {
/*
--
2.25.1
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2023-08-26 8:28 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-08-26 9:22 [RFC PATCH 0/2] mm/gup: move pinned pages to unevictable list to avoid meaningless scan Jinjiang Tu
2023-08-26 9:22 ` [RFC PATCH 1/2] " Jinjiang Tu
2023-08-26 9:22 ` [RFC PATCH 2/2] mm/gup: remove folio_maybe_dma_pinned() calls in shrink_page_list() Jinjiang Tu
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox