tools/testing/selftests/cgroup/test_memcontrol.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/cgroup/test_memcontrol.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/cgroup/test_memcontrol.c- Extension
.c- Size
- 39250 bytes
- Lines
- 1842
- 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
linux/limits.hlinux/oom.hfcntl.hstdio.hstdlib.hstring.hsys/stat.hsys/types.hunistd.hsys/inotify.hsys/socket.hsys/wait.harpa/inet.hnetinet/in.hnetdb.herrno.hsys/mman.hkselftest.hcgroup_util.h
Detected Declarations
struct tcp_server_argsstruct memcg_testfunction get_temp_fdfunction alloc_pagecachefunction alloc_anonfunction is_swap_enabledfunction set_oom_adj_scorefunction test_memcg_subtree_controlfunction alloc_anon_50M_checkfunction alloc_pagecache_50M_checkfunction test_memcg_current_peakfunction alloc_pagecache_50M_noexitfunction alloc_anon_noexitfunction cg_test_proc_killedfunction test_memcg_protectionfunction MBfunction test_memcg_minfunction test_memcg_lowfunction alloc_pagecache_max_30Mfunction test_memcg_highfunction alloc_anon_mlockfunction test_memcg_high_syncfunction test_memcg_maxfunction reclaim_untilfunction memoryfunction alloc_anon_50M_check_swapfunction test_memcg_swap_max_peakfunction test_memcg_oom_eventsfunction tcp_serverfunction tcp_clientfunction test_memcg_sockfunction test_memcg_oom_group_leaf_eventsfunction test_memcg_oom_group_parent_eventsfunction test_memcg_oom_group_score_eventsfunction read_eventfunction test_memcg_inotify_delete_filefunction test_memcg_inotify_delete_dirfunction main
Annotated Snippet
struct tcp_server_args {
unsigned short port;
int ctl[2];
};
static int tcp_server(const char *cgroup, void *arg)
{
struct tcp_server_args *srv_args = arg;
struct sockaddr_in6 saddr = { 0 };
socklen_t slen = sizeof(saddr);
int sk, client_sk, ctl_fd, yes = 1, ret = -1;
close(srv_args->ctl[0]);
ctl_fd = srv_args->ctl[1];
saddr.sin6_family = AF_INET6;
saddr.sin6_addr = in6addr_any;
saddr.sin6_port = htons(srv_args->port);
sk = socket(AF_INET6, SOCK_STREAM, 0);
if (sk < 0) {
/* Pass back errno to the ctl_fd */
write(ctl_fd, &errno, sizeof(errno));
return ret;
}
if (setsockopt(sk, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(yes)) < 0)
goto cleanup;
if (bind(sk, (struct sockaddr *)&saddr, slen)) {
write(ctl_fd, &errno, sizeof(errno));
goto cleanup;
}
if (listen(sk, 1))
goto cleanup;
ret = 0;
if (write(ctl_fd, &ret, sizeof(ret)) != sizeof(ret)) {
ret = -1;
goto cleanup;
}
client_sk = accept(sk, NULL, NULL);
if (client_sk < 0)
goto cleanup;
ret = -1;
for (;;) {
uint8_t buf[0x100000];
if (write(client_sk, buf, sizeof(buf)) <= 0) {
if (errno == ECONNRESET)
ret = 0;
break;
}
}
close(client_sk);
cleanup:
close(sk);
return ret;
}
static int tcp_client(const char *cgroup, unsigned short port)
{
const char server[] = "localhost";
struct addrinfo *ai;
char servport[6];
int retries = 0x10; /* nice round number */
int sk, ret;
long allocated;
allocated = cg_read_long(cgroup, "memory.current");
snprintf(servport, sizeof(servport), "%hd", port);
ret = getaddrinfo(server, servport, NULL, &ai);
if (ret)
return ret;
sk = socket(ai->ai_family, ai->ai_socktype, ai->ai_protocol);
if (sk < 0)
goto free_ainfo;
ret = connect(sk, ai->ai_addr, ai->ai_addrlen);
if (ret < 0)
goto close_sk;
ret = KSFT_FAIL;
while (retries--) {
Annotation
- Immediate include surface: `linux/limits.h`, `linux/oom.h`, `fcntl.h`, `stdio.h`, `stdlib.h`, `string.h`, `sys/stat.h`, `sys/types.h`.
- Detected declarations: `struct tcp_server_args`, `struct memcg_test`, `function get_temp_fd`, `function alloc_pagecache`, `function alloc_anon`, `function is_swap_enabled`, `function set_oom_adj_score`, `function test_memcg_subtree_control`, `function alloc_anon_50M_check`, `function alloc_pagecache_50M_check`.
- 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.