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 7FEACC77B61 for ; Thu, 13 Apr 2023 18:12:16 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id EA47D6B0072; Thu, 13 Apr 2023 14:12:15 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E5475900003; Thu, 13 Apr 2023 14:12:15 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CF5D5900002; Thu, 13 Apr 2023 14:12:15 -0400 (EDT) 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 C13616B0072 for ; Thu, 13 Apr 2023 14:12:15 -0400 (EDT) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 8B563403A4 for ; Thu, 13 Apr 2023 18:12:15 +0000 (UTC) X-FDA: 80677162230.04.4BD5401 Received: from out1-smtp.messagingengine.com (out1-smtp.messagingengine.com [66.111.4.25]) by imf03.hostedemail.com (Postfix) with ESMTP id CF98E20022 for ; Thu, 13 Apr 2023 18:12:11 +0000 (UTC) Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=devkernel.io header.s=fm1 header.b=QN5jiFmv; dkim=pass header.d=messagingengine.com header.s=fm3 header.b=S1Mbnl08; dmarc=none; spf=pass (imf03.hostedemail.com: domain of shr@devkernel.io designates 66.111.4.25 as permitted sender) smtp.mailfrom=shr@devkernel.io ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1681409532; 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=mHjMi001rdT9zkcgx9WuZ3TwwqhhBwYAfjHqVbYONwQ=; b=zOR4JMxd+sDiQ+PnGc17pYB321AnLfB9kR4xwcSw9CAqrL+C5EvzjVAo7zBE0Bn0BfgKtc Z4VVnLjs7wvHhlTufjI7LUSgnFCqXL/VuRbQbRMyMrqgQ8wY5rkojoYCoQE4J/KO4tpyxm NVAgRZ0FakWXhT1Z6v56id7raTMR6Q0= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=pass header.d=devkernel.io header.s=fm1 header.b=QN5jiFmv; dkim=pass header.d=messagingengine.com header.s=fm3 header.b=S1Mbnl08; dmarc=none; spf=pass (imf03.hostedemail.com: domain of shr@devkernel.io designates 66.111.4.25 as permitted sender) smtp.mailfrom=shr@devkernel.io ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1681409532; a=rsa-sha256; cv=none; b=uoqJj69Is1xUOQp1BbfMA69XwbYfOS/EybbKMYeaQ6eotyDhujH0s78FYMLZ3tG/yPaw5n CuaWlUJIMp0aV42wo3Se9ZIp9DLW7Wxi7mzjIObAp6CeyioiasHHLOlbIEJSolSb2cel5u eGm7TC7rmNRH87MWO5ecNphtUGvsAFI= Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id 1E1925C0097; Thu, 13 Apr 2023 14:12:11 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute4.internal (MEProxy); Thu, 13 Apr 2023 14:12:11 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=devkernel.io; h= cc:cc:content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:sender :subject:subject:to:to; s=fm1; t=1681409531; x=1681495931; bh=mH jMi001rdT9zkcgx9WuZ3TwwqhhBwYAfjHqVbYONwQ=; b=QN5jiFmvfK7Id5NhKO jcNG9TUYOXOqXoi5X8FrWnn4dWwNj5HRky84YgoVTpaa6weqPWIvCql6vFTfaNnv h1zPgvcJ2Shl+YCXIaTSOW3eAeRaH9wOXenEJeTLxph6PEKqD4xdh9CsnutXyaTR LOtbr8OHrV2oblucIpB/066THbuz0ynzNdaiT2OIvMkxJJ0TlH2MJqShfHXkOcfE Yj5JnB7gZ35Is/dzuQ7MRHJChgF/lcZw1dVC51KuxnscyLpOo7RKd7cjWS++CHXo twoFk7jFDspUQSIvLLfwp68ausIiVbjKLNkG1ywERuX8mbeuBhBKRFUVC8A/XpHR pwmg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:sender:subject :subject:to:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm3; t=1681409531; x=1681495931; bh=mHjMi001rdT9z kcgx9WuZ3TwwqhhBwYAfjHqVbYONwQ=; b=S1Mbnl08csEVGdnUDRUd15g0xhaaG au5MKaG0bB8lvLB5PSbstocS6Je4Z3oOP6NpIlpSPjcTwIpw2CJacg+WFEU43Unz h84vxHo1A+BsOaUucEaYd5Ap95zJR6/6gCI7LIyNKKRp2ndUixFNSlHVwqAtr3RK FsaZXBqB3+ca0tT4fzAYqwVDjlcwcYh6ornnMiL20oP4oRESkdUs8jQCiuT8O2tL gPMJNUvSyk6A24CxJ2gdF3oBzQxlX2l9LBOcArk9p8aNiF/foNNy/Bwa4bjjU8xQ FOL5/EASye0Vv69w9WxHg8OQWzCaukiZb3nLIVqjUFspIeCIriU2U4Qkw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedrvdekkedguddvfecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enucfjughrpehffgfhvfevufffjgfkgggtsehttdertddtredtnecuhfhrohhmpefuthgv fhgrnhcutfhovghstghhuceoshhhrhesuggvvhhkvghrnhgvlhdrihhoqeenucggtffrrg htthgvrhhnpeevlefggffhheduiedtheejveehtdfhtedvhfeludetvdegieekgeeggfdu geeutdenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpe hshhhrseguvghvkhgvrhhnvghlrdhioh X-ME-Proxy: Feedback-ID: i84614614:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 13 Apr 2023 14:12:08 -0400 (EDT) References: <20230412031648.2206875-1-shr@devkernel.io> <20230412031648.2206875-4-shr@devkernel.io> <7c5606cc-ca58-c505-b0d3-2eec29fe606a@redhat.com> User-agent: mu4e 1.10.1; emacs 28.2.50 From: Stefan Roesch To: David Hildenbrand Cc: kernel-team@fb.com, linux-mm@kvack.org, riel@surriel.com, mhocko@suse.com, linux-kselftest@vger.kernel.org, linux-doc@vger.kernel.org, akpm@linux-foundation.org, hannes@cmpxchg.org, willy@infradead.org, Bagas Sanjaya Subject: Re: [PATCH v6 3/3] selftests/mm: add new selftests for KSM Date: Thu, 13 Apr 2023 11:09:46 -0700 In-reply-to: <7c5606cc-ca58-c505-b0d3-2eec29fe606a@redhat.com> Message-ID: MIME-Version: 1.0 Content-Type: text/plain X-Rspam-User: X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: CF98E20022 X-Stat-Signature: n4a3xzhqh4frhzrssom6e1u13gta86oi X-HE-Tag: 1681409531-931066 X-HE-Meta: U2FsdGVkX1+1IHDOSy3x1gAgaKt4gssvPmZvgePQdIALu7kVzh21A4JctSkAhtwS1JS7RNQRbhP+r/qzfWDZHIMTcEG+lqgrrhGci0DWgO61tTvcVUlDW9yuVQ+z+ZNXaIKr+J9Nwds2uyRCw7pfIASzbJgdXsEHZzjALNRU+Z0kng1NzAJXAw7MgrZn9Y0W61WQwFknpeYKxDno7OZCFeWmRBFwnrlBVnNoL4pr3YwRrWV6n+X8hRD6r48RSMIbtAg7nttqeTNXhQZAwFm0qZ+eIigAMFv1hnIIO88DF1y3f0uKyneIbU7l+l7PFRzCKFF4iej+zJr+fPrWJGUEIRhjNpjJV13Ho4xD+Mi19RgoiH058+J4oWp9TTvX00ploTih1oz72DIXmyvqFzcakFxhRpyZ8mpTFd2vjwQjkrXVnFNUD9F3L2AqCJBbnGTHCA45rSb+XZc407SUys/Pt8rzGSwoeCgAvFZGR0biyA7komePzPmj65ilzEWhYzSE7RE4n37uRZdEO9gJe6BWebgQLhT1vB3V5L49l4K1Zjktge8nmt3HLeLvYWWe/RQ6cy9+34B9suK9x0gMQrBDQI6FN5BYYZmHjZJHTSX11KWItR/4yL8IDKFNqn3aEUAgr2yLCb/9kL99NC8At+WV3rRXLcmS25TQ/C9T1asbOiBE+tdYRBSOvN8Rw51//qB8CJvYfYhhPyciXeO6ewDD/Uc38cuYg4Im9bSdW7l9l/wUUJqRN3jbPwleiyuvwd0C3u8HlxqjkDSzip5kLDUZyVLbwGcMEW60LaxjmuYoPCrEMhZu0kzg9zLkOEVmKyTmmlNjNtF5LCpVXi9dFZ74HfZU8afu0tlS++sHy24F/ja8YslfRWCm/ELvril2HF9Ds5YvdJtbENSiPgOkTPfNxbO3g0TznM/XWhFnqPbKCvM+4gLSecTatGJ1H2vw0yYhNKPOk311EsxDIk7hG5c rAWg6DdC 1S6J+xRqN0IKbE7b/LcX0bPVphgHi6siHgouemmjs8NlJTPMTh8HzEFGM8+VI16d0hVqocELHCAXvRParfw8At04NjMTvq2EW2UtNZiSDzFKdbApOyfZOmyzjskIR0HU0DsWs/7Dv4eAwjuA6Gbq8cwCSezVu4nl9obLw 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: David Hildenbrand writes: > On 12.04.23 05:16, Stefan Roesch wrote: >> This adds three new tests to the selftests for KSM. These tests use the >> new prctl API's to enable and disable KSM. >> 1) add new prctl flags to prctl header file in tools dir >> This adds the new prctl flags to the include file prct.h in the >> tools directory. This makes sure they are available for testing. >> 2) add KSM prctl merge test >> This adds the -t option to the ksm_tests program. The -t flag >> allows to specify if it should use madvise or prctl ksm merging. >> 3) add KSM get merge type test >> This adds the -G flag to the ksm_tests program to query the KSM >> status with prctl after KSM has been enabled with prctl. >> 4) add KSM fork test >> Add fork test to verify that the MMF_VM_MERGE_ANY flag is inherited >> by the child process. >> 5) add two functions for debugging merge outcome >> 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="mm" --keep-going \ >> EXTRA_CFLAGS=-DDEBUG=1 > > Would it make sense to instead have a "-D" (if still unused) runtime options to > print this data? Dead code that's not compiled is a bit unfortunate as it can > easily bit-rot. > > In the next version I'll add -d option. I'll add a global debug variable for this. Otherwise we would need to pass down the debug option several levels. > > This patch essentially does two things > > 1) Add the option to run all tests/benchmarks with the PRCTL instead of MADVISE > > 2) Add some functional KSM tests for the new PRCTL (fork, enabling works, > disabling works). > > The latter should rather go into ksm_functional_tests(). > > [...] > >> -static int check_ksm_unmerge(int mapping, int prot, int timeout, size_t >> page_size) >> +/* Verify that prctl ksm flag is inherited. */ >> +static int check_ksm_fork(void) >> +{ >> + int rc = KSFT_FAIL; >> + pid_t child_pid; >> + >> + if (prctl(PR_SET_MEMORY_MERGE, 1)) { >> + perror("prctl"); >> + return KSFT_FAIL; >> + } >> + >> + child_pid = fork(); >> + if (child_pid == 0) { >> + int is_on = prctl(PR_GET_MEMORY_MERGE, 0); >> + >> + if (!is_on) >> + exit(KSFT_FAIL); >> + >> + exit(KSFT_PASS); >> + } >> + >> + if (child_pid < 0) >> + goto out; >> + >> + if (waitpid(child_pid, &rc, 0) < 0) >> + rc = KSFT_FAIL; >> + >> + if (prctl(PR_SET_MEMORY_MERGE, 0)) { >> + perror("prctl"); >> + rc = KSFT_FAIL; >> + } >> + >> +out: >> + if (rc == KSFT_PASS) >> + printf("OK\n"); >> + else >> + printf("Not OK\n"); >> + >> + return rc; >> +} >> + >> +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; >> +} > > Yes, these two are better located in ksm_functional_tests() to just run them > both automatically when the test is executed. I moved the check_ksm_get_merge_type() and check_ksm_fork() to the ksm_functional_test executable. The change will be in the next version.