From patchwork Mon Dec 4 18:48:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Roesch X-Patchwork-Id: 13478939 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 469A2C10DC3 for ; Mon, 4 Dec 2023 18:48:36 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C90BF6B00ED; Mon, 4 Dec 2023 13:48:34 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id C3A0C6B00EE; Mon, 4 Dec 2023 13:48:34 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B023A6B0100; Mon, 4 Dec 2023 13:48:34 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 92AF96B00ED for ; Mon, 4 Dec 2023 13:48:34 -0500 (EST) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 60D2812013E for ; Mon, 4 Dec 2023 18:48:34 +0000 (UTC) X-FDA: 81530021748.27.76D62D3 Received: from 66-220-144-179.mail-mxout.facebook.com (66-220-144-179.mail-mxout.facebook.com [66.220.144.179]) by imf18.hostedemail.com (Postfix) with ESMTP id C0E261C001C for ; Mon, 4 Dec 2023 18:48:32 +0000 (UTC) Authentication-Results: imf18.hostedemail.com; dkim=none; dmarc=none; spf=neutral (imf18.hostedemail.com: 66.220.144.179 is neither permitted nor denied by domain of shr@devkernel.io) smtp.mailfrom=shr@devkernel.io ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1701715712; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=UTjrGbU4I/RqcrucjyV8XvLhSKkL76lxJ1wr3bvi3b4=; b=7xC1huPaJL5pWaswRpx04qzGeHrwgpAeefUUZVrN7GJAieGt9dUlLuLq07aMRD9m0hjVlG 3z1kOduUPpfVpItEY5y8d0+nDapz/RoUI821roLfiH0JrQfJgFNk92ClowmGyGTksOxQhH g7O3XEKUGYc6MyxxdC2rXFK674CRml4= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=none; dmarc=none; spf=neutral (imf18.hostedemail.com: 66.220.144.179 is neither permitted nor denied by domain of shr@devkernel.io) smtp.mailfrom=shr@devkernel.io ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1701715712; a=rsa-sha256; cv=none; b=JPGaFTD2uzdTK7jNUg3XVECgMGSBqbxFnNqEGIh8WL+tbGPK8IJlpn4SPFjcN31Q5SUh57 drC8ROkujzsmasBidZtsmP+LO7rlIvFU5UgwqdxiVy0Xr04F8Xy2HajtwmZfW7h6YHX3kb q/9nwSP++zQmyg3EN/xrFH3StjjofCo= Received: by devbig1114.prn1.facebook.com (Postfix, from userid 425415) id 148D1105A5B35; Mon, 4 Dec 2023 10:48:20 -0800 (PST) From: Stefan Roesch To: kernel-team@fb.com Cc: shr@devkernel.io, david@redhat.com, oliver.sang@intel.com, linux-mm@kvack.org, ltp@lists.linux.it, pvorel@suse.cz, liwang@redhat.com Subject: [PATCH v3 1/2] mem: disable KSM smart scan for ksm tests Date: Mon, 4 Dec 2023 10:48:16 -0800 Message-Id: <20231204184817.3570465-2-shr@devkernel.io> X-Mailer: git-send-email 2.39.3 In-Reply-To: <20231204184817.3570465-1-shr@devkernel.io> References: <20231204184817.3570465-1-shr@devkernel.io> MIME-Version: 1.0 X-Rspam-User: X-Stat-Signature: q9q47sf5a4ngguxsjdqsoya4wayf7hcg X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: C0E261C001C X-HE-Tag: 1701715712-887412 X-HE-Meta: U2FsdGVkX19aWb2bFpnmk8wjYtWfMRDyjiyMv5/UyOdXjFviV08VSI3qSrYFwQI3shOSrxSOsrT+6f4vqxl74IQ1ofw2Cy12Xa4TLMJbEdsZm0pA1o07e3LCg/PGhJD+8H24d/Cskkj3Lag90sdjryrEglEi8BnXeV22iMHiq2K46M/qnjemBSpHadIFKvjiP3JkfAwHHD+nBZh8HBYxKTEY6P6+iS/Cji51mgfa3FWyWgfFqLhk/wtueYDymviiHcTkrCDDXL9S9UnZB6p/q26TCHlYcY6Bs/CnxVFdVOwnbxOT80nirWgRWr00eMZSv/5tyYt0Jty/XSXPKGylpjswvevx2PtE8cWFWcVeaPcvK29W8ZjEAUpHSdg0ECLY2tju+6v+LYv3V0mJ4yAa0TDnPAygAHQ894g9nKDgks3Zut8NAcI+M7bS4D5c/TS7NcR41v68gOTwdLJpiw8AFujEXHR/2IS2QdMqEeI741W0EPgpOqKIC50nAP5s48vQIR9s5er0YcYnBNFD6xmCgRso5KGYnr+wz5GIMZJA35rWZ/X5+XdLhP+yO+arJgPWW5G7iWdoyyUHzUIKAsDwnE4colrrTRBk22nylxrl7Of2el8HQIuJ3WlmtgGEOuI/iKnxt028Y3153Er7H5x3P32ebiEGmTUkJm4Ujp459BNprrxVm8hQAC5V0cv2rPpa9apbljpUb14MhzuIK8bk7N6h7Wg5TSXeOkRWY+zF3UwROM+uI7SitmeH7LDY20MkIfO5TQoLJkctJVvTLknSMw8NRJbbuIfq3yCgyxYJoPQHszakwtGiwsfxR8vf/3X+A9fbFb/iQpyxXuPOP5lOR/7L0GJ2PFqn6rBw7FdJERRzzkarH/70mnUf6O8dvCO1BnL/6tp1Damc7s2LZ3yXMcjMKiMIIkwyJYKgsmXjokUSOfuc1Cb766VHlqw+kKk7m0JgQWXSS0qbN/rCk9m JpeZKcui Wv0ItnrMIPFoCw4p5iy11Ru0RKa5y9a2UfdcB8Is1cE8M/kWLUlHth5h/0Xis1jtNHsGKSEo5Xkd4F5BvXwvjGTuM+DwVEF/ThKUZ X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: This disables the "smart scan" KSM feature to make sure that the volatile count remains at 0. Signed-off-by: Stefan Roesch Reviewed-by: Petr Vorel Reported-by: kernel test robot Closes: https://lore.kernel.org/oe-lkp/202311161132.13d8ce5a-oliver.sang@intel.com --- testcases/kernel/mem/ksm/ksm01.c | 2 ++ testcases/kernel/mem/ksm/ksm02.c | 2 ++ testcases/kernel/mem/ksm/ksm03.c | 2 ++ testcases/kernel/mem/ksm/ksm04.c | 2 ++ testcases/kernel/mem/ksm/ksm05.c | 2 ++ testcases/kernel/mem/ksm/ksm06.c | 2 ++ 6 files changed, 12 insertions(+) diff --git a/testcases/kernel/mem/ksm/ksm01.c b/testcases/kernel/mem/ksm/ksm01.c index bcd095865..e2d3d9e00 100644 --- a/testcases/kernel/mem/ksm/ksm01.c +++ b/testcases/kernel/mem/ksm/ksm01.c @@ -86,6 +86,8 @@ static struct tst_test test = { TST_SR_SKIP_MISSING | TST_SR_TCONF_RO}, {"/sys/kernel/mm/ksm/merge_across_nodes", "1", TST_SR_SKIP_MISSING | TST_SR_TCONF_RO}, + {"/sys/kernel/mm/ksm/smart_scan", "0", + TST_SR_SKIP_MISSING | TST_SR_TBROK_RO}, {} }, .needs_kconfigs = (const char *const[]){ diff --git a/testcases/kernel/mem/ksm/ksm02.c b/testcases/kernel/mem/ksm/ksm02.c index bce639dce..3707de95d 100644 --- a/testcases/kernel/mem/ksm/ksm02.c +++ b/testcases/kernel/mem/ksm/ksm02.c @@ -107,6 +107,8 @@ static struct tst_test test = { TST_SR_SKIP_MISSING | TST_SR_TCONF_RO}, {"/sys/kernel/mm/ksm/merge_across_nodes", "1", TST_SR_SKIP_MISSING | TST_SR_TCONF_RO}, + {"/sys/kernel/mm/ksm/smart_scan", "0", + TST_SR_SKIP_MISSING | TST_SR_TBROK_RO}, {} }, .needs_kconfigs = (const char *const[]){ diff --git a/testcases/kernel/mem/ksm/ksm03.c b/testcases/kernel/mem/ksm/ksm03.c index 4a733269f..cff74700d 100644 --- a/testcases/kernel/mem/ksm/ksm03.c +++ b/testcases/kernel/mem/ksm/ksm03.c @@ -89,6 +89,8 @@ static struct tst_test test = { TST_SR_SKIP_MISSING | TST_SR_TCONF_RO}, {"/sys/kernel/mm/ksm/merge_across_nodes", "1", TST_SR_SKIP_MISSING | TST_SR_TCONF_RO}, + {"/sys/kernel/mm/ksm/smart_scan", "0", + TST_SR_SKIP_MISSING | TST_SR_TBROK_RO}, {} }, .needs_kconfigs = (const char *const[]){ diff --git a/testcases/kernel/mem/ksm/ksm04.c b/testcases/kernel/mem/ksm/ksm04.c index 4f1f2f721..9935e32d7 100644 --- a/testcases/kernel/mem/ksm/ksm04.c +++ b/testcases/kernel/mem/ksm/ksm04.c @@ -109,6 +109,8 @@ static struct tst_test test = { TST_SR_SKIP_MISSING | TST_SR_TCONF_RO}, {"/sys/kernel/mm/ksm/merge_across_nodes", "1", TST_SR_SKIP_MISSING | TST_SR_TCONF_RO}, + {"/sys/kernel/mm/ksm/smart_scan", "0", + TST_SR_SKIP_MISSING | TST_SR_TBROK_RO}, {} }, .needs_kconfigs = (const char *const[]){ diff --git a/testcases/kernel/mem/ksm/ksm05.c b/testcases/kernel/mem/ksm/ksm05.c index 1f58c8325..61e740843 100644 --- a/testcases/kernel/mem/ksm/ksm05.c +++ b/testcases/kernel/mem/ksm/ksm05.c @@ -89,6 +89,8 @@ static struct tst_test test = { .test_all = test_ksm, .save_restore = (const struct tst_path_val[]) { {"/sys/kernel/mm/ksm/run", "1", TST_SR_TBROK}, + {"/sys/kernel/mm/ksm/smart_scan", "0", + TST_SR_SKIP_MISSING | TST_SR_TBROK_RO}, {} }, .needs_kconfigs = (const char *const[]){ diff --git a/testcases/kernel/mem/ksm/ksm06.c b/testcases/kernel/mem/ksm/ksm06.c index 0b159e5c7..80fdf1e47 100644 --- a/testcases/kernel/mem/ksm/ksm06.c +++ b/testcases/kernel/mem/ksm/ksm06.c @@ -142,6 +142,8 @@ static struct tst_test test = { {"/sys/kernel/mm/ksm/run", NULL, TST_SR_TBROK}, {"/sys/kernel/mm/ksm/sleep_millisecs", NULL, TST_SR_TBROK}, {"/sys/kernel/mm/ksm/merge_across_nodes", NULL, TST_SR_TCONF}, + {"/sys/kernel/mm/ksm/smart_scan", "0", + TST_SR_SKIP_MISSING | TST_SR_TBROK_RO}, {} }, .needs_kconfigs = (const char *const[]){ From patchwork Mon Dec 4 18:48:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Roesch X-Patchwork-Id: 13478940 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8147BC4167B for ; Mon, 4 Dec 2023 18:48:38 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 206E56B010F; Mon, 4 Dec 2023 13:48:37 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 1B66C6B0112; Mon, 4 Dec 2023 13:48:37 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id EAE746B0115; Mon, 4 Dec 2023 13:48:36 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id D6F066B010F for ; Mon, 4 Dec 2023 13:48:36 -0500 (EST) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id B3249140215 for ; Mon, 4 Dec 2023 18:48:36 +0000 (UTC) X-FDA: 81530021832.26.6584D31 Received: from 66-220-144-178.mail-mxout.facebook.com (66-220-144-178.mail-mxout.facebook.com [66.220.144.178]) by imf05.hostedemail.com (Postfix) with ESMTP id 1C09110001B for ; Mon, 4 Dec 2023 18:48:34 +0000 (UTC) Authentication-Results: imf05.hostedemail.com; dkim=none; dmarc=none; spf=neutral (imf05.hostedemail.com: 66.220.144.178 is neither permitted nor denied by domain of shr@devkernel.io) smtp.mailfrom=shr@devkernel.io ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1701715715; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=0e0Seqgxac5QGz3wN0aaFoXsyIiMmCnn/t8bXT7hgNY=; b=6hDzevorKTekDkfpnAYW4i3Z1EUmvR4HX9SlhgiUGY0IhEj9Mt94ODrUkpWRkhMCmsqvsc A/UmtnHDtNAAMUqNah7BhvFT2KELtAdrfCthw61vs0DJtAJZKenlPmvkK4v1VA+EHrN+Ag Tt90uyNqkMEygfflWijZyBuCHvzD1F4= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=none; dmarc=none; spf=neutral (imf05.hostedemail.com: 66.220.144.178 is neither permitted nor denied by domain of shr@devkernel.io) smtp.mailfrom=shr@devkernel.io ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1701715715; a=rsa-sha256; cv=none; b=d7zoVBBzia2ErrIfDE3uU5jc3UEku2tltPpnPCr/Teh0iA2NRmDv9sUmypPttWNbSxVzdT HiyVwri5rRmpwcShHeqD5AZWWoQueu1ea5jvNh27E/AKR/mbcngN62Mkv+diK6HLXEP8/W 4MNLC7ufl+mh8YAJsdRjP97lGIN8608= Received: by devbig1114.prn1.facebook.com (Postfix, from userid 425415) id 1AA8A105A5B36; Mon, 4 Dec 2023 10:48:20 -0800 (PST) From: Stefan Roesch To: kernel-team@fb.com Cc: shr@devkernel.io, david@redhat.com, oliver.sang@intel.com, linux-mm@kvack.org, ltp@lists.linux.it, pvorel@suse.cz, liwang@redhat.com Subject: [PATCH v3 2/2] add ksm test for smart-scan feature Date: Mon, 4 Dec 2023 10:48:17 -0800 Message-Id: <20231204184817.3570465-3-shr@devkernel.io> X-Mailer: git-send-email 2.39.3 In-Reply-To: <20231204184817.3570465-1-shr@devkernel.io> References: <20231204184817.3570465-1-shr@devkernel.io> MIME-Version: 1.0 X-Rspamd-Queue-Id: 1C09110001B X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: ifzgbz7waqgc1cn9dfkeqszfjhss88b3 X-HE-Tag: 1701715714-919421 X-HE-Meta: U2FsdGVkX1+Tgj6uCL0AJWelWSEC26GErRurirQLrq285F4l+RC1j2oSNyMrp17i7YrEdOGR/3pNKVC59l4fnjT9B0u3RIxq3hFNVvr0tovNXSNwyBBhoq0joepyJjFnlM7P9ht9zExmldcpzfL97+glfmYHOwfGFKGR0XG4NRW8EgnDCwKBYhBIqvNdPLRsv8EoX58DBYMK+ofFk/uOStTrWpX+Q6HWh0yql8J7bW7SRUv2eKkoY97N6/K8sPwY3qhXkhbE7QKBFmVfLAvfOaHNHeePyhrN/xeFtx53vlmkZXEzjxukxxOcVXBGhqwenZJSClnwog7QzPiUBE24YRb9eOAnYJI3F7I4kMTGWeYR41fdAFka/iav/LI+3hGHFxjRpQF8BejxwFPsaLBlvDsEQkPih9RIYavBWJ85rMyVNd4sJq5xHCl0lX0PnvYUW7gbkIkYg7z3b4dT5LwApbpim28CGJFYsYkRXYCyTB7EjeOF1PAscAz9tqtm3SkbeAm6lyz2dAecBK66ES+Pol35hEXj8z9HDUZO47JFo19/Fb6pdB7n6a35aXRNFAu6tq0ZyWADlJejaFv8ADDsPkWlbqqhbrsXMp9ByOgfz5N/zE/bUwf2oenMKZ3curMTYn/BiYMcQkHCxUOErwNPJHRdVHZOIOO7y0jqrnYEct64yb5XVXUf1brB3npOkyOsc5+/aDyYofbERWmDp445CiuaHiHIt/8sDO3UEL+bISw0FzUXqOL64NUqzBdrFMBAgwLMOxpwqLdxF4xNhHYLcVQnIOXrBuZpECLZhBhgikviQvMn1R1hjbwsLLwnbSHa3/1DAacgyqmoTTm27O2tN6kAfaYjfDmJdyVdWaX6Gz4gaAlEchgtylkGGw9XWwQ4lIyuCivG/So8tPEpAe1TWrnknhirSfG42qkAn8cuc0rSRy0KSKbsJTZkEwHs+kUq7RBlSkWsOUjOUYek4Yo HvLMft+E MVXhO1aYXXkTbWa+/I/3OdNr7xPrw4iGd2cK4 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: This adds a new ksm (kernel samepage merging) test to evaluate the new smart scan feature. It allocates a page and fills it with 'a' characters. It captures the pages_skipped counter, waits for a few iterations and captures the pages_skipped counter again. The expectation is that over 50% of the page scans are skipped (There is only one page that has KSM enabled and it gets scanned during each iteration and it cannot be de-duplicated). Signed-off-by: Stefan Roesch --- runtest/mm | 1 + testcases/kernel/mem/.gitignore | 1 + testcases/kernel/mem/ksm/ksm07.c | 131 +++++++++++++++++++++++++++++++ 3 files changed, 133 insertions(+) create mode 100644 testcases/kernel/mem/ksm/ksm07.c diff --git a/runtest/mm b/runtest/mm index f288fed36..d859b331c 100644 --- a/runtest/mm +++ b/runtest/mm @@ -70,6 +70,7 @@ ksm05 ksm05 -I 10 ksm06 ksm06 ksm06_1 ksm06 -n 10 ksm06_2 ksm06 -n 8000 +ksm07 ksm07 cpuset01 cpuset01 diff --git a/testcases/kernel/mem/.gitignore b/testcases/kernel/mem/.gitignore index 7258489ed..c96fe8bfc 100644 --- a/testcases/kernel/mem/.gitignore +++ b/testcases/kernel/mem/.gitignore @@ -53,6 +53,7 @@ /ksm/ksm04 /ksm/ksm05 /ksm/ksm06 +/ksm/ksm07 /mem/mem02 /mmapstress/mmap-corruption01 /mmapstress/mmapstress01 diff --git a/testcases/kernel/mem/ksm/ksm07.c b/testcases/kernel/mem/ksm/ksm07.c new file mode 100644 index 000000000..16153fdb2 --- /dev/null +++ b/testcases/kernel/mem/ksm/ksm07.c @@ -0,0 +1,131 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Copyright (C) 2010-2017 Red Hat, Inc. + */ +/*\ + * [Description] + * + * Kernel Samepage Merging (KSM) + * + * This adds a new ksm (kernel samepage merging) test to evaluate the new + * smart scan feature. It allocates a page and fills it with 'a' + * characters. It captures the pages_skipped counter, waits for a few + * iterations and captures the pages_skipped counter again. The expectation + * is that over 50% of the page scans are skipped (There is only one page + * that has KSM enabled and it gets scanned during each iteration and it + * cannot be de-duplicated). + * + * Prerequisites: + * + * 1) ksm and ksmtuned daemons need to be disabled. Otherwise, it could + * distrub the testing as they also change some ksm tunables depends + * on current workloads. + */ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "../include/mem.h" +#include "ksm_common.h" + +/* This test allocates one page, fills the page with a's, captures the + * full_scan and pages_skipped counters. Then it makes sure at least 3 + * full scans have been performed and measures the above counters again. + * The expectation is that at least 50% of the pages are skipped. + * + * To wait for at least 3 scans it uses the wait_ksmd_full_scan() function. In + * reality, it will be a lot more scans as the wait_ksmd_full_scan() function + * sleeps for one second. + */ +static void create_memory(void) +{ + int status; + int full_scans_begin; + int full_scans_end; + int pages_skipped_begin; + int pages_skipped_end; + int diff_pages; + int diff_scans; + unsigned long page_size; + char *memory; + + /* Apply for the space for memory. */ + page_size = sysconf(_SC_PAGE_SIZE); + memory = SAFE_MALLOC(page_size); + + for (int i = 0; i < 1; i++) { + memory = SAFE_MMAP(NULL, page_size, PROT_READ|PROT_WRITE, + MAP_ANONYMOUS|MAP_PRIVATE, -1, 0); +#ifdef HAVE_DECL_MADV_MERGEABLE + if (madvise(memory, page_size, MADV_MERGEABLE) == -1) + tst_brk(TBROK|TERRNO, "madvise"); +#endif + } + memset(memory, 'a', page_size); + + tst_res(TINFO, "KSM merging..."); + if (access(PATH_KSM "max_page_sharing", F_OK) == 0) { + SAFE_FILE_PRINTF(PATH_KSM "run", "2"); + } + + /* Set defalut ksm scan values. */ + SAFE_FILE_PRINTF(PATH_KSM "run", "1"); + SAFE_FILE_PRINTF(PATH_KSM "pages_to_scan", "%ld", 100l); + SAFE_FILE_PRINTF(PATH_KSM "sleep_millisecs", "0"); + + /* Measure pages skipped aka "smart scan". */ + SAFE_FILE_SCANF(PATH_KSM "full_scans", "%d", &full_scans_begin); + SAFE_FILE_SCANF(PATH_KSM "pages_skipped", "%d", &pages_skipped_begin); + wait_ksmd_full_scan(); + + tst_res(TINFO, "stop KSM."); + SAFE_FILE_PRINTF(PATH_KSM "run", "0"); + + SAFE_FILE_SCANF(PATH_KSM "full_scans", "%d", &full_scans_end); + SAFE_FILE_SCANF(PATH_KSM "pages_skipped", "%d", &pages_skipped_end); + diff_pages = pages_skipped_end - pages_skipped_begin; + diff_scans = full_scans_end - full_scans_begin; + + if (diff_pages < diff_scans * 50 / 100) { + tst_res(TFAIL, "not enough pages have been skipped by smart_scan."); + } else { + tst_res(TPASS, "smart_scan skipped more than 50%% of the pages."); + } + + while (waitpid(-1, &status, 0) > 0) + if (WEXITSTATUS(status) != 0) + tst_res(TFAIL, "child exit status is %d", + WEXITSTATUS(status)); +} + +static void verify_ksm(void) +{ + create_memory(); +} + +static struct tst_test test = { + .needs_root = 1, + .forks_child = 1, + .options = (struct tst_option[]) { + {} + }, + .save_restore = (const struct tst_path_val[]) { + {"/sys/kernel/mm/ksm/run", NULL, TST_SR_TCONF}, + {"/sys/kernel/mm/ksm/sleep_millisecs", NULL, TST_SR_TCONF}, + {"/sys/kernel/mm/ksm/smart_scan", "1", + TST_SR_SKIP_MISSING | TST_SR_TCONF}, + {} + }, + .needs_kconfigs = (const char *const[]){ + "CONFIG_KSM=y", + NULL + }, + .test_all = verify_ksm, +};