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 3132BC38142 for ; Tue, 24 Jan 2023 16:38:50 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B63B56B0071; Tue, 24 Jan 2023 11:38:49 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id AED276B0075; Tue, 24 Jan 2023 11:38:49 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 98E566B0078; Tue, 24 Jan 2023 11:38:49 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 89A0D6B0071 for ; Tue, 24 Jan 2023 11:38:49 -0500 (EST) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 5B46E120C0C for ; Tue, 24 Jan 2023 16:38:49 +0000 (UTC) X-FDA: 80390251578.24.68A6A42 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf15.hostedemail.com (Postfix) with ESMTP id D96B7A0020 for ; Tue, 24 Jan 2023 16:38:46 +0000 (UTC) Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=LO3NqKgY; spf=pass (imf15.hostedemail.com: domain of david@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=david@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1674578326; 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:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=9Rx2z0k7BUxOegxeHoQtWpkmv6MaMTCI5y68M3kfHOU=; b=hUb9gja6S3d4uaBn2/0JRKq9kedcOiK0m5RgqBPPVeCz6TdxEOFDNb677IRajndiYSn0uE +zzrQDSe16+Rxa6WHK4OKN85Nm0OPQmhU+oCGRxkIf1w84jQU+KMOSif9D/Iw2W8yNiy9+ XnaSJleZ0Z4gv9k16MIEzg734BaIwyA= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=LO3NqKgY; spf=pass (imf15.hostedemail.com: domain of david@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=david@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1674578326; a=rsa-sha256; cv=none; b=qhiTzo7kkmEFdn+BjeUUcAIx2MRT8bgJ1BG59KicZelgaYKJcMNG6T4ZnQNlooLp3pLYgg Jpu3v/GzL8MS1wrqS13a+VX0aPruGZy7VVTEniqNwHhLi9bThanG3vGbF06ZuvbGI+bSnm u/htPRlG6JVDVY5CC6aft+bbFZ06tHw= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1674578326; h=from:from: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:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=9Rx2z0k7BUxOegxeHoQtWpkmv6MaMTCI5y68M3kfHOU=; b=LO3NqKgYVRMVz5272VkA5xJeEvrlPdHYSV5jT1jW6asFkacAQbmXOAIljsUbDPC/3k+YkJ 8w6X1IVjhYsSXf+J4ey8yzls+pfc2OcztPZhOzOGiuMB/QKB2yG8t685vFyr3NfTlqIybf EbPHUShi035R0gty5Ax2FhZC+Wr/BaI= Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-222-8OnWVambMH6XPMBqFvsWgg-1; Tue, 24 Jan 2023 11:38:42 -0500 X-MC-Unique: 8OnWVambMH6XPMBqFvsWgg-1 Received: by mail-wm1-f70.google.com with SMTP id ay38-20020a05600c1e2600b003da7c41fafcso11458093wmb.7 for ; Tue, 24 Jan 2023 08:38:42 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:in-reply-to:subject:organization:from :references:cc:to:content-language:user-agent:mime-version:date :message-id:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=9Rx2z0k7BUxOegxeHoQtWpkmv6MaMTCI5y68M3kfHOU=; b=NmK5nQhHRU+lsse/PZFuofpAb/77ItegwIsUUSxNZtoAQUmcxPPaE6YFrqDUaPdRI4 wujkf/R20Pt95Qs/o1JZekRP/jvMmA0+oe6K6ct4ev1UNu79gOW9KBVKaTqpxA0tuJ4Q 5oxjuFQSlGcTmk7efHuSMmlA0FbLLVUSKjiU2iGbiysfI+DvNRQkybmoD5v27eAzvqQi kaDSd3Q1OdraWzP5NzOFa3Q9AZayFpfrWwISgHkV7loVhcAyLohOBhhzG3LeN5U5V5x8 fLk4qBlKDkehgrOBYRBlV6M9FoYJPiNM6fSfROjDwxo/DL4/HjrW7vd72gXYw9vJTdN1 ES8g== X-Gm-Message-State: AFqh2kqNO/A4CAD9QskqrsdAbdeo6TSJwyCXVM+SOdEPj8Z0RQiYdIt1 lVYwB1VGWLPgL2zSZfVFTSw+/5yJ7KcZI9RMwgDsM3lzEQwpS2u5XZZ3jobRhgVb/QfxURP3GCy sInWrVR2nooM= X-Received: by 2002:a1c:4b19:0:b0:3da:fb5c:8754 with SMTP id y25-20020a1c4b19000000b003dafb5c8754mr25522206wma.2.1674578321649; Tue, 24 Jan 2023 08:38:41 -0800 (PST) X-Google-Smtp-Source: AMrXdXvVtbfb9k89pLyrSioWTGvup1rj2EisIjnE2x0FKAleLGpTUyvPeeUYg++4LJXskdcWl0OzyA== X-Received: by 2002:a1c:4b19:0:b0:3da:fb5c:8754 with SMTP id y25-20020a1c4b19000000b003dafb5c8754mr25522189wma.2.1674578321360; Tue, 24 Jan 2023 08:38:41 -0800 (PST) Received: from ?IPV6:2003:cb:c707:9d00:9303:90ce:6dcb:2bc9? (p200300cbc7079d00930390ce6dcb2bc9.dip0.t-ipconnect.de. [2003:cb:c707:9d00:9303:90ce:6dcb:2bc9]) by smtp.gmail.com with ESMTPSA id h15-20020a05600c350f00b003db0b0cc2afsm15324053wmq.30.2023.01.24.08.38.40 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 24 Jan 2023 08:38:40 -0800 (PST) Message-ID: <5844ee9f-1992-a62a-2141-3b694a1e1915@redhat.com> Date: Tue, 24 Jan 2023 17:38:39 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.6.0 To: Stefan Roesch , linux-mm@kvack.org Cc: 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, CGEL , Michal Hocko , Jann Horn References: <20230123173748.1734238-1-shr@devkernel.io> From: David Hildenbrand Organization: Red Hat Subject: Re: [RESEND RFC PATCH v1 00/20] mm: process/cgroup ksm support In-Reply-To: <20230123173748.1734238-1-shr@devkernel.io> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: D96B7A0020 X-Stat-Signature: 4p1gecqtxcoy5ctiqta9tjw45k3x51b4 X-Rspam-User: X-HE-Tag: 1674578326-27133 X-HE-Meta: U2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bVD+N4fWT2GgXr6IAt421iZURnb/d0xnlsDrUfw+5BCjAlYAFmdmL83yMajQfx2uO0Q6f11nw8RwFV6iiHAJkIHt+UvuYPY6OurzFtmj9a7n101COU/MKOgz+U2ETbrbqtOKeluG5si2E04mmWpxdL/xiNCPyZ1+pCrylJRDu0ksmw6snaidnaop5rgPhpBDak5RoaGNMeBMRbIkGKREHYj/zQXR/iR7l5Pzbz0Skkw1DiFdbnWmIU8A5oYZqXaKJROg32Owb7HEBEEn4oxUmLNpzuVxlVJ7X/PM/G83oJ4qaT4xqsQnmQEWgVEQT30tuOtPrgfHaqDlr1uNa6gHhBPqZsXlf2ulMTfIM7AyIKvNrqxwyC5s4HD0NApvm/UGQjMNyzr1utu/oHE98GW8ESQFUm9+EWHSN8eKRYYlPA2iCfNSbuoUyp5UGgdCxknxY2PskgCsm6pukH0rBZs71fnIc+r4S96RalecehnrgH0ft5wlXkAMyR7NXsp+aTtG5A== 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: On 23.01.23 18:37, Stefan Roesch wrote: > 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. Did you stumble over the proposals from last year to enable this per-process [1] and system-wide [2]? I remember there was also regarding enabling it system-wide. I'm going to point out the security aspect, and that e.g., Windows used to enable it system-wide before getting taught by security experts otherwise. Details on KSM and security aspects can be found in that thread. Long story short: one has to be very careful with that and only enable it for very carefully selected worklads. Letting a workload opt-in on a VMA level is most probably safer than an admin blindly turning this on for random processes ... Last attempts got nacked ... [1] https://lore.kernel.org/all/20220517092701.1662641-1-xu.xin16@zte.com.cn/ [2] https://lore.kernel.org/all/20220609055658.703472-1-xu.xin16@zte.com.cn/ > > 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 tracepoints to KSM > Currently KSM has no tracepoints. This adds tracepoints to the key KSM functions > to make it easier to debug KSM. > > 4. 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. > > 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 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. > > > 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 -- Thanks, David / dhildenb