From patchwork Sat Oct 28 00:09:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Roesch X-Patchwork-Id: 13439319 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 CC421C27C4A for ; Sat, 28 Oct 2023 00:13:03 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 242D86B0403; Fri, 27 Oct 2023 20:13:02 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 1F2776B0402; Fri, 27 Oct 2023 20:13:02 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 092696B0404; Fri, 27 Oct 2023 20:13:01 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id DD57D6B0401 for ; Fri, 27 Oct 2023 20:13:01 -0400 (EDT) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id BCA24B636C for ; Sat, 28 Oct 2023 00:13:01 +0000 (UTC) X-FDA: 81392944962.10.1E3A97B 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 348AA180016 for ; Sat, 28 Oct 2023 00:12:59 +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=1698451980; 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=31VaYngcTYzlNRfnB5nKk/Q/RitTaJ38QTejLRm4eBI=; b=74P/jiGCfsGeuccNrBvF9zpvToZ6D7QYpNyL1NjEeMEubVYY1VPDjECVzxJ85UeYJOZQHV HhVXMj4Y8hrbmSIRSoUHVImMfCQ7g28ZRk++mZhlRnXXdGSv8bcOC1x77tKXHpzA6LFZfG qaUmzPC7dHHt9oP813M3K3rmb9KLTyE= 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=1698451980; a=rsa-sha256; cv=none; b=8jHKcPiolz90fGjMFmEBW+vzO9LQMAYDhaPpKtWesryaHEgvtU87JHVC66aFmPRLubRTle AVAQ8MweBllF69if1+fHsQ6sgPPwHTSK0eBPZEl9mEj+/27Za3jqT+m/+ZNkoi/SmeXQLO xetZTO1e/8oMjCUTpMG5Zr76BqmeYq4= Received: by devbig1114.prn1.facebook.com (Postfix, from userid 425415) id 6C454E5A25F5; Fri, 27 Oct 2023 17:10:25 -0700 (PDT) From: Stefan Roesch To: kernel-team@fb.com Cc: shr@devkernel.io, akpm@linux-foundation.org, david@redhat.com, hannes@cmpxchg.org, riel@surriel.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH v2 3/4] mm/ksm: add tracepoint for ksm advisor Date: Fri, 27 Oct 2023 17:09:44 -0700 Message-Id: <20231028000945.2428830-4-shr@devkernel.io> X-Mailer: git-send-email 2.39.3 In-Reply-To: <20231028000945.2428830-1-shr@devkernel.io> References: <20231028000945.2428830-1-shr@devkernel.io> MIME-Version: 1.0 X-Rspamd-Queue-Id: 348AA180016 X-Rspam-User: X-Rspamd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bJ3kjuaNH96rTSEtdj4MauJAp1+W X-Bogosity: Ham, tests=bogofilter, spamicity=0.000008, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: This adds a new tracepoint for the ksm advisor. It reports the last scan time, the new setting of the pages_to_scan parameter and the average cpu percent usage of the ksmd background thread for the last scan. Signed-off-by: Stefan Roesch --- include/trace/events/ksm.h | 33 +++++++++++++++++++++++++++++++++ mm/ksm.c | 1 + 2 files changed, 34 insertions(+) diff --git a/include/trace/events/ksm.h b/include/trace/events/ksm.h index b5ac35c1d0e8..e728647b5d26 100644 --- a/include/trace/events/ksm.h +++ b/include/trace/events/ksm.h @@ -245,6 +245,39 @@ TRACE_EVENT(ksm_remove_rmap_item, __entry->pfn, __entry->rmap_item, __entry->mm) ); +/** + * ksm_advisor - called after the advisor has run + * + * @scan_time: scan time in seconds + * @pages_to_scan: new pages_to_scan value + * @cpu_percent: cpu usage in percent + * + * Allows to trace the ksm advisor. + */ +TRACE_EVENT(ksm_advisor, + + TP_PROTO(s64 scan_time, unsigned long pages_to_scan, + unsigned int cpu_percent), + + TP_ARGS(scan_time, pages_to_scan, cpu_percent), + + TP_STRUCT__entry( + __field(s64, scan_time) + __field(unsigned long, pages_to_scan) + __field(unsigned int, cpu_percent) + ), + + TP_fast_assign( + __entry->scan_time = scan_time; + __entry->pages_to_scan = pages_to_scan; + __entry->cpu_percent = cpu_percent; + ), + + TP_printk("ksm scan time %lld pages_to_scan %lu cpu percent %u", + __entry->scan_time, __entry->pages_to_scan, + __entry->cpu_percent) +); + #endif /* _TRACE_KSM_H */ /* This part must be outside protection */ diff --git a/mm/ksm.c b/mm/ksm.c index 042ecaeb0beb..b2a519083d66 100644 --- a/mm/ksm.c +++ b/mm/ksm.c @@ -442,6 +442,7 @@ static void scan_time_advisor(unsigned long scan_time) advisor_ctx.cpu_time = cpu_time; ksm_thread_pages_to_scan = pages; + trace_ksm_advisor(scan_time, pages, cpu_percent); } static void run_advisor(void)