From patchwork Fri Feb 10 21:50:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Roesch X-Patchwork-Id: 13136493 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 0FF41C636D4 for ; Fri, 10 Feb 2023 21:50:47 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5F7316B01AA; Fri, 10 Feb 2023 16:50:47 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 5A7AA6B01AE; Fri, 10 Feb 2023 16:50:47 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 46FDE6B01B1; Fri, 10 Feb 2023 16:50:47 -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 377AC6B01AA for ; Fri, 10 Feb 2023 16:50:47 -0500 (EST) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 120921C6203 for ; Fri, 10 Feb 2023 21:50:47 +0000 (UTC) X-FDA: 80452727334.28.11DA8B0 Received: from 66-220-144-178.mail-mxout.facebook.com (66-220-144-178.mail-mxout.facebook.com [66.220.144.178]) by imf08.hostedemail.com (Postfix) with ESMTP id 77FC1160015 for ; Fri, 10 Feb 2023 21:50:45 +0000 (UTC) Authentication-Results: imf08.hostedemail.com; dkim=none; dmarc=none; spf=neutral (imf08.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=1676065845; 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=UUUVy5VYv5maynAsonzws5DkK+x5clK/UaCYTRGR24s=; b=dzWgpyWJpiR7Ko/gEkXV13h26f8lA7esFnCj2VPq3nxZogoAwifQNrtexgWlZUMN2qzz+Q I/gkMDrTb/UigbQeIcQzsMfvXwD1/j7yR1xzRBdsHoilGaJS9sdZc+aeTMz/QOsMvvnfwK V4zqayUpIfFEs8olbmaHPJfZlYXSSLw= ARC-Authentication-Results: i=1; imf08.hostedemail.com; dkim=none; dmarc=none; spf=neutral (imf08.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=1676065845; a=rsa-sha256; cv=none; b=Z5sy/LwJd2WL80lqJf8sWOV9hG0xJTtskBqmek9ZsBrJGms8vLjnZI9df6FQye1iQGS/JJ MrcVWohJtX7ffE0xTs5oMDJBO48H/a2uJFMi/5ItzqVDvpM4dR9zZvkz1LHQkHnf7ExIjP mKKpQEsdRJOiISKDrYEvZk9kUy4P78w= Received: by dev0134.prn3.facebook.com (Postfix, from userid 425415) id 62D1E6BFC2C0; 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 00/19] mm: process/cgroup ksm support Date: Fri, 10 Feb 2023 13:50:04 -0800 Message-Id: <20230210215023.2740545-1-shr@devkernel.io> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 77FC1160015 X-Stat-Signature: pojhmzdyth8y9obxxi7qi1m1mumefubc X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ter, 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. What is required to enable KSM for more workloads is to enable / disable it at the process / cgroup level. Use case: The madvise call is not available in the programming language. An example for this are programs with forked workloads using a garbage collected language without pointers. In such a language madvise cannot be made available. In addition the addresses of objects get moved around as they are garbage collected. KSM sharing needs to be enabled "from the outside" for these type of workloads. Experiments with using UKSM have shown a capacity increase of around 20%. 1. New options for prctl system command This patch series adds two new options to the prctl system call. The first 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 cgroup 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 inherited 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 general_profit metric The general_profit metric of KSM is specified in the documentation, but not calculated. This adds the general profit metric to /sys/kernel/debug/mm/ksm. 4. Add more metrics to ksm_stat This adds the process profit and ksm type metric to /proc//ksm_stat. 5. Add more tests to ksm_tests This adds an option to specify the merge type to the ksm_tests. This allows to test madvise and prctl KSM. It also adds a new option to query if prctl KSM has been enabled. It adds a fork test to verify that the KSM process setting is inherited by client processes. Changes: - V2: - Added use cases to the cover letter - Removed the tracing patch from the patch series and posted it as an individual patch - Refreshed repo Stefan Roesch (19): 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: 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 +- fs/proc/base.c | 5 + include/linux/ksm.h | 19 +- include/linux/sched/coredump.h | 1 + include/uapi/linux/prctl.h | 2 + kernel/sys.c | 29 ++ mm/ksm.c | 114 +++++++- tools/include/uapi/linux/prctl.h | 2 + tools/testing/selftests/mm/Makefile | 3 +- tools/testing/selftests/mm/ksm_tests.c | 254 +++++++++++++++--- 11 files changed, 389 insertions(+), 56 deletions(-) base-commit: 234a68e24b120b98875a8b6e17a9dead277be16a