From patchwork Mon Dec 18 23:10:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Roesch X-Patchwork-Id: 13497669 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 AAFA1C35274 for ; Mon, 18 Dec 2023 23:11:17 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 22BC26B0080; Mon, 18 Dec 2023 18:11:14 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 1DBA66B0081; Mon, 18 Dec 2023 18:11:14 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0C9566B0085; Mon, 18 Dec 2023 18:11:14 -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 EA2FA6B0080 for ; Mon, 18 Dec 2023 18:11:13 -0500 (EST) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id A85AE1C12CF for ; Mon, 18 Dec 2023 23:11:13 +0000 (UTC) X-FDA: 81581486826.02.F0C29DB Received: from 66-220-144-179.mail-mxout.facebook.com (66-220-144-179.mail-mxout.facebook.com [66.220.144.179]) by imf28.hostedemail.com (Postfix) with ESMTP id 1B31BC0019 for ; Mon, 18 Dec 2023 23:11:10 +0000 (UTC) Authentication-Results: imf28.hostedemail.com; dkim=none; dmarc=none; spf=neutral (imf28.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=1702941071; 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=1Fz3XLdrz2+bpgvBdPbZhoJrVUUleR20qZ12O9sFG0I=; b=qlZRRpll3DBemwmZZ1uFcNXgbfI09CDJfCetWLgXAVzTWXkEN+DnneKCPPwq3HpPhB8G5x AtL30kMJ9yCL8jaGId9Ywi3wu6WrpODhhbD+itWl3IxDm0d8b1wLHXyNz+G1eseKvbSN69 rjAzOs+E3KWHiA6YZsd7PveZN8tldcM= ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=none; dmarc=none; spf=neutral (imf28.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=1702941071; a=rsa-sha256; cv=none; b=fyrM+oxXqR7LIKpxkgLPUVnT2qUyIWUvgXBflmDjcB4KbH15gOb+CJo3Py4kJ6mrnHfTBj D7/SluCFm37u6pps6D69U13rp6quM3D6EJZ7SnKCLa5+XvgjpKUmCZfsR9Z8/D6PmNe9U8 MvRaw1mpjnH9C0n5PBYZKpNqiTYc4GI= Received: by devbig1114.prn1.facebook.com (Postfix, from userid 425415) id 7028E111427B3; Mon, 18 Dec 2023 15:10:57 -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 v5 3/4] mm/ksm: add tracepoint for ksm advisor Date: Mon, 18 Dec 2023 15:10:53 -0800 Message-Id: <20231218231054.1625219-4-shr@devkernel.io> X-Mailer: git-send-email 2.39.3 In-Reply-To: <20231218231054.1625219-1-shr@devkernel.io> References: <20231218231054.1625219-1-shr@devkernel.io> MIME-Version: 1.0 X-Rspamd-Server: rspam09 X-Rspamd-Queue-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ct9hnVkT 4CmIrmvGbbirCjQ2zye/+LCEkbuqLRcZJ64eA 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 10e2696907250..82688fc6f119f 100644 --- a/mm/ksm.c +++ b/mm/ksm.c @@ -458,6 +458,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)