Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp1154108rwi; Fri, 14 Oct 2022 13:50:22 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4/xkCpji0QtmljDoxfruWFWDnInzLNrhgTNtbuzULmPNgpBye/8JIE7PAAJrq08fOeky+8 X-Received: by 2002:a05:6402:448c:b0:457:52eb:b57e with SMTP id er12-20020a056402448c00b0045752ebb57emr5943193edb.178.1665780622507; Fri, 14 Oct 2022 13:50:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665780622; cv=none; d=google.com; s=arc-20160816; b=0oRX0XE0csAj56fjTNZJm+tyfSygBIoblggW8X2XuMs2F+kjp6N8Sh32dfPa8f1Yyq 9UA3RtI7oYr23icPZNBGdfocaYA52dJYfllSm1m7Vs9rxvymI/h/LEISaREwtcT365WD P9EerEnwy/2y49QhV1htg8MsTDMZyW4utvYuavFfuanWBM9OxABWOM7v9Mgr3tOrMSFY ExUxt2RsmZlim+fFfgAl7qXoyRhBVmcmR0gVMzz8qxY2rvm6/L/d668s2V/+G2XCYKrO ZoJopZ5ioKuSTsCybWO+PPIHXw+vJAyeXOOeF7fWf3HQi9yQf63G7ffJKMhEkEA9hIjE FDvw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=EpzOL2I39WBx4qybm1ABKOUs+/6ZbeAJj9uKHcYl/y0=; b=pbrPP8NNAfSW/eUtmOjFJKEcQ3y6wO9nM+Cn/f+qg6LGJm1FHx4DI0/YNp32OnmJEG F93fn0P5u0RXAj0m6rYvwpvkxzmZ9fJmKldTe61uPZwqevVcbXzoQpCBeDd6yByv0AiC lFGjqWuDUoV2IhnR2FyUSw3OR/Xsbw6lVpHuBumr4m+kCWjFUTEBE3utolE3SqLdDyJ/ /wJTIoBiOvuraFLRZVTPukc/oeyT+zUAcDao1CITey8jorVGIXjpI1a3txaM7+Fx+Lpo m4O2RvHlHtGYsSaWmSUJ2sBYZObpYZC6FtoukhkkB62khz2sobPEdSHMBrcnBn/LdtT2 /AMw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=rqSEwkAG; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b8-20020a056402350800b0045ca6518886si3625647edd.555.2022.10.14.13.49.56; Fri, 14 Oct 2022 13:50:22 -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=@google.com header.s=20210112 header.b=rqSEwkAG; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231373AbiJNUXn (ORCPT + 99 others); Fri, 14 Oct 2022 16:23:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56352 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231438AbiJNUXl (ORCPT ); Fri, 14 Oct 2022 16:23:41 -0400 Received: from mail-pj1-x1033.google.com (mail-pj1-x1033.google.com [IPv6:2607:f8b0:4864:20::1033]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ECB441D5843 for ; Fri, 14 Oct 2022 13:23:39 -0700 (PDT) Received: by mail-pj1-x1033.google.com with SMTP id t12-20020a17090a3b4c00b0020b04251529so5742095pjf.5 for ; Fri, 14 Oct 2022 13:23:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=EpzOL2I39WBx4qybm1ABKOUs+/6ZbeAJj9uKHcYl/y0=; b=rqSEwkAGNU0A9qJXTxV51byK3octUtAdTJqjspf3Zo48mhS2+uaup2U//kMV6Qoi62 syQwaRn9nsRagawb/MKhDXVvCpux2lI+M4XEw1iDZC0o2HhDC9k5j5PExZukHB5G/Jww j6ZItS6qhvBaudYRlPHGRKhhJBskxFwmJ78+J+X/HkBc6g758120CU0/QzDCX9fV81e4 Eq4ii2IUaIpi9bIJt80Lspql5uGcRZWW9z8VL+EdbkVPXwT4p5ov9Q0wzUY09iwHM/MJ H5vBxIMqou+Z9ewA89od4rWZTGb9L0mvjcwT/loTUek4I3GIZ9PlVAhIZ1LDxwyojwlB VDvA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=EpzOL2I39WBx4qybm1ABKOUs+/6ZbeAJj9uKHcYl/y0=; b=qlOu+ErcEDu9pRcQBdYOpZczXJlIvVga1U110xztnifLJMbZLNHACmPAmvUf8VtHyu YPPSng72ceC7GYYUFwwXyzr6+R5qwSoz2nBqIWsNgPCosDy37u6lnj+iuxJfyoyfCf5p 6dHkyWK1VBMYoc/HKytQbWHfr4Jtj8nxu69XC+7TBDU8Jx/SZqjOV1yuMxubYrw+iG7i uAbyTxD1FJxTOz1auAwazCNuRZVEOGBUpgyY+D/YWzQS+P9XwWuSteHQJ9OiKQ2VcXpv Z1VhBjOradarkBDXodbCrKdvpvh8wxEgYxE2t3jTfLp8Va+gzJ9n/IqhrITWHO6G65l3 z4qA== X-Gm-Message-State: ACrzQf19SKwaeA2OqDdNVt3T0Nox8M8vgAeOhtUkGyNwtWMsH0kgM9nu Rl9C5lcmMkVTTnKC9CtfZxxsK6Mr+7fo7wJhYXWIhw== X-Received: by 2002:a17:902:f786:b0:180:6f9e:23b with SMTP id q6-20020a170902f78600b001806f9e023bmr7264149pln.37.1665779019201; Fri, 14 Oct 2022 13:23:39 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Saravana Kannan Date: Fri, 14 Oct 2022 13:23:02 -0700 Message-ID: Subject: Re: [PATCH 07/10] crypto: Use ARCH_DMA_MINALIGN instead of ARCH_KMALLOC_MINALIGN To: Catalin Marinas 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 Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-17.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL 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 Fri, Oct 14, 2022 at 9:25 AM Catalin Marinas wrote: > > 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. This seems like a good compromise. > > > 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). Agreed. Even allowing a 64-byte kmalloc cache on a system with a 64-byte cacheline size saves quite a bit of memory. -Saravana