Skip to content

Commit cf58880

Browse files
committed
tunable: Convert docs to docparse
* update outdated documentation * use passive form * use links to man (as :man2:`mmap`) and to kernel doc (:kernel_doc:`admin-guide/sysctl/vm`) Signed-off-by: Petr Vorel <pvorel@suse.cz>
1 parent ffcc093 commit cf58880

3 files changed

Lines changed: 79 additions & 70 deletions

File tree

‎testcases/kernel/mem/tunable/max_map_count.c‎

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,43 @@
1+
// SPDX-License-Identifier: GPL-2.0-or-later
12
/*
3+
* Copyright (c) Linux Test Project, 2012-2025
24
* Copyright (C) 2012-2017 Red Hat, Inc.
5+
*/
6+
7+
/*\
8+
* Test ``/proc/sys/vm/max_map_count`` tunable file.
39
*
4-
* This program is free software; you can redistribute it and/or modify
5-
* it under the terms of the GNU General Public License as published by
6-
* the Free Software Foundation; either version 2 of the License, or
7-
* (at your option) any later version.
8-
*
9-
* This program is distributed in the hope that it will be useful,
10-
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
12-
* the GNU General Public License for more details.
13-
*
14-
* Description:
15-
*
16-
* The program is designed to test max_map_count tunable file
10+
* :kernel_doc:`admin-guide/sysctl/vm` claims:
1711
*
18-
* The kernel Documentation say that:
19-
* /proc/sys/vm/max_map_count contains the maximum number of memory map
20-
* areas a process may have. Memory map areas are used as a side-effect
21-
* of calling malloc, directly by mmap and mprotect, and also when
22-
* loading shared libraries.
12+
* /proc/sys/vm/max_map_count contains the maximum number of memory map
13+
* areas a process may have. Memory map areas are used as a side-effect
14+
* of calling malloc, directly by mmap and mprotect, and also when
15+
* loading shared libraries.
2316
*
2417
* Each process has his own maps file: /proc/[pid]/maps, and each line
2518
* indicates a map entry, so it can caculate the amount of maps by reading
2619
* the file lines' number to check the tunable performance.
2720
*
28-
* The program tries to invoke mmap() endlessly until it triggers MAP_FAILED,
29-
* then reads the process's maps file /proc/[pid]/maps, save the line number to
30-
* map_count variable, and compare it with /proc/sys/vm/max_map_count,
31-
* map_count should be greater than max_map_count by 1;
21+
* The program tries to invoke :man2:`mmap` endlessly until it triggers
22+
* ``MAP_FAILED``, then reads the process's maps file /proc/[pid]/maps, save
23+
* the line number to map_count variable, and compare it with
24+
* ``/proc/sys/vm/max_map_count``, map_count should be greater than
25+
* max_map_count by 1.
3226
*
33-
* Note: On some architectures there is a special vma VSYSCALL, which
27+
* NOTE: On some architectures there is a special vma VSYSCALL, which
3428
* is allocated without incrementing mm->map_count variable. On these
3529
* architectures each /proc/<pid>/maps has at the end:
36-
* ...
37-
* ...
38-
* ffffffffff600000-ffffffffff601000 r-xp 00000000 00:00 0 [vsyscall]
3930
*
40-
* so we ignore this line during /proc/[pid]/maps reading.
31+
* ::
32+
*
33+
* ...
34+
* ffffffffff600000-ffffffffff601000 r-xp 00000000 00:00 0 [vsyscall]
35+
*
36+
* Therefore this line is ignored during /proc/[pid]/maps reading.
37+
*
38+
* [References]
39+
*
40+
* - :kernel_doc:`admin-guide/sysctl/vm`
4141
*/
4242

4343
#define _GNU_SOURCE

‎testcases/kernel/mem/tunable/min_free_kbytes.c‎

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,27 @@
1+
// SPDX-License-Identifier: GPL-2.0-or-later
12
/*
3+
* Copyright (c) Linux Test Project, 2012-2025
24
* Copyright (C) 2012-2017 Red Hat, Inc.
3-
*
4-
* This program is free software; you can redistribute it and/or modify
5-
* it under the terms of the GNU General Public License as published by
6-
* the Free Software Foundation; either version 2 of the License, or
7-
* (at your option) any later version.
8-
*
9-
* This program is distributed in the hope that it will be useful,
10-
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
12-
* the GNU General Public License for more details.
13-
*
14-
* Description:
15-
*
16-
* The case is designed to test min_free_kbytes tunable.
5+
*/
6+
7+
/*\
8+
* Test ``/proc/sys/vm/min_free_kbytes`` tunable file.
179
*
1810
* The tune is used to control free memory, and system always
19-
* reserve min_free_kbytes memory at least.
11+
* reserve ``min_free_kbytes`` memory at least.
2012
*
2113
* Since the tune is not too large or too little, which will
22-
* lead to the system hang, so I choose two cases, and test them
23-
* on all overcommit_memory policy, at the same time, compare
14+
* lead to the system hang, the following cases are tested
15+
* on all ``overcommit_memory`` policy, at the same time, compare
2416
* the current free memory with the tunable value repeatedly.
2517
*
26-
* a) default min_free_kbytes with all overcommit memory policy
27-
* b) 2x default value with all overcommit memory policy
28-
* c) 5% of MemFree or %2 MemTotal with all overcommit memory policy
18+
* 1. default min_free_kbytes with all ``overcommit_memory`` policy
19+
* 2. 2x default value with all ``overcommit_memory`` policy
20+
* 3. 5% of MemFree or %2 MemTotal with all ``overcommit_memory`` policy
21+
*
22+
* [References]
23+
*
24+
* - :kernel_doc:`admin-guide/sysctl/vm`
2925
*/
3026

