Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp901606rwi; Fri, 14 Oct 2022 10:01:49 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5MkBDpBqnVLLdvoPMTkVD/q+FnM78WWEBjMJ1nWS98SLHkBKp5NjxzZahbpHBwJiL7+D/Z X-Received: by 2002:a17:907:9713:b0:78d:8e23:892c with SMTP id jg19-20020a170907971300b0078d8e23892cmr4188674ejc.449.1665766909598; Fri, 14 Oct 2022 10:01:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665766909; cv=none; d=google.com; s=arc-20160816; b=JvzvQkmlDhhCH/ysPfRuCIHat9njfHRa5Kpw4g5IrNhu2xeWtt4k1B5W+exL8xvH5k KOgomx0k6MDQck1NUncpVUFMi1GFEr1P+92oyB5HSyRJgBrB3LACPUT2G1IeIJ3iYW+A NgJrNSMBcqKxVNYoCPlMdWelwpmwZ73l9sB4D4cJ2XfRMiZUNSGT2PEnOZxSKSulNcY9 0hzxnODHOfLSdrfBpTlgDKu6wFYo3+wShlvqAxO1FJ9sbnlTkD0C+b/Tn3WRlH/WD6EI R91DnJo+CRfEMn+Ff7yTxbL+9IGPYfVYKJCYAA7A4ly91/QDSnm7DQHWkEB6SPRmJ95w TtfA== 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; bh=SOuySbzNUl0QzTzHJTFyXaK6zIExcJxbBxEtta1Bs0I=; b=oKXX/vKzeom78CfR8hFK9k4s+9JceLX/hh3wqoJ/QaO9j4Yu8rFSKyEVRFm/DXq2uO nFaqcWGGecXupxJIcLgckRLtHKPakv2sa20QzD79qGih5lJP2FGpXqRP9OavFLqMpl8n 4rSV2abTHsOngn9wyoApwkM/cH9PTL7FwMOIHOyL2792sPevbnZmrknvpgIb+zZwDH9h hQrfLkYq/66BDEf1/2ssSZArpc8fc+0KH4epzhxFPST6YTrjQj/fAdFIicYQtGMnZmkf dNi7hVAcAdJ9JmLV+hLSf7cnuUfJqicD22LfhLh/DY0YzgWM8eHVPjC9lrxhbHNGjqBv Wz6w== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id sg20-20020a170907a41400b0078cc8a2cf4bsi2875911ejc.614.2022.10.14.10.01.14; Fri, 14 Oct 2022 10:01:49 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230033AbiJNQZn (ORCPT + 99 others); Fri, 14 Oct 2022 12:25:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44392 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230273AbiJNQZl (ORCPT ); Fri, 14 Oct 2022 12:25:41 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9EEB7D8ED7 for ; Fri, 14 Oct 2022 09:25:39 -0700 (PDT) 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 B034E61BC5 for ; Fri, 14 Oct 2022 16:25:38 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 78F26C433C1; Fri, 14 Oct 2022 16:25:34 +0000 (UTC) Date: Fri, 14 Oct 2022 17:25:30 +0100 From: Catalin Marinas To: Saravana Kannan Cc: Isaac Manjarres , Herbert Xu , Ard Biesheuvel , Will Deacon , Marc Zyngier , Arnd Bergmann , Greg Kroah-Hartman , Andrew Morton , Linus Torvalds , Linux Memory Management List , Linux ARM , Linux Kernel Mailing List , "David S. Miller" , kernel-team@android.com Subject: Re: [PATCH 07/10] crypto: Use ARCH_DMA_MINALIGN instead of ARCH_KMALLOC_MINALIGN Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-6.7 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_HI,SPF_HELO_NONE,SPF_PASS 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 On Thu, Oct 13, 2022 at 11:58:22AM -0700, Saravana Kannan wrote: > On Thu, Oct 13, 2022 at 9:57 AM Catalin Marinas wrote: > > > If so, would there be concerns that the memory savings we get back from > > > reducing the memory footprint of kmalloc might be defeated by how much > > > memory is needed for bounce buffering? > > > > It's not necessarily about the saved memory but also locality of the > > small buffer allocations, less cache and TLB pressure. > > Part of the pushback we get when we try to move some of the Android > ecosystem from 32-bit to 64-bit is the memory usage increase. So, > while the main goal might not be memory savings, it'll be good to keep > that in mind too. I'd definitely not want this patch series to make > things worse. Ideally, it'd make things better. 10MB is considered a > lot on some of the super low speced devices. Well, we can still add the option to skip allocating from the small kmalloc caches if there's no swiotlb available. > > I wonder whether swiotlb is actually the best option for bouncing > > unaligned buffers. We could use something like mempool_alloc() instead > > if we stick to small buffers rather than any (even large) buffer that's > > not aligned to a cache line. Or just go for kmem_cache_alloc() directly. > > A downside is that we may need GFP_ATOMIC for such allocations, so > > higher risk of failure. > > Yeah, a temporary kmem_cache_alloc() to bounce buffers off of feels > like a better idea than swiotlb. Especially for small allocations (say > 8 byte allocations) that might have gone into the kmem-cache-64 if we > hadn't dropped KMALLOC_MIN_ALIGN to 8. I now remembered why this isn't trivial. On the dma_unmap_*() side, we can't easily tell whether the buffer was bounced and it needs freeing. The swiotlb solves this by checking whether the address is within the pre-allocated swiotlb range. With kmem_caches, we could dig into the slab internals and check whether the pointer is part of a slab page, then check with kmem_cache that was. It looks too complicated and I'm rather tempted to just go for swiotlb if available or prevent the creation of small kmalloc caches if no swiotlb (TBH, even the initial series was an improvement dropping KMALLOC_MIN_ALIGN from 128 to 64). -- Catalin