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 9E87FC25B50 for ; Mon, 23 Jan 2023 17:38:12 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0DAFF6B0078; Mon, 23 Jan 2023 12:38:12 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 08B876B007B; Mon, 23 Jan 2023 12:38:12 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E96C16B007D; Mon, 23 Jan 2023 12:38:11 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id DAB5E6B0078 for ; Mon, 23 Jan 2023 12:38:11 -0500 (EST) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 936CD1A17FF for ; Mon, 23 Jan 2023 17:38:11 +0000 (UTC) X-FDA: 80386772382.03.DAC39D9 Received: from 66-220-144-178.mail-mxout.facebook.com (66-220-144-178.mail-mxout.facebook.com [66.220.144.178]) by imf02.hostedemail.com (Postfix) with ESMTP id D74778001E for ; Mon, 23 Jan 2023 17:38:09 +0000 (UTC) Authentication-Results: imf02.hostedemail.com; dkim=none; dmarc=none; spf=neutral (imf02.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=1674495490; 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:references; bh=7YglR1CZKXAvC4T+wdwQslngclaaFB6aU7ngklOpDRU=; b=vzSy6VhhRFNCtYi1EmDX+D/aizy9agr/gft9ckJE6sRUP3RFaKuhYGjZBXKOpro8PebjHB n2GDvVj117rINF/KGaP4ybKuzO6Mfoy+eBjMm1ADPYYY4wrUc8BD4C4qv3g9irLifB1HSl +8oI+7KtqGORFApCqkEyQx1NLyTyZ8E= ARC-Authentication-Results: i=1; imf02.hostedemail.com; dkim=none; dmarc=none; spf=neutral (imf02.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=1674495490; a=rsa-sha256; cv=none; b=UHoYr3FuxZ35c4uLtJ/XEjVUVQPM5aPX8iIJiM1fYvA86PWufzM/O8KQeuOgE4oxlCrhJL DngYTHhJ5wLTERrD1SWYSbswu91fS/ffCwPquPmaiLiRY3IyEqCa1Y8z5c14Jp6yBbwCUt fvY1WKusooBx+v3Lg+WBid/3Bz2BngQ= Received: by dev0134.prn3.facebook.com (Postfix, from userid 425415) id 3F89A5616BD1; 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 00/20] mm: process/cgroup ksm support Date: Mon, 23 Jan 2023 09:37:28 -0800 Message-Id: <20230123173748.1734238-1-shr@devkernel.io> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Rspamd-Queue-Id: D74778001E X-Stat-Signature: r1f5nizzn7iz64jxwcz7suyr1gg1ohiu X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1674495489-605162 X-HE-Meta: U2FsdGVkX1893PKjZjSQ8KlXog+ZXn5g/fdAQkUlpXVKMPjX1buTWYgotJfYZbKE+jcMJlvepAlhxMtKzTPwxp6Zw8tXzisR9q4NpLsFdTbRlnUoB3a3ncFnWr7aDea0DG03Iloqo7EUfoHQ9yte8S1ue4r4pDxlxTB1wtyjAKDL0GEIcf2e9OpqyyU4sIKA3yDeeGEwU5PvF7t2WCuUzKljD0R2QMPXRp1Ow0OAyZhmzdpK3iJlfTI5ZMz9JTVGIuDfkKwu4lSEQfmrX463BUXYWx6tWnSCx1SmRAqKZEhNUN3uQG2EHWDbNnTn43uRwN0F8sZEEUR7amZRGrjpEPX2MKAebLTOO0pF/opL7/VD+4mHmKcKW3NdzTxwKgFb2UGim93b4YNqn40rlBco0gI+w7F7wnO3+ticRozY5HLTHrrLuiIPsCbnBmM1wcQEa6fX4G19AeiS82S2ntQdxbXwTPYxHYT8VdqdEz7j1kzSfqizbY1k+GlyEsa3mJA7tkvGUMcqKra/TPxHWpRtON9nNuf/Fyp0+WS63vw9OkMCQeKW6sRmMhRKT107SZSJY5HJj3WPHK2pfkj+EHTDtdcqzd5lZd/AAIs2uRhc089kFXpGpVG+A6ZHzpUt4GSmatCYchTtHpBR9wexmTF2SBp49CTSn7fZM+mHk4XTn1FQuBLG445/hZb1RtuL3NXFU6t8UFXdR5D5UHdoK3uIidr2ZCw8NuZFlPUJcLhp95KaI4Fi7/57Sm34PdlQl32p2HEO29VMHsg59i20toi5NvQPyq9kFtifsHFQNJms/i7BwNQgX24Oxkmedqepw/pvVQ2qCT//BA63h30ZIIlx/daVbFhosYFhrLTFgTCmEAOASQF5UtRz6nbIwvQnbSeutEWnRwFmA4QURbRTVZVB47kHCtJfHoYbVaX1wowo8Q3FkEsZ/eW9/f/I85XivgJtMYDYxh2vIqGib9c84Do gjB8HPHS Po/Ad9nRin32+uJxxLxy1AnafdZpEgxjYak8eowagIOqqLf4= 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: So far KSM can only be enabled by calling madvise for memory regions. Wha= t is required to enable KSM for more workloads is to enable / disable it at th= e process / cgroup level. 1. New options for prctl system command This patch series adds two new options to the prctl system call. The firs= t one allows to enable KSM at the process level and the second one to query= the setting. The setting will be inherited by child processes. With the above setting, KSM can be enabled for the seed process of a cgro= up and all processes in the cgroup will inherit the setting. 2. Changes to KSM processing When KSM is enabled at the process level, the KSM code will iterate over = all the VMA's and enable KSM for the eligible VMA's. When forking a process that has KSM enabled, the setting will be inherite= d by the new child process. In addition when KSM is disabled for a process, KSM will be disabled for = the VMA's where KSM has been enabled. 3. Add tracepoints to KSM Currently KSM has no tracepoints. This adds tracepoints to the key KSM fu= nctions to make it easier to debug KSM. 4. Add general_profit metric The general_profit metric of KSM is specified in the documentation, but n= ot calculated. This adds the general profit metric to /sys/kernel/debug/mm/k= sm. 5. Add more metrics to ksm_stat This adds the process profit and ksm type metric to /proc//ksm_stat. 6. Add more tests to ksm_tests This adds an option to specify the merge type to the ksm_tests. This allo= ws to test madvise and prctl KSM. It also adds a new option to query if prctl K= SM has been enabled. It adds a fork test to verify that the KSM process setting = is inherited by client processes. Stefan Roesch (20): mm: add new flag to enable ksm per process mm: add flag to __ksm_enter mm: add flag to __ksm_exit call mm: invoke madvise for all vmas in scan_get_next_rmap_item mm: support disabling of ksm for a process mm: add new prctl option to get and set ksm for a process mm: add tracepoints to ksm mm: split off pages_volatile function mm: expose general_profit metric docs: document general_profit sysfs knob mm: calculate ksm process profit metric mm: add ksm_merge_type() function mm: expose ksm process profit metric in ksm_stat mm: expose ksm merge type in ksm_stat docs: document new procfs ksm knobs tools: add new prctl flags to prctl in tools dir selftests/vm: add KSM prctl merge test selftests/vm: add KSM get merge type test selftests/vm: add KSM fork test selftests/vm: add two functions for debugging merge outcome Documentation/ABI/testing/sysfs-kernel-mm-ksm | 8 + Documentation/admin-guide/mm/ksm.rst | 8 +- MAINTAINERS | 1 + fs/proc/base.c | 5 + include/linux/ksm.h | 19 +- include/linux/sched/coredump.h | 1 + include/trace/events/ksm.h | 257 ++++++++++++++++++ include/uapi/linux/prctl.h | 2 + kernel/sys.c | 29 ++ mm/ksm.c | 134 ++++++++- tools/include/uapi/linux/prctl.h | 2 + tools/testing/selftests/vm/Makefile | 3 +- tools/testing/selftests/vm/ksm_tests.c | 254 ++++++++++++++--- 13 files changed, 665 insertions(+), 58 deletions(-) create mode 100644 include/trace/events/ksm.h base-commit: c1649ec55708ae42091a2f1bca1ab49ecd722d55 --=20 2.30.2