From patchwork Fri Feb 10 21:50:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Roesch X-Patchwork-Id: 13136526 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 196DBC636D7 for ; Fri, 10 Feb 2023 22:04:03 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DFB9A280021; Fri, 10 Feb 2023 17:04:01 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id D1DD1280031; Fri, 10 Feb 2023 17:04:01 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A0E4B280021; Fri, 10 Feb 2023 17:04:01 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 8567A28002F for ; Fri, 10 Feb 2023 17:04:01 -0500 (EST) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 4B0FA1A05CA for ; Fri, 10 Feb 2023 22:04:01 +0000 (UTC) X-FDA: 80452760682.29.E081287 Received: from 66-220-144-178.mail-mxout.facebook.com (66-220-144-178.mail-mxout.facebook.com [66.220.144.178]) by imf15.hostedemail.com (Postfix) with ESMTP id 92316A0017 for ; Fri, 10 Feb 2023 22:03:59 +0000 (UTC) Authentication-Results: imf15.hostedemail.com; dkim=none; dmarc=none; spf=neutral (imf15.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=1676066639; 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=0woeEgTWPevZl2H3kVJMxHO/DdZzzJ/9L78algaS/2E=; b=soRl6lAj+hDMITgN68IwCabUuYcK1ekGtGSLrw7TaiakJidxn6doFQXHTt/Z+faGjcByeM 7jxchuMryFMkIv5EIz55JY9XLe7Ih+nNNDdhPwsTS/tCeQwPsNnICB+LEPPTkUspxuqxfz Bn8qM4kMC6C0TGBbu/kG5FmJtDuVsx4= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=none; dmarc=none; spf=neutral (imf15.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=1676066639; a=rsa-sha256; cv=none; b=JP2vJmGlxajkHx4RrLyygcDTEeew/cpQHexwj7prTexAHJFpSNYYlPCXhDOHvFAFKtF6J4 km2wm/UPWLar409j7ThuUX+UbFJyf+CkPvE+/0AHWtVMgSZX78GsIcKd9GJd3PzN9bxw/d LER8h7WuMZtr05fdGnUpu8t7ixVyRHU= Received: by dev0134.prn3.facebook.com (Postfix, from userid 425415) id AC6A26BFC2EB; Fri, 10 Feb 2023 13:50:33 -0800 (PST) From: Stefan Roesch To: kernel-team@fb.com Cc: shr@devkernel.io, linux-mm@kvack.org, riel@surriel.com, mhocko@suse.com, david@redhat.com, linux-kselftest@vger.kernel.org, linux-doc@vger.kernel.org, akpm@linux-foundation.org Subject: [RFC PATCH v2 17/19] selftests/vm: add KSM get merge type test Date: Fri, 10 Feb 2023 13:50:21 -0800 Message-Id: <20230210215023.2740545-18-shr@devkernel.io> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230210215023.2740545-1-shr@devkernel.io> References: <20230210215023.2740545-1-shr@devkernel.io> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: 92316A0017 X-Stat-Signature: hce7knj3ppsxipszx7dmw3bw8owd3by4 X-HE-Tag: 1676066639-490441 X-HE-Meta: U2FsdGVkX18DUL8/woiFARpXTblxCHpLPw87H3O6KYhFPjxSpbAKJXu94GgaQmxpxhBRbRtp7Q4PXm+/PB/2V9K4WZTyiglRDZrMFagDR6PSSYej2tRdudJbihygnRTP7l3LW6vR8rl0cmlYSJHuOODmr9/Ytflqiz/iWAoUzHMdNLwPedAjYeWf9NoX5Nba65nocjrG6J1c60lAcUC0KrjpPAyfk8TmwO3zExDvQXRxPHlupoPD6IDbp49QbZ/KJSOICf0PUUqMVioYwEvJ79mfZK73XpSXNDhBuEoDNdLPcUATzJ0sniRCYBz/QuOX70gXZHthd42A8PAczMrthL/n9b5ufXztjWAL8p6KwB91YWMty/4wfoA4VhOc7L0kn5ZSp7GuYtyNULUfaKu1tjr6jRBDT9QLqOBLP1VsGIv8KRfGcIRLuV+RBugMNLy4D3VA0SpfFNUxhuVUIzg1PM2GkM89zbgp00Qf4phWcwCCC0+h9IhWed8pXL/YXRov7YEfUEVA9YwEqDxzzZ+/8gQraNQr+gfbmirAIc4DfTlg64/rI+Vq8671m3AOxur02Yd/uWPYod4dEO3AXKIPcJA/rnjl3RmrWfzOdmSFnM0qkywSLeU/XVNpsbk3W+86p9FIaRX67mffgl+uqzH4JuYEwKFuJim2d/HN2ZPNdrcHHs8iP1FFH7qjiJhC5WPPG911f9ZQ/k2n656G20oAd8dbMEmKeSOk1knI8B2A2wyZcMpin/zMLj+ipSvmuclgkWw09ih+O3FxP/rJpclSBnPAn2oz3WQyypuzU44m/4XArUpcSeDlFkWhgRRmZqtH2gXXt1ZBn0Stl05XlmdffQlTu+8RL2q+U0Qeg91PcrSRcWVAz3/jFE43rd4YFoPQNBMp/fi7JWjZCeGBmczDyALcFjbTtWMYiiKa5QlFOV70FJw78sj/YuFmD24ctYBkyP1lphrVmNiD80dRM56 v8592gWl 34DYhTpEpYEohOxZed9M2d91yxR3bUU51KwRn4TV832oqgFk= 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: This adds the -G flag to the ksm_tests to query if prctl has been used to enable ksm merging. Signed-off-by: Stefan Roesch --- tools/testing/selftests/mm/ksm_tests.c | 37 ++++++++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-) diff --git a/tools/testing/selftests/mm/ksm_tests.c b/tools/testing/selftests/mm/ksm_tests.c index 386a0929c8a3..9667cb3b8c6a 100644 --- a/tools/testing/selftests/mm/ksm_tests.c +++ b/tools/testing/selftests/mm/ksm_tests.c @@ -45,6 +45,7 @@ enum ksm_merge_type { enum ksm_test_name { CHECK_KSM_MERGE, CHECK_KSM_UNMERGE, + CHECK_KSM_GET_MERGE_TYPE, CHECK_KSM_ZERO_PAGE_MERGE, CHECK_KSM_NUMA_MERGE, KSM_MERGE_TIME, @@ -124,7 +125,8 @@ static void print_help(void) " -D evaluate unmerging time and speed when disabling KSM.\n" " For this test, the size of duplicated memory area (in MiB)\n" " must be provided using -s option\n" - " -C evaluate the time required to break COW of merged pages.\n\n"); + " -C evaluate the time required to break COW of merged pages.\n" + " -G query merge mode\n\n"); printf(" -a: specify the access protections of pages.\n" " must be of the form [rwx].\n" @@ -323,6 +325,31 @@ static int check_ksm_merge(int merge_type, int mapping, int prot, return KSFT_FAIL; } +static int check_ksm_get_merge_type(void) +{ + if (prctl(PR_SET_MEMORY_MERGE, 1)) { + perror("prctl set"); + return 1; + } + + int is_on = prctl(PR_GET_MEMORY_MERGE, 0); + + if (prctl(PR_SET_MEMORY_MERGE, 0)) { + perror("prctl set"); + return 1; + } + + int is_off = prctl(PR_GET_MEMORY_MERGE, 0); + + if (is_on && is_off) { + printf("OK\n"); + return KSFT_PASS; + } + + printf("Not OK\n"); + return KSFT_FAIL; +} + static int check_ksm_unmerge(int merge_type, int mapping, int prot, int timeout, size_t page_size) { void *map_ptr; @@ -733,7 +760,7 @@ int main(int argc, char *argv[]) bool merge_across_nodes = KSM_MERGE_ACROSS_NODES_DEFAULT; long size_MB = 0; - while ((opt = getopt(argc, argv, "ha:p:l:z:m:s:t:MUZNPCHD")) != -1) { + while ((opt = getopt(argc, argv, "ha:p:l:z:m:s:t:GMUZNPCHD")) != -1) { switch (opt) { case 'a': prot = str_to_prot(optarg); @@ -792,6 +819,9 @@ int main(int argc, char *argv[]) case 'Z': test_name = CHECK_KSM_ZERO_PAGE_MERGE; break; + case 'G': + test_name = CHECK_KSM_GET_MERGE_TYPE; + break; case 'N': test_name = CHECK_KSM_NUMA_MERGE; break; @@ -841,6 +871,9 @@ int main(int argc, char *argv[]) ret = check_ksm_unmerge(merge_type, MAP_PRIVATE | MAP_ANONYMOUS, prot, ksm_scan_limit_sec, page_size); break; + case CHECK_KSM_GET_MERGE_TYPE: + ret = check_ksm_get_merge_type(); + break; case CHECK_KSM_ZERO_PAGE_MERGE: ret = check_ksm_zero_page_merge(merge_type, MAP_PRIVATE | MAP_ANONYMOUS, prot, page_count, ksm_scan_limit_sec, use_zero_pages,