From patchwork Mon Jan 23 17:37:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Roesch X-Patchwork-Id: 13112636 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 BD371C05027 for ; Mon, 23 Jan 2023 17:38:17 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4AC3F6B0083; Mon, 23 Jan 2023 12:38:17 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 435EB6B0082; 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 2FCB56B0081; 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 2049A6B007E for ; Mon, 23 Jan 2023 12:38:17 -0500 (EST) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id E3E25C21F8 for ; Mon, 23 Jan 2023 17:38:16 +0000 (UTC) X-FDA: 80386772592.24.EC1C5D9 Received: from 66-220-144-178.mail-mxout.facebook.com (66-220-144-178.mail-mxout.facebook.com [66.220.144.178]) by imf16.hostedemail.com (Postfix) with ESMTP id 461BA18002C for ; Mon, 23 Jan 2023 17:38:15 +0000 (UTC) Authentication-Results: imf16.hostedemail.com; dkim=none; dmarc=none; spf=neutral (imf16.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=ukh/p78BTzUSB71/CCunrEk0jjIr0HEMFKTMZ8Ud6rI=; b=05y30Ei9noaB8SHYJMh7QudpNLGBdcA9FZ5NC1nsJpgaI6ossUCso1Y3zayOKo7VSIncd6 5sIUqyJxpMiHu6WO7ScSExpx9PSMTl8OLC9M35HC2c+yMcEDcfBdlWtwpTFYWKaYQk0hLt Mje0LEpBRR7pcv8S2DO00LUqtZjAG1k= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=none; dmarc=none; spf=neutral (imf16.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=G+ttFYwz3jGMHS1jAvLilZxSg79oTPN0nG1to2tzr7Eke7ECLW40+UeiBxYKeO8QYCs8Lv h9wDInecdF8rtNDyAEwo7LOB/DF2vS7VGDifCSvr+aJO7+uQvQagBS+YZL4lQ6Sc/raEmt umIX+fOF556nD1N/anwHHp6g4PawnD4= Received: by dev0134.prn3.facebook.com (Postfix, from userid 425415) id 45FC35616BD5; 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 02/20] mm: add flag to __ksm_enter Date: Mon, 23 Jan 2023 09:37:30 -0800 Message-Id: <20230123173748.1734238-3-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-Rspamd-Server: rspam05 X-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UdYX9NonJ lfdRX0Xm komwXCyEmJrxPHc2c/SNxpGeE4YW0pYtNrg8Uy3yRkAaH1mUsOtSyq/4jiaaREINayRfvsNAhU5mGWZ4Ml017Ueg269cmjh4bxQPm 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 dd02780c387f..d84a244fe224 100644 --- a/mm/ksm.c +++ b/mm/ksm.c @@ -2493,8 +2493,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; } @@ -2520,7 +2521,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; @@ -2553,7 +2554,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)