From patchwork Mon Jan 23 17:37:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Roesch X-Patchwork-Id: 13112641 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 E6602C38142 for ; Mon, 23 Jan 2023 17:38:24 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6F7376B0082; Mon, 23 Jan 2023 12:38:21 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 6CF9F6B0087; Mon, 23 Jan 2023 12:38:21 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 56E7E6B0088; Mon, 23 Jan 2023 12:38:21 -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 4212E6B0082 for ; Mon, 23 Jan 2023 12:38:21 -0500 (EST) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id E27681A12BB for ; Mon, 23 Jan 2023 17:38:20 +0000 (UTC) X-FDA: 80386772760.03.C448322 Received: from 66-220-144-178.mail-mxout.facebook.com (66-220-144-178.mail-mxout.facebook.com [66.220.144.178]) by imf27.hostedemail.com (Postfix) with ESMTP id 3662C40003 for ; Mon, 23 Jan 2023 17:38:19 +0000 (UTC) Authentication-Results: imf27.hostedemail.com; dkim=none; spf=neutral (imf27.hostedemail.com: 66.220.144.178 is neither permitted nor denied by domain of shr@devkernel.io) smtp.mailfrom=shr@devkernel.io; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1674495499; 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=dkTe6hQ1qB/aSBv2e8jZ4aQ5awR1SuR87QIIhlPyTwQ=; b=pMHsaBf35NZZT+JK9JnwcZ5f8yuXRzwA/i1YLUYLs4OUjh67ECZiw4O0qJC8FdoV/ZyGea 2OxwZIKzAbWtUi7sIMXu8F9LKBpTjNzdaSykqpzA1GMkcmLxA9dg80QyVlm6PZqqNqYdGH qzBzHDGWfgQQixWgTjbA338iFIedors= ARC-Authentication-Results: i=1; imf27.hostedemail.com; dkim=none; spf=neutral (imf27.hostedemail.com: 66.220.144.178 is neither permitted nor denied by domain of shr@devkernel.io) smtp.mailfrom=shr@devkernel.io; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1674495499; a=rsa-sha256; cv=none; b=gc64QCX0SDkNZZu03jQ6v3tyTx83hEJG7Rnc3dNr1cFFzMH4wSizrJf7xgOOvVHb7P72z+ 2LMe2jZhnWkL7dpUF45kT9hMYuF7wh8xVFDI3SJOHC5dXGUIvfYZvUktSQxNho1eQd/Fjp 2JlQgzbsYeq9b4okCDNdOPO55x517Ys= Received: by dev0134.prn3.facebook.com (Postfix, from userid 425415) id 530B85616BDB; 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 05/20] mm: support disabling of ksm for a process Date: Mon, 23 Jan 2023 09:37:33 -0800 Message-Id: <20230123173748.1734238-6-shr@devkernel.io> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230123173748.1734238-1-shr@devkernel.io> References: <20230123173748.1734238-1-shr@devkernel.io> MIME-Version: 1.0 X-Stat-Signature: x1zbq5m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W nobxUj+m NxcQUAeAOQbWyoLj9R2u1H8JP2G9j6lWyv0paYOF7wdP5ft+86Lr6F9pNyQ== 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: This adds the ability to disable ksm for a process if ksm has been enabled for the process. Signed-off-by: Stefan Roesch --- mm/ksm.c | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/mm/ksm.c b/mm/ksm.c index 967eda719fab..5fa6b46dfa3b 100644 --- a/mm/ksm.c +++ b/mm/ksm.c @@ -2588,6 +2588,27 @@ int __ksm_enter(struct mm_struct *mm, int flag) return 0; } +static void unmerge_vmas(struct mm_struct *mm) +{ + struct vm_area_struct *vma; + struct vma_iterator vmi; + + vma_iter_init(&vmi, mm, 0); + + mmap_read_lock(mm); + for_each_vma(vmi, vma) { + if (vma->vm_flags & VM_MERGEABLE) { + unsigned long flags = vma->vm_flags; + + if (ksm_madvise(vma, vma->vm_start, vma->vm_end, MADV_UNMERGEABLE, &flags)) + continue; + + vma->vm_flags = flags; + } + } + mmap_read_unlock(mm); +} + void __ksm_exit(struct mm_struct *mm, int flag) { struct ksm_mm_slot *mm_slot; @@ -2595,8 +2616,10 @@ void __ksm_exit(struct mm_struct *mm, int flag) int easy_to_free = 0; if (!(current->flags & PF_EXITING) && flag == MMF_VM_MERGE_ANY && - test_bit(MMF_VM_MERGE_ANY, &mm->flags)) + test_bit(MMF_VM_MERGE_ANY, &mm->flags)) { clear_bit(MMF_VM_MERGE_ANY, &mm->flags); + unmerge_vmas(mm); + } /* * This process is exiting: if it's straightforward (as is the