From patchwork Tue Mar 19 09:38:56 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Li Wang X-Patchwork-Id: 1058317 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=lists.linux.it (client-ip=213.254.12.146; helo=picard.linux.it; envelope-from=ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Received: from picard.linux.it (picard.linux.it [213.254.12.146]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 44Np0l1Wpwz9s6w for ; Tue, 19 Mar 2019 20:39:19 +1100 (AEDT) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id A8E563EAEC6 for ; Tue, 19 Mar 2019 10:39:16 +0100 (CET) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-5.smtp.seeweb.it (in-5.smtp.seeweb.it [IPv6:2001:4b78:1:20::5]) by picard.linux.it (Postfix) with ESMTP id 79DD03EAE91 for ; Tue, 19 Mar 2019 10:39:10 +0100 (CET) Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by in-5.smtp.seeweb.it (Postfix) with ESMTPS id E4A40600E39 for ; Tue, 19 Mar 2019 10:39:09 +0100 (CET) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id A323CC13070B; Tue, 19 Mar 2019 09:39:05 +0000 (UTC) Received: from dhcp-12-157.nay.redhat.com (dhcp-12-157.nay.redhat.com [10.66.12.157]) by smtp.corp.redhat.com (Postfix) with ESMTP id ACE7260CD3; Tue, 19 Mar 2019 09:39:02 +0000 (UTC) From: Li Wang To: ltp@lists.linux.it Date: Tue, 19 Mar 2019 17:38:56 +0800 Message-Id: <20190319093858.584-1-liwang@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Tue, 19 Mar 2019 09:39:05 +0000 (UTC) X-Virus-Scanned: clamav-milter 0.99.2 at in-5.smtp.seeweb.it X-Virus-Status: Clean X-Spam-Status: No, score=-0.0 required=7.0 tests=SPF_HELO_PASS,SPF_PASS autolearn=disabled version=3.4.0 X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on in-5.smtp.seeweb.it Cc: Vipin K Parashar Subject: [LTP] [PATCH RFC 1/3] min_free_kbytes: Fix child exit status check conditions X-BeenThere: ltp@lists.linux.it X-Mailman-Version: 2.1.18 Precedence: list List-Id: Linux Test Project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" From: Vipin K Parashar Fixes: #349 min_free_kbytes test has badly formed if conditions in mem_tune() for child exit status check. This is causing test to declare as FAILED despite that not being the case. Fix child exit status check conditions. ---ERROR LOG--- <..snip..> mem.c:839: INFO: set overcommit_memory to 1 mem.c:839: INFO: set min_free_kbytes to 11580 memfree is 6974720 kB before eatup mem memfree is 15488 kB after eatup mem min_free_kbytes.c:135: FAIL: child unexpectedly failed: 0 mem.c:839: INFO: set min_free_kbytes to 23160 memfree is 7104128 kB before eatup mem memfree is 26560 kB after eatup mem min_free_kbytes.c:135: FAIL: child unexpectedly failed: 0 mem.c:839: INFO: set min_free_kbytes to 145812 memfree is 7101504 kB before eatup mem memfree is 215872 kB after eatup mem min_free_kbytes.c:135: FAIL: child unexpectedly failed: 0 min_free_kbytes.c:81: PASS: min_free_kbytes test pass mem.c:839: INFO: set min_free_kbytes to 11580 --------------- Signed-off-by: Vipin K Parashar Signed-off-by: Li Wang Cc: Jan Stancek --- .../kernel/mem/tunable/min_free_kbytes.c | 40 +++++-------------- 1 file changed, 11 insertions(+), 29 deletions(-) diff --git a/testcases/kernel/mem/tunable/min_free_kbytes.c b/testcases/kernel/mem/tunable/min_free_kbytes.c index f114dc493..d2378a700 100644 --- a/testcases/kernel/mem/tunable/min_free_kbytes.c +++ b/testcases/kernel/mem/tunable/min_free_kbytes.c @@ -119,39 +119,21 @@ static void test_tune(unsigned long overcommit_policy) SAFE_WAITPID(pid[i], &status, WUNTRACED | WCONTINUED); - if (overcommit_policy == 2) { - if (!WIFEXITED(status) || WEXITSTATUS(status) != 0) - tst_res(TFAIL, - "child unexpectedly failed: %d", - status); - } else if (overcommit_policy == 1) { - if (!WIFSIGNALED(status) || WTERMSIG(status) != SIGKILL) + if (WIFEXITED(status) && WEXITSTATUS(status) != 0) { + tst_res(TFAIL, + "child unexpectedly failed: %d", status); + } else if (WIFSIGNALED(status) && WTERMSIG(status) != SIGKILL) { #if __WORDSIZE == 32 - { - if (total_mem < 3145728UL) + if (total_mem < 3145728UL) #endif - tst_res(TFAIL, - "child unexpectedly failed: %d", - status); + tst_res(TFAIL, + "child unexpectedly failed: %d", status); #if __WORDSIZE == 32 - /* in 32-bit system, a process allocate about 3Gb memory at most */ - else - tst_res(TINFO, "Child can't allocate " - ">3Gb memory in 32bit system"); - } + /* in 32-bit system, a process allocate about 3Gb memory at most */ + else + tst_res(TINFO, "Child can't allocate " + ">3Gb memory in 32bit system"); #endif - } else { - if (WIFEXITED(status)) { - if (WEXITSTATUS(status) != 0) { - tst_res(TFAIL, "child unexpectedly " - "failed: %d", status); - } - } else if (!WIFSIGNALED(status) || - WTERMSIG(status) != SIGKILL) { - tst_res(TFAIL, - "child unexpectedly failed: %d", - status); - } } } } From patchwork Tue Mar 19 09:38:57 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Li Wang X-Patchwork-Id: 1058316 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=lists.linux.it (client-ip=2001:1418:10:5::2; helo=picard.linux.it; envelope-from=ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Received: from picard.linux.it (picard.linux.it [IPv6:2001:1418:10:5::2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 44Np0h3hQKz9s6w for ; Tue, 19 Mar 2019 20:39:14 +1100 (AEDT) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 093BA3EAEB0 for ; Tue, 19 Mar 2019 10:39:12 +0100 (CET) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-5.smtp.seeweb.it (in-5.smtp.seeweb.it [217.194.8.5]) by picard.linux.it (Postfix) with ESMTP id 82B923EAE94 for ; Tue, 19 Mar 2019 10:39:10 +0100 (CET) Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by in-5.smtp.seeweb.it (Postfix) with ESMTPS id E8E29600E3A for ; Tue, 19 Mar 2019 10:39:09 +0100 (CET) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 03E36C05B1E9 for ; Tue, 19 Mar 2019 09:39:07 +0000 (UTC) Received: from dhcp-12-157.nay.redhat.com (dhcp-12-157.nay.redhat.com [10.66.12.157]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2CAF660CD3 for ; Tue, 19 Mar 2019 09:39:05 +0000 (UTC) From: Li Wang To: ltp@lists.linux.it Date: Tue, 19 Mar 2019 17:38:57 +0800 Message-Id: <20190319093858.584-2-liwang@redhat.com> In-Reply-To: <20190319093858.584-1-liwang@redhat.com> References: <20190319093858.584-1-liwang@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Tue, 19 Mar 2019 09:39:07 +0000 (UTC) X-Virus-Scanned: clamav-milter 0.99.2 at in-5.smtp.seeweb.it X-Virus-Status: Clean X-Spam-Status: No, score=-0.0 required=7.0 tests=SPF_HELO_PASS,SPF_PASS autolearn=disabled version=3.4.0 X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on in-5.smtp.seeweb.it Subject: [LTP] [PATCH RFC 2/3] min_free_kbytes: enable check_monitor in background X-BeenThere: ltp@lists.linux.it X-Mailman-Version: 2.1.18 Precedence: list List-Id: Linux Test Project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" Also: do i+=pagesize to make test write page faster cleanup work Signed-off-by: Li Wang --- .../kernel/mem/tunable/min_free_kbytes.c | 30 ++++++++----------- 1 file changed, 13 insertions(+), 17 deletions(-) diff --git a/testcases/kernel/mem/tunable/min_free_kbytes.c b/testcases/kernel/mem/tunable/min_free_kbytes.c index d2378a700..2eb51bf66 100644 --- a/testcases/kernel/mem/tunable/min_free_kbytes.c +++ b/testcases/kernel/mem/tunable/min_free_kbytes.c @@ -38,7 +38,7 @@ #define MAP_SIZE (1UL<<20) -volatile int end; +static volatile int end; static long default_tune = -1; static long orig_overcommit = -1; static unsigned long total_mem; @@ -83,8 +83,7 @@ static void min_free_kbytes_test(void) static void test_tune(unsigned long overcommit_policy) { - int status; - int pid[3]; + int status, pid; int ret, i; unsigned long tune, memfree, memtotal; @@ -97,7 +96,7 @@ static void test_tune(unsigned long overcommit_policy) /* case2 */ else if (i == 1) { set_sys_tune("min_free_kbytes", 2 * default_tune, 1); - /* case3 */ + /* case3 */ } else { memfree = SAFE_READ_MEMINFO("MemFree:"); memtotal = SAFE_READ_MEMINFO("MemTotal:"); @@ -109,15 +108,13 @@ static void test_tune(unsigned long overcommit_policy) } fflush(stdout); - switch (pid[i] = fork()) { - case -1: - tst_brk(TBROK | TERRNO, "fork"); - case 0: + pid = SAFE_FORK(); + if (pid == 0) { ret = eatup_mem(overcommit_policy); exit(ret); } - SAFE_WAITPID(pid[i], &status, WUNTRACED | WCONTINUED); + SAFE_WAITPID(pid, &status, WUNTRACED | WCONTINUED); if (WIFEXITED(status) && WEXITSTATUS(status) != 0) { tst_res(TFAIL, @@ -141,11 +138,10 @@ static void test_tune(unsigned long overcommit_policy) static int eatup_mem(unsigned long overcommit_policy) { int ret = 0; - unsigned long memfree; - void *addrs; + char *addrs; + unsigned long i, pagesz = getpagesize(); - memfree = SAFE_READ_MEMINFO("MemFree:"); - printf("memfree is %lu kB before eatup mem\n", memfree); + tst_res(TINFO, "memfree is %lu kB before eatup mem", SAFE_READ_MEMINFO("MemFree:")); while (1) { addrs = mmap(NULL, MAP_SIZE, PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_PRIVATE, -1, 0); @@ -156,10 +152,10 @@ static int eatup_mem(unsigned long overcommit_policy) } break; } - memset(addrs, 1, MAP_SIZE); + for (i = 0; i < MAP_SIZE; i += pagesz) + *(addrs + i) = 'a'; } - memfree = SAFE_READ_MEMINFO("MemFree:"); - printf("memfree is %lu kB after eatup mem\n", memfree); + tst_res(TINFO, "memfree is %lu kB after eatup mem", SAFE_READ_MEMINFO("MemFree:")); return ret; } @@ -169,7 +165,7 @@ static void check_monitor(void) unsigned long tune; unsigned long memfree; - while (end) { + while (!end) { memfree = SAFE_READ_MEMINFO("MemFree:"); tune = get_sys_tune("min_free_kbytes"); From patchwork Tue Mar 19 09:38:58 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Li Wang X-Patchwork-Id: 1058318 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=lists.linux.it (client-ip=2001:1418:10:5::2; helo=picard.linux.it; envelope-from=ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Received: from picard.linux.it (picard.linux.it [IPv6:2001:1418:10:5::2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 44Np0s1qZ0z9s6w for ; Tue, 19 Mar 2019 20:39:25 +1100 (AEDT) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 50A1E294AB5 for ; Tue, 19 Mar 2019 10:39:22 +0100 (CET) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-5.smtp.seeweb.it (in-5.smtp.seeweb.it [217.194.8.5]) by picard.linux.it (Postfix) with ESMTP id 3FF0A3EAEB3 for ; Tue, 19 Mar 2019 10:39:13 +0100 (CET) Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by in-5.smtp.seeweb.it (Postfix) with ESMTPS id 2F3A8600E34 for ; Tue, 19 Mar 2019 10:39:13 +0100 (CET) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 04DF799DBA for ; Tue, 19 Mar 2019 09:39:11 +0000 (UTC) Received: from dhcp-12-157.nay.redhat.com (dhcp-12-157.nay.redhat.com [10.66.12.157]) by smtp.corp.redhat.com (Postfix) with ESMTP id 812B260FAB; Tue, 19 Mar 2019 09:39:07 +0000 (UTC) From: Li Wang To: ltp@lists.linux.it Date: Tue, 19 Mar 2019 17:38:58 +0800 Message-Id: <20190319093858.584-3-liwang@redhat.com> In-Reply-To: <20190319093858.584-2-liwang@redhat.com> References: <20190319093858.584-1-liwang@redhat.com> <20190319093858.584-2-liwang@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Tue, 19 Mar 2019 09:39:11 +0000 (UTC) X-Virus-Scanned: clamav-milter 0.99.2 at in-5.smtp.seeweb.it X-Virus-Status: Clean X-Spam-Status: No, score=-0.0 required=7.0 tests=SPF_HELO_PASS,SPF_PASS autolearn=disabled version=3.4.0 X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on in-5.smtp.seeweb.it Cc: Rafael Aquini Subject: [LTP] [PATCH RFC 3/3] min_free_kbytes: allow MemFree to fluctuate nearby min_pages X-BeenThere: ltp@lists.linux.it X-Mailman-Version: 2.1.18 Precedence: list List-Id: Linux Test Project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" After enabling the check_monitor in last commit, I got many failures in this test, that's because it detects the system MemFree is less than min_free_kbytes at some moments then reprot FAIL. ----ERROR LOG---- min_free_kbytes.c:197: INFO: MemFree is 180032 kB, min_free_kbytes is 180224 kB min_free_kbytes.c:198: FAIL: MemFree < min_free_kbytes min_free_kbytes.c:197: INFO: MemFree is 179520 kB, min_free_kbytes is 180224 kB min_free_kbytes.c:198: FAIL: MemFree < min_free_kbytes min_free_kbytes.c:197: INFO: MemFree is 176704 kB, min_free_kbytes is 180224 kB min_free_kbytes.c:198: FAIL: MemFree < min_free_kbytes min_free_kbytes.c:197: INFO: MemFree is 176448 kB, min_free_kbytes is 180224 kB min_free_kbytes.c:198: FAIL: MemFree < min_free_kbytes min_free_kbytes.c:197: INFO: MemFree is 178880 kB, min_free_kbytes is 180224 kB min_free_kbytes.c:198: FAIL: MemFree < min_free_kbytes min_free_kbytes.c:197: INFO: MemFree is 174656 kB, min_free_kbytes is 180224 kB min_free_kbytes.c:198: FAIL: MemFree < min_free_kbytes ----------------- But I dont' think it's a kernel bug, since to compare MemFree with min_free_kbytes is NOT accurate in memory testing. Theoretically, min_free_kbytes is using for memory watermark setting. When memory in a certain zone drops below 'low' watermark, the kernel starts to reclaim memory, until there is again more than 'high' available memory. However, while the memory is less than 'min' watermark, only GFP_ATOMIC allocations are satisfied, everything else results in OOM. In this patch, the MemFree is allowed to fluctuate nearby min_free_kbytes, the main idea is to give a little accessible range (min_free_kbytes - 1/10*min_free_kbytes) for MemFree comparing. Otherwise this testcase is meaningless, or we can remove it from LTP. MORE REFERENCE INFO: Those watermarks behave accordingly to the picture below: ^ | f | \ / r | \ /[3] e |...\............../................ e | \ [0] / high_pages | \ / p |......\......../................... a | \[1] / low_pages g | \ / e |.........\../...................... s | \/[2] min_pages | +------------------------------------> time Memory is being allocated normally at [0] and [1]. When hash of free pages within a zone decreases below low_pages [1], kswapd is woken up to start scanning memory for reclamation. If the allocation load out-paces kswapd and the free memory level drops below min_pages [2] only ATOMIC allocations are granted and every other task in the system requesting memory starts doing the same work kswapd does -- putting the system into direct reclaim mode. Direct reclaim ceases as soon as the free memory level is restored to above min_pages [2] high_pages [3] marks the point where kswapd goes back to sleep as there's no more reclaim work to be done. Signed-off-by: Li Wang Cc: Rafael Aquini --- testcases/kernel/mem/tunable/min_free_kbytes.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/testcases/kernel/mem/tunable/min_free_kbytes.c b/testcases/kernel/mem/tunable/min_free_kbytes.c index 2eb51bf66..6b7da2215 100644 --- a/testcases/kernel/mem/tunable/min_free_kbytes.c +++ b/testcases/kernel/mem/tunable/min_free_kbytes.c @@ -169,7 +169,10 @@ static void check_monitor(void) memfree = SAFE_READ_MEMINFO("MemFree:"); tune = get_sys_tune("min_free_kbytes"); - if (memfree < tune) { + /* The MemFree is allowed to fluctuate nearby min_free_kbytes, + * here is to give a little accessible range(min_free_kbytes - + * 1/10 * min_free_kbytes) for MemFree comparing. */ + if ((memfree + 1/10*tune) < tune) { tst_res(TINFO, "MemFree is %lu kB, " "min_free_kbytes is %lu kB", memfree, tune); tst_res(TFAIL, "MemFree < min_free_kbytes");