Received: by 2002:a05:7412:251c:b0:e2:908c:2ebd with SMTP id w28csp2081077rda; Tue, 24 Oct 2023 11:39:28 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEmpTH+nxM6ghN8dE+NAc/o0eswMt5URof7dZrPdFW9CDH6R3pvzBmdi6fFRzFv09Ie5dWE X-Received: by 2002:a17:90a:7f93:b0:26d:17da:5e9f with SMTP id m19-20020a17090a7f9300b0026d17da5e9fmr10754211pjl.1.1698172768021; Tue, 24 Oct 2023 11:39:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698172768; cv=none; d=google.com; s=arc-20160816; b=LRuLzyK5BZX92tv6xNF2uVothCvg8A9WwFG6mtwq/Ab87wrzfCFrnlALR2C++fvVmZ YQGKTGD3OF7A5yjpkW4Ko9i1AvyS89YAbE0TIZlo7RE4MdPI5P4+jnOL09HQKSsnpKbm suTYdOTulSeScAlwsWUFwPIbq1qhJ4QaY0A3rZu/FZZM4xiy5UpAE+qX8ZFuRLkGz7fp 12kYMHWBb5mhl04RxcseSkxI+7C0uUSC2/ywgUSx3cE7DFabrH95vD6W1kY0+uzc173J LWOry9LHLzsexWNBJ+QpyNvu66XGoNOyw5IKzrm6Fx/Pz/LA07E1MGC2RjNe2kC4QFGS cIDg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=kYl/hPQ1QO/qnjhfpaigT8V90o1Z/zrFBqqxchQb6PA=; fh=FfoU0ET5QwnTqqxPFnIysHogbCP4U9SjwY4sZfirvBU=; b=akQlcva6AJA9v7sM6BayCoZeazYXPPajrkOjCgffk9RoENr5nCac+jApTvhR6jwuE9 Ernmj5+RemF6UEggo0nj5CyhIlp0W16PJa2M46b1h77nPynwTnPS9X+PX5t0NP6JaNmz t0Sdu123Q/0X/KJggw71kMyFhknLbR3iGoKY26zBgIH2bUw8YCwRPzQX7EvaWOCSalxa 3Fndc85gi4e7ce1JcssK3UIIkoBFelx47qxBXFB6pEJgRwWsntIUcjaOObUT8485xEZP eI+TomThICYtDftAY52RYtci22OnlJZic+jR9kUssd3xBiFQStAWa1DT1zXGifi4GACn 8cdQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=yCiaZWxX; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from pete.vger.email (pete.vger.email. [23.128.96.36]) by mx.google.com with ESMTPS id 3-20020a17090a034300b0027d567be2e5si8814359pjf.92.2023.10.24.11.39.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Oct 2023 11:39:28 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) client-ip=23.128.96.36; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=yCiaZWxX; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by pete.vger.email (Postfix) with ESMTP id 859E4802FD5F; Tue, 24 Oct 2023 11:39:25 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344118AbjJXSjL (ORCPT + 99 others); Tue, 24 Oct 2023 14:39:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33600 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344127AbjJXSjJ (ORCPT ); Tue, 24 Oct 2023 14:39:09 -0400 Received: from mail-wr1-x42c.google.com (mail-wr1-x42c.google.com [IPv6:2a00:1450:4864:20::42c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6A68EB9 for ; Tue, 24 Oct 2023 11:39:05 -0700 (PDT) Received: by mail-wr1-x42c.google.com with SMTP id ffacd0b85a97d-31c5cac3ae2so3490163f8f.3 for ; Tue, 24 Oct 2023 11:39:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1698172744; x=1698777544; darn=vger.kernel.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=kYl/hPQ1QO/qnjhfpaigT8V90o1Z/zrFBqqxchQb6PA=; b=yCiaZWxXRcnAxiUlTsv9w7FhSeSFqNa67B2b3PjcLp2h/ZumDiW6QSLTrRBQH9RaTj TSV2yfXmYFONRu5NIgMBuA4vev42FP04sO2ZTdbQ+5GgFeSM7tSZaqgxf/GapDfxIfPU 9xAikhkPlOFOObe6aupQlpMQT2eBHTGQ3JDVAnhf7oyYdcJ0ktOvvSspdJdesBZZQLuS I5Bc19S1TYS7Hzg8ArNDDgEwv10Rxvtyda7md2HP8tMN1kfkXH+dP2yXhM/n9EetSPXw g1mVoNIpzsaEv/WhfPSK2pnBz8Kc0zRyH92+tmfQvSP5rfw/HF/8XfE6a+/3PjqaZ75d RC5w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698172744; x=1698777544; 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=kYl/hPQ1QO/qnjhfpaigT8V90o1Z/zrFBqqxchQb6PA=; b=f/myfddR9z90TmhOa2cb1X4tLouGuUL+URadSqaMD6q55NehCnDja7gljtmSaSWgvl Yok8eqvKG6ZVIfDkI15/+HMvYFndVtEJMRfzd8SCEBBYu9pFS/o4RVg1j2L0lwO49obH 60+pO8tEO4A3qJM+WzNAFztxgypEFmQzLUti8o1a8X+/HAQF2FXw021kBLo9esw3O5NF gGZ1sZs2gT101Zl/yFrTVeRfL8pQACIj0nUtvAg+A4gBPuK+aeACbCeT68IBsh2ZE39H 8BIYGaJ/w6wSV6R1So9oW4ut786N5VF3J+9MOfAFqDHLnAUaPHscbHreb+g6ZMiqWSqy qpnw== X-Gm-Message-State: AOJu0YygwHId55OzpRh+4TL9dAxeTlZgf5WfDyew7IKi5cLxDY6rQT3t 1RJ2RIuJfHif0EaqppvQYFzBZqr5JQXYk7nNPv12nQ== X-Received: by 2002:adf:fe8a:0:b0:32d:ad05:906c with SMTP id l10-20020adffe8a000000b0032dad05906cmr10224110wrr.3.1698172743492; Tue, 24 Oct 2023 11:39:03 -0700 (PDT) MIME-Version: 1.0 References: <20231024134637.3120277-1-surenb@google.com> In-Reply-To: From: Suren Baghdasaryan Date: Tue, 24 Oct 2023 11:38:47 -0700 Message-ID: Subject: Re: [PATCH v2 00/39] Memory allocation profiling To: Roman Gushchin Cc: akpm@linux-foundation.org, kent.overstreet@linux.dev, mhocko@suse.com, vbabka@suse.cz, hannes@cmpxchg.org, 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, ldufour@linux.ibm.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-Spam-Status: No, score=-8.4 required=5.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on pete.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (pete.vger.email [0.0.0.0]); Tue, 24 Oct 2023 11:39:25 -0700 (PDT) On Tue, Oct 24, 2023 at 11:29=E2=80=AFAM Roman Gushchin wrote: > > On Tue, Oct 24, 2023 at 06:45:57AM -0700, Suren Baghdasaryan wrote: > > Updates since the last version [1] > > - Simplified allocation tagging macros; > > - Runtime enable/disable sysctl switch (/proc/sys/vm/mem_profiling) > > instead of kernel command-line option; > > - CONFIG_MEM_ALLOC_PROFILING_BY_DEFAULT to select default enable state; > > - Changed the user-facing API from debugfs to procfs (/proc/allocinfo); > > - Removed context capture support to make patch incremental; > > - Renamed uninstrumented allocation functions to use _noprof suffix; > > - Added __GFP_LAST_BIT to make the code cleaner; > > - Removed lazy per-cpu counters; it turned out the memory savings was > > minimal and not worth the performance impact; > > Hello Suren, > > > 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 is performa= nce > > comparison between the baseline kernel, profiling when enabled, profili= ng > > when disabled and (for comparison purposes) baseline with > > CONFIG_MEMCG_KMEM enabled and allocations using __GFP_ACCOUNT: > > > > kmalloc pgalloc > > (1 baseline) 12.041s 49.190s > > (2 default disabled) 14.970s (+24.33%) 49.684s (+1.00%) > > (3 default enabled) 16.859s (+40.01%) 56.287s (+14.43%) > > (4 runtime enabled) 16.983s (+41.04%) 55.760s (+13.36%) > > (5 memcg) 33.831s (+180.96%) 51.433s (+4.56%) > > some recent changes [1] to the kmem accounting should have made it quite = a bit > faster. Would be great if you can provide new numbers for the comparison. > Maybe with the next revision? > > And btw thank you (and Kent): your numbers inspired me to do this kmemcg > performance work. I expect it still to be ~twice more expensive than your > stuff because on the memcg side we handle separately charge and statistic= s, > but hopefully the difference will be lower. Yes, I saw them! Well done! I'll definitely update my numbers once the patches land in their final form. > > Thank you! Thank you for the optimizations! > > [1]: > patches from next tree, so no stable hashes: > mm: kmem: reimplement get_obj_cgroup_from_current() > percpu: scoped objcg protection > mm: kmem: scoped objcg protection > mm: kmem: make memcg keep a reference to the original objcg > mm: kmem: add direct objcg pointer to task_struct > mm: kmem: optimize get_obj_cgroup_from_current()