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 38261C43217 for ; Wed, 23 Nov 2022 09:21:07 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id AF0D06B0071; Wed, 23 Nov 2022 04:21:06 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id AA0166B0073; Wed, 23 Nov 2022 04:21:06 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 967706B0074; Wed, 23 Nov 2022 04:21:06 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 87AAA6B0071 for ; Wed, 23 Nov 2022 04:21:06 -0500 (EST) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 4E7D41C6259 for ; Wed, 23 Nov 2022 09:21:06 +0000 (UTC) X-FDA: 80164162932.26.D838206 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by imf08.hostedemail.com (Postfix) with ESMTP id A38D316000B for ; Wed, 23 Nov 2022 09:21:05 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id E341F1F85D; Wed, 23 Nov 2022 09:21:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1669195263; 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=6ChOqSLee0rmz2oTzjZlbgB7fmW7X2/L74cYDn2AHg0=; b=WQgMsxhWcA7MCx0a41UrCz/u4JTsY7RUImEW8PnEu86WjiGAMCg3F6nUUhlX3EuBRuacWo n0Gmoyuyg2nUK106MstNWvNnXiTaKLrexqJL6wt5lMK+g8h4ug02CiIP8GSqG9KN0DCje4 n2sC97Bu+gU0Yh6mJfkXKuufRRNfGNw= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1669195263; 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=6ChOqSLee0rmz2oTzjZlbgB7fmW7X2/L74cYDn2AHg0=; b=aSmEAcQJzrRTGdpNNKAo51TflwLScKhMBU23sl1iudaK2Oa+hdXzyHqSrn7y5JtZCArsSX ga2uwae5AtXn6jAQ== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id A97A513A37; Wed, 23 Nov 2022 09:21:03 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id QgwtKP/lfWMEDQAAMHmgww (envelope-from ); Wed, 23 Nov 2022 09:21:03 +0000 Message-ID: <74d14df1-faa7-dc12-d406-ba038682e134@suse.cz> Date: Wed, 23 Nov 2022 10:21:03 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.5.0 Subject: Re: [PATCH -next 1/2] mm/slab: add is_kmalloc_cache() helper macro Content-Language: en-US To: Feng Tang , Andrew Morton Cc: Christoph Lameter , Pekka Enberg , David Rientjes , Joonsoo Kim , Roman Gushchin , Hyeonggon Yoo <42.hyeyoo@gmail.com>, Andrey Konovalov , Dmitry Vyukov , Andrey Ryabinin , Alexander Potapenko , Vincenzo Frascino , linux-mm@kvack.org, kasan-dev@googlegroups.com, linux-kernel@vger.kernel.org References: <20221121135024.1655240-1-feng.tang@intel.com> <20221121121938.1f202880ffe6bb18160ef785@linux-foundation.org> From: Vlastimil Babka In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1669195266; a=rsa-sha256; cv=none; b=HrMIgHuI4AUDVe1Ki8IUSDYHNSOswTbF2neEKsa+CbrXFom3m609TEoSWdycZdipx2bF5I 5R86CD5XKq4TWO21XKN8gzYq223j1PQvAoBBNwInb19WwFx/LIvJbiCF7Qq+NILBrjHx58 k8k+GG4C7Kx2YaVHSoXnI8OC7xJJAy0= ARC-Authentication-Results: i=1; imf08.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=WQgMsxhW; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=aSmEAcQJ; dmarc=none; spf=pass (imf08.hostedemail.com: domain of vbabka@suse.cz designates 195.135.220.29 as permitted sender) smtp.mailfrom=vbabka@suse.cz ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1669195266; 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=6ChOqSLee0rmz2oTzjZlbgB7fmW7X2/L74cYDn2AHg0=; b=Mz5WeU0ZH5lqGtcvertkWQNT1Fo8grea+FMeL7PUMxdrx7fxV3DHWfZxfwGe3IdobzFbrc KxKpf4eWvvRp+ZUqT3xBjdq9FFbPL0eqvOJAmWF+oDRKcEWMC7gUjp6ieQG/Z9At3MjEkN vtYM7AORFHUGzO3YXNMjPgrWt17I3V4= X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: A38D316000B X-Rspam-User: Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=WQgMsxhW; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=aSmEAcQJ; dmarc=none; spf=pass (imf08.hostedemail.com: domain of vbabka@suse.cz designates 195.135.220.29 as permitted sender) smtp.mailfrom=vbabka@suse.cz X-Stat-Signature: as3s54htwzsdtq9tyf869ti53jd6garz X-HE-Tag: 1669195265-269628 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: On 11/22/22 06:30, Feng Tang wrote: > On Mon, Nov 21, 2022 at 12:19:38PM -0800, Andrew Morton wrote: >> On Mon, 21 Nov 2022 21:50:23 +0800 Feng Tang wrote: >> >> > +#ifndef CONFIG_SLOB >> > +#define is_kmalloc_cache(s) ((s)->flags & SLAB_KMALLOC) >> > +#else >> > +#define is_kmalloc_cache(s) (false) >> > +#endif >> >> Could be implemented as a static inline C function, yes? > > Right, I also did try inline function first, and met compilation error: > > " > ./include/linux/slab.h: In function ‘is_kmalloc_cache’: > ./include/linux/slab.h:159:18: error: invalid use of undefined type ‘struct kmem_cache’ > 159 | return (s->flags & SLAB_KMALLOC); > | ^~ > " > > The reason is 'struct kmem_cache' definition for slab/slub/slob sit > separately in slab_def.h, slub_def.h and mm/slab.h, and they are not > included in this 'include/linux/slab.h'. So I chose the macro way. You could try mm/slab.h instead, below the slub_def.h includes there. is_kmalloc_cache(s) shouldn't have random consumers in the kernel anyway. It's fine if kasan includes it, as it's intertwined with slab a lot anyway. > Btw, I've worked on some patches related with sl[auo]b recently, and > really felt the pain when dealing with 3 allocators, on both reading > code and writing patches. And I really like the idea of fading away > SLOB as the first step :) Can't agree more :) >> If so, that's always best. For (silly) example, consider the behaviour >> of >> >> x = is_kmalloc_cache(s++); >> >> with and without CONFIG_SLOB. > > Another solution I can think of is putting the implementation into > slab_common.c, like the below? The overhead of function call between compilation units (sans LTO) is not worth it. > Thanks, > Feng > > --- > diff --git a/include/linux/slab.h b/include/linux/slab.h > index 067f0e80be9e..e4fcdbfb3477 100644 > --- a/include/linux/slab.h > +++ b/include/linux/slab.h > @@ -149,6 +149,17 @@ > > struct list_lru; > struct mem_cgroup; > + > +#ifndef CONFIG_SLOB > +extern bool is_kmalloc_cache(struct kmem_cache *s); > +#else > +static inline bool is_kmalloc_cache(struct kmem_cache *s) > +{ > + return false; > +} > +#endif > + > /* > * struct kmem_cache related prototypes > */ > diff --git a/mm/slab_common.c b/mm/slab_common.c > index a5480d67f391..860e804b7c0a 100644 > --- a/mm/slab_common.c > +++ b/mm/slab_common.c > @@ -77,6 +77,13 @@ __setup_param("slub_merge", slub_merge, setup_slab_merge, 0); > __setup("slab_nomerge", setup_slab_nomerge); > __setup("slab_merge", setup_slab_merge); > > +#ifndef CONFIG_SLOB > +bool is_kmalloc_cache(struct kmem_cache *s) > +{ > + return (s->flags & SLAB_KMALLOC); > +} > +#endif > + > /* > * Determine the size of a slab object > */