tools/mm/page_owner_sort.c
Source file repositories/reference/linux-study-clean/tools/mm/page_owner_sort.c
File Facts
- System
- Linux kernel
- Corpus path
tools/mm/page_owner_sort.c- Extension
.c- Size
- 20708 bytes
- Lines
- 894
- Domain
- Support Tooling And Documentation
- Bucket
- tools
- Inferred role
- Support Tooling And Documentation: implementation source
- Status
- source implementation candidate
Why This File Exists
Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
stdio.hstdlib.hstdbool.hsys/types.hsys/stat.hfcntl.hunistd.hstring.hregex.herrno.hlinux/types.hgetopt.h
Detected Declarations
struct block_liststruct filter_conditionstruct sort_conditionenum FILTER_BITenum CULL_BITenum ALLOCATOR_BITenum ARG_TYPEenum SORT_ORDERenum COMP_FLAGfunction read_blockfunction compare_txtfunction compare_stacktracefunction compare_numfunction compare_page_numfunction compare_pidfunction compare_tgidfunction compare_allocatorfunction compare_commfunction compare_tsfunction compare_cull_conditionfunction compare_sort_conditionfunction remove_patternfunction search_patternfunction check_regcompfunction free_explodefunction get_page_numfunction get_pidfunction get_tgidfunction get_ts_nsecfunction get_arg_typefunction get_allocatorfunction match_num_listfunction match_str_listfunction is_needfunction add_listfunction parse_cull_argsfunction set_single_cmpfunction parse_sort_argsfunction print_allocatorfunction usagefunction main
Annotated Snippet
struct block_list {
char *txt;
char *comm; // task command name
char *stacktrace;
__u64 ts_nsec;
int len;
int num;
int page_num;
pid_t pid;
pid_t tgid;
int allocator;
};
enum FILTER_BIT {
FILTER_PID = 1<<1,
FILTER_TGID = 1<<2,
FILTER_COMM = 1<<3
};
enum CULL_BIT {
CULL_PID = 1<<1,
CULL_TGID = 1<<2,
CULL_COMM = 1<<3,
CULL_STACKTRACE = 1<<4,
CULL_ALLOCATOR = 1<<5
};
enum ALLOCATOR_BIT {
ALLOCATOR_CMA = 1<<1,
ALLOCATOR_SLAB = 1<<2,
ALLOCATOR_VMALLOC = 1<<3,
ALLOCATOR_OTHERS = 1<<4
};
enum ARG_TYPE {
ARG_TXT, ARG_COMM, ARG_STACKTRACE, ARG_ALLOC_TS, ARG_CULL_TIME,
ARG_PAGE_NUM, ARG_PID, ARG_TGID, ARG_UNKNOWN, ARG_ALLOCATOR
};
enum SORT_ORDER {
SORT_ASC = 1,
SORT_DESC = -1,
};
enum COMP_FLAG {
COMP_NO_FLAG = 0,
COMP_ALLOC = 1<<0,
COMP_PAGE_NUM = 1<<1,
COMP_PID = 1<<2,
COMP_STACK = 1<<3,
COMP_NUM = 1<<4,
COMP_TGID = 1<<5,
COMP_COMM = 1<<6
};
struct filter_condition {
pid_t *pids;
pid_t *tgids;
char **comms;
int pids_size;
int tgids_size;
int comms_size;
};
struct sort_condition {
int (**cmps)(const void *, const void *);
int *signs;
int size;
};
static struct filter_condition fc;
static struct sort_condition sc;
static regex_t order_pattern;
static regex_t pid_pattern;
static regex_t tgid_pattern;
static regex_t comm_pattern;
static regex_t ts_nsec_pattern;
static struct block_list *list;
static int list_size;
static int max_size;
static int cull;
static int filter;
static bool debug_on;
static void set_single_cmp(int (*cmp)(const void *, const void *), int sign);
int read_block(char *buf, char *ext_buf, int buf_size, FILE *fin)
{
char *curr = buf, *const buf_end = buf + buf_size;
while (buf_end - curr > 1 && fgets(curr, buf_end - curr, fin)) {
if (*curr == '\n') { /* empty line */
return curr - buf;
}
if (!strncmp(curr, "PFN", 3)) {
strcpy(ext_buf, curr);
continue;
}
curr += strlen(curr);
Annotation
- Immediate include surface: `stdio.h`, `stdlib.h`, `stdbool.h`, `sys/types.h`, `sys/stat.h`, `fcntl.h`, `unistd.h`, `string.h`.
- Detected declarations: `struct block_list`, `struct filter_condition`, `struct sort_condition`, `enum FILTER_BIT`, `enum CULL_BIT`, `enum ALLOCATOR_BIT`, `enum ARG_TYPE`, `enum SORT_ORDER`, `enum COMP_FLAG`, `function read_block`.
- Atlas domain: Support Tooling And Documentation / tools.
- Implementation status: source implementation candidate.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.