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 4DD90C48BC1 for ; Wed, 14 Feb 2024 19:09:46 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D4CE48D0012; Wed, 14 Feb 2024 14:09:45 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id CFCD18D000E; Wed, 14 Feb 2024 14:09:45 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BEC838D0012; Wed, 14 Feb 2024 14:09:45 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id ABE308D000E for ; Wed, 14 Feb 2024 14:09:45 -0500 (EST) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 3BE8B40D60 for ; Wed, 14 Feb 2024 19:09:45 +0000 (UTC) X-FDA: 81791348730.08.E30F0C9 Received: from mail-yb1-f170.google.com (mail-yb1-f170.google.com [209.85.219.170]) by imf06.hostedemail.com (Postfix) with ESMTP id 6A3E8180020 for ; Wed, 14 Feb 2024 19:09:43 +0000 (UTC) Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=ml5EJZPq; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf06.hostedemail.com: domain of surenb@google.com designates 209.85.219.170 as permitted sender) smtp.mailfrom=surenb@google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1707937783; 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=YYQ1iEqH1bC/aeDNG7RWtd5Zq4jRnkeS9Y1nPQkLhuU=; b=LiQmbZ8wKUokVMs3NEVBhXdEhGRkrIwTf64dG3ZqmuwoYxO8eU0jowPhmhmX0saZjtfYQh lClsjpqlJvEZOcmJ2z1PnIKQp3p7lPDU84CIoCdu9KwN8P/zzwrNeyGs/EEm4qvMHZIShx OVWAUFkSq+uAdVLmZr50bF9ISLh+dXI= ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=ml5EJZPq; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf06.hostedemail.com: domain of surenb@google.com designates 209.85.219.170 as permitted sender) smtp.mailfrom=surenb@google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1707937783; a=rsa-sha256; cv=none; b=S6EuafVN95SZYrMXARa4MghTH1VIEXRZtVk/lwidPgO/Bzb5C4wL++WZcsT8BIGuQwlQHE Gvs39kIh1J4H53m6gyv2+jx4UvnXqYaJLHn+6vsSrJQ/PlXTgLsN1Bu8TYZqaUhbnxmpns WQowKeiIogtwQyk4J06TXaPhYR/DKaE= Received: by mail-yb1-f170.google.com with SMTP id 3f1490d57ef6-dcdb210cb6aso925913276.2 for ; Wed, 14 Feb 2024 11:09:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1707937782; x=1708542582; darn=kvack.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=YYQ1iEqH1bC/aeDNG7RWtd5Zq4jRnkeS9Y1nPQkLhuU=; b=ml5EJZPqVlHY9lj7SdrRslUzoCioZO3dxhgjVdIBFh6KK0+Go80gkVxdDfrrQVvPC3 oGmMXbzgxnnAAQ7zSHahs4eJTdUat1aoMFClfNk9OMEtOVdrJF9UIIfKRmWiWqK9BBr/ RnRmS3nJxFY48G/yPiABMEtADq7FIV0p6LTBt5MokLUWIISGpylfGK7ixUCIj/CWjafV L7Tezs4na/BEe4Vd0qFmNMoeOlf7iPi2v1Lj/1xSEI08gUKvzUsbP1Sv4cicEYQit06w XmYedUbFk558R6T7bUpr5vZ2lRRh0cTS+ywV4+z2AjG1fJsVIGW2W0ZNCs72W2RAZCyK IuCQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707937782; x=1708542582; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=YYQ1iEqH1bC/aeDNG7RWtd5Zq4jRnkeS9Y1nPQkLhuU=; b=Xh6mMfpiEJhzanDtowIp8U3Q30kt5Y3EW0HpDKtci4PVFABY4DlaJEZTxSg1V9v49a 9TErqW+u05suuPZ/JDmt4RtwzjX5Noniup3gZ+783NUUYkE/SKp7MUNrPa1KJGaD2QY+ ec4CwxgMSG/iLJj411CBix5U1czdab+1rAjZOQtR10bMrx9pky6MND1tjcms/3Mj02sW ckX8O6TcjqwxNBex6h1PCLQbpsM4I68bDQF4A8yFmhA0HhZXV2gBF1Us2E07UMAyb0nA Siqzm8146NNUutHp0YbiMAK2umLRRY0DIyrDs9vShCUApe2ArZ7+cScwgaluLFK4To0L Jq9Q== X-Forwarded-Encrypted: i=1; AJvYcCXHaFVH8/3HuAvdH7dI/yjmdQvWAXvD/8CVZXTEw8Pq3EU4pMv45A7z+CJuGTvqFdFYalNwi/XVAipWDMC3TLJe8yU= X-Gm-Message-State: AOJu0YypS2PM9qOth0CK2H6XQDahoU+upAWc9Q4KotVHNNfBJ2eRY17r S1IpfdBwDtYVVwMw947G+pJEY7AfR9ziv2j/RfTNT/J8LsL7j/iDbdss2H8VgifQfiWxrQh667C jigIYNLBi516lZENNTd7M6a5eL2eJ0AvwvXS7 X-Google-Smtp-Source: AGHT+IE0myNa43nYnaJsvlAr1q2GXvgjSojXmvsXBpkzj6lBL3cERK/G4k9guWv0KYdWk2/nQyibRz7ihpshNEhuuEk= X-Received: by 2002:a25:2d01:0:b0:dcc:8114:5a54 with SMTP id t1-20020a252d01000000b00dcc81145a54mr3243973ybt.43.1707937782071; Wed, 14 Feb 2024 11:09:42 -0800 (PST) MIME-Version: 1.0 References: <20240212213922.783301-1-surenb@google.com> <4f24986587b53be3f9ece187a3105774eb27c12f.camel@linux.intel.com> In-Reply-To: <4f24986587b53be3f9ece187a3105774eb27c12f.camel@linux.intel.com> From: Suren Baghdasaryan Date: Wed, 14 Feb 2024 11:09:30 -0800 Message-ID: Subject: Re: [PATCH v3 00/35] Memory allocation profiling To: Tim Chen Cc: akpm@linux-foundation.org, kent.overstreet@linux.dev, mhocko@suse.com, vbabka@suse.cz, hannes@cmpxchg.org, roman.gushchin@linux.dev, mgorman@suse.de, dave@stgolabs.net, willy@infradead.org, liam.howlett@oracle.com, corbet@lwn.net, void@manifault.com, peterz@infradead.org, juri.lelli@redhat.com, catalin.marinas@arm.com, will@kernel.org, arnd@arndb.de, tglx@linutronix.de, mingo@redhat.com, dave.hansen@linux.intel.com, x86@kernel.org, peterx@redhat.com, david@redhat.com, axboe@kernel.dk, mcgrof@kernel.org, masahiroy@kernel.org, nathan@kernel.org, dennis@kernel.org, tj@kernel.org, muchun.song@linux.dev, rppt@kernel.org, paulmck@kernel.org, pasha.tatashin@soleen.com, yosryahmed@google.com, yuzhao@google.com, dhowells@redhat.com, hughd@google.com, andreyknvl@gmail.com, keescook@chromium.org, ndesaulniers@google.com, vvvvvv@google.com, gregkh@linuxfoundation.org, ebiggers@google.com, ytcoode@gmail.com, vincent.guittot@linaro.org, dietmar.eggemann@arm.com, rostedt@goodmis.org, bsegall@google.com, bristot@redhat.com, vschneid@redhat.com, cl@linux.com, penberg@kernel.org, iamjoonsoo.kim@lge.com, 42.hyeyoo@gmail.com, glider@google.com, elver@google.com, dvyukov@google.com, shakeelb@google.com, songmuchun@bytedance.com, jbaron@akamai.com, rientjes@google.com, minchan@google.com, kaleshsingh@google.com, kernel-team@android.com, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, iommu@lists.linux.dev, linux-arch@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-modules@vger.kernel.org, kasan-dev@googlegroups.com, cgroups@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Rspamd-Queue-Id: 6A3E8180020 X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: 5cze5diupsyibxq1pr44ey7xhwrm3f6i X-HE-Tag: 1707937783-967012 X-HE-Meta: U2FsdGVkX1+UIwXtkXOWJI1NKmiXRTcIhbxxyZde+q3IPSApVSNuovzdjA060YowrFCfrKhFefvrpVzrC3aGRYyp0WpDAI9wRqhPvtZn8cOQgjSAEU6WYM/TIvbww3WsRW/EmANvTYG+f8MWWqytmqteH41tkyCysbG64yf4xkzhchAO+GDkTLSqjZc7XskpzSmjC7WSIO9vuJrlbuIzctwWig2CTR0t2LgOQPxQAr2KmeUVkh5GgmDYJTmU+dA1B1MMyjt/88nNFrnfXWw4lEWxEbYms/y+bELHtTzMBY/x8eBkiTXHso8/9MJha1ZMt7CDa+hrOind2HuYPjKipGRWD0F5saYe1qt1SO/w4cqkAfkRwCogw2PJSy3YSuZAhIfS7wieeuvdPUaXFK4gjalGa/t1Ol2auMDMp2c7vvK7p5Xn7rzovSpqoVXBxWL7mlGsj3sfH/50RkYSJ8hx9Q/OziHqxEKSOVD/Phq+yHnPE4oJoeJlcwD7egUD6kD497vF2fLTlXjZJlpUgzzmHLq2lLQt1FEqMO7/ap37Mf+aaVenFp7mh2doLWDVOpP66w6LUdVMnHrhbouBvPjYGcijs03wiKbi6LlFsUhJ4xu2Cq2dwHzRS+4IR56xKEeg4ucfc0SOS2Qsez10D3KBQY3Pa6C7xlGYGXEvtMU+r8IShN5CI8baECrgd7Fuy6vxlQkJ5JDGOZSfr4MzsWOr/VVRirGip2jsx5Nxee448p3lCQpEnFkLNrdsmqud8GkcxhSZ7qC/xuzPllHO2fWl8wvBRIul5PVRoPJc4zJiiZzGdZLURVPXqCXVcdnyn0fcujwet4t8P6RRz48Bk17VSHIDMZYD4MzqsoRdG6NGSxae+08p1CiZlC0cBGJpOLcYVO5o2egfxm6c02aYfYsfBZ1Lv9GKTtjxpE10ZTzakPyXRXIZSJ3c5LC8f4usyvAAB/4M/ed+cl+FFLIcObm +V3Vh2X7 SThyZ+/fBTDkRoVGrmTBktB5aNo9/Rey8cM59YCOVlLAssAhZl46HcTKy9qUncHn0jjIM 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, Feb 14, 2024 at 10:54=E2=80=AFAM Tim Chen wrote: > > On Mon, 2024-02-12 at 13:38 -0800, Suren Baghdasaryan wrote: > > Memory allocation, v3 and final: > > > > Overview: > > Low overhead [1] per-callsite memory allocation profiling. Not just for= debug > > kernels, overhead low enough to be deployed in production. > > > > We're aiming to get this in the next merge window, for 6.9. The feedbac= k > > we've gotten has been that even out of tree this patchset has already > > been useful, and there's a significant amount of other work gated on th= e > > code tagging functionality included in this patchset [2]. > > > > Example output: > > root@moria-kvm:~# sort -h /proc/allocinfo|tail > > 3.11MiB 2850 fs/ext4/super.c:1408 module:ext4 func:ext4_alloc_in= ode > > 3.52MiB 225 kernel/fork.c:356 module:fork func:alloc_thread_sta= ck_node > > 3.75MiB 960 mm/page_ext.c:270 module:page_ext func:alloc_page_e= xt > > 4.00MiB 2 mm/khugepaged.c:893 module:khugepaged func:hpage_co= llapse_alloc_folio > > 10.5MiB 168 block/blk-mq.c:3421 module:blk_mq func:blk_mq_alloc= _rqs > > 14.0MiB 3594 include/linux/gfp.h:295 module:filemap func:folio_a= lloc_noprof > > 26.8MiB 6856 include/linux/gfp.h:295 module:memory func:folio_al= loc_noprof > > 64.5MiB 98315 fs/xfs/xfs_rmap_item.c:147 module:xfs func:xfs_rui_= init > > 98.7MiB 25264 include/linux/gfp.h:295 module:readahead func:folio= _alloc_noprof > > 125MiB 7357 mm/slub.c:2201 module:slub func:alloc_slab_page > > > > Since v2: > > - tglx noticed a circular header dependency between sched.h and percpu= .h; > > a bunch of header cleanups were merged into 6.8 to ameliorate this [= 3]. > > > > - a number of improvements, moving alloc_hooks() annotations to the > > correct place for better tracking (mempool), and bugfixes. > > > > - looked at alternate hooking methods. > > There were suggestions on alternate methods (compiler attribute, > > trampolines), but they wouldn't have made the patchset any cleaner > > (we still need to have different function versions for accounting vs= . no > > accounting to control at which point in a call chain the accounting > > happens), and they would have added a dependency on toolchain > > support. > > > > Usage: > > kconfig options: > > - CONFIG_MEM_ALLOC_PROFILING > > - CONFIG_MEM_ALLOC_PROFILING_ENABLED_BY_DEFAULT > > - CONFIG_MEM_ALLOC_PROFILING_DEBUG > > adds warnings for allocations that weren't accounted because of a > > missing annotation > > > > sysctl: > > /proc/sys/vm/mem_profiling > > > > Runtime info: > > /proc/allocinfo > > > > Notes: > > > > [1]: Overhead > > To measure the overhead we are comparing the following configurations: > > (1) Baseline with CONFIG_MEMCG_KMEM=3Dn > > (2) Disabled by default (CONFIG_MEM_ALLOC_PROFILING=3Dy && > > CONFIG_MEM_ALLOC_PROFILING_BY_DEFAULT=3Dn) > > (3) Enabled by default (CONFIG_MEM_ALLOC_PROFILING=3Dy && > > CONFIG_MEM_ALLOC_PROFILING_BY_DEFAULT=3Dy) > > (4) Enabled at runtime (CONFIG_MEM_ALLOC_PROFILING=3Dy && > > CONFIG_MEM_ALLOC_PROFILING_BY_DEFAULT=3Dn && /proc/sys/vm/mem_profi= ling=3D1) > > (5) Baseline with CONFIG_MEMCG_KMEM=3Dy && allocating with __GFP_ACCOUN= T > > > > Thanks for the work on this patchset and it is quite useful. > A clarification question on the data: > > I assume Config (2), (3) and (4) has CONFIG_MEMCG_KMEM=3Dn, right? Yes, correct. > If so do you have similar data for config (2), (3) and (4) but with > CONFIG_MEMCG_KMEM=3Dy for comparison with (5)? I have data for these additional configs (didn't think there were that important): (6) Disabled by default (CONFIG_MEM_ALLOC_PROFILING=3Dy && CONFIG_MEM_ALLOC_PROFILING_BY_DEFAULT=3Dn) && CONFIG_MEMCG_KMEM=3Dy (7) Enabled by default (CONFIG_MEM_ALLOC_PROFILING=3Dy && CONFIG_MEM_ALLOC_PROFILING_BY_DEFAULT=3Dy) && CONFIG_MEMCG_KMEM=3Dy > > Tim > > > Performance overhead: > > To evaluate performance we implemented an in-kernel test executing > > multiple get_free_page/free_page and kmalloc/kfree calls with allocatio= n > > sizes growing from 8 to 240 bytes with CPU frequency set to max and CPU > > affinity set to a specific CPU to minimize the noise. Below are results > > from running the test on Ubuntu 22.04.2 LTS with 6.8.0-rc1 kernel on > > 56 core Intel Xeon: > > > > kmalloc pgalloc > > (1 baseline) 6.764s 16.902s > > (2 default disabled) 6.793s (+0.43%) 17.007s (+0.62%) > > (3 default enabled) 7.197s (+6.40%) 23.666s (+40.02%) > > (4 runtime enabled) 7.405s (+9.48%) 23.901s (+41.41%) > > (5 memcg) 13.388s (+97.94%) 48.460s (+186.71%) (6 default disabled+memcg) 13.332s (+97.10%) 48.105s (+184.61%) (7 default enabled+memcg) 13.446s (+98.78%) 54.963s (+225.18%) (6) shows a bit better performance than (5) but it's probably noise. I would expect them to be roughly the same. Hope this helps. > > > >