linux/include/trace/events/filemap.h
Takaya Saeki b6273b55d8 filemap: add trace events for get_pages, map_pages, and fault
To allow precise tracking of page caches accessed, add new tracepoints
that trigger when a process actually accesses them.

The ureadahead program used by ChromeOS traces the disk access of programs
as they start up at boot up.  It uses mincore(2) or the
'mm_filemap_add_to_page_cache' trace event to accomplish this.  It stores
this information in a "pack" file and on subsequent boots, it will read
the pack file and call readahead(2) on the information so that disk
storage can be loaded into RAM before the applications actually need it.

A problem we see is that due to the kernel's readahead algorithm that can
aggressively pull in more data than needed (to try and accomplish the same
goal) and this data is also recorded.  The end result is that the pack
file contains a lot of pages on disk that are never actually used. 
Calling readahead(2) on these unused pages can slow down the system boot
up times.

To solve this, add 3 new trace events, get_pages, map_pages, and fault. 
These will be used to trace the pages are not only pulled in from disk,
but are actually used by the application.  Only those pages will be stored
in the pack file, and this helps out the performance of boot up.

With the combination of these 3 new trace events and
mm_filemap_add_to_page_cache, we observed a reduction in the pack file by
7.3% - 20% on ChromeOS varying by device.

Link: https://lkml.kernel.org/r/20240813100312.3930505-1-takayas@chromium.org
Signed-off-by: Takaya Saeki <takayas@chromium.org>
Reviewed-by: Masami Hiramatsu (Google) <mhiramat@kernel.org>
Reviewed-by: Steven Rostedt (Google) <rostedt@goodmis.org>
Cc: Junichi Uekawa <uekawa@chromium.org>
Cc: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Cc: Matthew Wilcox <willy@infradead.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
2024-09-01 20:26:10 -07:00

203 lines
4.6 KiB
C

