Received: by 2002:a05:7208:13ce:b0:7f:395a:35b6 with SMTP id r14csp848rbe; Wed, 28 Feb 2024 10:07:50 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXk/hqVfSN9QSA9LbzBmiPCwmPWlMTazyu5pe4LKB6Hhj20yDu9xruEBLxv1VUsuRNNRfGphhzOnOMkZyQ2ahoUfdPs1zGGJQh+0QRXJA== X-Google-Smtp-Source: AGHT+IEv/tDpqkJ/mFSM9ERcRx73AtzkMSrdhtxsSuFcnQ+kc7yAOxPT8510KruJYXxfnQCDfByM X-Received: by 2002:aa7:d3d3:0:b0:564:ded0:6072 with SMTP id o19-20020aa7d3d3000000b00564ded06072mr127071edr.1.1709143670688; Wed, 28 Feb 2024 10:07:50 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709143670; cv=pass; d=google.com; s=arc-20160816; b=oJ27n1EiGEdTeN7wWUhAooTsuRATtRR+jTHOjqtqT4/hl9qgBZIc+Qz95EoKXw06kU 1rRS1wHUZEGUFS8vnnNUxsbvLRRXZTZZaxyDYtGkRem2HRrr6YrbBdxnFDx3ceMlANDt S1yoHtVkp9oBIGjChrx8ad2GjpvBdzYBaUMA5Yf+gBVflS+lyhRa1rHiiesAU/ZjHbx/ 9T3y3tCPBc4B3+L9rCVCRCtfJMaJImEfGqJsBidljcZX0+srtU6L9vHyuUNhgEg4p23m QIQyFkM2ZRXVWZIvzwvyYx3OvTDfmy370u9GUyCm2GBY/59HBVctpNTqMlY/RlWdio12 U1SA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:dkim-signature; bh=TpJn79d7ymx24Tp5aF1RCceBrMYpEjjJMLmxKg1qMeo=; fh=k1XGvxJxAlY5utjHcpu1eZJaMqrfeo2CyVWqVF5eTg4=; b=jf8mh4pmLlA0WWhzG7jul5qTh6pR2aKWohtIqkT58kJ2lz0UccnxBi9+twr38LT/UM fNGkIKNTP91Re6Kgxmc9ZbMKiNPgaCQvS/KTJB4YpLJomXGGsU3xJasKU7eq5mDFqv+e Y0YeNTw5BppfVlQKQN51mj5L5HsavXetLKrYbiukfT/phGjA7GL4wnr4/+za5If6cWSX BMg66SkDQiqPjtufeYXm81bJqy5TcTdeqqtsozzFx6Eri+q0uru6ZZoY+4xbzvSpaKp6 A01z/6IKuxBz+T3B7O34VwomQYZobnuteSU5m1xOZx2fBEU8Tse7czK6PTDXxqZNzmKC VgiA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=I26LIUlD; arc=pass (i=1 spf=pass spfdomain=google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-85507-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-85507-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id j19-20020aa7c353000000b005642ea0a7besi1872754edr.164.2024.02.28.10.07.50 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Feb 2024 10:07:50 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-85507-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=I26LIUlD; arc=pass (i=1 spf=pass spfdomain=google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-85507-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-85507-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 467511F23A02 for ; Wed, 28 Feb 2024 18:07:50 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id EABDF3FBB3; Wed, 28 Feb 2024 18:07:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="I26LIUlD" Received: from mail-oo1-f49.google.com (mail-oo1-f49.google.com [209.85.161.49]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4277979B69 for ; Wed, 28 Feb 2024 18:07:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.161.49 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709143656; cv=none; b=P7xyh5pkyEdiNkuM/qvXbw6RuxX2x2Z4xs8I4qgADN1ajjqMC6DoYEp11nWpkpY3rOOr7jqmMIPP+ZyFx0peQv1DJveTp27598OC6d5GcvuV0Rce8muXbSvSC2r0vd/vIhrxuZUltI5T1YzszAumEIsoGFiDHO3ZcEVn80UXzDg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709143656; c=relaxed/simple; bh=rv47TPwMaL5mB4Ug9VuCbJFQC3RVZQfJetV44+QcIfk=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=mdbjSob1t8PMT8Ba3keHx+oOJJbKDCqBBnKjmS+cAXbJ0E7SyUp1VnUbxSh3qNzy/B4xQEllWjJBYm35Ufu/xi2jGUMRAbaAzs7Uhce8lIKerKIkl4H81TIzAk4tYmPAOa0V1E6K5lG33dJd3HV51LY/Swzx5ERghYtUq+L4tnA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=I26LIUlD; arc=none smtp.client-ip=209.85.161.49 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=google.com Received: by mail-oo1-f49.google.com with SMTP id 006d021491bc7-59d489e8d68so5558eaf.2 for ; Wed, 28 Feb 2024 10:07:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1709143653; x=1709748453; 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=TpJn79d7ymx24Tp5aF1RCceBrMYpEjjJMLmxKg1qMeo=; b=I26LIUlDAHkDBLXz3vWL7AcRTiKr8/ll6mVDEuxWMUsDvyKo6Gs+weBuyHxXp1Y+kO yJBVXecvpEki+8OZ1GTubMJYou2eewYBq3M9YCaRXSdVKU9PsBJ74cbni8NTEdQRS04f GgSqHdZyP/J47iELtUMR6d2HMQrHv5pA/t6NYXqxTZ48WK0xFLz5yuBUW6WuOoaLRbWl LvYIGG4G3PkbFnr3WOMUgnlkPgjAHEsG2px5MAU4lj3hIA7A5qa7UrIUlupai3dN2WnK 5V1n3s54PerdOa5bqlfwqlX/4xYf8mpNVtE/FHMhpXzZetUrgiPSAHIIE3Kpx5k3pT3E cXKg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709143653; x=1709748453; 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=TpJn79d7ymx24Tp5aF1RCceBrMYpEjjJMLmxKg1qMeo=; b=W/YSe3iZjb/Rsd+NKe16O9qe0rd2qcUMbpBRL3tH6ZgJF1fl9bbcvQlO43pU8DOV6W 8my8AXIpGTFyvmpLAAkgORna18le6YeKD8NHglFpNHz22+hU2pcEvAHg3KGDWI/A5k7+ mK8cfPNlmCQFqleQMcaCanqRN8sHIGTZWQ8wa5a5wvMi3DVrRoddA7A32hXF9mODTmoj qpaAmJc84uBRnttTwhqPzAPjrhsZYRDsE5CoS0LM5BOr7e0nef2FwYJRbtkOwjAB6onP So8NqNlFmDWCEsfVtzppIiV2yLjfmVurBT7hr5/vsoAh+MyGBHtyTafqgsionjjo8nWg NluQ== X-Forwarded-Encrypted: i=1; AJvYcCWlVM+O403FfHDhgIujRivEYvc3aGKbRJF9I7/IT4fYurJgHh5ucDqG+baxpLLcc4/l80Uyp9biFUAklU+4i9pZE9ukvPsGUyUFj868 X-Gm-Message-State: AOJu0YwuKqCkJPaKYREkOU6kI8HGZpqHtNKju6X/Dp6LozpaETbBYm+J pM2plKMCjWI12x7lB7lQC8P0cMzhpEHdID+lx6nfK3F5FMrOONtZq4vsQxr1Ve9Lagn5JUeX4y/ TV5iIaROARnXCczVrpFSBAfB6lskOuxkiFae7 X-Received: by 2002:a05:6358:80a8:b0:17b:521f:b2ae with SMTP id a40-20020a05635880a800b0017b521fb2aemr6472rwk.14.1709143652850; Wed, 28 Feb 2024 10:07:32 -0800 (PST) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240221194052.927623-1-surenb@google.com> <20240221194052.927623-15-surenb@google.com> In-Reply-To: From: Suren Baghdasaryan Date: Wed, 28 Feb 2024 18:07:18 +0000 Message-ID: Subject: Re: [PATCH v4 14/36] lib: add allocation tagging support for memory allocation profiling To: Vlastimil Babka Cc: akpm@linux-foundation.org, kent.overstreet@linux.dev, mhocko@suse.com, hannes@cmpxchg.org, roman.gushchin@linux.dev, mgorman@suse.de, dave@stgolabs.net, willy@infradead.org, liam.howlett@oracle.com, penguin-kernel@i-love.sakura.ne.jp, 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 On Wed, Feb 28, 2024 at 8:41=E2=80=AFAM Vlastimil Babka wr= ote: > > Another thing I noticed, dunno how critical > > On 2/21/24 20:40, Suren Baghdasaryan wrote: > > +static inline void __alloc_tag_sub(union codetag_ref *ref, size_t byte= s) > > +{ > > + struct alloc_tag *tag; > > + > > +#ifdef CONFIG_MEM_ALLOC_PROFILING_DEBUG > > + WARN_ONCE(ref && !ref->ct, "alloc_tag was not set\n"); > > +#endif > > + if (!ref || !ref->ct) > > + return; > > This is quite careful. > > > + > > + tag =3D ct_to_alloc_tag(ref->ct); > > + > > + this_cpu_sub(tag->counters->bytes, bytes); > > + this_cpu_dec(tag->counters->calls); > > + > > + ref->ct =3D NULL; > > +} > > + > > +static inline void alloc_tag_sub(union codetag_ref *ref, size_t bytes) > > +{ > > + __alloc_tag_sub(ref, bytes); > > +} > > + > > +static inline void alloc_tag_sub_noalloc(union codetag_ref *ref, size_= t bytes) > > +{ > > + __alloc_tag_sub(ref, bytes); > > +} > > + > > +static inline void alloc_tag_ref_set(union codetag_ref *ref, struct al= loc_tag *tag) > > +{ > > +#ifdef CONFIG_MEM_ALLOC_PROFILING_DEBUG > > + WARN_ONCE(ref && ref->ct, > > + "alloc_tag was not cleared (got tag for %s:%u)\n",\ > > + ref->ct->filename, ref->ct->lineno); > > + > > + WARN_ONCE(!tag, "current->alloc_tag not set"); > > +#endif > > + if (!ref || !tag) > > + return; > > This too. > > > + > > + ref->ct =3D &tag->ct; > > + /* > > + * We need in increment the call counter every time we have a new > > + * allocation or when we split a large allocation into smaller on= es. > > + * Each new reference for every sub-allocation needs to increment= call > > + * counter because when we free each part the counter will be dec= remented. > > + */ > > + this_cpu_inc(tag->counters->calls); > > +} > > + > > +static inline void alloc_tag_add(union codetag_ref *ref, struct alloc_= tag *tag, size_t bytes) > > +{ > > + alloc_tag_ref_set(ref, tag); > > We might have returned from alloc_tag_ref_set() due to !tag > > > + this_cpu_add(tag->counters->bytes, bytes); > > But here we still assume it's valid. Yes, this is a blunder on my side after splitting alloc_tag_ref_set() into a separate function. I'll fix this in the next version. Thanks! > > > +} > > + > > -- > To unsubscribe from this group and stop receiving emails from it, send an= email to kernel-team+unsubscribe@android.com. >