]>
Commit | Line | Data |
---|---|---|
f955d3a9 WB |
1 | From 4538af183c2f48563681f303c54cef0430741b83 Mon Sep 17 00:00:00 2001 |
2 | From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgraber@ubuntu.com> | |
3 | Date: Thu, 5 Nov 2020 15:20:26 -0500 | |
4 | Subject: [PATCH lxcfs 5/8] swap: Only report usage when swappiness is 0 | |
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 | src/proc_fuse.c | 28 ++++++++++++++++++++++++---- | |
12 | 1 file changed, 24 insertions(+), 4 deletions(-) | |
13 | ||
14 | diff --git a/src/proc_fuse.c b/src/proc_fuse.c | |
15 | index 0ad21b9..002aac9 100644 | |
16 | --- a/src/proc_fuse.c | |
17 | +++ b/src/proc_fuse.c | |
18 | @@ -318,13 +318,14 @@ static inline bool startswith(const char *line, const char *pref) | |
19 | static int proc_swaps_read(char *buf, size_t size, off_t offset, | |
20 | struct fuse_file_info *fi) | |
21 | { | |
22 | - __do_free char *cgroup = NULL, *memusage_str = NULL, *memswusage_str = NULL; | |
23 | + __do_free char *cgroup = NULL, *memusage_str = NULL, | |
24 | + *memswusage_str = NULL, *memswpriority_str = NULL; | |
25 | struct fuse_context *fc = fuse_get_context(); | |
26 | struct lxcfs_opts *opts = (struct lxcfs_opts *)fuse_get_context()->private_data; | |
27 | bool wants_swap = opts && !opts->swap_off && liblxcfs_can_use_swap(); | |
28 | struct file_info *d = INTTYPE_TO_PTR(fi->fh); | |
29 | uint64_t memswlimit = 0, memlimit = 0, memusage = 0, memswusage = 0, | |
30 | - swtotal = 0, swfree = 0, swusage = 0; | |
31 | + swtotal = 0, swfree = 0, swusage = 0, memswpriority = 1; | |
32 | ssize_t total_len = 0; | |
33 | ssize_t l = 0; | |
34 | char *cache = d->buf; | |
35 | @@ -380,6 +381,10 @@ static int proc_swaps_read(char *buf, size_t size, off_t offset, | |
36 | if (swtotal >= swusage) | |
37 | swfree = swtotal - swusage; | |
38 | } | |
39 | + | |
40 | + ret = cgroup_ops->get_memory_swappiness(cgroup_ops, cgroup, &memswpriority_str); | |
41 | + if (ret >= 0) | |
42 | + safe_uint64(memswpriority_str, &memswpriority, 10); | |
43 | } | |
44 | } | |
45 | ||
46 | @@ -404,6 +409,11 @@ static int proc_swaps_read(char *buf, size_t size, off_t offset, | |
47 | } | |
48 | } | |
49 | ||
50 | + // When swappiness is 0, pretend we can't swap. | |
51 | + if (memswpriority == 0) { | |
52 | + swtotal = swusage; | |
53 | + } | |
54 | + | |
55 | if (swtotal > 0) { | |
56 | l = snprintf(d->buf + total_len, d->size - total_len, | |
57 | "none%*svirtual\t\t%" PRIu64 "\t%" PRIu64 "\t0\n", | |
58 | @@ -1136,7 +1146,7 @@ static int proc_meminfo_read(char *buf, size_t size, off_t offset, | |
59 | struct fuse_file_info *fi) | |
60 | { | |
61 | __do_free char *cgroup = NULL, *line = NULL, *memusage_str = NULL, | |
62 | - *memswusage_str = NULL; | |
63 | + *memswusage_str = NULL, *memswpriority_str = NULL; | |
64 | __do_free void *fopen_cache = NULL; | |
65 | __do_fclose FILE *f = NULL; | |
66 | struct fuse_context *fc = fuse_get_context(); | |
67 | @@ -1144,7 +1154,8 @@ static int proc_meminfo_read(char *buf, size_t size, off_t offset, | |
68 | bool wants_swap = opts && !opts->swap_off && liblxcfs_can_use_swap(), host_swap = false; | |
69 | struct file_info *d = INTTYPE_TO_PTR(fi->fh); | |
70 | uint64_t memlimit = 0, memusage = 0, memswlimit = 0, memswusage = 0, | |
71 | - hosttotal = 0, swfree = 0, swusage = 0, swtotal = 0; | |
72 | + hosttotal = 0, swfree = 0, swusage = 0, swtotal = 0, | |
73 | + memswpriority = 1; | |
74 | struct memory_stat mstat = {}; | |
75 | size_t linelen = 0, total_len = 0; | |
76 | char *cache = d->buf; | |
77 | @@ -1209,6 +1220,10 @@ static int proc_meminfo_read(char *buf, size_t size, off_t offset, | |
78 | swusage = (memswusage - memusage) / 1024; | |
79 | } | |
80 | } | |
81 | + | |
82 | + ret = cgroup_ops->get_memory_swappiness(cgroup_ops, cgroup, &memswpriority_str); | |
83 | + if (ret >= 0) | |
84 | + safe_uint64(memswpriority_str, &memswpriority, 10); | |
85 | } | |
86 | ||
87 | f = fopen_cached("/proc/meminfo", "re", &fopen_cache); | |
88 | @@ -1257,6 +1272,11 @@ static int proc_meminfo_read(char *buf, size_t size, off_t offset, | |
89 | swtotal = hostswtotal; | |
90 | host_swap = true; | |
91 | } | |
92 | + | |
93 | + /* When swappiness is 0, pretend we can't swap. */ | |
94 | + if (memswpriority == 0) { | |
95 | + swtotal = swusage; | |
96 | + } | |
97 | } | |
98 | ||
99 | snprintf(lbuf, 100, "SwapTotal: %8" PRIu64 " kB\n", swtotal); | |
100 | -- | |
101 | 2.20.1 | |
102 |