Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp228279ybz; Wed, 15 Apr 2020 07:41:12 -0700 (PDT) X-Google-Smtp-Source: APiQypJbrpz3YznrcvlVkwrxupvRUS0CFqNW+EyXyapLp4nk5+E6UQX53+R/Jo+tDii3DcUfpv7/ X-Received: by 2002:a17:906:298f:: with SMTP id x15mr5305010eje.380.1586961672104; Wed, 15 Apr 2020 07:41:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1586961672; cv=none; d=google.com; s=arc-20160816; b=UyrFpN4B70AqthbmW5BPteW7HH08qMpBd/yzaGFt+YTDUNoUO1PvQjeOcxmzNEh8je bdOftjRjp5UCEpBi3cye/II5P7Yr1tx7gXO+8uUp+M6i4Ayo+IUy0F8OzFDAOZXxr/2M EsbTqBs74l6l8F8KjJ2vck7lb3C0o+AnZSriUDeA/ttRAau5WxXnC1q/1Gg6jvT3rrMF riJiMFA2Mrqt5FF4oskCHxUY8S2V5mB3TiiaTsRroA39tyZXA4uoRaurw5nDLvvTJ/sj hVKw7p+l5Wn6mwj2HVVMu+/bt9EBZOvUlQwpNQ1lS0wg1f3uF/o6+Wopnexfb8dOlRRM SXAQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :message-id:in-reply-to:subject:cc:to:from:date:dkim-signature; bh=ZqTkeiwENaudq21J8vTW1kd2VtXPsvTLGQP3XXO1NHU=; b=D2uSMadQBGRnSbcczs9fuJajRJurK41uW/xYXduiqxkWvU9pp01qmcwcO31MiwnRF9 IpkwhaxTyUT9JbtzukNogCnXBL9QR4NIPkroiZ7rIh6cJr4/W4wFMmF/mlAg++NHzIFv 1h5yeyFJ6XM7yMSQ2X51Ys9a0eF7iSQOJ7VDzF7K3C0h8U4T1/X3eJcNaFLBJUg7BT+k gDu7SEw9bWxq8pMBvuziXAVtynhMv1fC8r2pcX2HbA6DzXo/4SA5Ml+xppwl9fOSc9r3 L3Gl3HtDVtUVwdlWZPH03ae7Hs+C9W/YeDMntjraGeOUJRManyLM24nxhvormRkDyKGQ z8Hw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=S+BkzuaF; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id e9si3665734eds.63.2020.04.15.07.40.47; Wed, 15 Apr 2020 07:41:12 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=S+BkzuaF; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S2392217AbgDOAGY (ORCPT + 99 others); Tue, 14 Apr 2020 20:06:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46040 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2634559AbgDOAFG (ORCPT ); Tue, 14 Apr 2020 20:05:06 -0400 Received: from mail-pf1-x442.google.com (mail-pf1-x442.google.com [IPv6:2607:f8b0:4864:20::442]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 63A81C061A10 for ; Tue, 14 Apr 2020 17:05:04 -0700 (PDT) Received: by mail-pf1-x442.google.com with SMTP id u9so189945pfm.10 for ; Tue, 14 Apr 2020 17:05:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:from:to:cc:subject:in-reply-to:message-id:references :user-agent:mime-version; bh=ZqTkeiwENaudq21J8vTW1kd2VtXPsvTLGQP3XXO1NHU=; b=S+BkzuaFI/ql7zPm2jJufYxYG9LrRhNZMXcnwMDr7r8jFf1R3XOoh24P7ornVUb67I YnoIPO/xfD8edhC3LLxFzpaTtlRpgEOytqa8xPXxxqKqorQUvfz0wf8ZHtB5uGv0ZYVz qCBlHrTG4aJSE5yGfJsI37wsCiRMfGfxBRT2z9h5kbsqd+JhBFOC8+oF0kRc1t+emm+L msn8bCFxkGC6BDW+UG46VXrTXMQb6xMS6pbTr3Ee0LU4xkK3pHGDVgEBxgmItKzP8slj NK6YH0jTf2gwTzf64e5XUml8dQBx8sF1TInfy1UzMxRODBDmXLPg3IXznuV4qTtR0aKU wt8g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:in-reply-to:message-id :references:user-agent:mime-version; bh=ZqTkeiwENaudq21J8vTW1kd2VtXPsvTLGQP3XXO1NHU=; b=HynWN8NaBqsWngf9MrLoJv3Dk3MKOP9yX2MDUdOxnsZDwbcv5qDPeWxq9yShQZhdrh WOgnueO4eWEwuHm8z7u3f3xbTGlDkX3Gtv7l1xXdSdFKl27EFJROnt/uypEhMFPhNhrE WaUqQ5oOQPGepqNE3rMI9ZcvAjbknCkXHDgTMf4DF34yETpNtstwYLOhHEaDEHCb0Rbo hy9WLpM2uwtQ5VFZeeEu5Rn7ag43O0vZqugSTIBlG9vXboVrPjUl11vIluVuG9FP1PeG gy77axquVshQ3qXF/JgUdOe7HFqWfB95FUDhon/9Nmw6p0MRDIxl+UbXk0I+QARrN0+8 XbbA== X-Gm-Message-State: AGi0PuYFzQFokzIOu3cqR0PSBxkKpBVN7WglPz8WFQmAAAC3MTZtOK8N OWcdtn1aRuTXlfTHRq6PIvtRcg== X-Received: by 2002:a63:ff49:: with SMTP id s9mr5626054pgk.46.1586909103760; Tue, 14 Apr 2020 17:05:03 -0700 (PDT) Received: from [2620:15c:17:3:3a5:23a7:5e32:4598] ([2620:15c:17:3:3a5:23a7:5e32:4598]) by smtp.gmail.com with ESMTPSA id d203sm6772412pfd.79.2020.04.14.17.05.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Apr 2020 17:05:03 -0700 (PDT) Date: Tue, 14 Apr 2020 17:05:02 -0700 (PDT) From: David Rientjes X-X-Sender: rientjes@chino.kir.corp.google.com To: Christoph Hellwig , Tom Lendacky cc: Brijesh Singh , Jon Grimm , Joerg Roedel , linux-kernel@vger.kernel.org, iommu@lists.linux-foundation.org, Thomas Gleixner , Ingo Molnar , Borislav Petkov , x86@kernel.org Subject: [patch 7/7] dma-pool: scale the default DMA coherent pool size with memory capacity In-Reply-To: Message-ID: References: User-Agent: Alpine 2.22 (DEB 394 2020-01-19) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org When AMD memory encryption is enabled, some devices may use more than 256KB/sec from the atomic pools. It would be more appropriate to scale the default size based on memory capacity unless the coherent_pool option is used on the kernel command line. This provides a slight optimization on initial expansion and is deemed appropriate due to the increased reliance on the atomic pools. Note that the default size of 128KB per pool will normally be larger than the single coherent pool implementation since there are now up to three coherent pools (DMA, DMA32, and kernel). Note that even prior to this patch, coherent_pool= for sizes larger than 1 << (PAGE_SHIFT + MAX_ORDER-1) can fail. With new dynamic expansion support, this would be trivially extensible to allow even larger initial sizes. Signed-off-by: David Rientjes --- kernel/dma/pool.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/kernel/dma/pool.c b/kernel/dma/pool.c index 3e22022c933b..763b687569b0 100644 --- a/kernel/dma/pool.c +++ b/kernel/dma/pool.c @@ -22,8 +22,8 @@ static unsigned long pool_size_dma32; static unsigned long pool_size_kernel; #endif -#define DEFAULT_DMA_COHERENT_POOL_SIZE SZ_256K -static size_t atomic_pool_size = DEFAULT_DMA_COHERENT_POOL_SIZE; +/* Size can be defined by the coherent_pool command line */ +static size_t atomic_pool_size; /* Dynamic background expansion when the atomic pool is near capacity */ static struct work_struct atomic_pool_work; @@ -181,6 +181,16 @@ static int __init dma_atomic_pool_init(void) { int ret = 0; + /* + * If coherent_pool was not used on the command line, default the pool + * sizes to 128KB per 1GB of memory, min 128KB, max MAX_ORDER-1. + */ + if (!atomic_pool_size) { + atomic_pool_size = max(totalram_pages() >> PAGE_SHIFT, 1UL) * + SZ_128K; + atomic_pool_size = min_t(size_t, atomic_pool_size, + 1 << (PAGE_SHIFT + MAX_ORDER-1)); + } INIT_WORK(&atomic_pool_work, atomic_pool_work_fn); atomic_pool_kernel = __dma_atomic_pool_init(atomic_pool_size,