From patchwork Sat Aug 3 13:36:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: chenqiwu X-Patchwork-Id: 13752385 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 6127CC3DA4A for ; Sat, 3 Aug 2024 13:36:20 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5A0336B0089; Sat, 3 Aug 2024 09:36:19 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 550816B008A; Sat, 3 Aug 2024 09:36:19 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 417D86B008C; Sat, 3 Aug 2024 09:36:19 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 23BB46B0089 for ; Sat, 3 Aug 2024 09:36:19 -0400 (EDT) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 4AED78141E for ; Sat, 3 Aug 2024 13:36:18 +0000 (UTC) X-FDA: 82411033236.16.B96AE11 Received: from mail-oa1-f44.google.com (mail-oa1-f44.google.com [209.85.160.44]) by imf27.hostedemail.com (Postfix) with ESMTP id 8E82640006 for ; Sat, 3 Aug 2024 13:36:16 +0000 (UTC) Authentication-Results: imf27.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=ODR0O0vn; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf27.hostedemail.com: domain of qiwuchen55@gmail.com designates 209.85.160.44 as permitted sender) smtp.mailfrom=qiwuchen55@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1722692170; a=rsa-sha256; cv=none; b=dQIURy/Flu5uwNYvu/Tz/byC18h4BCxk5gfGaIDctF/jjCUv4nUcX/nTky7+jWEubQI012 KCt9YL3Ywh5B81UQFhv6mXzRXAPtFNb/KkR6UgIdAiFBRUDtZtx4BlHhJduOknE6TFqenx 5mc9X23+PexNTlOYohWjBPoxBSyuaYs= ARC-Authentication-Results: i=1; imf27.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=ODR0O0vn; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf27.hostedemail.com: domain of qiwuchen55@gmail.com designates 209.85.160.44 as permitted sender) smtp.mailfrom=qiwuchen55@gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1722692170; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:content-type: content-transfer-encoding:in-reply-to:references:dkim-signature; bh=/76okRFWOXJC7JJ9KQhVHqF3l6rzQxaPyzz3y9bru5Y=; b=FQViyukFTizDaqwtMS/CXFWxzvRDUFjen6VPzQUbd96v8GnSAM6nheKyfHpRk9TPrQMlqP Cr4ZOPJyysvt8xARC6JPOA1BkKGDFnImdFlUNMetlQPr3eTXx74q8Y8wc5OzxSoY1/FTo2 bNOtw0iNXP60vrJNGE9xxOg6CnaGVXU= Received: by mail-oa1-f44.google.com with SMTP id 586e51a60fabf-264a12e05b9so5249490fac.1 for ; Sat, 03 Aug 2024 06:36:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1722692175; x=1723296975; darn=kvack.org; h=message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=/76okRFWOXJC7JJ9KQhVHqF3l6rzQxaPyzz3y9bru5Y=; b=ODR0O0vnj2/b2sH0X6bbf+5Y5Pf5kKG4W2PMabGCW02QfWwPKd+WWepZNQxKHpMfoL riJl0LPsiVYRZguTewcrcds2MXKBxnnCPG+HjBJ+0fuoeu++ihSPEtkjGrmR4ivWF+bv JmGvJSZrgxU3HAXaG2xqFx3zzGuJlieiEQyZhbaXgfTfBjdw2HNHPcUaX0RekgPPMJw5 VvX9Smyp8Pqc21/VD56zqblp7xUQ0ED94FSI/Dl/zWKeO5dj7mZahz/LEXlhxm+elSL5 tp6C2GujK6bbPbMHBm1CYnGeNsXs4bfx45FJfBWtetVte3a0MIugmO0w2TFXl1GVcvf0 Skxw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722692175; x=1723296975; h=message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=/76okRFWOXJC7JJ9KQhVHqF3l6rzQxaPyzz3y9bru5Y=; b=nl1tAxgT/G7kXOTBRxZ5vXi/ab6U+mxXpdmK0wFLCZPiWiGzJymKZKi0zsYMyJZmSD phvh8QZ5Dw/y9v0aKA+hgTj9w/YzwPaBPdSaqYgcXHsynf2qCvZyzVLubxlWN724MPtd rgUC0/ZXGOJCXlGHGyNFmTphpV0Kuq47PamaKxZX1ulASSZzGeNvvyr8nuo4KQnCZEOC Vrzn5rLHUPKZoO+demBvbT3pEtjQTbASF7fnr0dRGVZAK4VEoGZsYUwEeIkwZBgq/A60 LrFuwH3ZBGHcwOfjAEUptHUX6nzm0/QY2ekhrzEQR47XFPPoPWcZOpzNd82NTp0BloHY mKUQ== X-Forwarded-Encrypted: i=1; AJvYcCVF4MkwVibnLqvpuBqRwKx49kZ7QdNwBTqRz+33Ju7+zYo/BrsXb10t8EW3TdaUubG4f8f+E2FBQICmGgGFoaXmV5g= X-Gm-Message-State: AOJu0Yyp/Uh5FW+dNXW2lvDlXF0RvIweeTKKh8RfOUPp3X95nBmsGX/1 7tCzB50pBknqIMpxXPg3vHxqE6kAOTi02sMgLENYz6i8ZJTmr94F X-Google-Smtp-Source: AGHT+IHdNfDR7R2UfLIHBPTE92C4N1nf4jEkrmvK8yzXpWuz5isggzmi4Yda6pBDgUsdRjQz0CpOWA== X-Received: by 2002:a05:6871:3325:b0:261:218:dae with SMTP id 586e51a60fabf-26891ea8f86mr8392010fac.33.1722692175477; Sat, 03 Aug 2024 06:36:15 -0700 (PDT) Received: from localhost ([183.226.244.186]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-7106ec4169csm2775658b3a.64.2024.08.03.06.36.14 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sat, 03 Aug 2024 06:36:15 -0700 (PDT) From: Qiwu Chen X-Google-Original-From: Qiwu Chen To: glider@google.com, elver@google.com, dvyukov@google.com, akpm@linux-foundation.org Cc: kasan-dev@googlegroups.com, linux-mm@kvack.org, "qiwu.chen" Subject: [PATCH] mm: kfence: print the age time for alloacted objectes to trace memleak Date: Sat, 3 Aug 2024 06:36:08 -0700 Message-Id: <20240803133608.2124-1-chenqiwu@xiaomi.com> X-Mailer: git-send-email 2.17.1 X-Rspam-User: X-Rspamd-Queue-Id: 8E82640006 X-Rspamd-Server: rspam01 X-Stat-Signature: ynenf78fej7xgum6wfzrqmaergkuqiyk X-HE-Tag: 1722692176-128712 X-HE-Meta: U2FsdGVkX1+ZCQancpBzJa0ssM0N0VYxpxNPobncFtmccWSEn5wWpPQIJ9d+Bgv7+jhWbZ1Q3N0B4jiafFEw8oYeOOlpOSHQ4FjDeWyjZ6DUwa6eFU20/CL9eq8mGcWDFlITSEmbRD5DckteWOwLO7bNmFGdUWHoaWOQ57XLzQLDfSuv579XqTOgzpcanEt6uf7h2HUJDs01pSLc1b+/RLtOv0MMZLFwXe2ZXcTalUQYnSOL+AGs87Org1IRouJoXKXtraHpBWZQWg3h0uOMMS0mj6dsKqcYqxiTmWys4G8qStvMHIVKVoBNH6UjK1TGhGhofg5aZHUxtfQRgPW5RT1Secp1kI3/FW/XoHMEPc6nWEv4QjHRws+FD9vhrS7f9Aem6Nt+Gwr3YACUKaF2Jar5T1JEbQY/vwNhVSbzQquaQOMR5DJrm3oR1y/we1y8HmHERsKTTKcwDlE8b6+BD6IL3BteE8svgKERhdvuuKwoGiUhI6grjVAau3jMhMSOhemktw5kM4nrZDPsfdZdHmudeC8+8pNKnvropjekfH4MN+oq62Bzr4VOtC2esPha3ZRaxCWxLwjuA7tMipvkMCwJOo56gkKdugIWgpO9dDrWxr+u4JvrRwI0SkuiSglFTsQmtKwWN4/tEpeQ4fjrV5n6sn0PTknxcGQXP8kPSv80C9o/KiOBjOVgd0iYt8VQr7mj+yenzYDYKuRUoV1Yy2o/qh/TOon739GbhtgaGUUbCU3KOpfoSTvyeY9iUulHXHMKZ9dEDP55wuf37EJQ+/fsjEmGwtYx17dhYupb6UHhEuGJLH/EH0DqwrORyZpwBZr2navdGg/qUQnSkdPtvYQgDiD4zmM4FATXoEkoyCikEcK4RrMNQqk6eg2pODD71fzz4FxJKnqo4Lk0vkyPRT3ByntKxHmLs6UQSecLJm2WsevTR91m+hz2Zlv6kPOTKUKz0vycxbj/xyLnpoS /JEEvB8u 5VuFFfxZK4jPteD4w86SqAjHTFEpOEuQQSb9ECCEPR0Glb5apxU6iBsR75+scf0QY6fkijeFuKB2WDqUWnAcXv3ToVY/6eSaPs2rIq8u5bkvmypt/kThZQ+pQVFOxfC67ipyCawmWmoa/621j1qESz1eCBzzVHsbLQ79BvZO3c9UO4HHUBQSMEvhiSrqH8aad7s8Of/+Q7TkQ7RDA1MK8SvFwaPJxmLt12+e1Fzj06wSEzti9pWUVFKhfFjcOj5qr2y3cRvOVzjcBEIsaCCPFVJo23tCAYcz22AA8kAG+0C4M9yOiiMmN4Ji2IxD6wkwA3pAwGVyMvNZqMFqSwuAe1SjTaQ== X-Bogosity: Ham, tests=bogofilter, spamicity=0.290091, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: From: "qiwu.chen" For a convienince of tracing slab object leak, print the age time for alloacted objectes in kfence_print_stack(). Signed-off-by: qiwu.chen --- mm/kfence/report.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/mm/kfence/report.c b/mm/kfence/report.c index c509aed326ce..44c3f82b25a8 100644 --- a/mm/kfence/report.c +++ b/mm/kfence/report.c @@ -16,6 +16,7 @@ #include #include #include +#include #include #include @@ -110,9 +111,18 @@ static void kfence_print_stack(struct seq_file *seq, const struct kfence_metadat unsigned long rem_nsec = do_div(ts_sec, NSEC_PER_SEC); /* Timestamp matches printk timestamp format. */ - seq_con_printf(seq, "%s by task %d on cpu %d at %lu.%06lus:\n", + if (meta->state == KFENCE_OBJECT_ALLOCATED) { + u64 interval_nsec = local_clock() - meta->alloc_track.ts_nsec; + unsigned long rem_interval_nsec = do_div(interval_nsec, NSEC_PER_SEC); + + seq_con_printf(seq, "%s by task %d on cpu %d at %lu.%06lus (age: %lu.%06lus):\n", show_alloc ? "allocated" : "freed", track->pid, - track->cpu, (unsigned long)ts_sec, rem_nsec / 1000); + track->cpu, (unsigned long)ts_sec, rem_nsec / 1000, + (unsigned long)interval_nsec, rem_interval_nsec / 1000); + } else + seq_con_printf(seq, "%s by task %d on cpu %d at %lu.%06lus:\n", + show_alloc ? "allocated" : "freed", track->pid, + track->cpu, (unsigned long)ts_sec, rem_nsec / 1000); if (track->num_stack_entries) { /* Skip allocation/free internals stack. */