Received: by 2002:ab2:2994:0:b0:1ef:ca3e:3cd5 with SMTP id n20csp919834lqb; Fri, 15 Mar 2024 09:53:22 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXi6uBoKPPKEHeGj0LUjtNGw3jwWWaD/Ha0pjDmnOIXX3BE/XTslbFmfhjC2NU4q25/Ma2iXyGICCCFjCPEkjm3T5IJN09KZSSibyV3sw== X-Google-Smtp-Source: AGHT+IHi3lG1RlwK8nC5RVh1lssNww8OIA2EoHFSvHw/X7flABxMZnnkLgpDm2IBIrBFNT3VuOCW X-Received: by 2002:ae9:ea06:0:b0:788:23c5:8e16 with SMTP id f6-20020ae9ea06000000b0078823c58e16mr4933874qkg.6.1710521601824; Fri, 15 Mar 2024 09:53:21 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1710521601; cv=pass; d=google.com; s=arc-20160816; b=VAVQUCX6SrC2N7D+5W9Ndex7ZbM7yP8M3x12vDrFFZCAP+V/idBtEgnZXIRvF9Cf1D s1zgvi4d/Oq1t/ZtvCHtR8YPZKwF8vAtCnu2wNRl9tlz+2rmLrB6tHW06n+Y9mTLD+2J qdYQBdtdBrTcDqyRT5cB2eX/JSOizM+xzIgiw07xzP7pGiD4DG+q4EJKuIxAgqVOXtTT fqjIIVDLmWZBh1FcWlRc2PPgNUxBsnZrxJQZWokklVNszuNptdda+7xdm9Z4eN1z7fV2 PAoGGfPCrNGYRKpDbrLzq3QtNCk0tMI84fkBKohe+cBaROXVTEP6cTgvp/8lUzaHQbK4 MMUw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:message-id:dkim-signature :dkim-signature:dkim-signature:dkim-signature; bh=Y4ELQ8jx6kpMYkwxWHw4XIu0o8oKQ+ttZ5iD5/+0aoI=; fh=CwiIpABL37Oixn0hxgMfgXRQfSyFmVhOL2dxilYmEyg=; b=ggorhsgOJr/T3GlV7AOxonTb+fylE8GcjZDrFHPdp3+WkT8cxXVZ96mm4S42kcJbug P36w3bMH04IGZDowrZtiExEayRZ5m7J/IHyoIr7+NzGWVqGLGCsS8slWLUwcsETj5svn OAWHCf0cBiM0quPvTJETIp0Med11oNCfJzdc4vVpycLwNBVSkmh0e183b3klqmpCE8dE oTuvDwvCsFkVoc0QwmbY/sUe8LBcjdmv0bpPvqnZ8n++Yl6p9zzlnAevreYGWt82tkN7 sbNlxjsY7HoX4RrGXQXEseLLNzbDKyh1WKyZEL/cK01O9iQibSdY6LgPyFrSKyJcBUza JVUw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=GIVcH5dt; dkim=neutral (no key) header.i=@suse.cz header.s=susede2_ed25519; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=GIVcH5dt; dkim=neutral (no key) header.i=@suse.cz header.s=susede2_ed25519; arc=pass (i=1 spf=pass spfdomain=suse.cz dkim=pass dkdomain=suse.cz dkim=pass dkdomain=suse.cz); spf=pass (google.com: domain of linux-kernel+bounces-104652-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-104652-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id a11-20020a05620a124b00b00789e5ef1817si1379607qkl.443.2024.03.15.09.53.21 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Mar 2024 09:53:21 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-104652-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=GIVcH5dt; dkim=neutral (no key) header.i=@suse.cz header.s=susede2_ed25519; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=GIVcH5dt; dkim=neutral (no key) header.i=@suse.cz header.s=susede2_ed25519; arc=pass (i=1 spf=pass spfdomain=suse.cz dkim=pass dkdomain=suse.cz dkim=pass dkdomain=suse.cz); spf=pass (google.com: domain of linux-kernel+bounces-104652-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-104652-linux.lists.archive=gmail.com@vger.kernel.org" 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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 7ACE71C21965 for ; Fri, 15 Mar 2024 16:53:21 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 331B746537; Fri, 15 Mar 2024 16:52:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=suse.cz header.i=@suse.cz header.b="GIVcH5dt"; dkim=permerror (0-bit key) header.d=suse.cz header.i=@suse.cz header.b="v9OBHnLK"; dkim=pass (1024-bit key) header.d=suse.cz header.i=@suse.cz header.b="GIVcH5dt"; dkim=permerror (0-bit key) header.d=suse.cz header.i=@suse.cz header.b="v9OBHnLK" Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.223.131]) (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 04BDB46544; Fri, 15 Mar 2024 16:52:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=195.135.223.131 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710521575; cv=none; b=ekl6km9mc+d/CQr3EvYS8POoBOd9UKdB3UyIIPueAt6lCwLKksGJRgDSysHVXRMidM14dNd3kIiukjJoPfJVBEYnm8tuRkKsT2eGbJQlXAIHMUqbSpsQLrt+FVfo3g7cM+aebkyKAO4KUyu3aYM4oa09yf2uPCuWVswf48poiUc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710521575; c=relaxed/simple; bh=GymzEVzWnJExJHnhAe7WBPtD33yCrqjQV+HKZXGqHkE=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=nVnZLBY3h0H5BZvvrvLosR3UZLbDT6Ev68GW3W1yQRU0WIyasNQni1AB8AMb6S0jAJWX2Vf7nddDgl0VYoUmftZczVOeZxk8NbKFULHg0z04kbJhxrjrfY5rmJlVCFLiY19QkYneIZYR4olp0HtX6bLwzjIb7Z0Ts3LhAmwqpO0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=suse.cz; spf=pass smtp.mailfrom=suse.cz; dkim=pass (1024-bit key) header.d=suse.cz header.i=@suse.cz header.b=GIVcH5dt; dkim=permerror (0-bit key) header.d=suse.cz header.i=@suse.cz header.b=v9OBHnLK; dkim=pass (1024-bit key) header.d=suse.cz header.i=@suse.cz header.b=GIVcH5dt; dkim=permerror (0-bit key) header.d=suse.cz header.i=@suse.cz header.b=v9OBHnLK; arc=none smtp.client-ip=195.135.223.131 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=suse.cz Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.cz Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104:10:150:64:97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 30C061FB77; Fri, 15 Mar 2024 16:52:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1710521571; h=from:from:reply-to: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=Y4ELQ8jx6kpMYkwxWHw4XIu0o8oKQ+ttZ5iD5/+0aoI=; b=GIVcH5dtOURRjsdtUmCD+8IDbDFZfndkzp834onReclyzr3ZSsGzmKoG48Q3RIstX5UoFO EzKBDq+9pMXna3n4ZEBof828Uw6Dsb9kv4FwJRm/OVnxA+xXwas3cGxIxx2NiCfRTgWRUc 1t6fi4yhOmG1E7l7RXRD/lGQuIcIduM= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1710521571; h=from:from:reply-to: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=Y4ELQ8jx6kpMYkwxWHw4XIu0o8oKQ+ttZ5iD5/+0aoI=; b=v9OBHnLKouzjKpvvHgKihPfEoR5Q62+JbhEIKayzSwUE6wLlA2eYmYRzKueSggUnWW2ior OKON2/VpvyuA/JCw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1710521571; h=from:from:reply-to: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=Y4ELQ8jx6kpMYkwxWHw4XIu0o8oKQ+ttZ5iD5/+0aoI=; b=GIVcH5dtOURRjsdtUmCD+8IDbDFZfndkzp834onReclyzr3ZSsGzmKoG48Q3RIstX5UoFO EzKBDq+9pMXna3n4ZEBof828Uw6Dsb9kv4FwJRm/OVnxA+xXwas3cGxIxx2NiCfRTgWRUc 1t6fi4yhOmG1E7l7RXRD/lGQuIcIduM= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1710521571; h=from:from:reply-to: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=Y4ELQ8jx6kpMYkwxWHw4XIu0o8oKQ+ttZ5iD5/+0aoI=; b=v9OBHnLKouzjKpvvHgKihPfEoR5Q62+JbhEIKayzSwUE6wLlA2eYmYRzKueSggUnWW2ior OKON2/VpvyuA/JCw== Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 92B6B1368C; Fri, 15 Mar 2024 16:52:50 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id o1p9I+J89GVLbwAAD6G6ig (envelope-from ); Fri, 15 Mar 2024 16:52:50 +0000 Message-ID: Date: Fri, 15 Mar 2024 17:52:50 +0100 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v5 23/37] mm/slab: add allocation accounting into slab allocation and free paths Content-Language: en-US To: Suren Baghdasaryan 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 References: <20240306182440.2003814-1-surenb@google.com> <20240306182440.2003814-24-surenb@google.com> <1f51ffe8-e5b9-460f-815e-50e3a81c57bf@suse.cz> From: Vlastimil Babka In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Level: Authentication-Results: smtp-out2.suse.de; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=GIVcH5dt; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=v9OBHnLK X-Rspamd-Server: rspamd2.dmz-prg2.suse.org X-Spamd-Result: default: False [-3.00 / 50.00]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; R_DKIM_ALLOW(-0.20)[suse.cz:s=susede2_rsa,suse.cz:s=susede2_ed25519]; XM_UA_NO_VERSION(0.01)[]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; MID_RHS_MATCH_FROM(0.00)[]; TAGGED_RCPT(0.00)[]; MIME_GOOD(-0.10)[text/plain]; NEURAL_HAM_LONG(-1.00)[-1.000]; BAYES_HAM(-3.00)[100.00%]; RCVD_COUNT_THREE(0.00)[3]; TO_MATCH_ENVRCPT_SOME(0.00)[]; DKIM_SIGNED(0.00)[suse.cz:s=susede2_rsa,suse.cz:s=susede2_ed25519]; DKIM_TRACE(0.00)[suse.cz:+]; MX_GOOD(-0.01)[]; RCPT_COUNT_GT_50(0.00)[76]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.cz:dkim,suse.cz:email]; FUZZY_BLOCKED(0.00)[rspamd.com]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; NEURAL_HAM_SHORT(-0.20)[-0.999]; FREEMAIL_CC(0.00)[linux-foundation.org,linux.dev,suse.com,cmpxchg.org,suse.de,stgolabs.net,infradead.org,oracle.com,i-love.sakura.ne.jp,lwn.net,manifault.com,redhat.com,arm.com,kernel.org,arndb.de,linutronix.de,linux.intel.com,kernel.dk,nvidia.com,soleen.com,google.com,gmail.com,chromium.org,linuxfoundation.org,linaro.org,goodmis.org,linux.com,lge.com,bytedance.com,akamai.com,android.com,vger.kernel.org,lists.linux.dev,kvack.org,googlegroups.com]; RCVD_TLS_ALL(0.00)[]; SUSPICIOUS_RECIPS(1.50)[] X-Spam-Score: -3.00 X-Rspamd-Queue-Id: 30C061FB77 X-Spam-Flag: NO On 3/15/24 16:43, Suren Baghdasaryan wrote: > On Fri, Mar 15, 2024 at 3:58 AM Vlastimil Babka wrote: >> >> On 3/6/24 19:24, Suren Baghdasaryan wrote: >> > Account slab allocations using codetag reference embedded into slabobj_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 = s->object_size; >> > + struct slabobj_ext *obj_exts; >> > bool kasan_init = init; >> > size_t i; >> > gfp_t init_flags = 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 = 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? >> > + alloc_tag_add(&obj_exts->ref, current->alloc_tag, s->size); >> > +#endif >> >> I think you could still do this a bit better: >> >> Check mem_alloc_profiling_enabled() once before the whole block calling >> 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()==false. 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 slab *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, struct 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 freelist >> > * to remove objects, whose reuse must be delayed. >>