From patchwork Fri Dec 1 21:09:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Roesch X-Patchwork-Id: 13476396 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 0B14AC4167B for ; Fri, 1 Dec 2023 21:09:52 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 68D0D6B04F9; Fri, 1 Dec 2023 16:09:52 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 639266B04FC; Fri, 1 Dec 2023 16:09:52 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4987A6B04FB; Fri, 1 Dec 2023 16:09:52 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 362E26B04F8 for ; Fri, 1 Dec 2023 16:09:52 -0500 (EST) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id E77E180354 for ; Fri, 1 Dec 2023 21:09:51 +0000 (UTC) X-FDA: 81519491382.30.64D72D4 Received: from 66-220-144-178.mail-mxout.facebook.com (66-220-144-178.mail-mxout.facebook.com [66.220.144.178]) by imf16.hostedemail.com (Postfix) with ESMTP id 45527180028 for ; Fri, 1 Dec 2023 21:09:49 +0000 (UTC) Authentication-Results: imf16.hostedemail.com; dkim=none; dmarc=none; spf=neutral (imf16.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=1701464989; a=rsa-sha256; cv=none; b=alJp6uEAj/OSLC2EJzp+/F+ggDaagqLQ2STkVuy/7ovL4+KuVJgwQ8lcN/YeLMuIWpHpGE lnC6X+PBu/OZCYJUIFTKUouHUYUc1IpTY2L8v+XJ4aRtMQoYaqQsHcRdMhVyGZ5yr8PGIQ ylHXy2KbZN/dgGiVt7hSS1bAwD4fHLg= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=none; dmarc=none; spf=neutral (imf16.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=1701464989; 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=sY6IqtcP04r6RV1mp6TiYY/liZn+u5PstEwXT43YFRI=; b=bop8E/yHku3ShPckuXPUEJ8YUXsG5NF3P4fAu/YMUGcYYMjBNpD7KXm4gHRL5CB4p0GkEB a2RboZEl8AnA1x975QFFxvFSQX6QdA/HMRqvQIvHWc77k5gtUkwTmpoEv+DlRfwE51Cagd MpOidUG++s//5c8jlBaISMc+xfcV4OQ= Received: by devbig1114.prn1.facebook.com (Postfix, from userid 425415) id 21E3D10340489; Fri, 1 Dec 2023 13:09:34 -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 v2 1/2] mem: disable KSM smart scan for ksm tests Date: Fri, 1 Dec 2023 13:09:29 -0800 Message-Id: <20231201210930.2651725-2-shr@devkernel.io> X-Mailer: git-send-email 2.39.3 In-Reply-To: <20231201210930.2651725-1-shr@devkernel.io> References: <20231201210930.2651725-1-shr@devkernel.io> MIME-Version: 1.0 X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: 45527180028 X-Stat-Signature: jmt1msmum5gd6tiqixcrgwxu7ad7zqcf X-Rspam-User: X-HE-Tag: 1701464989-568244 X-HE-Meta: U2FsdGVkX1/j2IiIWt8l808cv659ZA4rJ63eZSbsd5iX9+dhuKgL09ACN3SAr4dPZm/mgv3Mjd3cB9tpsQ7EBzNvxteFH2JdfEgnXObKRqavwDc2Cc+Qt4g/tWYkMgx6YOjLM5J0BM9ou7mXXufufGbsVuAH+NEn9Xs5QY2Q8AfNIXgzLKMQ+mcej2jygknFy63DkFfiWpiuifELLVig9JUFVYIdOaVfvWjocoHWHmYSiH1qdRGIbIuUNp6nzSVuEPOqSY7EYmWWHnVZjB0L8smSfjbUqcY30Ue8wD6JoTfiTAwLQ7Ouz0TMd206HMc3GRNbgbhyvDBeN/+/YT15w9ofPeawZ1MrUkFGxQ8pTZwYgoW79EKpCBHMwX+3lkOhce/GwOjXuhZa1OnkZJrmQCL25S2dEJaH3rTqpxO1cJesr7HRxvvW2wjyQNMahiFW0HmwnTYdMBDd4cJ/Q7ba2RnKexxR175tUV1Rnvpk+jgzosgWBdaYRzmyf5R+W+GAlN1BtBQ8LJt2JQqRBOA1qf4SvU87zYC2kCX1EiALOwt3e5dW2W8mtXv0gSEbMFXS0w37Pr/spDy1jVLQuDLh3dzXDvhHGcYcYksisp9XqZ0nX/Zb71pAAB7+yVPl/Z6EOaHwRXgMf4LhYKW+joPXfnJkZK7j7qacvEHt4DD4lAzrcp3YRJUoVs0V8HWx0qNlInPI2JQkkakTFqZSJiDENyWVZr73wyp8eg7Dd+KDaDfS5xjybH4K/6cVwLIeLybf2EGLbtAChh3PFy04ZbMNkZhHuJKai+ZPvHlL8c7yttuyK7S/l3sgkvys0SgnJxM0ZlbjRWJSlPFXVuG2p8W1/23ndfgNpf5zPLvRT+kLDfg8GAX203FORwqHKQvpExu3b/C6yLcqzyVbjAhmt/YUNkhkqVc4HjMOVbapYxEh7+ec1kg0r/KpBadmOCA6LCxZlxKWLZofA391GaqVNks Sf66BuCp Nt5p1eICMr3jZsjdfD4qg6CNIcBr8j6ZdUca8xtKaK8z9xZoirCBP98eE93M76BgjPMIeND8jEL/orhVZRYD5aoK2YGGHtL8itYWk77+opKZrkwJ2c770N52rwg== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000001, 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 Reported-by: kernel test robot Closes: https://lore.kernel.org/oe-lkp/202311161132.13d8ce5a-oliver.sang@intel.com Reviewed-by: Petr Vorel --- 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 ++ 4 files changed, 8 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[]){ From patchwork Fri Dec 1 21:09:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Roesch X-Patchwork-Id: 13476398 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 D4C73C4167B for ; Fri, 1 Dec 2023 21:09:55 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C7CD76B04F8; Fri, 1 Dec 2023 16:09:52 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id C2E356B04FC; Fri, 1 Dec 2023 16:09:52 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9E3466B04F8; Fri, 1 Dec 2023 16:09:52 -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 6A9226B04FB for ; Fri, 1 Dec 2023 16:09:52 -0500 (EST) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 3521D120336 for ; Fri, 1 Dec 2023 21:09:52 +0000 (UTC) X-FDA: 81519491424.25.40A3322 Received: from 66-220-144-178.mail-mxout.facebook.com (66-220-144-178.mail-mxout.facebook.com [66.220.144.178]) by imf13.hostedemail.com (Postfix) with ESMTP id 863DD20029 for ; Fri, 1 Dec 2023 21:09:50 +0000 (UTC) Authentication-Results: imf13.hostedemail.com; dkim=none; spf=neutral (imf13.hostedemail.com: 66.220.144.178 is neither permitted nor denied by domain of shr@devkernel.io) smtp.mailfrom=shr@devkernel.io; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1701464990; a=rsa-sha256; cv=none; b=udZj76NHeEaaM2dNXannazTMCbH9m8PSIK60aqeGI01ifEvdaBAzOM021XHh7NLXAZUjy0 AJVjNYVIIZma6O9OU2loC2ciQuTaS3jhynW50UDC49JlDNBRvL1rdoaI6bft2uYma8c/yb uXwFpQWwl9iMVkz87zZp1nf6w9yZp+k= ARC-Authentication-Results: i=1; imf13.hostedemail.com; dkim=none; spf=neutral (imf13.hostedemail.com: 66.220.144.178 is neither permitted nor denied by domain of shr@devkernel.io) smtp.mailfrom=shr@devkernel.io; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1701464990; 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=4xM+x7XD/VNuJbRPZJBAelQG8iet7RphVHmYQ7b65j4=; b=fNNAEJvtrObcFiQ7jY0vtvGW+21O2Bz3tP8vggWarqovhBm6w5h42J86XK2az+0Q0cOT44 7uLsmX7UXO2IQ9P+fsXUZfVWn7ALhWJ5GWJEWIOLOJMWeXgOvDOc35HlCr4Hoxb9v7QIwn 5tj/lYSRqeFs3OFW1cFVzhPY51t2Pkw= Received: by devbig1114.prn1.facebook.com (Postfix, from userid 425415) id 934B01034048C; Fri, 1 Dec 2023 13:09:34 -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 v2 2/2] add ksm test for smart-scan feature Date: Fri, 1 Dec 2023 13:09:30 -0800 Message-Id: <20231201210930.2651725-3-shr@devkernel.io> X-Mailer: git-send-email 2.39.3 In-Reply-To: <20231201210930.2651725-1-shr@devkernel.io> References: <20231201210930.2651725-1-shr@devkernel.io> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 863DD20029 X-Stat-Signature: rub7qq4qgn4qx6c3ujg3eqrfctwr3qgb X-HE-Tag: 1701464990-670076 X-HE-Meta: U2FsdGVkX1/xudznAZAHA9GoHOQQsUkyCH+S9GSNDScG75tTVemsCzajaflvAHDSTRg3hRfdsVTWXJHE6BN5VkxjNT1+u4H4oq/SfPyEjATjv56AJJbWyCw6kx2gQ5zxTJ6KgHlxZjEsxsOk4IhGPXtzdcgnXelhESnNWLxzcJsJ/Y0BXOk0VMBTwqxMAMr5yGlEWCBX/byrZOFVSjFcS5mYWE5lr7n4Ji/sH27YFVo92STTkx9o7Mf/2E02rCkAOjcf+ulUGxRJQKmwOa35i7upuEbsyJtEQrNuLq0SWF9RxNEJVsEPOod4oJkbyUAq0q1N6ypksSu8D1xYYTgJneqhMw1oKaG9RMhAIwB2aZkblMpIpK/lGcQjzmbIB87pvmRbnkYE9zPrFCOlkbUaP1kv8UsDXJjn2OJHc/wa74KKlDGAGddHJkGfY14RpcEGAOQSxUCrKPFFv56RfGDKQdBmR1LleCgWaxVmphYHd94HPXFdydCc8WyELM+blpvicqG+h2XdHIfsn5S5wpMdCP+m7OrF0Kyd0378bKav8MUiQIiGp5kquv1AVXTgkVlBylppOJJF9qoFhRv2GHxOwMSbOP07aodrqhOlHPOLWyv5BntNyyx5tAStFu9AnWWkqwgif62UwuJ0rBjqLzW9KXNOlXfENd8106RrnLTNOP4gEHHB6bl0V2kXh99XLw+nMMr7cXcf8m1Q0qhl71EpIm9ESeNbUwk0UZ6gMWmk7Wj5zrkL2sM+YDBzUy0GtC3OcEdNTf3mNn/tsUpTdaC3qkfE+GPJx1dzrJU2bKppJgEhQ0AsCssh0sLs7ehPX5tPJDqmh85Nvh7JIJQ9YBwhnQP4w0Eh73Ej8tyYnYwhrB7JCztuA6ez8k0UcudN9JETvSetR9Md1u3OfRRIbh1texsA5A0l8gNFJ+CBufAuRvyDNIYLfYPd+9oPqIMoYru0SryRjOEKuIH5E1PdNw9 +2pnREWc hWInLUKxvCY1KikD+dUhEe+m2YOKXuBCU711F 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 --- testcases/kernel/mem/.gitignore | 1 + testcases/kernel/mem/include/mem.h | 1 + testcases/kernel/mem/ksm/ksm07.c | 69 +++++++++++++++++++++++++++++ testcases/kernel/mem/lib/mem.c | 70 ++++++++++++++++++++++++++++++ 4 files changed, 141 insertions(+) create mode 100644 testcases/kernel/mem/ksm/ksm07.c 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/include/mem.h b/testcases/kernel/mem/include/mem.h index cdc3ca146..dbc3eb9ec 100644 --- a/testcases/kernel/mem/include/mem.h +++ b/testcases/kernel/mem/include/mem.h @@ -48,6 +48,7 @@ void testoom(int mempolicy, int lite, int retcode, int allow_sigkill); /* KSM */ void create_same_memory(int size, int num, int unit); +void create_memory_for_smartscan(void); void test_ksm_merge_across_nodes(unsigned long nr_pages); void ksm_group_check(int run, int pg_shared, int pg_sharing, int pg_volatile, int pg_unshared, int sleep_msecs, int pages_to_scan); diff --git a/testcases/kernel/mem/ksm/ksm07.c b/testcases/kernel/mem/ksm/ksm07.c new file mode 100644 index 000000000..9cde64c82 --- /dev/null +++ b/testcases/kernel/mem/ksm/ksm07.c @@ -0,0 +1,69 @@ +/* + * Copyright (C) 2010-2017 Red Hat, Inc. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See + * the GNU General Public License for more details. + * + * 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" + +static void verify_ksm(void) +{ + create_memory_for_smartscan(); +} + +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_TBROK}, + {"/sys/kernel/mm/ksm/sleep_millisecs", NULL, TST_SR_TBROK}, + {"/sys/kernel/mm/ksm/smart_scan", "1", + TST_SR_SKIP_MISSING | TST_SR_TBROK_RO}, + {} + }, + .needs_kconfigs = (const char *const[]){ + "CONFIG_KSM=y", + NULL + }, + .test_all = verify_ksm, +}; diff --git a/testcases/kernel/mem/lib/mem.c b/testcases/kernel/mem/lib/mem.c index fbfeef026..b27a017fc 100644 --- a/testcases/kernel/mem/lib/mem.c +++ b/testcases/kernel/mem/lib/mem.c @@ -438,6 +438,76 @@ static void resume_ksm_children(int *child, int num) fflush(stdout); } +/* 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. + */ +void create_memory_for_smartscan(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)); +} + void create_same_memory(int size, int num, int unit) { int i, j, status, *child;