From mboxrd@z Thu Jan 1 00:00:00 1970 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 AE33DC10F04 for ; Tue, 5 Dec 2023 13:16:18 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 36E766B0082; Tue, 5 Dec 2023 08:16:18 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 31E196B0083; Tue, 5 Dec 2023 08:16:18 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1C0316B0085; Tue, 5 Dec 2023 08:16:18 -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 06A116B0082 for ; Tue, 5 Dec 2023 08:16:18 -0500 (EST) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id B91B44016B for ; Tue, 5 Dec 2023 13:16:17 +0000 (UTC) X-FDA: 81532813194.26.B40406E Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.223.131]) by imf12.hostedemail.com (Postfix) with ESMTP id 53EBB40022 for ; Tue, 5 Dec 2023 13:16:13 +0000 (UTC) Authentication-Results: imf12.hostedemail.com; dkim=none; spf=pass (imf12.hostedemail.com: domain of pvorel@suse.cz designates 195.135.223.131 as permitted sender) smtp.mailfrom=pvorel@suse.cz; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1701782173; h=from:from:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=fcjVrAQiDbJHTTI4LKAr1BPu+pifThTChJ3uAWEkkII=; b=nDjLafteNn1xrTOdraHM3nRLWo4BcdfdhED+iiONwguvTqLSXeMFOZHSieNHrR5oQ/MdWQ O3Hds7CzPAVvvlE3uI7WnaaOf95t3KpZHGOQ0D6u/yxPxRvRkA7s4sG5BjGRtkbGaxJ3AD 6UhTJrPilsbAGxB/Y4JTQuYZtH7LUgE= ARC-Authentication-Results: i=1; imf12.hostedemail.com; dkim=none; spf=pass (imf12.hostedemail.com: domain of pvorel@suse.cz designates 195.135.223.131 as permitted sender) smtp.mailfrom=pvorel@suse.cz; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1701782173; a=rsa-sha256; cv=none; b=7MUygy154RFvTxi7mIXWPPdv7Kperg5pVytgyWxt2VaQ7JYD4VpEsV4QxOSm1uGTh5hr/H 7dil4tdhBgkRvyoCT7ACv8OjIFWa+ZZnSFVNhWTn17ow5vQbXy9OWq9IIevw+CKVTuVTKh DMMwFIDXlxkLgaJE00hZM8Kfjt4/JJE= Received: from imap2.dmz-prg2.suse.org (imap2.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104:10:150:64:98]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 30B3B1F7AB; Tue, 5 Dec 2023 13:16:11 +0000 (UTC) Received: from imap2.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap2.dmz-prg2.suse.org (Postfix) with ESMTPS id 985E013924; Tue, 5 Dec 2023 13:16:10 +0000 (UTC) Received: from dovecot-director2.suse.de ([10.150.64.162]) by imap2.dmz-prg2.suse.org with ESMTPSA id KMgVHpoib2VwbgAAn2gu4w (envelope-from ); Tue, 05 Dec 2023 13:16:10 +0000 Date: Tue, 5 Dec 2023 14:16:08 +0100 From: Petr Vorel To: Stefan Roesch Cc: kernel-team@fb.com, david@redhat.com, oliver.sang@intel.com, linux-mm@kvack.org, ltp@lists.linux.it, liwang@redhat.com Subject: Re: [PATCH v3 2/2] add ksm test for smart-scan feature Message-ID: <20231205131608.GB55404@pevik> Reply-To: Petr Vorel References: <20231204184817.3570465-1-shr@devkernel.io> <20231204184817.3570465-3-shr@devkernel.io> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20231204184817.3570465-3-shr@devkernel.io> X-Rspamd-Queue-Id: 53EBB40022 X-Rspam-User: X-Stat-Signature: tyywjf19qikdiy9bjs1ydoxs4iytj6hs X-Rspamd-Server: rspam01 X-HE-Tag: 1701782173-256705 X-HE-Meta: U2FsdGVkX1+aV4Aw5SH0gCDg2jXm2NJwPrNz4o/CepZslzZQdR4lq4KGI5FSJlO1uUHNPzhlPOjiAzlH8xH5hIEwJ/qsVhQt4Vv4dj1+mB9eO5CFwA9F9IGOxHlbUHMNU8/zmRIBQ97C8YkK+67aEiduUNuSYYp09/sOpIqOkJLM9askVR138sGzHeXCHNKuRQyjtU9MCmNsq2yGK05YQWYQZvckCnZmJxzsO500k4ySXAI4nMNHci5vHAUTnq5mFwq9IWW3H/iUNNqays2h8ii6KEpzKAZV1QPnRuichsOw2zOX3pGFXmX/sFR08ZFHgEjZt/s5qLd3rM/DeIdrihdsOZHyvdohg1nXU8VklMnJ5srDipn4iPX4HbA8TqaBsMJEbg/M3G/Uy+wAQpZySW5RGBrZqh8bQVVyCk0lr6buokDaR8ZNRSOZGr/cmoRV9uzUeGJDWwwvFeDO2cnEFJsLArYRgaRYCt3N4BRx4phHPyJHcF2qaDMy/vIdHX7w2UiYJYFCJseXZyNbP6S82AsAfsPn06ZEqxXfME6HlO+SKBA4xWpVppt3GATtJjlM7pqvgRNCgS/iQeW9Xgl/7ycW1IIrvoLdi/eDs6/7zHZs4NXULNQGdsCsaKnjRNUtb9qufEYTKUphfnvw0HTp8AuGkit+tcgqdue5zRc+RtPU5tjAM18zC//vsRo3wZgv8u89SGJ8iStFxOznb/K6HfBhzaNuFryPIzymBa4gs3tn3J9Ww37rUSyVrYnQdXkliFDSKWitCgDaqSJ2nOV3lFwznVmd848VEb68ynRniPt/VZxSSiWQ/0dSThrb8mzt3ceRbpV8L5OVv9z/f50CwvWiCIaLU+ViIO0xfVli5gOZbqI6N2/e6EoafC4NS39YzbzxO7rRO9CMcpWrtvEhFH+BdFcIvvnGN9L/P451A3UARlMF2H3MyEPVX7VP9kPDpAo0Tubm0LqMXHalzK4 w7OtxdiJ qhRrqZX2EeODutJiZNh5qmwwNJnnl7JtCX6NcyiybCuqt8H+0kqTBNjm5eLjMRxMHICOAUxHCv3sL864X5/n6hEoCb/8ve4OLXhCaG7pvZDFki55qCCTRX4JU3ULErifpmMm2HgNiltmXuFv9u9ViOYYeqZRlOK9MkJfEOjCBj3SnX57JD6c1O3aGLm7QjBb0M26ixCH0qVSDZdY= 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: Hi Stefan, > 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); Unfortunately SAFE_FILE_SCANF quits on missing file and /sys/kernel/mm/ksm/pages_skipped is not on kernel < 6.7. safe_file_vprintf() which SAFE_FILE_SCANF() internally uses does not support any flag to quit with TCONF instead TBROK when /sys/kernel/mm/ksm/pages_skipped does not exists. We could use access() in setup function, but another line in .save_restore will help: {PATH_KSM "pages_skipped", NULL, TST_SR_TCONF} > + 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; I was going to merge this (with minor cleanup), but the only remaining issue is that we allow to test run repeatedly via -iN: # ./ksm07 -i2 tst_test.c:1574: TINFO: Timeout per run is 0h 00m 30s ksm07.c:73: TINFO: KSM merging... ksm_helper.c:36: TINFO: ksm daemon takes 1s to run two full scans ksm07.c:88: TINFO: stop KSM. ksm07.c:99: TPASS: smart_scan skipped more than 50% of the pages. ksm07.c:73: TINFO: KSM merging... ksm_helper.c:36: TINFO: ksm daemon takes 1s to run two full scans ksm07.c:88: TINFO: stop KSM. ksm07.c:97: TFAIL: not enough pages have been skipped by smart_scan. I'm confused, how to reset KSM to be able to run the test more times? > + > + 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)); > +} This is not needed, done by check_child_status() in lib/tst_test.c. > + > +static void verify_ksm(void) > +{ > + create_memory(); > +} Why this wrapper? "verify_" as a pattern name is not a must. > + > +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", We have PATH_KSM definition, lets use it. > + TST_SR_SKIP_MISSING | TST_SR_TCONF}, > + {} > + }, > + .needs_kconfigs = (const char *const[]){ > + "CONFIG_KSM=y", > + NULL > + }, > + .test_all = verify_ksm, > +}; I was going to merge your patch with following changes. We just need solve -i2 issue. Kind regards, Petr diff --git testcases/kernel/mem/ksm/ksm07.c testcases/kernel/mem/ksm/ksm07.c index 16153fdb2..e5c31775b 100644 --- testcases/kernel/mem/ksm/ksm07.c +++ testcases/kernel/mem/ksm/ksm07.c @@ -5,35 +5,25 @@ /*\ * [Description] * - * Kernel Samepage Merging (KSM) + * Kernel Samepage Merging (KSM) for smart scan feature * - * 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). + * Test 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: + * Smart scan feature was added in kernel v6.7. * - * 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. + * [Prerequisites] + * + * 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" +#include "mem.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 @@ -46,7 +36,6 @@ */ static void create_memory(void) { - int status; int full_scans_begin; int full_scans_end; int pages_skipped_begin; @@ -70,10 +59,10 @@ static void create_memory(void) } memset(memory, 'a', page_size); - tst_res(TINFO, "KSM merging..."); - if (access(PATH_KSM "max_page_sharing", F_OK) == 0) { + 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"); @@ -85,7 +74,7 @@ static void create_memory(void) SAFE_FILE_SCANF(PATH_KSM "pages_skipped", "%d", &pages_skipped_begin); wait_ksmd_full_scan(); - tst_res(TINFO, "stop KSM."); + tst_res(TINFO, "stop KSM"); SAFE_FILE_PRINTF(PATH_KSM "run", "0"); SAFE_FILE_SCANF(PATH_KSM "full_scans", "%d", &full_scans_end); @@ -93,21 +82,10 @@ static void create_memory(void) 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(); + 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"); } static struct tst_test test = { @@ -117,9 +95,10 @@ static struct tst_test test = { {} }, .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", + {PATH_KSM "pages_skipped", NULL, TST_SR_TCONF}, + {PATH_KSM "run", NULL, TST_SR_TCONF}, + {PATH_KSM "sleep_millisecs", NULL, TST_SR_TCONF}, + {PATH_KSM "smart_scan", "1", TST_SR_SKIP_MISSING | TST_SR_TCONF}, {} }, @@ -127,5 +106,5 @@ static struct tst_test test = { "CONFIG_KSM=y", NULL }, - .test_all = verify_ksm, + .test_all = create_memory, };