tools/testing/selftests/mm/cow.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/mm/cow.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/mm/cow.c- Extension
.c- Size
- 47099 bytes
- Lines
- 1921
- 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
stdlib.hstring.hstdbool.hstdint.hunistd.herrno.hfcntl.hassert.hlinux/mman.hsys/mman.hsys/ioctl.hsys/wait.hlinux/memfd.hlocal_config.hliburing.h../../../../mm/gup_test.hkselftest.hvm_util.hthp_settings.h
Detected Declarations
struct comm_pipesstruct test_casestruct non_anon_test_caseenum ro_pin_testenum thp_runenum anon_thp_collapse_testfunction detect_thp_sizesfunction range_is_swappedfunction populate_page_checkedfunction setup_comm_pipesfunction close_comm_pipesfunction child_memcmp_fnfunction child_vmsplice_memcmp_fnfunction do_test_cow_in_parentfunction test_cow_in_parentfunction test_cow_in_parent_mprotectfunction test_vmsplice_in_childfunction test_vmsplice_in_child_mprotectfunction do_test_vmsplice_in_parentfunction test_vmsplice_before_forkfunction test_vmsplice_after_forkfunction do_test_iouringfunction test_iouring_rofunction test_iouring_forkfunction do_test_ro_pinfunction test_ro_pin_on_sharedfunction test_ro_fast_pin_on_sharedfunction test_ro_pin_on_ro_previously_sharedfunction test_ro_fast_pin_on_ro_previously_sharedfunction test_ro_pin_on_ro_exclusivefunction test_ro_fast_pin_on_ro_exclusivefunction do_run_with_base_pagefunction run_with_base_pagefunction run_with_base_page_swapfunction do_run_with_thpfunction run_with_thpfunction run_with_thp_swapfunction run_with_pte_mapped_thpfunction run_with_pte_mapped_thp_swapfunction run_with_single_pte_of_thpfunction run_with_single_pte_of_thp_swapfunction run_with_partial_mremap_thpfunction run_with_partial_shared_thpfunction run_with_hugetlbfunction run_anon_test_casefunction run_anon_test_casesfunction tests_per_anon_test_casefunction do_test_anon_thp_collapse
Annotated Snippet
struct comm_pipes {
int child_ready[2];
int parent_ready[2];
};
static int setup_comm_pipes(struct comm_pipes *comm_pipes)
{
if (pipe(comm_pipes->child_ready) < 0) {
ksft_perror("pipe() failed");
return -errno;
}
if (pipe(comm_pipes->parent_ready) < 0) {
ksft_perror("pipe() failed");
close(comm_pipes->child_ready[0]);
close(comm_pipes->child_ready[1]);
return -errno;
}
return 0;
}
static void close_comm_pipes(struct comm_pipes *comm_pipes)
{
close(comm_pipes->child_ready[0]);
close(comm_pipes->child_ready[1]);
close(comm_pipes->parent_ready[0]);
close(comm_pipes->parent_ready[1]);
}
static int child_memcmp_fn(char *mem, size_t size,
struct comm_pipes *comm_pipes)
{
char *old = malloc(size);
char buf;
/* Backup the original content. */
memcpy(old, mem, size);
/* Wait until the parent modified the page. */
write(comm_pipes->child_ready[1], "0", 1);
while (read(comm_pipes->parent_ready[0], &buf, 1) != 1)
;
/* See if we still read the old values. */
return memcmp(old, mem, size);
}
static int child_vmsplice_memcmp_fn(char *mem, size_t size,
struct comm_pipes *comm_pipes)
{
struct iovec iov = {
.iov_base = mem,
.iov_len = size,
};
ssize_t cur, total, transferred;
char *old, *new;
int fds[2];
char buf;
old = malloc(size);
new = malloc(size);
/* Backup the original content. */
memcpy(old, mem, size);
if (pipe(fds) < 0)
return -errno;
/* Trigger a read-only pin. */
transferred = vmsplice(fds[1], &iov, 1, 0);
if (transferred < 0)
return -errno;
if (transferred == 0)
return -EINVAL;
/* Unmap it from our page tables. */
if (munmap(mem, size) < 0)
return -errno;
/* Wait until the parent modified it. */
write(comm_pipes->child_ready[1], "0", 1);
while (read(comm_pipes->parent_ready[0], &buf, 1) != 1)
;
/* See if we still read the old values via the pipe. */
for (total = 0; total < transferred; total += cur) {
cur = read(fds[0], new + total, transferred - total);
if (cur < 0)
return -errno;
}
Annotation
- Immediate include surface: `stdlib.h`, `string.h`, `stdbool.h`, `stdint.h`, `unistd.h`, `errno.h`, `fcntl.h`, `assert.h`.
- Detected declarations: `struct comm_pipes`, `struct test_case`, `struct non_anon_test_case`, `enum ro_pin_test`, `enum thp_run`, `enum anon_thp_collapse_test`, `function detect_thp_sizes`, `function range_is_swapped`, `function populate_page_checked`, `function setup_comm_pipes`.
- 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.