From patchwork Fri Feb 10 21:50:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Roesch X-Patchwork-Id: 13136517 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 D7513C636D7 for ; Fri, 10 Feb 2023 21:58:02 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 68E96280026; Fri, 10 Feb 2023 16:58:02 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 63F09280027; Fri, 10 Feb 2023 16:58:02 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 52D2A280026; Fri, 10 Feb 2023 16:58:02 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 43772280021 for ; Fri, 10 Feb 2023 16:58:02 -0500 (EST) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 24210C055F for ; Fri, 10 Feb 2023 21:58:02 +0000 (UTC) X-FDA: 80452745604.04.1FF2794 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 86ABD180008 for ; Fri, 10 Feb 2023 21:58:00 +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=1676066280; 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=HecBqyzdPVfVOZLrZ7DgKpBJ1v8oqJWfpqRSd/dw0a4=; b=07TbtfWR2b4S/PqLGcm+Y2q7MVXLcaj5P8PvL7ybY8xxpR64Lx24t7KPe4KkOxemE+f6tH WtM0BAriZ8MbaM1UwhSbcGGtZ3TiO9Wid5t4tmeQ/1AdHb52MiayfLhAWDtB9gaez5poJR B2b4r/ixj9qOb2af5+wCHLbnxuZNfco= 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=1676066280; a=rsa-sha256; cv=none; b=Pv/LyACWfy4877dkOK0scFFmo1Ur7EiAvWkpIDuCsgJEHwpyU4Vqqzfe2R6y4/TyQCApVS 4S6LEZ2bsR6o8Cs8Bw9fewn3Ja6qjevaJ6PRzXh3MzOLjONs8xaKtophkPVEWsXwXw4DJu atxCY2WrZrS/iYWlILY3q5FMFGYnh3Q= Received: by dev0134.prn3.facebook.com (Postfix, from userid 425415) id 914026BFC2DB; 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 11/19] mm: add ksm_merge_type() function Date: Fri, 10 Feb 2023 13:50:15 -0800 Message-Id: <20230210215023.2740545-12-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-Server: rspam07 X-Rspamd-Que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Ti4 LU5go29TQu/43PQAb29T0NVYXk19epOwpFN/qwdJIb9CODnKmAW7iNvsRw/10XVuyXOPiFV7XjfuhOz5zvgVtHh9xaR8D3gi4c1vV 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 ksm_merge_type function. The function returns the merge type for the process. For madvise it returns "madvise", for prctl it returns "process" and otherwise it returns "none". Signed-off-by: Stefan Roesch --- include/linux/ksm.h | 1 + mm/ksm.c | 11 +++++++++++ 2 files changed, 12 insertions(+) diff --git a/include/linux/ksm.h b/include/linux/ksm.h index a18cd03efcfb..d5f69f18ee5a 100644 --- a/include/linux/ksm.h +++ b/include/linux/ksm.h @@ -57,6 +57,7 @@ void folio_migrate_ksm(struct folio *newfolio, struct folio *folio); #ifdef CONFIG_PROC_FS long ksm_process_profit(struct mm_struct *); +const char *ksm_merge_type(struct mm_struct *mm); #endif /* CONFIG_PROC_FS */ #else /* !CONFIG_KSM */ diff --git a/mm/ksm.c b/mm/ksm.c index b3db29605303..3121bc0f48f3 100644 --- a/mm/ksm.c +++ b/mm/ksm.c @@ -3030,6 +3030,17 @@ long ksm_process_profit(struct mm_struct *mm) return (long)mm->ksm_merging_pages * PAGE_SIZE - mm->ksm_rmap_items * sizeof(struct ksm_rmap_item); } + +/* Return merge type name as string. */ +const char *ksm_merge_type(struct mm_struct *mm) +{ + if (test_bit(MMF_VM_MERGE_ANY, &mm->flags)) + return "process"; + else if (test_bit(MMF_VM_MERGEABLE, &mm->flags)) + return "madvise"; + else + return "none"; +} #endif /* CONFIG_PROC_FS */ #ifdef CONFIG_SYSFS