tools/testing/selftests/bpf/progs/cgroup_iter_memcg.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/bpf/progs/cgroup_iter_memcg.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/bpf/progs/cgroup_iter_memcg.c- Extension
.c- Size
- 1279 bytes
- Lines
- 46
- 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.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
vmlinux.hbpf/bpf_core_read.hcgroup_iter_memcg.h
Detected Declarations
function cgroup_memcg_query
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0
/* Copyright (c) 2025 Meta Platforms, Inc. and affiliates. */
#include <vmlinux.h>
#include <bpf/bpf_core_read.h>
#include "cgroup_iter_memcg.h"
char _license[] SEC("license") = "GPL";
/* The latest values read are stored here. */
struct memcg_query memcg_query SEC(".data.query");
SEC("iter.s/cgroup")
int cgroup_memcg_query(struct bpf_iter__cgroup *ctx)
{
struct cgroup *cgrp = ctx->cgroup;
struct cgroup_subsys_state *css;
struct mem_cgroup *memcg;
if (!cgrp)
return 1;
css = &cgrp->self;
memcg = bpf_get_mem_cgroup(css);
if (!memcg)
return 1;
bpf_mem_cgroup_flush_stats(memcg);
memcg_query.nr_anon_mapped = bpf_mem_cgroup_page_state(
memcg,
bpf_core_enum_value(enum node_stat_item, NR_ANON_MAPPED));
memcg_query.nr_shmem = bpf_mem_cgroup_page_state(
memcg, bpf_core_enum_value(enum node_stat_item, NR_SHMEM));
memcg_query.nr_file_pages = bpf_mem_cgroup_page_state(
memcg, bpf_core_enum_value(enum node_stat_item, NR_FILE_PAGES));
memcg_query.nr_file_mapped = bpf_mem_cgroup_page_state(
memcg,
bpf_core_enum_value(enum node_stat_item, NR_FILE_MAPPED));
memcg_query.pgfault = bpf_mem_cgroup_vm_events(
memcg, bpf_core_enum_value(enum vm_event_item, PGFAULT));
bpf_put_mem_cgroup(memcg);
return 0;
}
Annotation
- Immediate include surface: `vmlinux.h`, `bpf/bpf_core_read.h`, `cgroup_iter_memcg.h`.
- Detected declarations: `function cgroup_memcg_query`.
- 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.