From patchwork Fri Sep 22 21:11:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Roesch X-Patchwork-Id: 13396392 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 DB651CE7A8A for ; Fri, 22 Sep 2023 21:12:08 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B3DBD6B0302; Fri, 22 Sep 2023 17:12:07 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A9DA06B0300; Fri, 22 Sep 2023 17:12:07 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 93EF56B0302; Fri, 22 Sep 2023 17:12:07 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 7E0B16B02FB for ; Fri, 22 Sep 2023 17:12:07 -0400 (EDT) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 4E2CD41182 for ; Fri, 22 Sep 2023 21:12:07 +0000 (UTC) X-FDA: 81265481094.25.A99AB88 Received: from 66-220-144-178.mail-mxout.facebook.com (66-220-144-178.mail-mxout.facebook.com [66.220.144.178]) by imf26.hostedemail.com (Postfix) with ESMTP id A9EE4140006 for ; Fri, 22 Sep 2023 21:12:05 +0000 (UTC) Authentication-Results: imf26.hostedemail.com; dkim=none; dmarc=none; spf=neutral (imf26.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=1695417125; 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=7iTDGizWpIb8FZfB8TU7wmmmnqqKOWotVSPof36YeIg=; b=LdkogKFzejR6U0Mmnh1l7SD8nFgqjFGjLa1NvXuQfhE1AwJtusF4hN2HQjxeH1MWdVpOwo vbX6TTEpnNpXc/dWWgr1GudvA7W2kifw0xq0lQ5x/efHQhPCVJv5InOsMlgABpzUgAHPi/ 3xTG8ud4ldGHitaQMw0ERbqFykvo9hk= ARC-Authentication-Results: i=1; imf26.hostedemail.com; dkim=none; dmarc=none; spf=neutral (imf26.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=1695417125; a=rsa-sha256; cv=none; b=tdX7FTTQHKNeUoufyjYPG/VToj/f1OwNKff6+JGhFkujt7R1Q8JxIihAxmgTG92f7ft2aU yxRDn6jnFOcCxmU+b7NRaqrcuIUDj6W5lyMXK1oCHg/MxL8fdUJExPW5adU1iuIENMBGAf QMTfB5LdFV46BRuoQuS9RLHKBAvWF14= Received: by devbig1114.prn1.facebook.com (Postfix, from userid 425415) id 7D7E9C60DC4C; Fri, 22 Sep 2023 14:11:49 -0700 (PDT) From: Stefan Roesch To: kernel-team@fb.com Cc: shr@devkernel.io, akpm@linux-foundation.org, david@redhat.com, hannes@cmpxchg.org, riel@surriel.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Carl Klemm Subject: [PATCH v4 1/2] mm/ksm: support fork/exec for prctl Date: Fri, 22 Sep 2023 14:11:40 -0700 Message-Id: <20230922211141.320789-2-shr@devkernel.io> X-Mailer: git-send-email 2.39.3 In-Reply-To: <20230922211141.320789-1-shr@devkernel.io> References: <20230922211141.320789-1-shr@devkernel.io> MIME-Version: 1.0 X-Rspam-User: X-Stat-Signature: kxpyj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lUZeAo iijC++n0wRAR6eoIV1lnOByZQga5Oir6hP3GRFtJJG05g2uDbnCkSs//PNwGo7Q6zzUalqdg6RbAoXw+OQupxbMn0oyn998NAyrIkKXVWNnCVX+Igz/dLSRLamiRrdgmkPPqMAhAyeqrvwLgE7iCrgj1BtBPMkDrIklDacqmoUWnBsqtUTCZg9NT4btHV3EhOLbxi 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: Today we have two ways to enable KSM: 1) madvise system call This allows to enable KSM for a memory region for a long time. 2) prctl system call This is a recent addition to enable KSM for the complete process. In addition when a process is forked, the KSM setting is inherited. This change only affects the second case. One of the use cases for (2) was to support the ability to enable KSM for cgroups. This allows systemd to enable KSM for the seed process. By enabling it in the seed process all child processes inherit the setting. This works correctly when the process is forked. However it doesn't support fork/exec workflow. From the previous cover letter: .... Use case 3: With the madvise call sharing opportunities are only enabled for the current process: it is a workload-local decision. A considerable number of sharing opportunities may exist across multiple workloads or jobs (if they are part of the same security domain). Only a higler level entity like a job scheduler or container can know for certain if its running one or more instances of a job. That job scheduler however doesn't have the necessary internal workload knowledge to make targeted madvise calls. .... In addition it can also be a bit surprising that fork keeps the KSM setting and fork/exec does not. Signed-off-by: Stefan Roesch Fixes: d7597f59d1d3 ("mm: add new api to enable ksm per process") Reviewed-by: David Hildenbrand Reported-by: Carl Klemm Tested-by: Carl Klemm --- include/linux/sched/coredump.h | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/include/linux/sched/coredump.h b/include/linux/sched/coredump.h index 0ee96ea7a0e9..205aa9917394 100644 --- a/include/linux/sched/coredump.h +++ b/include/linux/sched/coredump.h @@ -87,8 +87,11 @@ static inline int get_dumpable(struct mm_struct *mm) #define MMF_DISABLE_THP_MASK (1 << MMF_DISABLE_THP) +#define MMF_VM_MERGE_ANY 29 +#define MMF_VM_MERGE_ANY_MASK (1 << MMF_VM_MERGE_ANY) + #define MMF_INIT_MASK (MMF_DUMPABLE_MASK | MMF_DUMP_FILTER_MASK |\ - MMF_DISABLE_THP_MASK | MMF_HAS_MDWE_MASK) + MMF_DISABLE_THP_MASK | MMF_HAS_MDWE_MASK |\ + MMF_VM_MERGE_ANY_MASK) -#define MMF_VM_MERGE_ANY 29 #endif /* _LINUX_SCHED_COREDUMP_H */