From patchwork Mon Jan 23 17:37:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Roesch X-Patchwork-Id: 13112652 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 C4F89C05027 for ; Mon, 23 Jan 2023 17:38:47 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D10DB6B0096; Mon, 23 Jan 2023 12:38:42 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id C721F6B0098; Mon, 23 Jan 2023 12:38:42 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A9F946B0099; Mon, 23 Jan 2023 12:38:42 -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 88A796B0098 for ; Mon, 23 Jan 2023 12:38:42 -0500 (EST) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 3F19BC2B04 for ; Mon, 23 Jan 2023 17:38:42 +0000 (UTC) X-FDA: 80386773684.08.C3B9A3F Received: from 66-220-144-178.mail-mxout.facebook.com (66-220-144-178.mail-mxout.facebook.com [66.220.144.178]) by imf20.hostedemail.com (Postfix) with ESMTP id 85C091C001C for ; Mon, 23 Jan 2023 17:38:40 +0000 (UTC) Authentication-Results: imf20.hostedemail.com; dkim=none; spf=neutral (imf20.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=1674495520; a=rsa-sha256; cv=none; b=3iu43tXdWgQ3hdjEoSaQlcRlTzW32a6kXnMa2Ta1NaV+s7BYZ5Qfa/Jp8UKMENknQdz+Gl YQNTOqQddmuUjmg9reYVCspiN0c+1ehXE7ZI8QVRktYS98bFIbZE+Rd3hEKTdSCEYXEnI9 Spk+6RnEGKbS44ZHPoUfdfAb6iEQiFE= ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=none; spf=neutral (imf20.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=1674495520; 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=taEcnC/WZm0w3gtaQ6mI5xKRplneQ9QYqvw5OXfWRYE=; b=Vd2DyfPWMiyXZ1ACMhDlOkSsWxdcgzLkysUYkBPoIT1ck2vAub+198ImhtPL7MdUAk44xM fanzQXs0GdYPVTt/Mrrq6fynNE7IOVCQFLLqYleJboeXDVSXHrl8eMZ6kYghoeAj3If+32 dN1Rkx4D+s0Ra/HY25u0wTCGVO+cAmU= Received: by dev0134.prn3.facebook.com (Postfix, from userid 425415) id 910905616BFB; 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 20/20] selftests/vm: add two functions for debugging merge outcome Date: Mon, 23 Jan 2023 09:37:48 -0800 Message-Id: <20230123173748.1734238-21-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-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Ft/MPTBoj/XO+LKhlv5twp pI9+lfYS DCOx3X95QfQwSZBDqfHuqNPJReu8RZHuXz56jI31ZuB3onm0= 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 two functions to report the metrics in /proc/self/ksm_stat and /sys/kernel/debug/mm/ksm. The debugging can be enabled with the following command line: make -C tools/testing/selftests TARGETS="vm" --keep-going \ EXTRA_CFLAGS=-DDEBUG=1 Signed-off-by: Stefan Roesch --- tools/testing/selftests/vm/ksm_tests.c | 54 ++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/tools/testing/selftests/vm/ksm_tests.c b/tools/testing/selftests/vm/ksm_tests.c index a0a48ac43b29..9fb21b982dc9 100644 --- a/tools/testing/selftests/vm/ksm_tests.c +++ b/tools/testing/selftests/vm/ksm_tests.c @@ -93,6 +93,55 @@ static int ksm_read_sysfs(const char *file_path, unsigned long *val) return 0; } +#ifdef DEBUG +static void ksm_print_sysfs(void) +{ + unsigned long max_page_sharing, pages_sharing, pages_shared; + unsigned long full_scans, pages_unshared, pages_volatile; + unsigned long stable_node_chains, stable_node_dups; + long general_profit; + + if (ksm_read_sysfs(KSM_FP("pages_shared"), &pages_shared) || + ksm_read_sysfs(KSM_FP("pages_sharing"), &pages_sharing) || + ksm_read_sysfs(KSM_FP("max_page_sharing"), &max_page_sharing) || + ksm_read_sysfs(KSM_FP("full_scans"), &full_scans) || + ksm_read_sysfs(KSM_FP("pages_unshared"), &pages_unshared) || + ksm_read_sysfs(KSM_FP("pages_volatile"), &pages_volatile) || + ksm_read_sysfs(KSM_FP("stable_node_chains"), &stable_node_chains) || + ksm_read_sysfs(KSM_FP("stable_node_dups"), &stable_node_dups) || + ksm_read_sysfs(KSM_FP("general_profit"), (unsigned long *)&general_profit)) + return; + + printf("pages_shared : %lu\n", pages_shared); + printf("pages_sharing : %lu\n", pages_sharing); + printf("max_page_sharing : %lu\n", max_page_sharing); + printf("full_scans : %lu\n", full_scans); + printf("pages_unshared : %lu\n", pages_unshared); + printf("pages_volatile : %lu\n", pages_volatile); + printf("stable_node_chains: %lu\n", stable_node_chains); + printf("stable_node_dups : %lu\n", stable_node_dups); + printf("general_profit : %ld\n", general_profit); +} + +static void ksm_print_procfs(void) +{ + const char *file_name = "/proc/self/ksm_stat"; + char buffer[512]; + FILE *f = fopen(file_name, "r"); + + if (!f) { + fprintf(stderr, "f %s\n", file_name); + perror("fopen"); + return; + } + + while (fgets(buffer, sizeof(buffer), f)) + printf("%s", buffer); + + fclose(f); +} +#endif + static int str_to_prot(char *prot_str) { int prot = 0; @@ -237,6 +286,11 @@ static bool assert_ksm_pages_count(long dupl_page_count) ksm_read_sysfs(KSM_FP("max_page_sharing"), &max_page_sharing)) return false; +#ifdef DEBUG + ksm_print_sysfs(); + ksm_print_procfs(); +#endif + /* * Since there must be at least 2 pages for merging and 1 page can be * shared with the limited number of pages (max_page_sharing), sometimes