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 ECB7CC4167B for ; Tue, 5 Dec 2023 11:02:12 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 21F886B007B; Tue, 5 Dec 2023 06:02:12 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 1D0726B007E; Tue, 5 Dec 2023 06:02:12 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0978F6B0080; Tue, 5 Dec 2023 06:02:12 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id F10E26B007B for ; Tue, 5 Dec 2023 06:02:11 -0500 (EST) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id B97E816032D for ; Tue, 5 Dec 2023 11:02:11 +0000 (UTC) X-FDA: 81532475262.25.1E9CF2C Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) by imf28.hostedemail.com (Postfix) with ESMTP id 58871C0020 for ; Tue, 5 Dec 2023 11:02:08 +0000 (UTC) Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=ZHRNvYRV; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=YDjKYyUZ; dmarc=none; spf=pass (imf28.hostedemail.com: domain of chrubis@suse.cz designates 195.135.223.130 as permitted sender) smtp.mailfrom=chrubis@suse.cz ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1701774128; 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-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=gyYO7o6BbiObRjMvlwvXOl8N5YoIoYx7sY6bMOUePcs=; b=xdy0oNsoXLbjDVz2BaMLwOxX4XhgJPnDQn7Zlk1biyt3j66aLs8x8yLqUDOL8vxQr9bpVD 64ckxTJbCC7SVYUyiCZ+DtxMOM58UiG07Bpvt9T18eap1w7e2DTvOfoshrJWXubaG180Cd XBxqxBV4bOOVpOCHD25H1doafls/YEs= ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=ZHRNvYRV; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=YDjKYyUZ; dmarc=none; spf=pass (imf28.hostedemail.com: domain of chrubis@suse.cz designates 195.135.223.130 as permitted sender) smtp.mailfrom=chrubis@suse.cz ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1701774128; a=rsa-sha256; cv=none; b=KET/zJjce8L+K8tVZmGDWLC11o2O10ZkeKlMWK06CQlJXB3Ku4l3B/lt8OLnH5dhWrB3R6 Tz1zG21X+lP2ncw41WCRhvHlOHfuSpJMKlQND9SZpt5W5EzslbZ2nUeAhRG3oyoDEEuyKU 2bESdMwGom9jOrxhIHOzrlUV8dC8o0g= Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [10.150.64.97]) (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-out1.suse.de (Postfix) with ESMTPS id B1EB421EE8; Tue, 5 Dec 2023 11:02:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1701774125; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=gyYO7o6BbiObRjMvlwvXOl8N5YoIoYx7sY6bMOUePcs=; b=ZHRNvYRVaootn/+AnP/Y7e2BAS8evpq0PC4H0VVm7EtBw5n+Zec4/katsdP7Rx0JhpulWe 80WR8FIjX0064cUJqfvJw8Ekv/Mn+CDhKm9aZzTM0sPAjifiv2m5A1mZOCJMeZpC7cRw1h LtA0T8j3/sfquy0vcKzR5QSE1rlZCeQ= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1701774125; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=gyYO7o6BbiObRjMvlwvXOl8N5YoIoYx7sY6bMOUePcs=; b=YDjKYyUZPm6FBTsT4Y63qmocrzwC42zpZ+jMLYHUVmKW3Qk6Ln1K0s7rY81TYq7JhFMWIf yTWgMUg0ZVCEujDw== Received: from imap1.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 imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id A30D2136CF; Tue, 5 Dec 2023 11:02:05 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id 90rIJi0Db2XTeQAAD6G6ig (envelope-from ); Tue, 05 Dec 2023 11:02:05 +0000 Date: Tue, 5 Dec 2023 12:02:46 +0100 From: Cyril Hrubis To: Stefan Roesch Cc: kernel-team@fb.com, linux-mm@kvack.org, david@redhat.com, oliver.sang@intel.com, ltp@lists.linux.it Subject: Re: [LTP] [PATCH v3 2/2] add ksm test for smart-scan feature Message-ID: 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: 58871C0020 X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: tgbhutir1mchuom6z7k7ddks55o4x7ia X-HE-Tag: 1701774128-774171 X-HE-Meta: U2FsdGVkX1+pUxgk2YaMNF53lyOBqNyk97aZFmJMbeAYQAvK64gdtYB6waYFafJH811N6ifr/9QLRVpvDHu15nh1G9oyZIchKTyrGU1wZ+kMIKgUPOsPAVuXL9HzAm/i6akK1Vs8v5GlfOXvyKt8S3puZbcVGAxbHdp3wIf834SurQtICHfUjQXqnU0oXR85K9LT+4cY60Gw5/kvof5UM7m0OWsHYD2p0kOuZGwsXST3M5Dj/UDlmbaGCxsNgTd0Qt/MGdUT2JkOkdODKOzoTwSal1pcGgGecoBW+GBJN1zdqEVvsgneaQ+5Gx3Sfvyyz0RTYdmEzjJdrIF4eEABSKu38HMYGMreHJaH6uTZc5xDX5l+4C75s+J+Sj8VXfS1Q43Aaz1fujzB4OjdppiFETCF0olOLpd3Y/VwAlRIb0qJaGJWxVHFDbuIitaSmdMlhRTR+UTGLkDYwIvkFsrHtS4BYfDpnnXIHqxI1xSbqtq6Z+cx48ARdNwIq1K77erUQEwpzRw1kiDD7SP+IyTnm5JnNP2ujhDx09UGRr54FKklQr4pLvaYB7GpLN7Hr/f7TLfu70i+QZy9UHY6kZdXzxNakJBezDdNWsfM/F/l/thB6hWi2vPSGQcIG99wWjLj70m6qALqfgCUlCrO+M+cvEcT6uDMo6rrA/WUOIA/Bz7UcEVTLvHmedPemeBCuxRURhmGtT7np2Rzt4UAZOJGmvhmSXhcNkxscvqCb/0i390I4YlwwuktRNpKgLHN1rhkxMe27qY5UmUFt6D5foatx6bd3lrh4f5+MdmvLWr0CqYUk71R3d/GB8YP5g5DjmlWR8xZTGsKeqh3I0/UpoBjCGkOGIll5+ETk+VvGge0tzhycE33DUOzjIxAKzCJdSHtTzutA9MgxDvvJNdJSOPTrVxKHKzpXJz5eWa3weiLCoZh43cx4BpIb3KLGIV4Saqe0nOv2S2SfK4m6TMeqUe mBFId3t0 QX50fYJfy1QAgbBsmUQeJ6AAajva4X4oq/eybEUsa+sGbwaOYps3DKRJFJid/OnCSVLsUiRTgwmCfSwW0FAYEqCsntBae5d5kfobKxeuv16kvDRC+oL5Lz589Uhf1E6GWjXPHdEIpw1W3/VRzbFy2RXJoQm9bO4M7RP+CBxY2RKIZI2tIB27Sl7kFmJGCXZ79e8Epw8wWflNvaE/vDcTEgKIJxcC755VlT408l4AvcjZoZPZJ/3L6oVHCgtHYCgN6X2Ad4jk1RZJUQL7P/feJGRKG5w== 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! > 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. ^ 2023? > + */ > +/*\ > + * [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. I guess that it would be more user friendly to check if a process with such name is running and at least print a warning, or even skip the test. I suppose that we can add a library function that would loop over /proc/*/comm and return true if we find a match. > + */ > +#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)); Does the test fork a child? I do not see any place in the code that would do so, did I miss something? > +} > + > +static void verify_ksm(void) > +{ > + create_memory(); This is useless indirection. > +} > + > +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, > +}; > -- > 2.39.3 > > > -- > Mailing list info: https://lists.linux.it/listinfo/ltp -- Cyril Hrubis chrubis@suse.cz