|
1 | 1 | // SPDX-License-Identifier: GPL-2.0-or-later |
2 | 2 | /* |
3 | | - * Copyright (c) 2012-2023 Linux Test Project |
| 3 | + * Copyright (c) 2012-2025 Linux Test Project |
4 | 4 | * Copyright (c) 2012-2017 Red Hat, Inc. |
| 5 | + */ |
| 6 | + |
| 7 | +/*\ |
| 8 | + * Test for ``overcommit_memory`` and ``overcommit_ratio`` tunables. |
5 | 9 | * |
6 | 10 | * There are two tunables overcommit_memory and overcommit_ratio under |
7 | 11 | * /proc/sys/vm/, which can control memory overcommitment. |
8 | 12 | * |
9 | 13 | * The overcommit_memory contains a flag that enables memory |
10 | 14 | * overcommitment, it has three values: |
| 15 | + * |
11 | 16 | * - When this flag is 0, the kernel attempts to estimate the amount |
12 | 17 | * of free memory left when userspace requests more memory. |
13 | 18 | * - When this flag is 1, the kernel pretends there is always enough |
|
21 | 26 | * percentage added to the amount of actual RAM in a system when |
22 | 27 | * considering whether to grant a particular memory request. |
23 | 28 | * 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. |
26 | 32 | * |
27 | 33 | * The program is designed to test the two tunables: |
28 | 34 | * |
29 | 35 | * When overcommit_memory = 0, allocatable memory can't overextend |
30 | 36 | * 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. |
33 | 40 | * |
34 | 41 | * When overcommit_memory = 1, it can alloc enough much memory, I |
35 | 42 | * 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 |
40 | 49 | * |
41 | 50 | * When overcommit_memory = 2, the total virtual address space on |
42 | 51 | * the system is limited to CommitLimit(Swap+RAM*overcommit_ratio) |
43 | 52 | * 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. |
55 | 53 | * |
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` |
59 | 72 | */ |
60 | 73 |
|
61 | 74 | #include <errno.h> |
|
0 commit comments