From patchwork Fri Jul 5 03:15:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Li Wang X-Patchwork-Id: 1957098 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=HFf0Cu2S; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.linux.it (client-ip=2001:1418:10:5::2; helo=picard.linux.it; envelope-from=ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it; receiver=patchwork.ozlabs.org) Received: from picard.linux.it (picard.linux.it [IPv6:2001:1418:10:5::2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4WFdtc0VJnz1xqw for ; Fri, 5 Jul 2024 13:15:19 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id C23533D3D17 for ; Fri, 5 Jul 2024 05:15:16 +0200 (CEST) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-5.smtp.seeweb.it (in-5.smtp.seeweb.it [IPv6:2001:4b78:1:20::5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by picard.linux.it (Postfix) with ESMTPS id D095C3D3CE9 for ; Fri, 5 Jul 2024 05:15:13 +0200 (CEST) Authentication-Results: in-5.smtp.seeweb.it; spf=pass (sender SPF authorized) smtp.mailfrom=redhat.com (client-ip=170.10.133.124; helo=us-smtp-delivery-124.mimecast.com; envelope-from=liwang@redhat.com; receiver=lists.linux.it) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by in-5.smtp.seeweb.it (Postfix) with ESMTPS id 849CA600F8D for ; Fri, 5 Jul 2024 05:15:11 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1720149310; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=papE8zaFuP2O5faDmq71axnYBZVZR6shGu76OLKtqts=; b=HFf0Cu2Sl7wrlKAOVAL1Vf57N1q9MgOtBk+QUpzmM+HghPBcR8NnH+v3z0GMiKpqKkPGlD U79qTPBhy0bvjb3hrIIbM/JtvE89VEKitCZNsl+yHpZqt6wgUoH6JZb3FTeEDdO33P1YqH WfIZ47YcLWrJsaWVNMG2Z1szgK+ek8A= Received: from mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-206-MfJEDZqLOxKHYvr1Uy3FHw-1; Thu, 04 Jul 2024 23:15:08 -0400 X-MC-Unique: MfJEDZqLOxKHYvr1Uy3FHw-1 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id D0F20196CE3E; Fri, 5 Jul 2024 03:15:07 +0000 (UTC) Received: from fedora-laptop.redhat.com (unknown [10.72.116.64]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 720D83000180; Fri, 5 Jul 2024 03:15:04 +0000 (UTC) From: Li Wang To: ltp@lists.linux.it Date: Fri, 5 Jul 2024 11:15:02 +0800 Message-ID: <20240705031502.9041-1-liwang@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=0.1 required=7.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,NORMAL_HTTP_TO_IP,NUMERIC_HTTP_ADDR, SPF_HELO_NONE,SPF_PASS shortcircuit=no autolearn=disabled version=4.0.0 X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-13) on in-5.smtp.seeweb.it X-Virus-Scanned: clamav-milter 1.0.3 at in-5.smtp.seeweb.it X-Virus-Status: Clean Subject: [LTP] [PATCH] perf_event_open: improve the memory leak detection X-BeenThere: ltp@lists.linux.it X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux Test Project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" The goal is to add more robust memory leak detection by periodically sampling memory availability during the test run and checking for significant decreases in available memory. To avoid false postive: perf_event_open03.c:95: TFAIL: Likely kernel memory leak detected Signed-off-by: Li Wang Reviewed-by: Martin Doucha --- .../perf_event_open/perf_event_open03.c | 32 +++++++++++++++---- 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/testcases/kernel/syscalls/perf_event_open/perf_event_open03.c b/testcases/kernel/syscalls/perf_event_open/perf_event_open03.c index 7dd31d3d2..1aab43e82 100644 --- a/testcases/kernel/syscalls/perf_event_open/perf_event_open03.c +++ b/testcases/kernel/syscalls/perf_event_open/perf_event_open03.c @@ -26,6 +26,7 @@ const int iterations = 12000000; static int fd = -1; static int runtime; +static int sample; static void setup(void) { @@ -77,22 +78,41 @@ static void check_progress(int i) static void run(void) { - long diff; + long diff, diff_total, mem_avail, mem_avail_prev; int i; - diff = SAFE_READ_MEMINFO("MemAvailable:"); + sample = 0; + diff_total = 0; + + mem_avail_prev = SAFE_READ_MEMINFO("MemAvailable:"); tst_timer_start(CLOCK_MONOTONIC); /* leak about 100MB of RAM */ for (i = 0; i < iterations; i++) { ioctl(fd, PERF_EVENT_IOC_SET_FILTER, "filter,0/0@abcd"); check_progress(i); - } - diff -= SAFE_READ_MEMINFO("MemAvailable:"); + /* + * Every 1200000 iterations, calculate the difference in memory + * availability. If the difference is greater than 10 * 1024 (10MB), + * increment the sample counter and log the event. + */ + if ((i % 1200000) == 0) { + mem_avail = SAFE_READ_MEMINFO("MemAvailable:"); + diff = mem_avail_prev - mem_avail; + diff_total += diff; + + if (diff > 20 * 1024) { + sample++; + tst_res(TINFO, "MemAvailable decreased by %ld kB at iteration %d", diff, i); + } + + mem_avail_prev = mem_avail; + } + } - if (diff > 50 * 1024) - tst_res(TFAIL, "Likely kernel memory leak detected"); + if ((sample > 5) || (diff_total > 100 * 1024)) + tst_res(TFAIL, "Likely kernel memory leak detected, total decrease: %ld kB", diff_total); else tst_res(TPASS, "No memory leak found"); }