Received: by 2002:ab2:2994:0:b0:1ef:ca3e:3cd5 with SMTP id n20csp936306lqb; Fri, 15 Mar 2024 10:17:40 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUl1zFuMz5mprdeEpmHjviTrSjaffmm23VQGNkYvoiH6kMX32daTMa+s3BNJTrrLr3tSSlKt9GJjtNMatjk7hPItQn4UYxhsGq6tNw3+A== X-Google-Smtp-Source: AGHT+IF5CvVPNo6jNF5KS1Op4vDSvdhmjwLQlu0M0aCHvR3KvM/wTgbH5EcR7Mp2spsB3PYO3eBy X-Received: by 2002:a17:906:a8b:b0:a46:8b1d:3d4f with SMTP id y11-20020a1709060a8b00b00a468b1d3d4fmr1887213ejf.28.1710523060387; Fri, 15 Mar 2024 10:17:40 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1710523060; cv=pass; d=google.com; s=arc-20160816; b=VjPb9CmvdQKxT2q4w++IIhHEEexpdlZRfAW6Rk3TGn7TCMmjDczDdRA4NeqxaYY3Zx QJTPQM3/Tqz3lFr+D1BJP9TnOmgQVgbh/4zv/e5+hjMG9rclQAvimiPhvzYLK9+R5dXN Bh2mQ28hkMvDTh5XMMKjUPw8Em+0y8qcX0nJWggwwhqsk3BS836UDE+AWGg4XWxCDnbZ fCOEq/JWsWcgVsfyLrH0M+1D3zjnh7Bu50OZMsYY6Z6JsitE0jE7kXmiN00jwRM7SrYp BcCkmHwbIjs0Tz8SFar6cXyJaHYBhr6mNHv9Ha4aC8cPA8qKpuS+aaATw76YujWk4xm8 FM4w== 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=rC572A3yia7X47ZYtWd+ymj431bX9Z5tiP3vPmrWrg8=; fh=fjBbPuVfFKQI3Bic5eZNrwqjZcz+QkJGPITogkqaGSU=; b=o4hM86cc1jfWshaOcqM09I/W8N9UKlskYGe7JuC1IycjfREK4fHp0A42eMKtltpZ0z vfMgPgW4IVMzDVapfAaOXD2hPze1/O6QNdUvRlWuoA73I/N8Hfy1Q0Myr2wFptFHXTrA CwO8N6YcX3DDZVUwcfJu74dJvGhB8xRQw7Nv/NoZ01Pa7+TsYSdz6Y0g7z67Id3UwLys 5qqCRD10aQ3yaEJzzCXIz3SEoHHEuOYef57lQFfuVy3vs4at19V1LBzwTcprRLfW4S58 lZhReZAJRvQzk/6/3Ld2ulgqDGQVvd9vgaRSm4q9aOKN9/5tPMIQBWKB2VAKxS0R1TR4 hPTg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=rya3Xw3T; 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-104693-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-104693-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. [147.75.80.249]) by mx.google.com with ESMTPS id kz15-20020a17090777cf00b00a433bdc3b00si1852658ejc.435.2024.03.15.10.17.40 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Mar 2024 10:17:40 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-104693-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=rya3Xw3T; 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-104693-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-104693-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 5C9131F233FD for ; Fri, 15 Mar 2024 17:09:54 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A38074EB3F; Fri, 15 Mar 2024 17:06:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="rya3Xw3T" Received: from mail-yb1-f169.google.com (mail-yb1-f169.google.com [209.85.219.169]) (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 35BB94C600 for ; Fri, 15 Mar 2024 17:06:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.169 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710522409; cv=none; b=ZU75SuIH/XZUxB4AMRTpG9HZkdGCw4BUejx+tyYalToKrf94RmiEv4lmnEOaTtCuydXB6//lRfmOp4djIuLpHRuOGulUudcE1XRfVzES54zmKEHbuvrCCL8HN3wH0SqE/JaKwRPQj3gdKIwGWoaLbE97mBx+ZLltaCTpxCPwiio= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710522409; c=relaxed/simple; bh=LNQjeHjDBEInTCwCSWcroDRYdeiq48Ic8r1TtkNrkfA=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=BrG4RE45OjLDT9bzYM8C0U3uRceLFuu/bQ0r+9NqREdXWCEWinmML5eYZbbsDBCJqZvcyrmVZQy5HOFCAdKWkyG5+oOmPSFLnW9IRcwkG2PYTXkG/MEQldFTNJMMqbKoY9IWUp+/lN3uUYpZcQo3zKNh0cvdcXf+mw87YwodpkY= 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=rya3Xw3T; arc=none smtp.client-ip=209.85.219.169 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-yb1-f169.google.com with SMTP id 3f1490d57ef6-dcc84ae94c1so2146417276.1 for ; Fri, 15 Mar 2024 10:06:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1710522406; x=1711127206; 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=rC572A3yia7X47ZYtWd+ymj431bX9Z5tiP3vPmrWrg8=; b=rya3Xw3T8AljDIaTfGNOGJm/xQWnLA6e+ZFuT6jbITv9/8xLt5COBXTWischjeSkEL rnMXSbvPATe554rW5eGDTfCeeFdaD8nW3JAf8wT82TppRYwdT3x72FYEM738kQxk97j2 e9SQrSQ3+Dv3JdQBc6bOako7jAkylCOdV8OdcNqwCOXaPTCgLB0mE/CLtbe6dazWnTNU GWnZ7sT7bqE8I/nC8Nv3G6fWRL9v18fMNEpYC8lc2MPPJe02fKAMilCfnaHzYjv+Z3J4 X2rTSGjpnkKyZX0B1/1JDuTfEU2y628Levs1yUskk//5ZUR2/QtZsttHAEYggz+fXfHu w47g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710522406; x=1711127206; 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=rC572A3yia7X47ZYtWd+ymj431bX9Z5tiP3vPmrWrg8=; b=oylJxft2m1p2qeUA8vg8azxHoOtbnLF9edRCNVgfLMZq6CL+ThjfQXJAGRmKQSVozo jFi03C1UWvv06xZC0U0C4Veh4gMW6/GGgEuDaOf4XEdOUN/zeA5Xelnkvxotvpt/lwrs zAElMuQ9rpyXgQeioYEi0aIehJhStlD2Ema7HlDUtBfNDuyjTr18uEnbaLb9Cx/1LDEc PduQZ4v+rxIzzIippKV83C1dxeA8eVlRO9o+vO3kKqRj3sr3KXOXN2xT8EBIOdxjWea2 ypY79aVXWdVl08FUtE1lorHef2YtPWrEFUbm6Lngj8YIIBuzRTLH1ibYIhJXPFP5iEm/ zBPw== X-Forwarded-Encrypted: i=1; AJvYcCWjGfJEgi0fkp9Fn7FfBw1BGV16RJZuLMDs0ASyjR2DPblGkez6sqZMVMA9g2YxPEKK7gvVh+xFli5RShnTHM0Bl268xvhyEqtEKurU X-Gm-Message-State: AOJu0YyzfAR6sV6sND7k0Ry28u09lGefJqL1wDdBJjKUUYSv7WJtMPiY vBN9NYIJNscF++xwrkScUPDJCL/waXW6HfqyNqCDA/bozBBobhfmZTFrwQSyWlOqDthUVvXG9uu tbYjklcoccMGb9jFzPiTAEmrqS5RAC7oRghe7 X-Received: by 2002:a25:dbca:0:b0:dcc:273e:1613 with SMTP id g193-20020a25dbca000000b00dcc273e1613mr5471648ybf.40.1710522405619; Fri, 15 Mar 2024 10:06:45 -0700 (PDT) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240306182440.2003814-1-surenb@google.com> <20240306182440.2003814-24-surenb@google.com> <1f51ffe8-e5b9-460f-815e-50e3a81c57bf@suse.cz> In-Reply-To: From: Suren Baghdasaryan Date: Fri, 15 Mar 2024 17:06:32 +0000 Message-ID: Subject: Re: [PATCH v5 23/37] mm/slab: add allocation accounting into slab allocation and free paths 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, jhubbard@nvidia.com, 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, aliceryhl@google.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 Fri, Mar 15, 2024 at 4:52=E2=80=AFPM Vlastimil Babka wr= ote: > > On 3/15/24 16:43, Suren Baghdasaryan wrote: > > On Fri, Mar 15, 2024 at 3:58=E2=80=AFAM Vlastimil Babka wrote: > >> > >> On 3/6/24 19:24, Suren Baghdasaryan wrote: > >> > Account slab allocations using codetag reference embedded into slabo= bj_ext. > >> > > >> > Signed-off-by: Suren Baghdasaryan > >> > Co-developed-by: Kent Overstreet > >> > Signed-off-by: Kent Overstreet > >> > Reviewed-by: Kees Cook > >> > >> Reviewed-by: Vlastimil Babka > >> > >> Nit below: > >> > >> > @@ -3833,6 +3913,7 @@ void slab_post_alloc_hook(struct kmem_cache *s= , struct obj_cgroup *objcg, > >> > unsigned int orig_size) > >> > { > >> > unsigned int zero_size =3D s->object_size; > >> > + struct slabobj_ext *obj_exts; > >> > bool kasan_init =3D init; > >> > size_t i; > >> > gfp_t init_flags =3D flags & gfp_allowed_mask; > >> > @@ -3875,6 +3956,12 @@ void slab_post_alloc_hook(struct kmem_cache *= s, struct obj_cgroup *objcg, > >> > kmemleak_alloc_recursive(p[i], s->object_size, 1, > >> > s->flags, init_flags); > >> > kmsan_slab_alloc(s, p[i], init_flags); > >> > + obj_exts =3D prepare_slab_obj_exts_hook(s, flags, p[i]= ); > >> > +#ifdef CONFIG_MEM_ALLOC_PROFILING > >> > + /* obj_exts can be allocated for other reasons */ > >> > + if (likely(obj_exts) && mem_alloc_profiling_enabled()) > > Could you at least flip these two checks then so the static key one goes = first? Yes, definitely. I was thinking about removing need_slab_obj_ext() from prepare_slab_obj_exts_hook() and adding this instead of the above code: + if (need_slab_obj_ext()) { + obj_exts =3D prepare_slab_obj_exts_hook(s, flags, p[i]); +#ifdef CONFIG_MEM_ALLOC_PROFILING + /* + * Currently obj_exts is used only for allocation profiling. If other users appear + * then mem_alloc_profiling_enabled() check should be added here. + */ + if (likely(obj_exts)) + alloc_tag_add(&obj_exts->ref, current->alloc_tag, s->size); +#endif + } Does that look good? > >> > +#ifdef CONFIG_MEM_ALLOC_PROFILING > >> > + /* obj_exts can be allocated for other reasons */ > >> > + if (likely(obj_exts) && mem_alloc_profiling_enabled()) > > >> > + alloc_tag_add(&obj_exts->ref, current->alloc_t= ag, s->size); > >> > +#endif > >> > >> I think you could still do this a bit better: > >> > >> Check mem_alloc_profiling_enabled() once before the whole block callin= g > >> prepare_slab_obj_exts_hook() and alloc_tag_add() > >> Remove need_slab_obj_ext() check from prepare_slab_obj_exts_hook() > > > > Agree about checking mem_alloc_profiling_enabled() early and one time, > > except I would like to use need_slab_obj_ext() instead of > > mem_alloc_profiling_enabled() for that check. Currently they are > > equivalent but if there are more slab_obj_ext users in the future then > > there will be cases when we need to prepare_slab_obj_exts_hook() even > > when mem_alloc_profiling_enabled()=3D=3Dfalse. need_slab_obj_ext() will= be > > easy to extend for such cases. > > I thought we don't generally future-proof internal implementation details > like this until it's actually needed. But at least what I suggested above > would help, thanks. > > > Thanks, > > Suren. > > > >> > >> > } > >> > > >> > memcg_slab_post_alloc_hook(s, objcg, flags, size, p); > >> > @@ -4353,6 +4440,7 @@ void slab_free(struct kmem_cache *s, struct sl= ab *slab, void *object, > >> > unsigned long addr) > >> > { > >> > memcg_slab_free_hook(s, slab, &object, 1); > >> > + alloc_tagging_slab_free_hook(s, slab, &object, 1); > >> > > >> > if (likely(slab_free_hook(s, object, slab_want_init_on_free(s)= ))) > >> > do_slab_free(s, slab, object, object, 1, addr); > >> > @@ -4363,6 +4451,7 @@ void slab_free_bulk(struct kmem_cache *s, stru= ct slab *slab, void *head, > >> > void *tail, void **p, int cnt, unsigned long addr) > >> > { > >> > memcg_slab_free_hook(s, slab, p, cnt); > >> > + alloc_tagging_slab_free_hook(s, slab, p, cnt); > >> > /* > >> > * With KASAN enabled slab_free_freelist_hook modifies the fre= elist > >> > * to remove objects, whose reuse must be delayed. > >> > > -- > To unsubscribe from this group and stop receiving emails from it, send an= email to kernel-team+unsubscribe@android.com. >