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 EB8DAC433F5 for ; Thu, 7 Apr 2022 09:18:47 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3363E6B0071; Thu, 7 Apr 2022 05:18:37 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 2E6366B0073; Thu, 7 Apr 2022 05:18:37 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 185D96B0074; Thu, 7 Apr 2022 05:18:37 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0245.hostedemail.com [216.40.44.245]) by kanga.kvack.org (Postfix) with ESMTP id 06ACF6B0071 for ; Thu, 7 Apr 2022 05:18:37 -0400 (EDT) Received: from smtpin29.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 9FD7A184040FE for ; Thu, 7 Apr 2022 09:18:26 +0000 (UTC) X-FDA: 79329532212.29.57E1BE7 Received: from mail-pg1-f178.google.com (mail-pg1-f178.google.com [209.85.215.178]) by imf05.hostedemail.com (Postfix) with ESMTP id 1BDDE100006 for ; Thu, 7 Apr 2022 09:18:25 +0000 (UTC) Received: by mail-pg1-f178.google.com with SMTP id 32so2343261pgl.4 for ; Thu, 07 Apr 2022 02:18:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=5gURCAriqkaAtBbfKf62b2z4rl8Y51p+M4glQXpt9x8=; b=iGLO9qe/PLwc1g6gOO9kH9kQ/Zco0tV2QRxPA5NnhsCk8qICB1T+hQV3mEZfZ5Oh6C iyj+HWjI9UtZ7/mcTu4BNNcZxvlrpzPqYw0rdtj8y8W2AwTj/kQlncQWMVnfaXoMF/3o FAj3X8m0QYcAYrA/Jx6w4I1Pe/mRUW7vPpYmrRoSuEDxahR3qjQCAUs/JaCyMB2UtnTJ +tNjfj83dJc+388hr0Xgvs7T6qgxO6dk6ty9hqyTO2N6rvbaPw5yDZl3sP8b0qWg3hpp 1QVn8ZR6pWKB+0Rh7Xeu+yOvK/o/ljXRRFsh1kDbVHArhHeRLecj/BofTQYCtNIHEHwT Z6NA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=5gURCAriqkaAtBbfKf62b2z4rl8Y51p+M4glQXpt9x8=; b=CspbXUFKAij/ORCHpxTgFlNF1zgFxNxky7Hjt3ooGaCYlc7N/4HM+e+XelkGPXsrWW ow2N30spDphymZf7LnGaj2AxwUIkFY9GTWp+WxCh1WULYrgSam5I+OT4SlcMbPgNoIyw O7pKpijrjeOawBGJxzfmpRr4hxoWGsGUf3tYwP8qXeI38o6IP6OmmS0sG0lqW/nFZKRo M2iNTeJV9GZdthOTL92woTQb1AMGD2K48j0MHS1WvHrt/zmo9KIw0ORiP9q4jYpZ7A8D ZqzYu/l9L001I8h/LLzD551l7hKVBupXgsz3xD7ksybIjAis1M65h3suay1SNpm15SVx h09Q== X-Gm-Message-State: AOAM532eB+2g7BzVlsZE/dwvhBdph3L2Z9g1dmqAZhUOcpx0Sbej0V9Z P77H+QUTgbshT8scpbc9p7s= X-Google-Smtp-Source: ABdhPJxlX1yOTDW7FCqeMUgd+SHwts+POqKUD0XmCnmbloTbgSQo0fWVa+V2PUrlzMGI9pF6xNdFQw== X-Received: by 2002:aa7:8049:0:b0:4fd:bfde:45eb with SMTP id y9-20020aa78049000000b004fdbfde45ebmr13388148pfm.76.1649323104933; Thu, 07 Apr 2022 02:18:24 -0700 (PDT) Received: from hyeyoo ([114.29.24.243]) by smtp.gmail.com with ESMTPSA id p10-20020a056a000b4a00b004fd9a6a2a39sm22754230pfo.184.2022.04.07.02.18.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Apr 2022 02:18:23 -0700 (PDT) Date: Thu, 7 Apr 2022 18:18:16 +0900 From: Hyeonggon Yoo <42.hyeyoo@gmail.com> To: Catalin Marinas 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: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 1BDDE100006 X-Stat-Signature: jx5yud3rrcbiz1j4s8nqk6gabazkqfdq Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b="iGLO9qe/"; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf05.hostedemail.com: domain of 42.hyeyoo@gmail.com designates 209.85.215.178 as permitted sender) smtp.mailfrom=42.hyeyoo@gmail.com X-Rspam-User: X-HE-Tag: 1649323105-763370 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 09:50:23AM +0100, Catalin Marinas wrote: > 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. AFAIK there are bunch of drivers that directly calls kmalloc(). It becomes tricky when e.g.) a driver allocates just 32 bytes, but architecture requires it to be 128-byte aligned. That's why everything allocated from kmalloc() need to be aligned in ARCH_DMA_MINALIGN. And It's too hard to update all of drivers that depends on this fact. So I'm yet skeptical on decoupling ARCH_DMA/KMALLOC_MINALIGN. Instead of decoupling it, I'm more into dynamically decreasing it. Please kindly let me know If I'm missing something ;-) > > > @@ -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 -- Thanks, Hyeonggon