From mboxrd@z Thu Jan 1 00:00:00 1970 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 8E3B2C3DA7F for ; Sun, 4 Aug 2024 03:46:33 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A3E0F6B007B; Sat, 3 Aug 2024 23:46:32 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 9C6216B0082; Sat, 3 Aug 2024 23:46:32 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 83F8D6B0085; Sat, 3 Aug 2024 23:46:32 -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 5CB376B007B for ; Sat, 3 Aug 2024 23:46:32 -0400 (EDT) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id C4B58A8242 for ; Sun, 4 Aug 2024 03:46:31 +0000 (UTC) X-FDA: 82413175782.22.F585F5C Received: from mail-yw1-f178.google.com (mail-yw1-f178.google.com [209.85.128.178]) by imf05.hostedemail.com (Postfix) with ESMTP id E799210000F for ; Sun, 4 Aug 2024 03:46:29 +0000 (UTC) Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=hIjeZK3b; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf05.hostedemail.com: domain of qiwuchen55@gmail.com designates 209.85.128.178 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=1722743123; 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-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=aKeNnkpQpwJqSEwqqAlpkjAwyz2FvuskXOfxkNi23iw=; b=72MsvqNIu23f8Acpjbepe4eB+ULVjKZZxcDWmJ9QCpy5O9hspB/SuVDkaK0HxXGyec+HxD zg3lN8VDjBQ47qc1GwH1aBNwC+Vzg83tq8duDeg3BWI+7s2E0AjzoIUo0Wbw8P8osmTm5z ujeeduEwn9vOrKmI6VF8Zy9FRRBr7mw= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1722743123; a=rsa-sha256; cv=none; b=AVwScjEjZ0COluFSFY5EFRAHvHxjADKeQmoGbe8N6f41nxj/BjVGfrN1YjNAPjUSoC33Rr y30UWT1z3L/TbWpr/HwCZ87N9FcRqkovVy025x8B92Z8/UMjeoQelzSUuNCdZ1TRIiTKNP yWeNkNVNyPNF6yCTysj+awrRLAt6YSQ= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=hIjeZK3b; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf05.hostedemail.com: domain of qiwuchen55@gmail.com designates 209.85.128.178 as permitted sender) smtp.mailfrom=qiwuchen55@gmail.com Received: by mail-yw1-f178.google.com with SMTP id 00721157ae682-690404fd27eso4872287b3.2 for ; Sat, 03 Aug 2024 20:46:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1722743189; x=1723347989; darn=kvack.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:date:from:from:to:cc:subject:date:message-id:reply-to; bh=aKeNnkpQpwJqSEwqqAlpkjAwyz2FvuskXOfxkNi23iw=; b=hIjeZK3bjxtlNlefkXBVP4s3a+3Jno52gIllleXpXwyAZkmNrU16JJD89E9Ge6T30T +xYGZGAH6r5VJGZTERtwX4PgQMTklOmGgGfIxeo7KnI5+SKY+fk1mjLt37mrXFHE6pFR TPvfXpX9GT40AY7n5WYXjcwUPYl4xpAMHsFj+fDBHncm2GKJHvkK/ILgfLj6wQvI9O+K wfrAYE5mZtZ4RahJIp/DDDFqmvQwkUro33dA8Vfd4YMYArDnHFidPdLN/pCVAzRG1Mu9 1udjRBVlqDotN1ZXXEA3+mBSL3GFLsiLG9vYTSBupKGfaZ3OjvZMBBx0XJeAh4GKSrzY l+dw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722743189; x=1723347989; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:date:from:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=aKeNnkpQpwJqSEwqqAlpkjAwyz2FvuskXOfxkNi23iw=; b=gyYXmpM4gVJ6Ys2njGnaxlkE3u/hm88o0v2w3snGcTVihFiOkkor1yiPL3Uor4rN6H xVggomg8WIXs6c84RidsvjwHgqwmKWhgTiuJ0yGGEKyLQb6dtGoqFe79xlDt2pWYEyyR 8k9BJfzlYIa4GY4kyL0nO1EGxhmNQ+yrFafl1CuJZP0t/P/4G1G6vOqCLVSZlCRs6ddH 83xqXK3V1iZ9GNGRTMsOoTKxr1+TpMvun3DWXJ4qN7AliQ7yK26jWFwO18zPLBSlBDHD pcQ7UVlh1xDYfkYG5p+WEjZtQnh1ic0glMlptAGxjYXyoYUn2ztmRbcAnCTCXINls2Ep cWUw== X-Forwarded-Encrypted: i=1; AJvYcCXyO0YNvXW5afoXapuRmnEM+ophqcwn3rhl/G0EzIzuCE0aaD84VuQWU7vBWJXXVksfbbMTX6NgCOXC/s8DSzxPgY4= X-Gm-Message-State: AOJu0Yw65+Y4nCU5Gr7RDNky0DfWvNhb8a39QNjaiSLNwif+3VRMmjQc 29x7JOV0R80fERs82PUqfZE5lDZ0ip5xz+K1HOKhTypdGdu+IMo/ X-Google-Smtp-Source: AGHT+IHFCrV5HGKQnVIpqCcluy1ItfHNTh3QPmsNchXRTIuw46Sl8nXUakINME1bO8yDy41IUZXOAw== X-Received: by 2002:a0d:ed83:0:b0:664:a26e:5ab2 with SMTP id 00721157ae682-68960491085mr85910277b3.11.1722743188892; Sat, 03 Aug 2024 20:46:28 -0700 (PDT) Received: from localhost ([183.226.244.186]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-7106ece3b99sm3499202b3a.98.2024.08.03.20.46.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 03 Aug 2024 20:46:28 -0700 (PDT) From: chenqiwu X-Google-Original-From: chenqiwu Date: Sun, 4 Aug 2024 11:46:07 +0800 To: Marco Elver Cc: Qiwu Chen , glider@google.com, dvyukov@google.com, akpm@linux-foundation.org, kasan-dev@googlegroups.com, linux-mm@kvack.org Subject: Re: [PATCH] mm: kfence: print the age time for alloacted objectes to trace memleak Message-ID: <20240804034607.GA11291@rlk> References: <20240803133608.2124-1-chenqiwu@xiaomi.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: E799210000F X-Stat-Signature: gqkcubkezkym883y5ohdr6tyen6h8a7y X-Rspam-User: X-HE-Tag: 1722743189-535553 X-HE-Meta: U2FsdGVkX1+cEdxtLy/snACjOK0ahqiP9R5FJjnNrwSIhoun/sFSVW1M/xm7PkpifByf0vXoTNrC3oa0R3uywCDYAkJZolH7D8NlkveNnXXYxGqzhotvw3vW2wH6vMwz6E2xbJGDx80CCCsunhQ3eI01cHzoB4k4Z5izcmXVTQSIomosg1S0gLht8gwCWv7Uvdf4wJHA+RSTZndfvjebaw6VDeke/M9+tIEuf6ELCS4fEJSjASN76iAg1+vqqPaHEWNukERJDfElXXZevwDwu+WeJXdjZgbDrdI4v3OVdDMblAI+6PtXTZo+c6/2Lj+cqJJng2oRLca7XaCb15pwt5vKDVHYR+qk4ZGgkcy2fYKGVjK03zjTAqFbWQAv1dJ9qdcejcC4p5qcYdvAACyqu+/mGWHPsMdx+jKcw8SD00TEQgVrxLYH9HlxGmF31QJJh4pwiW3lRZ96c1ELsuExcmOFgV6i7v/ASKe+ZpgSJ7Kb7kCdAooxg+lpEjWzGWJQqFV57Lyd4KAp0QqB1Ff68ZzhJ0yHPdS1MkAtoC9m6jlrm85sJGugwAqI13Ihbf0+OjQrGj003XR6t/h8NLrcb4NMftSjOhNws5MMdGtUkpvBD4OrV1/N0ed7H4Hnw6aEzzE/XwQdS+YPkNHf1CO95s6Dx2FYuC66Iegr/siMNc+UjOjavs72mBwZ2f0jmGbT8gOUc3+CN9T8Jjg2gfrpRK3SaLNZp4Y7KewOcR0fgl/DjgO+MgeQ6wW2VBS1XHQf42PaB/Pa9HCAvmC1L6OZnzByERhyGEqLKJEL5GWiWuPPZX3DldAr+Ov3JYq/TpkMdNbu59x3uzIoT87Zvb2xBeXa1bnsbiE/U8uoLJVjivbETQ4zLe5DkCsAdBX+aUwzaCSQNM3MPXWuCEJ2mnH0jHTkomO0mFX8uq8v0u+McKOVz5CUjLMg/ZuruehN0cHCcNhomlaiJ46ZtWAn3IM RK1R8sqR pcGMeEPtK5P2HidmlhcATjogPRIzLRx4cvugG/jYKalyomePZVIRd7H8RBDv52mdxwWo+buYKse5Dl+eL/vnzDGYqaU2WWX3FYyp3748C9DU2hheX0PxcDE6p1H6bwMQ8aU9nzyGdN7eaxpvIaMurzD5PL26dVMrfYHdrM4im0pmhvXgYplpZrRf/X+u85406mH/w31zM+X0IJWUhQ1ytL2/zZMLCPxIHRvf8Ll3gvKqsYM7AbJ7d+UdW/9hM/C2iwrDnKQ4BzMw7FnnqLJxQ5zx1WSaJW768nV9+uY//rrMAddx/U1Oyst5JwJpF/HJ/pkoQNOkRMEZYRPGaW48r6b3fq6isikdR3wEicJlUojXQiOkzFvV7du6aVw== X-Bogosity: Ham, tests=bogofilter, spamicity=0.002660, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: On Sat, Aug 03, 2024 at 04:51:45PM +0200, Marco Elver wrote: > > typo: convenience > > What do you mean by "object leak"? > It means an allocated object of slab memory which is considered orphan, perhaps it's more clear to say "For a convenience of tracing memory leaks by kfence", what do you think? > From what I see the additional info is only printed on out-of-bounds access. > > Or do you mean when you inspect /sys/kernel/debug/kfence/objects? If > so, that information would be useful in the commit message. > The extra elapsed time of current allocated object would be useful to figure out memory leaks when inspect /sys/kernel/debug/kfence/objects. > However, to detect leaks there are better tools than KFENCE. Have you > tried KMEMLEAK? KFENCE is really not a good choice to manually look > for old objects, which themselves are sampled, to find leaks. > Have you been able to successfully debug a leak this way? > The kmemleak tool has limitations and drawbacks which cannot be used in productive environment directly. KFENCE is a good choice to find leaks in productive environment. > > alloacted objectes in kfence_print_stack(). > > typo: allocated objects > Thank's for your comment. > > In principle, the additonal info is convenient, but I'd like to > generalize if possible. > > > + 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", > > I've found myself trying to figure out the elapsed time since the > allocation or free, based on the current timestamp. > > So something that would be more helpful is if you just change the > printed line for all alloc and free stack infos to say something like: > > seq_con_printf(seq, "%s by task %d on cpu %d at %lu.%06lus > (%lu.%06lus ago):\n", > > So rather than saying this info is the "age", we just say the elapsed > time. That generalizes this bit of info, and it'll be available for > both alloc and free stacks. > > Does that work for you? > It does not work for me actually, since it's unintuitive to figure out memory leaks by the elapsed time of allocated stacks when inspect /sys/kernel/debug/kfence/objects. It's unnecessary to print the elapsed time of allocated stacks for the objects in KFENCE_OBJECT_FREED state. For the elapsed time of free stacks, it seems no available scenarion currently. BTW, The change from "age" to "ago" is okay to me! > > 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 > > Add braces {} even though it's a single statement - it spans several > lines and the above is also {}-enclosed, so it looks balanced. > > But if you follow my suggestion, you won't have the else branch anymore. > I'm not opposed to convert a single statement, but it will have an effort to find leaks. This change will be helpful to find leaks easier by grep "ago" keyword when inspect /sys/kernel/debug/kfence/objects. Thanks Qiwu