Received: by 2002:a05:7412:37c9:b0:e2:908c:2ebd with SMTP id jz9csp2982656rdb; Fri, 22 Sep 2023 14:13:35 -0700 (PDT) X-Google-Smtp-Source: AGHT+IE1xcir1ibj7zPIR0A5UwZyfsNQSqa1XZnBA/MTOoUU7NodwWKDAHQ56aGd9NL/JyQ5hVXg X-Received: by 2002:a05:6a00:180c:b0:68e:2c3a:8775 with SMTP id y12-20020a056a00180c00b0068e2c3a8775mr564843pfa.33.1695417214678; Fri, 22 Sep 2023 14:13:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695417214; cv=none; d=google.com; s=arc-20160816; b=o/NznVX1EseNgWPSWxmA7JamdJM8HLPmRj08TJq3MhMbFlFtz0H7TN2ASgTZe3+z0Z dJH15gIg1XODRU0cXmDlbQv2eGuJyv6SnIYJVfqz0BYE0/6wL0cxV9xX1bJDV174uead OyccloLiX7cBg7x+GJaOLSw2NM+AIIl02XfxosomkSWV5OiFA4YXrfWbPlgR6E/XlzuW U0wARUTpeqOGAclCmvF91a9CC/QJZGiw/21FbTyp7SHK4S2Amis2uk+ugFtss5j1QwT/ MUfhpWtypruKpz1cSunMNYgUknI9zQG9rGzsmQA517SVIiqVVyiueuAovZRHFZYz+w0/ XUMA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=7iTDGizWpIb8FZfB8TU7wmmmnqqKOWotVSPof36YeIg=; fh=trQN94Iqca1GMQF1AkSOofuqg8pe0AKHPTTlJaXdYFw=; b=uE+7jm+lLCAoprpcw2n+RoRXcTFjAQCSvhmSHHNGagH4se4kfq1VNSxa6XQpC9a4+5 oWIjOm4GI1QYDvSE9LnelCQpqUiwFC1qmtrKYc63BdjOMPB2FApJ4D6hoW7roex/gL2Z dCOc+hcsOldhftD6J4MU5D09WR1/CLTXZR+vy03nXX1TuiwIOgFXa8L1m9TFd6fdGk8O 4WDkYtId+2Sm+EUNTsx2T6E3iTPinTD9rTTB7sLbeVazcVU7L3Hl0zJ77jsL/RqXzejw kRIQN9Y2cYnGs4zl3E9/3rMJvcbEb8NBKF2rLcn/kpyRvO/H+7BCbY32OHvvwLkE7ZMT C82Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from morse.vger.email (morse.vger.email. [23.128.96.31]) by mx.google.com with ESMTPS id s30-20020a63925e000000b00578cbee11e2si4661876pgn.642.2023.09.22.14.13.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Sep 2023 14:13:34 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) client-ip=23.128.96.31; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by morse.vger.email (Postfix) with ESMTP id 6C6C681CDBAF; Fri, 22 Sep 2023 14:12:32 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229902AbjIVVMT (ORCPT + 99 others); Fri, 22 Sep 2023 17:12:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38980 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229866AbjIVVML (ORCPT ); Fri, 22 Sep 2023 17:12:11 -0400 Received: from 66-220-144-179.mail-mxout.facebook.com (66-220-144-179.mail-mxout.facebook.com [66.220.144.179]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4C5AEFB for ; Fri, 22 Sep 2023 14:12:05 -0700 (PDT) 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 Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=2.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_SBL_CSS,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on morse.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (morse.vger.email [0.0.0.0]); Fri, 22 Sep 2023 14:12:32 -0700 (PDT) X-Spam-Level: ** 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/coredum= p.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) =20 #define MMF_DISABLE_THP_MASK (1 << MMF_DISABLE_THP) =20 +#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) =20 -#define MMF_VM_MERGE_ANY 29 #endif /* _LINUX_SCHED_COREDUMP_H */ --=20 2.39.3