From patchwork Wed Dec 13 18:27:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Roesch X-Patchwork-Id: 13491747 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 C4DBAC4332F for ; Wed, 13 Dec 2023 18:27:52 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A79D16B0502; Wed, 13 Dec 2023 13:27:49 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id A04186B0504; Wed, 13 Dec 2023 13:27:49 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8C9D96B0506; Wed, 13 Dec 2023 13:27:49 -0500 (EST) 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 759406B0504 for ; Wed, 13 Dec 2023 13:27:49 -0500 (EST) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 4F09780289 for ; Wed, 13 Dec 2023 18:27:49 +0000 (UTC) X-FDA: 81562628658.18.FDD1254 Received: from 66-220-144-179.mail-mxout.facebook.com (66-220-144-179.mail-mxout.facebook.com [66.220.144.179]) by imf02.hostedemail.com (Postfix) with ESMTP id AEF5680008 for ; Wed, 13 Dec 2023 18:27:47 +0000 (UTC) Authentication-Results: imf02.hostedemail.com; dkim=none; dmarc=none; spf=neutral (imf02.hostedemail.com: 66.220.144.179 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=1702492067; 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=Ju2E2+1OfMe8Vr4nHnwCyl1I0bs/30hKeMFq9hcWi4w=; b=GexTl3IRvuT6BXyvb0dmz+pPMfVITGDwCAV7LY5/+628bFNnXzdSKmt3XE+VpACFzfUUap aOwUvlTdwWzzC8VNwUikh2WgtDRXcjhEMzMLdhwc0d9hAHhfpX2dx3W8Yl3zclGO/naIH0 oXh8qLWFxPf+3nPffxCH1bxu4yFZ4Zw= ARC-Authentication-Results: i=1; imf02.hostedemail.com; dkim=none; dmarc=none; spf=neutral (imf02.hostedemail.com: 66.220.144.179 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=1702492067; a=rsa-sha256; cv=none; b=UKwztn7ASoixx3OgJjKs2VrV46YF1OP73+RCDBXyUnhTWInECcz48PJpJipkVEEBVY9wpp aDQHTwUTJCp5QazsMEte5NBBjB8HnqfjgZTs3FEJQ6f1NlV8kVFeeH8JkY3Ksct/zEEXfG NdUqs/hK51Vb0IHM17JhQ5wDQMN1Zj8= Received: by devbig1114.prn1.facebook.com (Postfix, from userid 425415) id BCBAB10CFA72C; Wed, 13 Dec 2023 10:27:33 -0800 (PST) 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 v4 3/4] mm/ksm: add tracepoint for ksm advisor Date: Wed, 13 Dec 2023 10:27:28 -0800 Message-Id: <20231213182729.587081-4-shr@devkernel.io> X-Mailer: git-send-email 2.39.3 In-Reply-To: <20231213182729.587081-1-shr@devkernel.io> References: <20231213182729.587081-1-shr@devkernel.io> MIME-Version: 1.0 X-Rspamd-Queue-Id: AEF5680008 X-Rspam-User: X-Rspam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CLq0v7QEc2xgz38G1uvGuE 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: 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 Acked-by: David Hildenbrand --- 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 b5ac35c1d0e88..e728647b5d268 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 f7387a6d02050..4962e44131e68 100644 --- a/mm/ksm.c +++ b/mm/ksm.c @@ -452,6 +452,7 @@ static void scan_time_advisor(void) advisor_ctx.cpu_time = cpu_time; ksm_thread_pages_to_scan = pages; + trace_ksm_advisor(scan_time, pages, cpu_percent); } static void advisor_stop_scan(void)