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 D1200C3ABBF for ; Thu, 8 May 2025 00:02:07 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id AC9366B0085; Wed, 7 May 2025 20:02:05 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A77C56B0088; Wed, 7 May 2025 20:02:05 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 965236B0089; Wed, 7 May 2025 20:02:05 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 778DD6B0085 for ; Wed, 7 May 2025 20:02:05 -0400 (EDT) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 962CFBEB74 for ; Thu, 8 May 2025 00:02:06 +0000 (UTC) X-FDA: 83417787852.10.2941073 Received: from out-188.mta1.migadu.com (out-188.mta1.migadu.com [95.215.58.188]) by imf03.hostedemail.com (Postfix) with ESMTP id 8F1F920003 for ; Thu, 8 May 2025 00:02:04 +0000 (UTC) Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=k6ccbOhD; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf03.hostedemail.com: domain of kent.overstreet@linux.dev designates 95.215.58.188 as permitted sender) smtp.mailfrom=kent.overstreet@linux.dev ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1746662525; a=rsa-sha256; cv=none; b=Qg1UaL1N4id85jjtq96JZ1FGXcTfe+duVUpZG4fWXc9T/ig55BXbCNUrjOWbSuKHH9T2uQ SK6EtaGulsA1UcOm8/LV5Ym8jyWtqVr13oLzfO/jsKkdCnmrkG9B/iDfuk80UT6P8RYATv yiWEne1CBQ7ZmIjLTJHg0jpLdtf/nho= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=k6ccbOhD; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf03.hostedemail.com: domain of kent.overstreet@linux.dev designates 95.215.58.188 as permitted sender) smtp.mailfrom=kent.overstreet@linux.dev ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1746662525; 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:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=YKAtqXzVTLH8wPvJLES2aUCAeeyN4Lo1bqm+iZNm+TQ=; b=4YubQyAk+YQrzt/e0GE1QwlOyg4s8J4KPfnR01EGLtc7hrfG2gh5Pe3U9uzcRoZrwzbTWH /+VgCbvuD5ozFHlvAZExzjPCOxTVe3I0dQc0wCJtwZ8s3k/4EXHpiDB524yW8Cbqn7eD38 jItHSuTnfMBW3V5DuJx8gNwM9xwhY+k= Date: Wed, 7 May 2025 20:01:55 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1746662521; 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: in-reply-to:in-reply-to:references:references; bh=YKAtqXzVTLH8wPvJLES2aUCAeeyN4Lo1bqm+iZNm+TQ=; b=k6ccbOhDSului3wVk45CKX2d5nPbGxOU/HxjeZ2RAG6ZVtQqJoxdMFrLGJ2fF/5BI+U6dv /e5fM1gToFZZtWdIfkHiJRE8YN9Ro6vnocB7YgBl75BNyBt0CfJPGjLJYrUF8Tf1H9BHcQ llMjvJjUdbrGWQ5OAaNeMt6EnNWyKrM= X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Kent Overstreet To: Suren Baghdasaryan Cc: David Wang <00107082@163.com>, akpm@linux-foundation.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] alloc_tag: avoid mem alloc and iter reset when reading allocinfo Message-ID: References: <20250507175500.204569-1-00107082@163.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-Migadu-Flow: FLOW_OUT X-Rspam-User: X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: 8F1F920003 X-Stat-Signature: qn7p8s8fxhbgmuxztefuj87jyhat9en7 X-HE-Tag: 1746662524-80567 X-HE-Meta: U2FsdGVkX19OxjYCl8CO0Dm1RP7UcXQ6Bi1PcdqzuNDzUlvfWekcsMJMO4megH8YLB/8kodk0c6bXKf575VQqsZWJ7aiTuHj2U5VFZ5vAiGgX4oSbtn54YNm6CiEUd//wpihummymtxMgz9ev7Kzvlt/d0LVH2wR2IZxXQY9Tf8s6HWsuQMO9kp/q8YLWQpxA8mF1s+nBl7IoLzS4m0N8cyg+5uxjJfZRztvLZ3xFNz7w8Z4Cx5mTPz8SXAWyZFqOxAKLVmRMKRu/ANWkkz5U2TKGVaXk1DmD9Mj5lMNSJ8/JtqkcqNLjw4j0jie62QfEJFSMkPQ6kaK5YyzjIbm4cmTflen+ka9FVyPKdeElsiwzswWZq7ImMKzgboKwrV87gceBgd1Obg9H66T54DFU5f8x4sg0HI3rghlnyxz+uNLwy/x7zc7OOA6LUiveN4odWgLoTvcId2WZ6pYXXaOHFCDN5do7oGd5XxfkII5bcSr8xSO6HccZS2jfI5nQYwhkI7MS+pxc1K0NWi6DMUg57nAmrvw/CLHTpq5l4gzR9je5Y2kOaNy8EECMArmv2AldgPSMXzyH1YRiFNvqtlIkuEksGtln5nmF1i1mmrwSTSolEAB0JnqNBXrOPGHIB3/GpicoyFsUamq5b5Tol9QpZi77vNoblLX2EfxAS97CEKyu3OxjnXjyjcNZE2o0N5eStId3nr0j5R8t5vqG07hapT1QbdMU3NgjIorbgDrLWF17bSUxx8ZJxTWjY7ccm739d2ZXv4ASftGohAFsyVGCM/tU5r4oKceUSZ8Uwi6OqW9fvc3p0dANS1iKNay2B17H7GeK3sgJvsIdlPpzo0F63d4fSCLV1YfRAQxkWPFexp+MEAz4ZZWfSRUkQAFRV5sbe+iMclNbzQIFSX9KMlO0OnOxc60kf1mLgx64nm/BUTRlV25oqzyfeDqJnFj/Mgk1mKqGDYxHjmpavywWYA fHZzARSL 9CIFCwMOrSib8WGQOkdffDlIQxaDDcdHhpqUqF4S3ALo30EWu1qiYowfZEZUC3qmVLY9eGxI6G6SklPPyg0HAQeiaV+67lxmAUfVBexnlAA3DW97nuKOA8g6sJZTaliWL2U/ymRxL5lRA6Z7MxeAtqKo21+XgH8ZX33MGgLt1f9o2r+F+ueE8laZZiw2jOwZkdw3VUp1rzjIK917sG0L8B1a4miRy1KLRyV3GNF0ggy9Et6ikpLwefw2usOWQ0grSEx1950Hovc4oIEiGdjxhfMg0Kar6xwgT2VLScw0E7kOgYym9QfgWpGhyQvVIhTkWwPhr0M83UzpnSGLv8xpK0jYmKUhgIzmsjU5IAxlX1Y1II9Q= 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: On Wed, May 07, 2025 at 11:42:56PM +0000, Suren Baghdasaryan wrote: > On Wed, May 7, 2025 at 6:19 PM David Wang <00107082@163.com> wrote: > > > > Hi, > > Just want to share how I notice those memory allocation behaivors: the cumulative counters~! > > > > With cumulative counters, I can identify which module keeps alloc/free memory, by the ratio between > > cumulative calls and remaining calls, and maybe an optimization could be applied. > > Following is top16 I got on my system: > > > > +-----------------------------------------+-------+------------------+--------------------+ > > | alloc | calls | cumulative calls | ratio | > > +-----------------------------------------+-------+------------------+--------------------+ > > | fs/seq_file.c:584 | 2 | 18064825 | 9032412.5 | > > | fs/seq_file.c:38 | 5 | 18148288 | 3629657.6 | > > | fs/seq_file.c:63 | 15 | 18153271 | 1210218.0666666667 | > > | net/core/skbuff.c:577 | 9 | 10679975 | 1186663.888888889 | > > | net/core/skbuff.c:658 | 21 | 11013437 | 524449.380952381 | > > | fs/select.c:168 | 7 | 2831226 | 404460.85714285716 | > > | lib/alloc_tag.c:51 | 1 | 340649 | 340649.0 | <--- Here I started > > | kernel/signal.c:455 | 1 | 300730 | 300730.0 | > > | fs/notify/inotify/inotify_fsnotify.c:96 | 1 | 249831 | 249831.0 | > > | fs/ext4/dir.c:675 | 3 | 519734 | 173244.66666666666 | > > | drivers/usb/host/xhci.c:1555 | 4 | 126402 | 31600.5 | > > | fs/locks.c:275 | 36 | 986957 | 27415.472222222223 | > > | fs/proc/inode.c:502 | 3 | 63753 | 21251.0 | > > | fs/pipe.c:125 | 123 | 2143378 | 17425.837398373984 | > > | net/core/scm.c:84 | 3 | 43267 | 14422.333333333334 | > > | fs/kernel_read_file.c:80 | 2 | 26910 | 13455.0 | > > +-----------------------------------------+-------+------------------+--------------------+ > > > > I think this is another "good" usage for cumulative counters: if a module just keeps alloc/free memory, > > maybe it is good to move the memory alloc/free to somewhere less frequent. > > > > In the case of this patch, a memory allocation for each read-calls, can be moved to opan-calls. > > > > If interested, I can re-send the patch for cumulative counters for further discussions. > > Yeah, my issue with cumulative counters is that while they might be > useful for some analyses, most usecases would probably not benefit > from them while sharing the performance overhead. OTOH making it > optional with a separate CONFIG that affects the content of the > /proc/allocinfo seems like a bad idea to me. Userspace parsers now > would have to check not only the file version but also whether this > kernel config is enabled, or handle a possibility of an additional > column in the output. Does not seem like a good solution to me. Yeah, I don't see much benefit for cumulative counters over just running a profiler. Running a profiler is always the first thing you should do when you care about CPU usage, that's always the thing that will give you the best overall picture. If memory allocations are an issue, they'll show up there. But generally they're not, because slub is _really damn fast_. People generally worry about memory allocation overhead a bit too much. (Memory _layout_, otoh, avoid pointer chasing - that's always worth worrying about, but cumulative counters won't show you that).