From patchwork Fri Feb 10 21:50:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Roesch X-Patchwork-Id: 13136502 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 7559FC636D7 for ; Fri, 10 Feb 2023 21:53:57 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0C5E928001D; Fri, 10 Feb 2023 16:53:57 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 0019E280003; Fri, 10 Feb 2023 16:53:56 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E30E428001D; Fri, 10 Feb 2023 16:53:56 -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 D5663280003 for ; Fri, 10 Feb 2023 16:53:56 -0500 (EST) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id A73C21404C1 for ; Fri, 10 Feb 2023 21:53:56 +0000 (UTC) X-FDA: 80452735272.10.7FFCAE1 Received: from 66-220-144-178.mail-mxout.facebook.com (66-220-144-178.mail-mxout.facebook.com [66.220.144.178]) by imf20.hostedemail.com (Postfix) with ESMTP id 170741C0012 for ; Fri, 10 Feb 2023 21:53:54 +0000 (UTC) Authentication-Results: imf20.hostedemail.com; dkim=none; dmarc=none; spf=neutral (imf20.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=1676066035; 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=qoDCnA3OIyYoGrZnZvSN6iClB0BUnKy9hnpZKbMb2eA=; b=Nfjp1fsgeloKHgfxOlaq/ylNkB687sEvZHDo06Lw/BLlU+oZ07DBA6303ktv9GkWvb6Nb0 QZvHjSlqkkmtt9O+NoJ1DsjqPYA637+hkLihadVUzVpkWwXj8Qjm327gEQGYv3cQ5U/po4 VhZA5siA5yxqi1AX5zbMSsedbUNDKu4= ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=none; dmarc=none; spf=neutral (imf20.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=1676066035; a=rsa-sha256; cv=none; b=dRemHK4hy65N0w1EYDIIJpQEMhWeLkbh2Geg6k/4WH0AqBX4QloBpAWlpQODAsDmKrlWcQ 3B9gnOQ7MjzRDgKyRPnTq8RICtER0TF6WC37uoo2zkOxkZoXZSnEu7Ov2A/3mXdWnyvLgr bIUtUw0D+nsCRxizWjL6iqjXvqw3icM= Received: by dev0134.prn3.facebook.com (Postfix, from userid 425415) id 8D1306BFC2D9; 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 10/19] mm: calculate ksm process profit metric Date: Fri, 10 Feb 2023 13:50:14 -0800 Message-Id: <20230210215023.2740545-11-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-Rspam-User: X-Rspamd-Server: rspam04 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yerTkZC Qp+ynCxpv6dgepQu4Zhx8Rc6xm7Tfi01NGc3ROkzidObUcNfPvZAnSRt1qw== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000003, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: The ksm documentation mentions the process profit metric and how to calculate it. This adds the calculation of the metric. Signed-off-by: Stefan Roesch --- include/linux/ksm.h | 4 ++++ mm/ksm.c | 8 ++++++++ 2 files changed, 12 insertions(+) diff --git a/include/linux/ksm.h b/include/linux/ksm.h index d38a05a36298..a18cd03efcfb 100644 --- a/include/linux/ksm.h +++ b/include/linux/ksm.h @@ -55,6 +55,10 @@ struct page *ksm_might_need_to_copy(struct page *page, void rmap_walk_ksm(struct folio *folio, struct rmap_walk_control *rwc); void folio_migrate_ksm(struct folio *newfolio, struct folio *folio); +#ifdef CONFIG_PROC_FS +long ksm_process_profit(struct mm_struct *); +#endif /* CONFIG_PROC_FS */ + #else /* !CONFIG_KSM */ static inline int ksm_fork(struct mm_struct *mm, struct mm_struct *oldmm) diff --git a/mm/ksm.c b/mm/ksm.c index a0b4611112c0..b3db29605303 100644 --- a/mm/ksm.c +++ b/mm/ksm.c @@ -3024,6 +3024,14 @@ static void wait_while_offlining(void) } #endif /* CONFIG_MEMORY_HOTREMOVE */ +#ifdef CONFIG_PROC_FS +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); +} +#endif /* CONFIG_PROC_FS */ + #ifdef CONFIG_SYSFS /* * This all compiles without CONFIG_SYSFS, but is a waste of space.