From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5B82B1DF72C for ; Tue, 9 Jun 2026 11:46:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781005566; cv=none; b=JWTgB8ZNhljZ8swBKi1LYNVcESRqG5OF5ON5rtRWOs8LKQ3J5kwxYK7aeeyVIYBCxEhfBHdqMi/N+gtEBmjYnXejgjWAT3mofEpIKaA4aXuO22CIbZTuWu/thhXucbn2MMrczGOG77vCoZ3ni3SwYz0/CpMNBmqoWiXEhGulUrw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781005566; c=relaxed/simple; bh=YzKy+xUNeCmt3wguMX1X+o0LiqckVZB8LOcCrEwFJbs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=nvjT5B4RyVLKXFgl/78Bwn4uN3tfVUukTGGfk/0+87hlbtjU/jfyHIgblBQ7QeAE/Tzp5LofhtCEwUXTntaJNNTXWO8HN6KeZi0yVVY9YMz49fjlVc7meLBRhieAtRm2iJSyykXMkG6/2lD4y8IYnbiM3zhWAUNuEHAYSm0IImE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=GlML1/GO; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="GlML1/GO" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1781005564; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=WSdj657fa4gXpzsbJKokHpr6K4JuaFM31TDRG7+aFWU=; b=GlML1/GOyg7U4YvfZg2wKettuLHJdRDUlujQZEVOdIAdeSWZEsMW7O71ebfbuV4vEG99RZ 5vYQAvqsBkUX+hbM9WkfgX7wmHEbjUiUcE2l4aP8lYlpiLih1WkSOHChlGzVYVaTWVqb+g MNUIPsj3aVhEjySo6JUBsJjlt42Fz2E= Received: from mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-490-JFUwVjzMOx6eHBee42jbWA-1; Tue, 09 Jun 2026 07:46:01 -0400 X-MC-Unique: JFUwVjzMOx6eHBee42jbWA-1 X-Mimecast-MFC-AGG-ID: JFUwVjzMOx6eHBee42jbWA_1781005558 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 93CDA19560BB; Tue, 9 Jun 2026 11:45:57 +0000 (UTC) Received: from p1.redhat.com (unknown [10.44.22.33]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 8124A1955DC9; Tue, 9 Jun 2026 11:45:48 +0000 (UTC) From: Nico Pache To: linux-kernel@vger.kernel.org, linux-mm@kvack.org, Usama Arif , Yu Zhao Cc: aarcange@redhat.com, Nico Pache , Andrew Morton , David Hildenbrand , Xu Xin , Chengming Zhou , Lorenzo Stoakes , Zi Yan , Baolin Wang , "Liam R. Howlett" , Ryan Roberts , Dev Jain , Barry Song , Lance Yang , Matthew Brost , Joshua Hahn , Rakie Kim , Byungchul Park , Gregory Price , Ying Huang , Alistair Popple Subject: [PATCH mm-unstable v1 1/3] mm/ksm: export ksm_is_running() to check KSM merge state Date: Tue, 9 Jun 2026 05:46:13 -0600 Message-ID: <20260609114619.144416-2-npache@redhat.com> In-Reply-To: <20260609114619.144416-1-npache@redhat.com> References: <20260609114619.144416-1-npache@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 Add ksm_is_running() which returns true when KSM is actively merging (ksm_run & KSM_RUN_MERGE). This will be used by try_to_map_unused_to_zeropage() to skip zero-page remapping in VM_MERGEABLE VMAs when KSM is active. Signed-off-by: Nico Pache --- include/linux/ksm.h | 6 ++++++ mm/ksm.c | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/include/linux/ksm.h b/include/linux/ksm.h index d39d0d5483a2..c1048b690a92 100644 --- a/include/linux/ksm.h +++ b/include/linux/ksm.h @@ -17,6 +17,7 @@ #ifdef CONFIG_KSM int ksm_madvise(struct vm_area_struct *vma, unsigned long start, unsigned long end, int advice, vm_flags_t *vm_flags); +bool ksm_is_running(void); vma_flags_t ksm_vma_flags(struct mm_struct *mm, const struct file *file, vma_flags_t vma_flags); int ksm_enable_merge_any(struct mm_struct *mm); @@ -144,6 +145,11 @@ static inline int ksm_madvise(struct vm_area_struct *vma, unsigned long start, return 0; } +static inline bool ksm_is_running(void) +{ + return false; +} + static inline struct folio *ksm_might_need_to_copy(struct folio *folio, struct vm_area_struct *vma, unsigned long addr) { diff --git a/mm/ksm.c b/mm/ksm.c index 7d5b76478f0b..edc2b961ff59 100644 --- a/mm/ksm.c +++ b/mm/ksm.c @@ -3015,6 +3015,12 @@ int ksm_madvise(struct vm_area_struct *vma, unsigned long start, } EXPORT_SYMBOL_GPL(ksm_madvise); +bool ksm_is_running(void) +{ + return ksm_run & KSM_RUN_MERGE; +} +EXPORT_SYMBOL_GPL(ksm_is_running); + int __ksm_enter(struct mm_struct *mm) { struct ksm_mm_slot *mm_slot; -- 2.54.0