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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 73918C433F5 for ; Thu, 7 Apr 2022 09:43:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References: Message-ID:Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=a0N9xRBhLJ5YxfyI5w04E87ByUg/LoD9SZXy0G+3PGg=; b=SfJvI7NeM3wfF4 VWC66X2QqU0F3k20ZdcStN4xGOyHGYWLP7e1QtMphLH/KVEHuQZh/HyB60YZvcLWXVgKO+r6aivde 3W+TucUIEoJVMHtJU76vmqx/NMYQsfPRljbkQIhl1w3T1+ixsZFMXClfZr7kr+Wel594Jy8gERqPa e7fBVSsUmJxiB2BSySccSub6uJOpHrsjeyKmKQ7E4udJ3HBm9r55GH4OWn9vb0wVVYDI+CL6CivuK W0E2ouj8xW8VGghr3yQYdoTUTkH7Bo+NQerKEB1jiBB0t4QziNqU/CSsVOA2Bzb9ke9NV87lclrYi pRKYNVX/zgHtjqTdzo6g==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1ncOe6-00Awzl-CM; Thu, 07 Apr 2022 09:41:44 +0000 Received: from mail-pg1-x52e.google.com ([2607:f8b0:4864:20::52e]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1ncOHb-00AmRm-Gh for linux-arm-kernel@lists.infradead.org; Thu, 07 Apr 2022 09:18:29 +0000 Received: by mail-pg1-x52e.google.com with SMTP id d185so4433566pgc.13 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=Fs1d3GMPyZIV1Fr6RKid6eEYfVcnr+uiJEUiRho1/e5WRO4s3XUoYVRy7bjqHR2A47 bWV1NSQff2NJF5OoCp69DRDvOFmS0l3J1JjdzDtJ+aKVoVybySwH74ENmhcbbHdZiGCv GCiWQYEaksTrn6TL6ZGm5QTwCYbsypMoO75uZ8k7+767pNpaiHlVKoi9UzRCznub6vGM exDWXkTMLTbSb1SanGvYwVRVnvbRpXIavdc5XXuzI6GUrq1iV4+OOU5tuJYK7FomB5wt i6h1GzBZx5pB0f+GiubexT4+ECXrJP9RLF/8MMjDrVVjD8aaYWtJBPh0ETb6XFueLnoA F26w== X-Gm-Message-State: AOAM5316wIae3LWbywQxMTWHuWgIVI9zgORY8EfYGxY7B2KRFl8JCWMD 29BqFn4Tf5P3YWao6f3efK0= 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-Disposition: inline In-Reply-To: X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220407_021827_737643_2B914CC1 X-CRM114-Status: GOOD ( 32.55 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel