]>
Commit | Line | Data |
---|---|---|
f955d3a9 WB |
1 | From 22ba5818484aa5ffaa26967d5d2ab228b2789205 Mon Sep 17 00:00:00 2001 |
2 | From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgraber@ubuntu.com> | |
3 | Date: Wed, 4 Nov 2020 23:06:00 -0500 | |
4 | Subject: [PATCH lxcfs 2/8] README: clarify SWAP | |
5 | MIME-Version: 1.0 | |
6 | Content-Type: text/plain; charset=UTF-8 | |
7 | Content-Transfer-Encoding: 8bit | |
8 | ||
9 | Signed-off-by: Stéphane Graber <stgraber@ubuntu.com> | |
10 | --- | |
11 | README.md | 47 +++++++++++++++++++++++++++++++++++++++++++++++ | |
12 | 1 file changed, 47 insertions(+) | |
13 | ||
14 | diff --git a/README.md b/README.md | |
15 | index 5272a6c..3c638c3 100644 | |
16 | --- a/README.md | |
17 | +++ b/README.md | |
18 | @@ -104,3 +104,50 @@ docker run -it -m 256m --memory-swap 256m \ | |
19 | In a system with swap enabled, the parameter "-u" can be used to set all values in "meminfo" that refer to the swap to 0. | |
20 | ||
21 | sudo lxcfs -u /var/lib/lxcfs | |
22 | + | |
23 | +## Swap handling | |
24 | +If you noticed LXCFS not showing any SWAP in your container despite | |
25 | +having SWAP on your system, please read this section carefully and look | |
26 | +for instructions on how to enable SWAP accounting for your distribution. | |
27 | + | |
28 | +Swap cgroup handling on Linux is very confusing and there just isn't a | |
29 | +perfect way for LXCFS to handle it. | |
30 | + | |
31 | +Terminology used below: | |
32 | + - RAM refers to `memory.usage_in_bytes` and `memory.limit_in_bytes` | |
33 | + - RAM+SWAP refers to `memory.memsw.usage_in_bytes` and `memory.memsw.limit_in_bytes` | |
34 | + | |
35 | +The main issues are: | |
36 | + - SWAP accounting is often opt-in and, requiring a special kernel boot | |
37 | + time option (`swapaccount=1`) and/or special kernel build options | |
38 | + (`CONFIG_MEMCG_SWAP`). | |
39 | + | |
40 | + - Both a RAM limit and a RAM+SWAP limit can be set. The delta however | |
41 | + isn't the available SWAP space as the kernel is still free to SWAP as | |
42 | + much of the RAM as it feels like. This makes it impossible to render | |
43 | + a SWAP device size as using the delta between RAM and RAM+SWAP for that | |
44 | + wouldn't account for the kernel swapping more pages, leading to swap | |
45 | + usage exceeding swap total. | |
46 | + | |
47 | + - It's impossible to disable SWAP in a given container. The closest | |
48 | + that can be done is setting swappiness down to 0 which severly limits | |
49 | + the risk of swapping pages but doesn't eliminate it. | |
50 | + | |
51 | +As a result, LXCFS had to make some compromise which go as follow: | |
52 | + - When SWAP accounting isn't enabled, no SWAP space is reported at all. | |
53 | + This is simply because there is no way to know the SWAP consumption. | |
54 | + The container may very much be using some SWAP though, there's just | |
55 | + no way to know how much of it and showing a SWAP device would require | |
56 | + some kind of SWAP usage to be reported. Showing the host value would be | |
57 | + completely wrong, showing a 0 value would be equallty wrong. | |
58 | + | |
59 | + - Because SWAP usage for a given container can exceed the delta between | |
60 | + RAM and RAM+SWAP, the SWAP size is always reported to be the smaller of | |
61 | + the RAM+SWAP limit or the host SWAP device itself. This ensures that at no | |
62 | + point SWAP usage will be allowed to exceed the SWAP size. | |
63 | + | |
64 | + - If the swappiness is set to 0 and there is no SWAP usage, no SWAP is reported. | |
65 | + However if there is SWAP usage, then a SWAP device of the size of the | |
66 | + usage (100% full) is reported. This provides adequate reporting of | |
67 | + the memory consumption while preventing applications from assuming more | |
68 | + SWAP is available. | |
69 | -- | |
70 | 2.20.1 | |
71 |