ltp.lists.linux.it archive mirror
 help / color / mirror / Atom feed
* [LTP] [PATCH v4 1/2] lib: memutils: respect minimum memory watermark when polluting memory
@ 2021-10-21  8:35 Krzysztof Kozlowski
  2021-10-21  8:35 ` [LTP] [PATCH v4 2/2] lib: memutils: include also available memory when polluting Krzysztof Kozlowski
  2021-10-26  2:46 ` [LTP] [PATCH v4 1/2] lib: memutils: respect minimum memory watermark when polluting memory Li Wang
  0 siblings, 2 replies; 5+ messages in thread
From: Krzysztof Kozlowski @ 2021-10-21  8:35 UTC (permalink / raw)
  To: ltp

Previous fix for an out-of-memory killer killing ioctl_sg01 process
in commit 4d2e3d44fad5 ("lib: memutils: don't pollute
entire system memory to avoid OoM") was not fully effective.  While it
covers most of the cases, an ARM64 machine with 128 GB of memory, 64 kB
page size and v5.11 kernel hit it again.  Polluting the memory fails
with OoM:

  LTP: starting ioctl_sg01
  ioctl_sg01 invoked oom-killer: gfp_mask=0x100dca(GFP_HIGHUSER_MOVABLE|__GFP_ZERO), order=0, oom_score_adj=0
  ...
  Mem-Info:
  active_anon:309 inactive_anon:1964781 isolated_anon:0
                  active_file:94 inactive_file:0 isolated_file:0
                  unevictable:305 dirty:0 writeback:0
                  slab_reclaimable:1510 slab_unreclaimable:5012
                  mapped:115 shmem:339 pagetables:463 bounce:0
                  free:112043 free_pcp:1 free_cma:3159
  Node 0 active_anon:19776kB inactive_anon:125745984kB active_file:6016kB inactive_file:0kB unevictable:19520kB ...
  Node 0 DMA free:710656kB min:205120kB low:256384kB high:307648kB reserved_highatomic:0KB active_anon:0kB inactive_anon:3332032kB ...
  lowmem_reserve[]: 0 0 7908 7908 7908
  Node 0 Normal free:6460096kB min:6463168kB low:8078912kB high:9694656kB reserved_highatomic:0KB active_anon:19776kB inactive_anon:122413952kB ...
  lowmem_reserve[]: 0 0 0 0 0

The important part are details of memory on Node 0 in Normal zone:
1. free memory: 6460096 kB
2. min (minimum watermark): 6463168 kB

Parse the /proc/sys/vm/min_free_kbytes which contains the free
memory level used as minimum watermark (triggering OoM killer).

Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@canonical.com>

---

Changes since v3:
1. None

Changes since v2:
1. Use /proc/sys/vm/min_free_kbytes instead of parsing zoneinfo, thanks
   tgo Liu Xinpeng.

Changes since v1:
1. Add static and rename to count_min_pages().
---
 lib/tst_memutils.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/lib/tst_memutils.c b/lib/tst_memutils.c
index af132bcc6c24..df53c542d239 100644
--- a/lib/tst_memutils.c
+++ b/lib/tst_memutils.c
@@ -16,12 +16,18 @@
 void tst_pollute_memory(size_t maxsize, int fillchar)
 {
 	size_t i, map_count = 0, safety = 0, blocksize = BLOCKSIZE;
+	unsigned long min_free;
 	void **map_blocks;
 	struct sysinfo info;
 
+	SAFE_FILE_SCANF("/proc/sys/vm/min_free_kbytes", "%lu", &min_free);
+	min_free *= 1024;
+	/* Apply a margin because we cannot get below "min" watermark */
+	min_free += min_free / 10;
+
 	SAFE_SYSINFO(&info);
 	safety = MAX(4096 * SAFE_SYSCONF(_SC_PAGESIZE), 128 * 1024 * 1024);
-	safety = MAX(safety, (info.freeram / 64));
+	safety = MAX(safety, min_free);
 	safety /= info.mem_unit;
 
 	if (info.freeswap > safety)
-- 
2.30.2


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [LTP] [PATCH v4 2/2] lib: memutils: include also available memory when polluting
  2021-10-21  8:35 [LTP] [PATCH v4 1/2] lib: memutils: respect minimum memory watermark when polluting memory Krzysztof Kozlowski
@ 2021-10-21  8:35 ` Krzysztof Kozlowski
  2021-10-21  9:45   ` Li Wang
  2021-10-21 10:51   ` liuxp11
  2021-10-26  2:46 ` [LTP] [PATCH v4 1/2] lib: memutils: respect minimum memory watermark when polluting memory Li Wang
  1 sibling, 2 replies; 5+ messages in thread
From: Krzysztof Kozlowski @ 2021-10-21  8:35 UTC (permalink / raw)
  To: ltp

Usually available memory (MemAvailable from /proc/meminfo) is higher
than free memory, although not always. On kernel v5.14 the formula is
approximately:
  available = free - reserved + pagecache + reclaimable

The reserved part comes from vm.min_free_kbytes (already included in
previous patch: lib: memutils: respect minimum memory watermark when
polluting memory) and vm.lowmem_reserve_ratio. If user set specific
vm.lowmem_reserve_ratio (sysctl), the available memory could be actually
lower than free.

Use lower value of these (free/available), to avoid out-of-memory killer
for such system configurations.

Reported-by: Li Wang <liwang@redhat.com>
Reported-by: Liu Xinpeng <liuxp11@chinatelecom.cn>
Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@canonical.com>

---

Changes since v3:
1. New patch
---
 lib/tst_memutils.c | 16 +++++++++++++---
 1 file changed, 13 insertions(+), 3 deletions(-)

diff --git a/lib/tst_memutils.c b/lib/tst_memutils.c
index df53c542d239..bd09cf6fad9b 100644
--- a/lib/tst_memutils.c
+++ b/lib/tst_memutils.c
@@ -16,6 +16,7 @@
 void tst_pollute_memory(size_t maxsize, int fillchar)
 {
 	size_t i, map_count = 0, safety = 0, blocksize = BLOCKSIZE;
+	unsigned long long freeram;
 	unsigned long min_free;
 	void **map_blocks;
 	struct sysinfo info;
@@ -33,15 +34,24 @@ void tst_pollute_memory(size_t maxsize, int fillchar)
 	if (info.freeswap > safety)
 		safety = 0;
 
+	/*
+	 * MemFree usually is lower than MemAvailable, although when setting
+	 * sysctl vm.lowmem_reserve_ratio, this could reverse.
+	 *
+	 * Use the lower value of both for pollutable memory. Usually this
+	 * means we will not evict any caches.
+	 */
+	freeram = MIN(info.freeram, (tst_available_mem() * 1024));
+
 	/* Not enough free memory to avoid invoking OOM killer */
-	if (info.freeram <= safety)
+	if (freeram <= safety)
 		return;
 
 	if (!maxsize)
 		maxsize = SIZE_MAX;
 
-	if (info.freeram - safety < maxsize / info.mem_unit)
-		maxsize = (info.freeram - safety) * info.mem_unit;
+	if (freeram - safety < maxsize / info.mem_unit)
+		maxsize = (freeram - safety) * info.mem_unit;
 
 	blocksize = MIN(maxsize, blocksize);
 	map_count = maxsize / blocksize;
-- 
2.30.2


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [LTP] [PATCH v4 2/2] lib: memutils: include also available memory when polluting
  2021-10-21  8:35 ` [LTP] [PATCH v4 2/2] lib: memutils: include also available memory when polluting Krzysztof Kozlowski
@ 2021-10-21  9:45   ` Li Wang
  2021-10-21 10:51   ` liuxp11
  1 sibling, 0 replies; 5+ messages in thread
From: Li Wang @ 2021-10-21  9:45 UTC (permalink / raw)
  To: Krzysztof Kozlowski; +Cc: LTP List


[-- Attachment #1.1: Type: text/plain, Size: 117 bytes --]

Hi Krzysztof,

Thanks for the fixes. For the series:

Reviewed-by: Li Wang <liwang@redhat.com>

-- 
Regards,
Li Wang

[-- Attachment #1.2: Type: text/html, Size: 604 bytes --]

[-- Attachment #2: Type: text/plain, Size: 60 bytes --]


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [LTP] [PATCH v4 2/2] lib: memutils: include also available memory when polluting
  2021-10-21  8:35 ` [LTP] [PATCH v4 2/2] lib: memutils: include also available memory when polluting Krzysztof Kozlowski
  2021-10-21  9:45   ` Li Wang
@ 2021-10-21 10:51   ` liuxp11
  1 sibling, 0 replies; 5+ messages in thread
From: liuxp11 @ 2021-10-21 10:51 UTC (permalink / raw)
  To: Krzysztof Kozlowski, ltp

Good solution,thanks.

Reviewed-by: Liu Xinpeng <liuxp11@chinatelecom.cn>

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [LTP] [PATCH v4 1/2] lib: memutils: respect minimum memory watermark when polluting memory
  2021-10-21  8:35 [LTP] [PATCH v4 1/2] lib: memutils: respect minimum memory watermark when polluting memory Krzysztof Kozlowski
  2021-10-21  8:35 ` [LTP] [PATCH v4 2/2] lib: memutils: include also available memory when polluting Krzysztof Kozlowski
@ 2021-10-26  2:46 ` Li Wang
  1 sibling, 0 replies; 5+ messages in thread
From: Li Wang @ 2021-10-26  2:46 UTC (permalink / raw)
  To: Krzysztof Kozlowski; +Cc: LTP List


[-- Attachment #1.1: Type: text/plain, Size: 62 bytes --]

Hi Krzysztof,

Patchset pushed, thanks!

-- 
Regards,
Li Wang

[-- Attachment #1.2: Type: text/html, Size: 449 bytes --]

[-- Attachment #2: Type: text/plain, Size: 60 bytes --]


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2021-10-26  2:46 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-21  8:35 [LTP] [PATCH v4 1/2] lib: memutils: respect minimum memory watermark when polluting memory Krzysztof Kozlowski
2021-10-21  8:35 ` [LTP] [PATCH v4 2/2] lib: memutils: include also available memory when polluting Krzysztof Kozlowski
2021-10-21  9:45   ` Li Wang
2021-10-21 10:51   ` liuxp11
2021-10-26  2:46 ` [LTP] [PATCH v4 1/2] lib: memutils: respect minimum memory watermark when polluting memory Li Wang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).