Files
Matthew Wilcox (Oracle) 53fbef56e0 mm: introduce memdesc_flags_t
Patch series "Add and use memdesc_flags_t".

At some point struct page will be separated from struct slab and struct
folio.  This is a step towards that by introducing a type for the 'flags'
word of all three structures.  This gives us a certain amount of type
safety by establishing that some of these unsigned longs are different
from other unsigned longs in that they contain things like node ID,
section number and zone number in the upper bits.  That lets us have
functions that can be easily called by anyone who has a slab, folio or
page (but not easily by anyone else) to get the node or zone.

There's going to be some unusual merge problems with this as some odd bits
of the kernel decide they want to print out the flags value or something
similar by writing page->flags and now they'll need to write page->flags.f
instead.  That's most of the churn here.  Maybe we should be removing
these things from the debug output?


This patch (of 11):

Wrap the unsigned long flags in a typedef.  In upcoming patches, this will
provide a strong hint that you can't just pass a random unsigned long to
functions which take this as an argument.

[[email protected]: s/flags/flags.f/ in several architectures]
  Link: https://lkml.kernel.org/r/[email protected]
[[email protected]: mips: fix compilation error]
  Link: https://lore.kernel.org/lkml/CA+G9fYvkpmqGr6wjBNHY=dRp71PLCoi2341JxOudi60yqaeUdg@mail.gmail.com/
  Link: https://lkml.kernel.org/r/[email protected]
Link: https://lkml.kernel.org/r/[email protected]
Link: https://lkml.kernel.org/r/[email protected]
Signed-off-by: Matthew Wilcox (Oracle) <[email protected]>
Signed-off-by: Matthew Wilcox (Oracle) <[email protected]>
Acked-by: Zi Yan <[email protected]>
Cc: Shakeel Butt <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
2025-09-13 16:55:07 -07:00

136 lines
3.0 KiB
C

/* SPDX-License-Identifier: GPL-2.0 */
#undef TRACE_SYSTEM
#define TRACE_SYSTEM page_ref
#if !defined(_TRACE_PAGE_REF_H) || defined(TRACE_HEADER_MULTI_READ)
#define _TRACE_PAGE_REF_H
#include <linux/types.h>
#include <linux/page_ref.h>
#include <linux/tracepoint.h>
#include <trace/events/mmflags.h>
DECLARE_EVENT_CLASS(page_ref_mod_template,
TP_PROTO(struct page *page, int v),
TP_ARGS(page, v),
TP_STRUCT__entry(
__field(unsigned long, pfn)
__field(unsigned long, flags)
__field(int, count)
__field(int, mapcount)
__field(void *, mapping)
__field(int, mt)
__field(int, val)
),
TP_fast_assign(
__entry->pfn = page_to_pfn(page);
__entry->flags = page->flags.f;
__entry->count = page_ref_count(page);
__entry->mapcount = atomic_read(&page->_mapcount);
__entry->mapping = page->mapping;
__entry->mt = get_pageblock_migratetype(page);
__entry->val = v;
),
TP_printk("pfn=0x%lx flags=%s count=%d mapcount=%d mapping=%p mt=%d val=%d",
__entry->pfn,
show_page_flags(__entry->flags & PAGEFLAGS_MASK),
__entry->count,
__entry->mapcount, __entry->mapping, __entry->mt,
__entry->val)
);
DEFINE_EVENT(page_ref_mod_template, page_ref_set,
TP_PROTO(struct page *page, int v),
TP_ARGS(page, v)
);
DEFINE_EVENT(page_ref_mod_template, page_ref_mod,
TP_PROTO(struct page *page, int v),
TP_ARGS(page, v)
);
DECLARE_EVENT_CLASS(page_ref_mod_and_test_template,
TP_PROTO(struct page *page, int v, int ret),
TP_ARGS(page, v, ret),
TP_STRUCT__entry(
__field(unsigned long, pfn)
__field(unsigned long, flags)
__field(int, count)
__field(int, mapcount)
__field(void *, mapping)
__field(int, mt)
__field(int, val)
__field(int, ret)
),
TP_fast_assign(
__entry->pfn = page_to_pfn(page);
__entry->flags = page->flags.f;
__entry->count = page_ref_count(page);
__entry->mapcount = atomic_read(&page->_mapcount);
__entry->mapping = page->mapping;
__entry->mt = get_pageblock_migratetype(page);
__entry->val = v;
__entry->ret = ret;
),
TP_printk("pfn=0x%lx flags=%s count=%d mapcount=%d mapping=%p mt=%d val=%d ret=%d",
__entry->pfn,
show_page_flags(__entry->flags & PAGEFLAGS_MASK),
__entry->count,
__entry->mapcount, __entry->mapping, __entry->mt,
__entry->val, __entry->ret)
);
DEFINE_EVENT(page_ref_mod_and_test_template, page_ref_mod_and_test,
TP_PROTO(struct page *page, int v, int ret),
TP_ARGS(page, v, ret)
);
DEFINE_EVENT(page_ref_mod_and_test_template, page_ref_mod_and_return,
TP_PROTO(struct page *page, int v, int ret),
TP_ARGS(page, v, ret)
);
DEFINE_EVENT(page_ref_mod_and_test_template, page_ref_mod_unless,
TP_PROTO(struct page *page, int v, int ret),
TP_ARGS(page, v, ret)
);
DEFINE_EVENT(page_ref_mod_and_test_template, page_ref_freeze,
TP_PROTO(struct page *page, int v, int ret),
TP_ARGS(page, v, ret)
);
DEFINE_EVENT(page_ref_mod_template, page_ref_unfreeze,
TP_PROTO(struct page *page, int v),
TP_ARGS(page, v)
);
#endif /* _TRACE_PAGE_COUNT_H */
/* This part must be outside protection */
#include <trace/define_trace.h>