3127
#include <sys/wait.h>

‎testcases/kernel/mem/tunable/overcommit_memory.c‎

Lines changed: 36 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
11
// SPDX-License-Identifier: GPL-2.0-or-later
22
/*
3-
* Copyright (c) 2012-2023 Linux Test Project
3+
* Copyright (c) 2012-2025 Linux Test Project
44
* Copyright (c) 2012-2017 Red Hat, Inc.
5+
*/
6+
7+
/*\
8+
* Test for ``overcommit_memory`` and ``overcommit_ratio`` tunables.
59
*
610
* There are two tunables overcommit_memory and overcommit_ratio under
711
* /proc/sys/vm/, which can control memory overcommitment.
812
*
913
* The overcommit_memory contains a flag that enables memory
1014
* overcommitment, it has three values:
15+
*
1116
* - When this flag is 0, the kernel attempts to estimate the amount
1217
* of free memory left when userspace requests more memory.
1318
* - When this flag is 1, the kernel pretends there is always enough
@@ -21,41 +26,49 @@
2126
* percentage added to the amount of actual RAM in a system when
2227
* considering whether to grant a particular memory request.
2328
* The general formula for this tunable is:
24-
* CommitLimit = SwapTotal + MemTotal * overcommit_ratio
25-
* CommitLimit, SwapTotal and MemTotal can read from /proc/meminfo.
29+
*
30+
* * CommitLimit = SwapTotal + MemTotal * overcommit_ratio
31+
* * CommitLimit, SwapTotal and MemTotal can read from /proc/meminfo.
2632
*
2733
* The program is designed to test the two tunables:
2834
*
2935
* When overcommit_memory = 0, allocatable memory can't overextend
3036
* the amount of total memory:
31-
* a. less than free_total: free_total / 2, alloc should pass.
32-
* b. greater than sum_total: sum_total * 2, alloc should fail.
37+
*
38+
* 1. less than free_total: free_total / 2, alloc should pass.
39+
* 2. greater than sum_total: sum_total * 2, alloc should fail.
3340
*
3441
* When overcommit_memory = 1, it can alloc enough much memory, I
3542
* choose the three cases:
36-
* a. less than sum_total: sum_total / 2, alloc should pass
37-
* b. equal to sum_total: sum_total, alloc should pass
38-
* c. greater than sum_total: sum_total * 2, alloc should pass
39-
* *note: sum_total = SwapTotal + MemTotal
43+
*
44+
* 1. less than sum_total: sum_total / 2, alloc should pass
45+
* 2. equal to sum_total: sum_total, alloc should pass
46+
* 3. greater than sum_total: sum_total * 2, alloc should pass
47+
*
48+
* NOTE: sum_total = SwapTotal + MemTotal
4049
*
4150
* When overcommit_memory = 2, the total virtual address space on
4251
* the system is limited to CommitLimit(Swap+RAM*overcommit_ratio)
4352
* commit_left(allocatable memory) = CommitLimit - Committed_AS
44-
* a. less than commit_left: commit_left / 2, alloc should pass
45-
* b. overcommit limit: CommitLimit + TotalBatchSize, should fail
46-
* c. greater than commit_left: commit_left * 2, alloc should fail
47-
* *note: CommitLimit is the current overcommit limit.
48-
* Committed_AS is the amount of memory that system has used.
49-
* it couldn't choose 'equal to commit_left' as a case, because
50-
* commit_left rely on Committed_AS, but the Committed_AS is not stable.
51-
* *note2: TotalBatchSize is the total number of bytes, that can be
52-
* accounted for in the per cpu counters for the vm_committed_as
53-
* counter. Since the check used by malloc only looks at the
54-
* global counter of vm_committed_as, it can overallocate a bit.
5553
*
56-
* References:
57-
* - Documentation/sysctl/vm.txt
58-
* - Documentation/vm/overcommit-accounting
54+
* 1. less than commit_left: commit_left / 2, alloc should pass
55+
* 2. overcommit limit: CommitLimit + TotalBatchSize, should fail
56+
* 3. greater than commit_left: commit_left * 2, alloc should fail
57+
*
58+
* NOTE: CommitLimit is the current overcommit limit.
59+
* Committed_AS is the amount of memory that system has used.
60+
*
61+
* It couldn't choose 'equal to commit_left' as a case, because commit_left rely
62+
* on Committed_AS, but the Committed_AS is not stable.
63+
*
64+
* NOTE: TotalBatchSize is the total number of bytes, that can be accounted for
65+
* in the per cpu counters for the vm_committed_as counter. Since the check used
66+
* by malloc only looks at the global counter of vm_committed_as, it can
67+
* overallocate a bit.
68+
*
69+
* [References]
70+
*
71+
* - :kernel_doc:`admin-guide/sysctl/vm`
5972
*/
6073

6174
#include <errno.h>

0 commit comments

Comments
 (0)