From patchwork Mon Jan 23 17:37:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Roesch X-Patchwork-Id: 13112645 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 8AA06C25B50 for ; Mon, 23 Jan 2023 17:38:31 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D863D6B008A; Mon, 23 Jan 2023 12:38:30 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id D0F1C6B008C; Mon, 23 Jan 2023 12:38:30 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BD72C6B0092; Mon, 23 Jan 2023 12:38:30 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id A89B36B008A for ; Mon, 23 Jan 2023 12:38:30 -0500 (EST) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 7564BC0A39 for ; Mon, 23 Jan 2023 17:38:30 +0000 (UTC) X-FDA: 80386773180.05.FAB1202 Received: from 66-220-144-178.mail-mxout.facebook.com (66-220-144-178.mail-mxout.facebook.com [66.220.144.178]) by imf15.hostedemail.com (Postfix) with ESMTP id BD4CBA0011 for ; Mon, 23 Jan 2023 17:38:28 +0000 (UTC) Authentication-Results: imf15.hostedemail.com; dkim=none; dmarc=none; spf=neutral (imf15.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=1674495508; 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=FWkDwqnduO/ODHyQgdE5Zu/r/6qm0MdGBf1NS8vrglw=; b=QCtRyGSVFYrCVy5iEija+LGqXSdc2OjeJlIULMBFx0OshQ8EBfvJIKFhgV6JxW4f5RW0sx 4n1VV9JKGovBiXFuSlbwuF1ma8BWWFlR/KhrMNQRr108IO6+3YtCyN73A38NsyCgbK1+C9 2/zLNjfzdvD5dBhgLt7Y7W6DCG0VEKM= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=none; dmarc=none; spf=neutral (imf15.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=1674495508; a=rsa-sha256; cv=none; b=7MfufwMn+kBKtv5zxqs4O6srL3petFZ3pqE6ATFQ333Kk8Q6NnedRg4DqVuRtHbMYwj6ZZ rF6jNo/r91X+1mbLciL2ZgaLEdWmeYrtH7GJZkx4r84baHEJ5sGPoW3/t1WyHSAMFc0USS PBGkskL/5Qq6PzDIf1KDVOtPZGUhwrE= Received: by dev0134.prn3.facebook.com (Postfix, from userid 425415) id 6B83A5616BE7; 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 11/20] mm: calculate ksm process profit metric Date: Mon, 23 Jan 2023 09:37:39 -0800 Message-Id: <20230123173748.1734238-12-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-Queue-Id: BD4CBA0011 X-Stat-Signature: uhkbi8jj33gebup69mtfxgwtzcixd7fa X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1674495508-482496 X-HE-Meta: U2FsdGVkX18Nfa+dBLklpwbxvE/M9TpM7/PNnf+jg5nYngNG9+mN98nf64PN5Wg6T08/QfPTXYH23O/LrToJIexnj4N9PSzy69jJcBBNHqBHdm+u0N5aqIQN8kcrRLaxk08uwaxCjjfS5EbCJ3H+hab358SESkEkIKeHMm9uYjKGk/Jdv1qXbub75KOAe73HNO/NLshJnUrPHwqbrxFifFB2HNiRMaczWgpgOctiSvC2u/+VMPOeK0EMsGmDrwNZI0fefW/b/Nx28gbuVgttZJJI86ERso/7JegoqCuN6fNY/Zg9gaieVuR9D8P2/6TUZSBNISc3OyMNv3PMmABxNLhOO+BE2Cmi4uZVB97arQ0QjO7f4lp5efzov6KrHO+Hkc34+tFWZsZXHlpstvoJPZjus5+lGEqyL4ivKGl41XE93XBY8xstaCGnNmWOCDFhv498AD3dW8vEt42Afb8XRwjySiE61i/4sMfy0pBlGm3y8W16IvgUFY8odrk2qYfBu8IsbuWY+y1HdFAEXnwgrrBdsSf2DQ0CFTY2jCf1/YTQfAXGy6aQLRgw+xwC6CwdKxEuSdED+zkNIVtP6N+xvmpAV52EkrABgu+sQ3DpGcjzjezrmB5lqdxWbB5nG3umw+BPIQDljAmspRZvrShb7mPCqmxTo813GPDTO/03dn4L5wY9zeCy4gODCi3UbyOscetKgZzGuTATFcDphf+Ah9PrEqQ7LKgNt3NtDBVj2A+4dqpueOBhj3OAZ2DaK8FFmtvaIKsdTfZf095edMM01PygI3XCTw74RDmtxG1EGApB+LaAR1VTAWsjW46kp78iXFB+R6YjuIGgm3LVlyaOhHsbsVQnc65zkXUwDHjkkY1MN3xfvAThXNp2W1U2WT8RyGNzmTzpB907/ZwrLpwo/Prg0X5h2vrGOXGUKqIKGx4oasoiRM15ZJNsN3sr6kC/aYAXchrWFY4ke0DYkwE xw4sLv/E IKdl+wUd+uzqpWb9WZS+5hSlkhUCz1AJC7+SHDY+ljs/gDaHziRInjcodBg== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000048, 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 d29454a802a0..288689b59527 100644 --- a/mm/ksm.c +++ b/mm/ksm.c @@ -2935,6 +2935,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.