Received: by 2002:a05:6358:701b:b0:131:369:b2a3 with SMTP id 27csp2803077rwo; Mon, 24 Jul 2023 01:11:44 -0700 (PDT) X-Google-Smtp-Source: APBJJlHW+h0HI9xDJkY/NILNWNXhGhaFMvBvJgO+m9ZwH2EBF4iGf4RPkBkZYamGOT+v232z5TT9 X-Received: by 2002:a05:6808:1701:b0:39c:93e7:d5b0 with SMTP id bc1-20020a056808170100b0039c93e7d5b0mr8052166oib.21.1690186304249; Mon, 24 Jul 2023 01:11:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690186304; cv=none; d=google.com; s=arc-20160816; b=r6nB80CqtIGNboJ8uJecgoe2zrW7ypJQeCiaaYpZeQp6bKg7j6tEDL6srgT21o6sin 6pFv7tRwpbpksW2sQFrpkSxpQ91mUGTTjEbLq13duVExsF2n+u8bTWHpkiq//4TQOhHG Dn9zTp2EtkiYQjgl4R/sthM83qVyU/GC/4umOG6lV/RXicUvImDCOKdzhgHO0GrICn7P lnT3LYqLbSGmf/7vBEDNf5+9zsuHfnHtWhFtY3TnIp7nJHEYRpsSevuNVJtKK2HgqW1+ i0Gnh6fdlTVnoV2BK2hw5xfRNstU21+yW94PrAZ+xxCRTKxyFZWj4/OX38J9vFkhFH7b WJ2Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=A+kwbVV67/8xjXQlCdBs320E+QdGyl/EXUVN3gq01mI=; fh=uoww57x4a6tBgmrAVGrOUFcChtDQAkMNLak7ep0S9no=; b=VvLWtjYiynQTS1P0UIXOR36O+1AHj1VLxgwPtQ4sXLSsrK/x8Gkwi5pu19zaJWM8TX 5EevaAEwKtU4QMf8k8WgmoGirCqrJ4w+2A4zBQZePmPkOsxYheY1srAhVzDFgtwoXMdR vDN51UTNURyT0dymQyRgJIh+ve49ocL59oMzDEUOAEuZMSmY1ENMXlgZdwV9KncSSyI4 +ycDUTto6cDBDZgwaWh1CcLHrLrxD9QnoJTftl+ScJrZk6aPO2bDD3u/dUVOSc5g05kT Ant5yOfXdJuenOyylZULCTULeoa8UMubYEkJa9kYLRWg+boRZi5wDp05/rkTp5zLicIL bYwA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@microchip.com header.s=mchp header.b=2HJht70f; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=microchip.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id nl10-20020a17090b384a00b0025bcbba10c6si9554771pjb.85.2023.07.24.01.11.30; Mon, 24 Jul 2023 01:11:44 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@microchip.com header.s=mchp header.b=2HJht70f; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=microchip.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230261AbjGXHuO (ORCPT + 99 others); Mon, 24 Jul 2023 03:50:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37768 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229583AbjGXHuM (ORCPT ); Mon, 24 Jul 2023 03:50:12 -0400 Received: from esa.microchip.iphmx.com (esa.microchip.iphmx.com [68.232.153.233]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DCAD51A2 for ; Mon, 24 Jul 2023 00:50:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=microchip.com; i=@microchip.com; q=dns/txt; s=mchp; t=1690185011; x=1721721011; h=date:from:to:cc:subject:message-id:references: mime-version:in-reply-to; bh=cFSk2zmVNjF+ma0HjJ0LslmgIPzvLIjCxHLecSYlzvM=; b=2HJht70fU5+CtqYxQLJ18Bj5b/fwq3WRfOPnNOm0WEbZnkMIn8+fAy6a iF7D1vd/1D5w/KmBQmDDG7KnlkpA0EpL+uDnlrenimkqsasNupSQZDNEZ 45+YLcZI3yk98pRKDxDM3ShUbfNOda/8nvn2P6kbPAWKduFShsJYqbuB+ IqCpXS8ArjNk/dsxz0Tk51aS0HHoVOJwjM6F8TcLyFqstslzJbci6FVM1 z80rcj0/qnRTC28YW6KaZbJQzpGcfm53dFGp3aTwGrvJeJvkXkjWozBSX n/NHDmIX8TQBLHrV3DvwP5V0kOFS8KwluW5iP9hXCHJSBainhdzqzMvqo w==; X-IronPort-AV: E=Sophos;i="6.01,228,1684825200"; d="asc'?scan'208";a="237267499" X-Amp-Result: UNKNOWN X-Amp-Original-Verdict: FILE UNKNOWN Received: from unknown (HELO email.microchip.com) ([170.129.1.10]) by esa1.microchip.iphmx.com with ESMTP/TLS/AES256-SHA256; 24 Jul 2023 00:50:09 -0700 Received: from chn-vm-ex03.mchp-main.com (10.10.85.151) by chn-vm-ex03.mchp-main.com (10.10.85.151) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.21; Mon, 24 Jul 2023 00:50:02 -0700 Received: from wendy (10.10.115.15) by chn-vm-ex03.mchp-main.com (10.10.85.151) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.21 via Frontend Transport; Mon, 24 Jul 2023 00:50:01 -0700 Date: Mon, 24 Jul 2023 08:49:27 +0100 From: Conor Dooley To: Jisheng Zhang CC: Paul Walmsley , Palmer Dabbelt , Albert Ou , , Subject: Re: [PATCH v3 1/2] riscv: allow kmalloc() caches aligned to the smallest value Message-ID: <20230724-next-shifter-3ec32114b34e@wendy> References: <20230718152214.2907-1-jszhang@kernel.org> <20230718152214.2907-2-jszhang@kernel.org> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="lbLuWTJ0u5bINZ3+" Content-Disposition: inline In-Reply-To: <20230718152214.2907-2-jszhang@kernel.org> X-Spam-Status: No, score=-5.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, RCVD_IN_MSPIKE_H5,RCVD_IN_MSPIKE_WL,SPF_HELO_PASS,SPF_NONE, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org --lbLuWTJ0u5bINZ3+ Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Tue, Jul 18, 2023 at 11:22:13PM +0800, Jisheng Zhang wrote: > Currently, riscv defines ARCH_DMA_MINALIGN as L1_CACHE_BYTES, I.E > 64Bytes, if CONFIG_RISCV_DMA_NONCOHERENT=3Dy. To support unified kernel > Image, usually we have to enable CONFIG_RISCV_DMA_NONCOHERENT, thus > it brings some bad effects to coherent platforms: >=20 > Firstly, it wastes memory, kmalloc-96, kmalloc-32, kmalloc-16 and > kmalloc-8 slab caches don't exist any more, they are replaced with > either kmalloc-128 or kmalloc-64. >=20 > Secondly, larger than necessary kmalloc aligned allocations results > in unnecessary cache/TLB pressure. >=20 > This issue also exists on arm64 platforms. From last year, Catalin > tried to solve this issue by decoupling ARCH_KMALLOC_MINALIGN from > ARCH_DMA_MINALIGN, limiting kmalloc() minimum alignment to > dma_get_cache_alignment() and replacing ARCH_KMALLOC_MINALIGN usage > in various drivers with ARCH_DMA_MINALIGN etc.[1] >=20 > One fact we can make use of for riscv: if the CPU doesn't support > ZICBOM or T-HEAD CMO, we know the platform is coherent. Based on > Catalin's work and above fact, we can easily solve the kmalloc align > issue for riscv: we can override dma_get_cache_alignment(), then let > it return ARCH_DMA_MINALIGN at the beginning and return 1 once we know > the underlying HW neither supports ZICBOM nor supports T-HEAD CMO. >=20 > So what about if the CPU supports ZICBOM or T-HEAD CMO, but all the > devices are dma coherent? Well, we use ARCH_DMA_MINALIGN as the > kmalloc minimum alignment, nothing changed in this case. This case > can be improved in the future. >=20 > After this patch, a simple test of booting to a small buildroot rootfs > on qemu shows: >=20 > kmalloc-96 5041 5041 96 ... > kmalloc-64 9606 9606 64 ... > kmalloc-32 5128 5128 32 ... > kmalloc-16 7682 7682 16 ... > kmalloc-8 10246 10246 8 ... >=20 > So we save about 1268KB memory. The saving will be much larger in normal > OS env on real HW platforms. >=20 > Link: https://lore.kernel.org/linux-arm-kernel/20230524171904.3967031-1-c= atalin.marinas@arm.com/ [1] >=20 > Signed-off-by: Jisheng Zhang Reviewed-by: Conor Dooley Thanks, Conor. --lbLuWTJ0u5bINZ3+ Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iHUEABYIAB0WIQRh246EGq/8RLhDjO14tDGHoIJi0gUCZL4tBwAKCRB4tDGHoIJi 0jIWAQDK3i9Q+yWDW+zT3HKMI/9vFe2vBFuaDRF2zhYd1DnQmAD/eQucZDuJ1yvE Dnzs8qBMYSXxWuN7amY5rN5pjrjroAo= =PbNw -----END PGP SIGNATURE----- --lbLuWTJ0u5bINZ3+--