Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp28350ybl; Thu, 30 Jan 2020 16:20:26 -0800 (PST) X-Google-Smtp-Source: APXvYqwtvaEtEzhLMLsmsvGMDCq0eOYsax/LTh9HaE6TERzPKli4T3tSqWrBGbDyWbxCOPfw1QsX X-Received: by 2002:aca:b483:: with SMTP id d125mr4833245oif.167.1580430026558; Thu, 30 Jan 2020 16:20:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1580430026; cv=none; d=google.com; s=arc-20160816; b=iFMUusNmmKjx70E4ZpJdaZt/IgVAP5QhJHoyTY4Qq1UIAbVIE6JaCXodCTlQSOK5fC YItXOcISuRNYvan+4wxAvNGPxbLv0x9kZvZQ4y43E1pBpWpdUhTlkrVzNtMFkfZ2oPXB i745PSUw3pqyC4x0/DTIMjiZzOKHPFJ2NebW5p8q2ZpyqZpCs9690Jtsz+hfYvHoIn+I /NSV+FyM8X0bkfVXZVx7jyNwVfB7yHLBng1XvmcQRNED2RnA07yp9CdnQlkLB4le8ODU C0H+/4F/yQv6+vTm8Vw6oKlODa/JFkDYbQqORBP6tAiLeTKbmP05rr5sD8M8Tna76wJm PFtA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=hF2uri2aH+78mejNdKG+rVcZv1FZ9AQQm5DHda9hg3Y=; b=Ne2anUol7AqFZ28kYi6kbMesc5BJ/ZQxnUTEUSD0erYI7PCq2+M6hVz94C8ZDung+l HOh0M8BlATZZ8RHY5d93zSoE1hAtOYWALxfxiq0UASLwFJIWMd2Pt5a/cx912kA9S/TC MqnGXV4Lco4bUsymlzE1uarWNzoXVDtVH3XxHKCb+Bex8gNKPy93pI5Mxxt9ncJC2N4h JCsyd0TRU9eqijLPUB4LbcIHWRMdQ4DNsqk6a53S3a/YOUEbqpIfXWMxggv/H4MIkvBV c3BqG41JVPtzQO4Fj4DZ93XEXKDZDvOdD1rRt88T9uG5ZPO0JBZzzr4XzjIBgoMlsczc bglw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=LEMVWagj; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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. [209.132.180.67]) by mx.google.com with ESMTP id z62si3468066oiz.271.2020.01.30.16.20.14; Thu, 30 Jan 2020 16:20:26 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=LEMVWagj; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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 S1727689AbgAaASF (ORCPT + 99 others); Thu, 30 Jan 2020 19:18:05 -0500 Received: from mail-yb1-f193.google.com ([209.85.219.193]:39549 "EHLO mail-yb1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727380AbgAaASF (ORCPT ); Thu, 30 Jan 2020 19:18:05 -0500 Received: by mail-yb1-f193.google.com with SMTP id x18so2362920ybk.6 for ; Thu, 30 Jan 2020 16:18:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=hF2uri2aH+78mejNdKG+rVcZv1FZ9AQQm5DHda9hg3Y=; b=LEMVWagjq9IHsRT1N0YSQld0Z9pg/FWjOVQTVDm0DCgkz6rN6RJnt/Wx4NmoLjvMsX qlfO2naQ+BxZd6O36bK4trB+Pwy2LAQoJRiZZjSlqlfiYI551etXcJfCOhBktx+VeJkB oNoBfx7XcF0yagmyOWlMfhG7DWsPz+UhQsipxQ20UMNRoktF37WDBf+fP8vq2ocY2Ck/ /BTfRI+qIXouLpv+wvG1Y6c9UC2BEMpOI5l5V80rJIWmjE7JuQ3DwHYXiWQdzs8pkgCp 25VDee8OzEChxWLgmIBw+DIBEaV38wmUWHqv5Ubwc+8qlMpqGI3JiiHzfejl/82UZrL6 Cs4A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=hF2uri2aH+78mejNdKG+rVcZv1FZ9AQQm5DHda9hg3Y=; b=K9trxahEFj9u1j4aftqsJ1CV2in3Zb+QKfy7vmXbr5XxXaJdrXc0dL+fVdZ+mb7VCX 0sukDIlmdLvhXtwXBdJeMnr0DL/q2GpGgOk7EjQIlxZbUFQVZedqK858MWNjY2IPJSPh b65WUZclv3L4zrGAuU3tlU/IHF9mH3eWAlc15NxAskIOJWEYhs+Fx2vS6tzIrXru6ld8 1KgNAneHoibgxv/ByzJOXm7KMISRXcLrvBR08p65T3AY9/rVIPlQrzFe3n6QbvBaBArk TBYpBB5dUNAjLNcvxxblfsSAJjTQ39gri3KqUe9etg6l5vz6pW/sW6xjrsy/lLU/oRQD nhgA== X-Gm-Message-State: APjAAAV1NCFCUFd3wgYsIObUhu2NuI0lKrL16TVxHk9e7KzQvTBXTZ/O 42O+IhdGsDr/D2Nne+rEuFU+CW3dJaBBZ9/IZeKtGhQ2sT4= X-Received: by 2002:a5b:489:: with SMTP id n9mr5859875ybp.395.1580429883367; Thu, 30 Jan 2020 16:18:03 -0800 (PST) MIME-Version: 1.0 References: <20200130191049.190569-1-edumazet@google.com> In-Reply-To: From: Eric Dumazet Date: Thu, 30 Jan 2020 16:17:52 -0800 Message-ID: Subject: Re: [PATCH] dma-debug: dynamic allocation of hash table To: Robin Murphy Cc: Christoph Hellwig , Joerg Roedel , iommu@lists.linux-foundation.org, Eric Dumazet , Geert Uytterhoeven , linux-kernel Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Jan 30, 2020 at 3:46 PM Robin Murphy wrote: > > Hi Eric, > > On 2020-01-30 7:10 pm, Eric Dumazet via iommu wrote: > > Increasing the size of dma_entry_hash size by 327680 bytes > > has reached some bootloaders limitations. > > [ That might warrant some further explanation - I don't quite follow how > this would relate to a bootloader specifically :/ ] I had no details, please look at the prior thread where this has been discussed. https://www.spinics.net/lists/linux-renesas-soc/msg46157.html > > > Simply use dynamic allocations instead, and take > > this opportunity to increase the hash table to 65536 > > buckets. Finally my 40Gbit mlx4 NIC can sustain > > line rate with CONFIG_DMA_API_DEBUG=y. > > That's pretty cool, but I can't help but wonder if making the table > bigger caused a problem in the first place, whether making it bigger yet > again in the name of a fix is really the wisest move. How might this > impact DMA debugging on 32-bit embedded systems with limited vmalloc > space and even less RAM, for instance? More to the point, does vmalloc() > even work for !CONFIG_MMU builds? Obviously we don't want things to be > *needlessly* slow if avoidable, but is there a genuine justification for > needing to optimise what is fundamentally an invasive heavyweight > correctness check - e.g. has it helped expose race conditions that were > otherwise masked? Not sure what you are saying. vmalloc() _is_ supported by all arches, even !CONFIG_MMU I can not test all platforms, and this is a debugging feature no one uses in production. > > That said, by moving to dynamic allocation maybe there's room to be > cleverer and make HASH_SIZE scale with, say, system memory size? (I > assume from the context it's not something we can expand on-demand like > we did for the dma_debug_entry pool) > How memory size can serve as a proxy of the number of entries ? Current 10Gbit NIC need about 256,000 entries in the table. Needless to say, the prior hash size was unusable. As I suggested one month ago, HASH_SIZE can be tuned by a developper eager to use this facility. 65536 slots are 768 KB on 32bit platforms. > Robin. > > > Fixes: 5e76f564572b ("dma-debug: increase HASH_SIZE") > > Signed-off-by: Eric Dumazet > > Reported-by: Geert Uytterhoeven > > Cc: Christoph Hellwig > > --- > > kernel/dma/debug.c | 10 ++++++++-- > > 1 file changed, 8 insertions(+), 2 deletions(-) > > > > diff --git a/kernel/dma/debug.c b/kernel/dma/debug.c > > index 2031ed1ad7fa109bb8a8c290bbbc5f825362baba..a310dbb1515e92c081f8f3f9a7290dd5e53fc889 100644 > > --- a/kernel/dma/debug.c > > +++ b/kernel/dma/debug.c > > @@ -27,7 +27,7 @@ > > > > #include > > > > -#define HASH_SIZE 16384ULL > > +#define HASH_SIZE 65536ULL > > #define HASH_FN_SHIFT 13 > > #define HASH_FN_MASK (HASH_SIZE - 1) > > > > @@ -90,7 +90,8 @@ struct hash_bucket { > > }; > > > > /* Hash list to save the allocated dma addresses */ > > -static struct hash_bucket dma_entry_hash[HASH_SIZE]; > > +static struct hash_bucket *dma_entry_hash __read_mostly; > > + > > /* List of pre-allocated dma_debug_entry's */ > > static LIST_HEAD(free_entries); > > /* Lock for the list above */ > > @@ -934,6 +935,10 @@ static int dma_debug_init(void) > > if (global_disable) > > return 0; > > > > + dma_entry_hash = vmalloc(HASH_SIZE * sizeof(*dma_entry_hash)); > > + if (!dma_entry_hash) > > + goto err; > > + > > for (i = 0; i < HASH_SIZE; ++i) { > > INIT_LIST_HEAD(&dma_entry_hash[i].list); > > spin_lock_init(&dma_entry_hash[i].lock); > > @@ -950,6 +955,7 @@ static int dma_debug_init(void) > > pr_warn("%d debug entries requested but only %d allocated\n", > > nr_prealloc_entries, nr_total_entries); > > } else { > > +err: > > pr_err("debugging out of memory error - disabled\n"); > > global_disable = true; > > > >