tools/testing/selftests/mm/madv_populate.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/mm/madv_populate.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/mm/madv_populate.c- Extension
.c- Size
- 7412 bytes
- Lines
- 295
- 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.
Dependency Surface
stdlib.hstring.hstdbool.hstdint.hunistd.herrno.hfcntl.hlinux/mman.hsys/mman.hkselftest.hvm_util.h
Detected Declarations
function sense_supportfunction test_prot_readfunction test_prot_writefunction test_holesfunction range_is_populatedfunction range_is_not_populatedfunction test_populate_readfunction test_populate_writefunction range_is_softdirtyfunction range_is_not_softdirtyfunction test_softdirtyfunction main
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0-only
/*
* MADV_POPULATE_READ and MADV_POPULATE_WRITE tests
*
* Copyright 2021, Red Hat, Inc.
*
* Author(s): David Hildenbrand <david@redhat.com>
*/
#define _GNU_SOURCE
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#include <stdint.h>
#include <unistd.h>
#include <errno.h>
#include <fcntl.h>
#include <linux/mman.h>
#include <sys/mman.h>
#include "kselftest.h"
#include "vm_util.h"
/*
* For now, we're using 2 MiB of private anonymous memory for all tests.
*/
#define SIZE (2 * 1024 * 1024)
static size_t pagesize;
static void sense_support(void)
{
char *addr;
int ret;
addr = mmap(0, pagesize, PROT_READ | PROT_WRITE,
MAP_ANONYMOUS | MAP_PRIVATE, 0, 0);
if (!addr)
ksft_exit_fail_msg("mmap failed\n");
ret = madvise(addr, pagesize, MADV_POPULATE_READ);
if (ret)
ksft_exit_skip("MADV_POPULATE_READ is not available\n");
ret = madvise(addr, pagesize, MADV_POPULATE_WRITE);
if (ret)
ksft_exit_skip("MADV_POPULATE_WRITE is not available\n");
munmap(addr, pagesize);
}
static void test_prot_read(void)
{
char *addr;
int ret;
ksft_print_msg("[RUN] %s\n", __func__);
addr = mmap(0, SIZE, PROT_READ, MAP_ANONYMOUS | MAP_PRIVATE, 0, 0);
if (addr == MAP_FAILED)
ksft_exit_fail_msg("mmap failed\n");
ret = madvise(addr, SIZE, MADV_POPULATE_READ);
ksft_test_result(!ret, "MADV_POPULATE_READ with PROT_READ\n");
ret = madvise(addr, SIZE, MADV_POPULATE_WRITE);
ksft_test_result(ret == -1 && errno == EINVAL,
"MADV_POPULATE_WRITE with PROT_READ\n");
munmap(addr, SIZE);
}
static void test_prot_write(void)
{
char *addr;
int ret;
ksft_print_msg("[RUN] %s\n", __func__);
addr = mmap(0, SIZE, PROT_WRITE, MAP_ANONYMOUS | MAP_PRIVATE, 0, 0);
if (addr == MAP_FAILED)
ksft_exit_fail_msg("mmap failed\n");
ret = madvise(addr, SIZE, MADV_POPULATE_READ);
ksft_test_result(ret == -1 && errno == EINVAL,
"MADV_POPULATE_READ with PROT_WRITE\n");
ret = madvise(addr, SIZE, MADV_POPULATE_WRITE);
ksft_test_result(!ret, "MADV_POPULATE_WRITE with PROT_WRITE\n");
munmap(addr, SIZE);
Annotation
- Immediate include surface: `stdlib.h`, `string.h`, `stdbool.h`, `stdint.h`, `unistd.h`, `errno.h`, `fcntl.h`, `linux/mman.h`.
- Detected declarations: `function sense_support`, `function test_prot_read`, `function test_prot_write`, `function test_holes`, `function range_is_populated`, `function range_is_not_populated`, `function test_populate_read`, `function test_populate_write`, `function range_is_softdirty`, `function range_is_not_softdirty`.
- 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.