/* SPDX-License-Identifier: GPL-2.0 */
#undef TRACE_SYSTEM
#define TRACE_SYSTEM filemap
#if !defined(_TRACE_FILEMAP_H) || defined(TRACE_HEADER_MULTI_READ)
#define _TRACE_FILEMAP_H
#include <linux/types.h>
#include <linux/tracepoint.h>
#include <linux/mm.h>
#include <linux/memcontrol.h>
#include <linux/device.h>
#include <linux/kdev_t.h>
#include <linux/errseq.h>
DECLARE_EVENT_CLASS(mm_filemap_op_page_cache,
TP_PROTO(struct folio *folio),
TP_ARGS(folio),
TP_STRUCT__entry(
__field(unsigned long, pfn)
__field(unsigned long, i_ino)
__field(unsigned long, index)
__field(dev_t, s_dev)
__field(unsigned char, order)
),
TP_fast_assign(
__entry->pfn = folio_pfn(folio);
__entry->i_ino = folio->mapping->host->i_ino;
__entry->index = folio->index;
if (folio->mapping->host->i_sb)
__entry->s_dev = folio->mapping->host->i_sb->s_dev;
else
__entry->s_dev = folio->mapping->host->i_rdev;
__entry->order = folio_order(folio);
),
TP_printk("dev %d:%d ino %lx pfn=0x%lx ofs=%lu order=%u",
MAJOR(__entry->s_dev), MINOR(__entry->s_dev),
__entry->i_ino,
__entry->pfn,
__entry->index << PAGE_SHIFT,
__entry->order)
);
DEFINE_EVENT(mm_filemap_op_page_cache, mm_filemap_delete_from_page_cache,
TP_PROTO(struct folio *folio),
TP_ARGS(folio)
);
DEFINE_EVENT(mm_filemap_op_page_cache, mm_filemap_add_to_page_cache,
TP_PROTO(struct folio *folio),
TP_ARGS(folio)
);
DECLARE_EVENT_CLASS(mm_filemap_op_page_cache_range,
TP_PROTO(
struct address_space *mapping,
pgoff_t index,
pgoff_t last_index
),
TP_ARGS(mapping, index, last_index),
TP_STRUCT__entry(
__field(unsigned long, i_ino)
__field(dev_t, s_dev)
__field(unsigned long, index)
__field(unsigned long, last_index)
),
TP_fast_assign(
__entry->i_ino = mapping->host->i_ino;
if (mapping->host->i_sb)
__entry->s_dev =
mapping->host->i_sb->s_dev;
else
__entry->s_dev = mapping->host->i_rdev;
__entry->index = index;
__entry->last_index = last_index;
),
TP_printk(
"dev=%d:%d ino=%lx ofs=%lld-%lld",
MAJOR(__entry->s_dev),
MINOR(__entry->s_dev), __entry->i_ino,
((loff_t)__entry->index) << PAGE_SHIFT,
((((loff_t)__entry->last_index + 1) << PAGE_SHIFT) - 1)
)
);
DEFINE_EVENT(mm_filemap_op_page_cache_range, mm_filemap_get_pages,
TP_PROTO(
struct address_space *mapping,
pgoff_t index,
pgoff_t last_index
),
TP_ARGS(mapping, index, last_index)
);
DEFINE_EVENT(mm_filemap_op_page_cache_range, mm_filemap_map_pages,
TP_PROTO(
struct address_space *mapping,
pgoff_t index,
pgoff_t last_index
),
TP_ARGS(mapping, index, last_index)
);
TRACE_EVENT(mm_filemap_fault,
TP_PROTO(struct address_space *mapping, pgoff_t index),
TP_ARGS(mapping, index),
TP_STRUCT__entry(
__field(unsigned long, i_ino)
__field(dev_t, s_dev)
__field(unsigned long, index)
),
TP_fast_assign(
__entry->i_ino = mapping->host->i_ino;
if (mapping->host->i_sb)
__entry->s_dev =
mapping->host->i_sb->s_dev;
else
__entry->s_dev = mapping->host->i_rdev;
__entry->index = index;
),
TP_printk(
"dev=%d:%d ino=%lx ofs=%lld",
MAJOR(__entry->s_dev),
MINOR(__entry->s_dev), __entry->i_ino,
((loff_t)__entry->index) << PAGE_SHIFT
)
);
TRACE_EVENT(filemap_set_wb_err,
TP_PROTO(struct address_space *mapping, errseq_t eseq),
TP_ARGS(mapping, eseq),
TP_STRUCT__entry(
__field(unsigned long, i_ino)
__field(dev_t, s_dev)
__field(errseq_t, errseq)
),
TP_fast_assign(
__entry->i_ino = mapping->host->i_ino;
__entry->errseq = eseq;
if (mapping->host->i_sb)
__entry->s_dev = mapping->host->i_sb->s_dev;
else
__entry->s_dev = mapping->host->i_rdev;
),
TP_printk("dev=%d:%d ino=0x%lx errseq=0x%x",
MAJOR(__entry->s_dev), MINOR(__entry->s_dev),
__entry->i_ino, __entry->errseq)
);
TRACE_EVENT(file_check_and_advance_wb_err,
TP_PROTO(struct file *file, errseq_t old),
TP_ARGS(file, old),
TP_STRUCT__entry(
__field(struct file *, file)
__field(unsigned long, i_ino)
__field(dev_t, s_dev)
__field(errseq_t, old)
__field(errseq_t, new)
),
TP_fast_assign(
__entry->file = file;
__entry->i_ino = file->f_mapping->host->i_ino;
if (file->f_mapping->host->i_sb)
__entry->s_dev =
file->f_mapping->host->i_sb->s_dev;
else
__entry->s_dev =
file->f_mapping->host->i_rdev;
__entry->old = old;
__entry->new = file->f_wb_err;
),
TP_printk("file=%p dev=%d:%d ino=0x%lx old=0x%x new=0x%x",
__entry->file, MAJOR(__entry->s_dev),
MINOR(__entry->s_dev), __entry->i_ino, __entry->old,
__entry->new)
);
#endif /* _TRACE_FILEMAP_H */
/* This part must be outside protection */
#include <trace/define_trace.h>