[PATCH v17 45/47] dept: track PG_writeback with dept

Byungchul Park
2025-10-02T08:14:08Z

Makes dept able to track PG_writeback waits and events, which will be
useful in practice.

Signed-off-by: Byungchul Park <byungchul@sk.com>
---
include/linux/mm_types.h | 1 +
include/linux/page-flags.h | 7 +++++++
mm/filemap.c | 11 +++++++++++
mm/mm_init.c | 1 +
4 files changed, 20 insertions(+)

diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
index 8ccbb030500c..bed1a3bc81e1 100644
--- a/include/linux/mm_types.h
+++ b/include/linux/mm_types.h
@@ -226,6 +226,7 @@ struct page {
#endif
struct dept_page_usage usage;
struct dept_ext_wgen pg_locked_wgen;
+ struct dept_ext_wgen pg_writeback_wgen;
} _struct_page_alignment;

/*
diff --git a/include/linux/page-flags.h b/include/linux/page-flags.h
index 3fd3660ddc6f..b965b16c8cee 100644
--- a/include/linux/page-flags.h
+++ b/include/linux/page-flags.h
@@ -203,6 +203,7 @@ enum pageflags {
#include <linux/dept.h>

extern struct dept_map pg_locked_map;
+extern struct dept_map pg_writeback_map;

static inline int dept_set_page_usage(struct page *p,
unsigned int new_type)
@@ -279,6 +280,8 @@ static inline void dept_page_set_bit(struct page *p, int bit_nr)
dept_update_page_usage(p);
if (bit_nr == PG_locked)
dept_request_event(&pg_locked_map, &p->pg_locked_wgen);
+ else if (bit_nr == PG_writeback)
+ dept_request_event(&pg_writeback_map, &p->pg_writeback_wgen);
}

static inline void dept_page_clear_bit(struct page *p, int bit_nr)
@@ -288,6 +291,8 @@ static inline void dept_page_clear_bit(struct page *p, int bit_nr)
evt_f = dept_event_flags(p, false);
if (bit_nr == PG_locked)
dept_event(&pg_locked_map, evt_f, _RET_IP_, __func__, &p->pg_locked_wgen);
+ else if (bit_nr == PG_writeback)
+ dept_event(&pg_writeback_map, evt_f, _RET_IP_, __func__, &p->pg_writeback_wgen);
}

static inline void dept_page_wait_on_bit(struct page *p, int bit_nr)
@@ -298,6 +303,8 @@ static inline void dept_page_wait_on_bit(struct page *p, int bit_nr)
evt_f = dept_event_flags(p, true);
if (bit_nr == PG_locked)
dept_wait(&pg_locked_map, evt_f, _RET_IP_, __func__, 0, -1L);
+ else if (bit_nr == PG_writeback)
+ dept_wait(&pg_writeback_map, evt_f, _RET_IP_, __func__, 0, -1L);
}

static inline void dept_folio_set_bit(struct folio *f, int bit_nr)
diff --git a/mm/filemap.c b/mm/filemap.c
index edb0710ddb3f..d8f1816dc6c2 100644
--- a/mm/filemap.c
+++ b/mm/filemap.c
@@ -1187,6 +1187,13 @@ static void folio_wake_bit(struct folio *folio, int bit_nr)
key.bit_nr = bit_nr;
key.page_match = 0;

+ /*
+ * dept_page_clear_bit() being called multiple times is harmless.
+ * The worst case is to miss some dependencies but it's okay.
+ */
+ if (bit_nr == PG_locked || bit_nr == PG_writeback)
+ dept_page_clear_bit(&folio->page, bit_nr);
+
spin_lock_irqsave(&q->lock, flags);
__wake_up_locked_key(q, TASK_NORMAL, &key);

@@ -1241,6 +1248,9 @@ static inline bool folio_trylock_flag(struct folio *folio, int bit_nr,
struct dept_map __maybe_unused pg_locked_map = DEPT_MAP_INITIALIZER(pg_locked_map, NULL);
EXPORT_SYMBOL(pg_locked_map);

+struct dept_map __maybe_unused pg_writeback_map = DEPT_MAP_INITIALIZER(pg_writeback_map, NULL);
+EXPORT_SYMBOL(pg_writeback_map);
+
static inline int folio_wait_bit_common(struct folio *folio, int bit_nr,
int state, enum behavior behavior)
{
@@ -1683,6 +1693,7 @@ void folio_end_writeback(struct folio *folio)
* reused before the folio_wake_bit().
*/
folio_get(folio);
+ dept_page_clear_bit(&folio->page, PG_writeback);
if (__folio_end_writeback(folio))
folio_wake_bit(folio, PG_writeback);

diff --git a/mm/mm_init.c b/mm/mm_init.c
index 09e4ac6a73c7..fd2bf6689afa 100644
--- a/mm/mm_init.c
+++ b/mm/mm_init.c
@@ -589,6 +589,7 @@ void __meminit __init_single_page(struct page *page, unsigned long pfn,
page_cpupid_reset_last(page);
page_kasan_tag_reset(page);
dept_ext_wgen_init(&page->pg_locked_wgen);
+ dept_ext_wgen_init(&page->pg_writeback_wgen);

INIT_LIST_HEAD(&page->lru);
#ifdef WANT_PAGE_VIRTUAL
--
2.17.1