From patchwork Mon Jan 23 17:37:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Roesch X-Patchwork-Id: 13112650 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 7BE2EC54EAA for ; Mon, 23 Jan 2023 17:38:44 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DFB946B0093; Mon, 23 Jan 2023 12:38:41 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id D5CC06B0095; Mon, 23 Jan 2023 12:38:41 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A9C9A6B0098; Mon, 23 Jan 2023 12:38:41 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 7B4676B0093 for ; Mon, 23 Jan 2023 12:38:41 -0500 (EST) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 5AE1C162226 for ; Mon, 23 Jan 2023 17:38:41 +0000 (UTC) X-FDA: 80386773642.17.9B1336B Received: from 66-220-144-178.mail-mxout.facebook.com (66-220-144-178.mail-mxout.facebook.com [66.220.144.178]) by imf29.hostedemail.com (Postfix) with ESMTP id 860C312000F for ; Mon, 23 Jan 2023 17:38:39 +0000 (UTC) Authentication-Results: imf29.hostedemail.com; dkim=none; dmarc=none; spf=neutral (imf29.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=1674495519; 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=qo39C54PDBSxRE2rOgUDTJu01fh/PEDP/brvH8YsOkc=; b=7emCvSyUEeG0ger1C0rOSSrBMYdrOB8sPwwgH4h2nYxE4gf3KYNCOvIEXnAIt73fLwV78y 6VWEeP/2/IuIwzx1XItQ7r7Xg0qbpWDeKB6W81P6az1+6ZHLz1+FIMefx0pWubOtwYIAWa lPdcIAK/p2kjV7sxXCHFDeihgXyBVpQ= ARC-Authentication-Results: i=1; imf29.hostedemail.com; dkim=none; dmarc=none; spf=neutral (imf29.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=1674495519; a=rsa-sha256; cv=none; b=E2qbU0tXhii9Tw4p58dbxhs8+2mzoBq3w/bQzJ9sJlgzHF3DYUR/jInssHR6h+btnDFWlt txmrpdKOHV5LCkMAaYpCRqUI6R31f+SyIJXXbDQoUwzWYCwac8F5qprFo8/jQ/U9VZrZoN DcaKTQohB3eBnkWzHSVdRFOCTuY+4Xo= Received: by dev0134.prn3.facebook.com (Postfix, from userid 425415) id 8864D5616BF7; Mon, 23 Jan 2023 09:37:56 -0800 (PST) From: Stefan Roesch To: linux-mm@kvack.org Cc: shr@devkernel.io, linux-doc@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-trace-kernel@vger.kernel.org Subject: [RESEND RFC PATCH v1 18/20] selftests/vm: add KSM get merge type test Date: Mon, 23 Jan 2023 09:37:46 -0800 Message-Id: <20230123173748.1734238-19-shr@devkernel.io> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230123173748.1734238-1-shr@devkernel.io> References: <20230123173748.1734238-1-shr@devkernel.io> MIME-Version: 1.0 X-Rspam-User: X-Rspam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FIXQT5l H5ffPeVuBnvo9hRxri5JPEaSlhnt4qk3KzkgrPfJRJ1nUDMQ= 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/vm/ksm_tests.c | 37 ++++++++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-) diff --git a/tools/testing/selftests/vm/ksm_tests.c b/tools/testing/selftests/vm/ksm_tests.c index 386a0929c8a3..9667cb3b8c6a 100644 --- a/tools/testing/selftests/vm/ksm_tests.c +++ b/tools/testing/selftests/vm/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,