From patchwork Fri Feb 10 21:50:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Roesch X-Patchwork-Id: 13136495 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 4BB5EC64ED8 for ; Fri, 10 Feb 2023 21:50:53 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 71D60280015; Fri, 10 Feb 2023 16:50:52 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 670BA280003; Fri, 10 Feb 2023 16:50:52 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3F9076B01F2; Fri, 10 Feb 2023 16:50:52 -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 25C816B01F0 for ; Fri, 10 Feb 2023 16:50:52 -0500 (EST) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 0163BA01CB for ; Fri, 10 Feb 2023 21:50:51 +0000 (UTC) X-FDA: 80452727544.23.7CB599F 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 4DD1D40008 for ; Fri, 10 Feb 2023 21:50:50 +0000 (UTC) Authentication-Results: imf27.hostedemail.com; dkim=none; dmarc=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 ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1676065850; 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=WX9C0EVQ1MCmBYsInw+wO/0YO449MXgKGXrN8NBE9ds=; b=Qk8p1UlyRmUSVhYGFJpqCRrP4zI7XoC5rK2+XzYWaUnAtUQg9Wp9VrxlZMW4qDGHTErXMt XfNknEg07o5pxX3cXNrc0dY2tDl0YeXXawoUZudb+P2kGH9MyyYhagrFVCQpCsnCNFlTe/ gmvQHasOB29wLDdXqVYIKybpBEdJVTA= ARC-Authentication-Results: i=1; imf27.hostedemail.com; dkim=none; dmarc=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 ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1676065850; a=rsa-sha256; cv=none; b=Y8quJWG8CAIvjsNTW7T8lH43XMx13l+UC+KOsEuiB1KjJYkaHV972av30/qjWxN9d2dm1V 6u++wzE+U+wa6Rt9A7RpMKR9LVJLiTeoxKKCv1BuVFIUF3j8mft/qLRG3pqNi/qvVycRRB J/CrgGKMiPqg3YpehPpBiisPDq9zBxM= Received: by dev0134.prn3.facebook.com (Postfix, from userid 425415) id 69CB96BFC2C7; Fri, 10 Feb 2023 13:50:33 -0800 (PST) From: Stefan Roesch To: kernel-team@fb.com Cc: shr@devkernel.io, linux-mm@kvack.org, riel@surriel.com, mhocko@suse.com, david@redhat.com, linux-kselftest@vger.kernel.org, linux-doc@vger.kernel.org, akpm@linux-foundation.org Subject: [RFC PATCH v2 02/19] mm: add flag to __ksm_enter Date: Fri, 10 Feb 2023 13:50:06 -0800 Message-Id: <20230210215023.2740545-3-shr@devkernel.io> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230210215023.2740545-1-shr@devkernel.io> References: <20230210215023.2740545-1-shr@devkernel.io> MIME-Version: 1.0 X-Rspamd-Queue-Id: 4DD1D40008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5yveI guLFzM6xrgxTwLNpE/M6YNX7wnMTyB/kX5lfgrYbJluPRKgpfT0nhwheCFzxP8u1KvCaG11jQeuORF2oZWnCAmN248ETN0SlUrsXd 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 change adds the flag parameter to __ksm_enter. This allows to distinguish if ksm was called by prctl or madvise. Signed-off-by: Stefan Roesch --- include/linux/ksm.h | 6 ++++-- mm/ksm.c | 9 +++++---- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/include/linux/ksm.h b/include/linux/ksm.h index 7e232ba59b86..50e6b56092f3 100644 --- a/include/linux/ksm.h +++ b/include/linux/ksm.h @@ -18,13 +18,15 @@ #ifdef CONFIG_KSM int ksm_madvise(struct vm_area_struct *vma, unsigned long start, unsigned long end, int advice, unsigned long *vm_flags); -int __ksm_enter(struct mm_struct *mm); void __ksm_exit(struct mm_struct *mm); +int __ksm_enter(struct mm_struct *mm, int flag); static inline int ksm_fork(struct mm_struct *mm, struct mm_struct *oldmm) { + if (test_bit(MMF_VM_MERGE_ANY, &oldmm->flags)) + return __ksm_enter(mm, MMF_VM_MERGE_ANY); if (test_bit(MMF_VM_MERGEABLE, &oldmm->flags)) - return __ksm_enter(mm); + return __ksm_enter(mm, MMF_VM_MERGEABLE); return 0; } diff --git a/mm/ksm.c b/mm/ksm.c index 56808e3bfd19..afc0980592af 100644 --- a/mm/ksm.c +++ b/mm/ksm.c @@ -2595,8 +2595,9 @@ int ksm_madvise(struct vm_area_struct *vma, unsigned long start, return 0; #endif - if (!test_bit(MMF_VM_MERGEABLE, &mm->flags)) { - err = __ksm_enter(mm); + if (!test_bit(MMF_VM_MERGEABLE, &mm->flags) && + !test_bit(MMF_VM_MERGE_ANY, &mm->flags)) { + err = __ksm_enter(mm, MMF_VM_MERGEABLE); if (err) return err; } @@ -2622,7 +2623,7 @@ int ksm_madvise(struct vm_area_struct *vma, unsigned long start, } EXPORT_SYMBOL_GPL(ksm_madvise); -int __ksm_enter(struct mm_struct *mm) +int __ksm_enter(struct mm_struct *mm, int flag) { struct ksm_mm_slot *mm_slot; struct mm_slot *slot; @@ -2655,7 +2656,7 @@ int __ksm_enter(struct mm_struct *mm) list_add_tail(&slot->mm_node, &ksm_scan.mm_slot->slot.mm_node); spin_unlock(&ksm_mmlist_lock); - set_bit(MMF_VM_MERGEABLE, &mm->flags); + set_bit(flag, &mm->flags); mmgrab(mm); if (needs_wakeup)