From patchwork Mon Jan 23 17:37:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Roesch X-Patchwork-Id: 13112637 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 0853BC38142 for ; Mon, 23 Jan 2023 17:38:19 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 768086B007E; Mon, 23 Jan 2023 12:38:17 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 6F2A56B0085; Mon, 23 Jan 2023 12:38:17 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4AA9A6B0080; Mon, 23 Jan 2023 12:38:17 -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 31C1A6B007E for ; Mon, 23 Jan 2023 12:38:17 -0500 (EST) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id ED72D822B6 for ; Mon, 23 Jan 2023 17:38:16 +0000 (UTC) X-FDA: 80386772592.25.1AE6107 Received: from 66-220-144-178.mail-mxout.facebook.com (66-220-144-178.mail-mxout.facebook.com [66.220.144.178]) by imf17.hostedemail.com (Postfix) with ESMTP id 3983740005 for ; Mon, 23 Jan 2023 17:38:15 +0000 (UTC) Authentication-Results: imf17.hostedemail.com; dkim=none; dmarc=none; spf=neutral (imf17.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=1674495495; 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=euBbnlChzh5NyXkxd3+rY9w1+gYxyY5ES33Gy0DFQi0=; b=8T2USIz+xO/j9m73u+EWfzN07plHyYhtmbyG1LmWuk6wgNVaj+9oCSgdEnyU5CD1eTSwe3 PreqrKBBQ9kSDyf63CD0qmOa78p1njU/F8+uikVWVRyrDabSRPBkWHIjSa9Znwls6/8QDX cxLttxhhmQ5zd4zsUfgXLlIkse8mnxY= ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=none; dmarc=none; spf=neutral (imf17.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=1674495495; a=rsa-sha256; cv=none; b=6yMrnU08iCKc0yGiLHf0m4kEcePSXKuMhjf1Pqza4CHyKGaa7N++4ZVbYiCLLC0Sgi7S+j z/smdT/X0gZFPcwrACSdvHzWIgJwJSgEYi0/VlBK4IG8r7wbzRbiMQ8XasgHv5v7Tb/gKi Dl3jjPT/vve0/3kzXkbFEAfLk7iYdrg= Received: by dev0134.prn3.facebook.com (Postfix, from userid 425415) id 4A5615616BD7; 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 03/20] mm: add flag to __ksm_exit call Date: Mon, 23 Jan 2023 09:37:31 -0800 Message-Id: <20230123173748.1734238-4-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-Rspam-User: X-Rspamd-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0 usuMh/GckrLKzK90OS+IHkcexxWwAYVolbbI+uvg2lmPZFeWIWzyaMYI9mJAzhn2sbtsWUDVUX0IZH5nJhwxMd8KapaY4MYDc7hJE 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 flag parameter to the __ksm_exit() call. This allows to distinguish if this call is for an prctl or madvise invocation. Signed-off-by: Stefan Roesch --- include/linux/ksm.h | 8 +++++--- mm/ksm.c | 8 ++++++-- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/include/linux/ksm.h b/include/linux/ksm.h index 50e6b56092f3..d38a05a36298 100644 --- a/include/linux/ksm.h +++ b/include/linux/ksm.h @@ -18,8 +18,8 @@ #ifdef CONFIG_KSM int ksm_madvise(struct vm_area_struct *vma, unsigned long start, unsigned long end, int advice, unsigned long *vm_flags); -void __ksm_exit(struct mm_struct *mm); int __ksm_enter(struct mm_struct *mm, int flag); +void __ksm_exit(struct mm_struct *mm, int flag); static inline int ksm_fork(struct mm_struct *mm, struct mm_struct *oldmm) { @@ -32,8 +32,10 @@ static inline int ksm_fork(struct mm_struct *mm, struct mm_struct *oldmm) static inline void ksm_exit(struct mm_struct *mm) { - if (test_bit(MMF_VM_MERGEABLE, &mm->flags)) - __ksm_exit(mm); + if (test_bit(MMF_VM_MERGE_ANY, &mm->flags)) + __ksm_exit(mm, MMF_VM_MERGE_ANY); + else if (test_bit(MMF_VM_MERGEABLE, &mm->flags)) + __ksm_exit(mm, MMF_VM_MERGEABLE); } /* diff --git a/mm/ksm.c b/mm/ksm.c index d84a244fe224..83796328574c 100644 --- a/mm/ksm.c +++ b/mm/ksm.c @@ -2563,12 +2563,16 @@ int __ksm_enter(struct mm_struct *mm, int flag) return 0; } -void __ksm_exit(struct mm_struct *mm) +void __ksm_exit(struct mm_struct *mm, int flag) { struct ksm_mm_slot *mm_slot; struct mm_slot *slot; int easy_to_free = 0; + if (!(current->flags & PF_EXITING) && flag == MMF_VM_MERGE_ANY && + test_bit(MMF_VM_MERGE_ANY, &mm->flags)) + clear_bit(MMF_VM_MERGE_ANY, &mm->flags); + /* * This process is exiting: if it's straightforward (as is the * case when ksmd was never running), free mm_slot immediately. @@ -2595,7 +2599,7 @@ void __ksm_exit(struct mm_struct *mm) if (easy_to_free) { mm_slot_free(mm_slot_cache, mm_slot); - clear_bit(MMF_VM_MERGEABLE, &mm->flags); + clear_bit(flag, &mm->flags); mmdrop(mm); } else if (mm_slot) { mmap_write_lock(mm);