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 AAC0FC433EF for ; Thu, 7 Apr 2022 08:50:51 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1CEDB6B0071; Thu, 7 Apr 2022 04:50:41 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 17DF26B0073; Thu, 7 Apr 2022 04:50:41 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 06DAE6B0074; Thu, 7 Apr 2022 04:50:41 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (relay.hostedemail.com [64.99.140.27]) by kanga.kvack.org (Postfix) with ESMTP id ED3556B0071 for ; Thu, 7 Apr 2022 04:50:40 -0400 (EDT) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id B43D4295BA for ; Thu, 7 Apr 2022 08:50:30 +0000 (UTC) X-FDA: 79329461820.13.63A5A40 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf19.hostedemail.com (Postfix) with ESMTP id 42DDD1A0003 for ; Thu, 7 Apr 2022 08:50:30 +0000 (UTC) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 4728C60CBA; Thu, 7 Apr 2022 08:50:29 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D2175C385A0; Thu, 7 Apr 2022 08:50:26 +0000 (UTC) Date: Thu, 7 Apr 2022 09:50:23 +0100 From: Catalin Marinas To: Hyeonggon Yoo <42.hyeyoo@gmail.com> Cc: Will Deacon , Marc Zyngier , Arnd Bergmann , Greg Kroah-Hartman , Andrew Morton , Linus Torvalds , linux-mm@kvack.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH 08/10] mm/slab: Allow dynamic kmalloc() minimum alignment Message-ID: References: <20220405135758.774016-1-catalin.marinas@arm.com> <20220405135758.774016-9-catalin.marinas@arm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Authentication-Results: imf19.hostedemail.com; dkim=none; dmarc=fail reason="SPF not aligned (relaxed), No valid DKIM" header.from=arm.com (policy=none); spf=pass (imf19.hostedemail.com: domain of cmarinas@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=cmarinas@kernel.org X-Stat-Signature: hwe4mtrpmxeprgmbax3owhfi9teopycm X-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 42DDD1A0003 X-HE-Tag: 1649321430-357154 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 Thu, Apr 07, 2022 at 03:46:37AM +0000, Hyeonggon Yoo wrote: > On Tue, Apr 05, 2022 at 02:57:56PM +0100, Catalin Marinas wrote: > > --- a/mm/slab_common.c > > +++ b/mm/slab_common.c > > @@ -838,9 +838,18 @@ void __init setup_kmalloc_cache_index_table(void) > > } > > } > > > > -static void __init > > +unsigned int __weak arch_kmalloc_minalign(void) > > +{ > > + return ARCH_KMALLOC_MINALIGN; > > +} > > + > > As ARCH_KMALLOC_ALIGN and arch_kmalloc_minalign() may not be same after > patch 10, I think s/ARCH_KMALLOC_ALIGN/arch_kmalloc_minalign/g > for every user of it would be more correct? Not if the code currently using ARCH_KMALLOC_MINALIGN needs a constant. Yes, there probably are a few places where the code can cope with a dynamic arch_kmalloc_minalign() but there are two other cases where a constant is needed: 1. As a BUILD_BUG check because the code is storing some flags in the bottom bits of a pointer. A smaller ARCH_KMALLOC_MINALIGN works just fine here. 2. As a static alignment for DMA requirements. That's where the newly exposed ARCH_DMA_MINALIGN should be used. Note that this series doesn't make the situation any worse than before since ARCH_DMA_MINALIGN stays at 128 bytes for arm64. Current users can evolve to use a dynamic alignment in future patches. My main aim with this series is to be able to create kmalloc-64 caches on arm64. > > @@ -851,10 +860,17 @@ new_kmalloc_cache(int idx, enum kmalloc_cache_type type, slab_flags_t flags) > > flags |= SLAB_ACCOUNT; > > } > > > > - kmalloc_caches[type][idx] = create_kmalloc_cache( > > - kmalloc_info[idx].name[type], > > - kmalloc_info[idx].size, flags, 0, > > - kmalloc_info[idx].size); > > + if (minalign > ARCH_KMALLOC_MINALIGN) { > > + aligned_size = ALIGN(aligned_size, minalign); > > + aligned_idx = __kmalloc_index(aligned_size, false); > > + } > > + > > + if (!kmalloc_caches[type][aligned_idx]) > > + kmalloc_caches[type][aligned_idx] = create_kmalloc_cache( > > + kmalloc_info[aligned_idx].name[type], > > + aligned_size, flags, 0, aligned_size); > > + if (idx != aligned_idx) > > + kmalloc_caches[type][idx] = kmalloc_caches[type][aligned_idx]; > > I would prefer detecting minimum kmalloc size in create_kmalloc_caches() > in runtime instead of changing behavior of new_kmalloc_cache(). That was my initial attempt but we have a couple of create_kmalloc_cache() (not *_caches) calls directly, one of them in mm/slab.c kmem_cache_init(). So I wanted all the minalign logic in a single place, hence I replaced the explicit create_kmalloc_cache() call with new_kmalloc_cache(). See this patch and patch 9 for some clean-up. -- Catalin