Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp4217125yba; Tue, 23 Apr 2019 17:41:15 -0700 (PDT) X-Google-Smtp-Source: APXvYqzlTbvshfSJtNmk9gEbS8rEgfDnl9FQjrDnmgCV0uj4aKAPTFVLOwCqLrZjkTw/qCSBWjJM X-Received: by 2002:a65:5246:: with SMTP id q6mr7949577pgp.296.1556066475210; Tue, 23 Apr 2019 17:41:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1556066475; cv=none; d=google.com; s=arc-20160816; b=J5OS8FMTHnCu5EZp7Oldj/TAnilo5oapORhHE2Pmc06v+mUdC7CuUkAlZCK6hMkaGr a4ukTcgSyyZTMZJc03aoBEbnWFq9opAx8SFLx7oaC8FILUPzf/4InY9HoyyL1ZTXGJKY uGCfmZkTj40AjWHqMcxFkLjAifIb5+fOZsuriu2Y206IPU5RWoSDpPxmYJ/RaFlVByKd T/WqujJLbXhA+vKQcJNV9FrUy6KQcoGg2audQotR2/91YmbgmiiSITgfyk5FuUtPwLng exxE3zcfC7hPGQaL6dNev8CBTYv7GcgVz2Uoj8XQhsEwSgaVhe9TOFSPFerC1AJhmX7N HFbw== 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; bh=HAJ+tsuhVeXXnt5g0+5qfIDYODvPMMpK3Zh37chKNPc=; b=a4vEv09WdMpaDQNERHRy0vCwWWw1TSl/BKm4u/9VTXg+8aKqDm/HzVV8Pu+E8wCZ+l +g0YlhqijUOcYePYasIRYp5BELPUuHWT1dg82Q+//l8FfPuALrCbF+0T750D7YQol2o8 Zfk85ETMptZHiVV+5LK06SxSTt1AKJVaRy7q773CfQMvTLoDgvrHbQ/6J28gbPL8QaJ8 5ZwL1/uygK/QeEg4ZmtYO2B8nRVx1IXYXEpDcZu6sCFmm++ehN7okP+3oyHl8oU58y/p CMA0uBPhvvuhJF/aSk6kPFRnRDI4saMtQzt/H35wsKe/9xmuj9t8+sTspxptaSH7ecrS sRrQ== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=canonical.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 33si16797950pgm.385.2019.04.23.17.40.59; Tue, 23 Apr 2019 17:41:15 -0700 (PDT) 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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=canonical.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728899AbfDXAkF (ORCPT + 99 others); Tue, 23 Apr 2019 20:40:05 -0400 Received: from youngberry.canonical.com ([91.189.89.112]:51414 "EHLO youngberry.canonical.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727045AbfDXAkF (ORCPT ); Tue, 23 Apr 2019 20:40:05 -0400 Received: from mail-oi1-f198.google.com ([209.85.167.198]) by youngberry.canonical.com with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.76) (envelope-from ) id 1hJ5xD-0004c2-36 for linux-kernel@vger.kernel.org; Wed, 24 Apr 2019 00:40:03 +0000 Received: by mail-oi1-f198.google.com with SMTP id w10so6850185oie.1 for ; Tue, 23 Apr 2019 17:40:03 -0700 (PDT) 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=HAJ+tsuhVeXXnt5g0+5qfIDYODvPMMpK3Zh37chKNPc=; b=f62AkrBPsebRTq/i38NOCMpAMQSPAWtzlXxIPI7N9P8SzNpS5bpJI5G1VuhNn1eRw7 aF/TA3SUf1yReQDUnWJQVesdfPbF7mY1v/Db3dLG9LFA/lzqnsn+UXv7pXYGKgGxJ3a/ RbgV9eTIEYhMx8yjDvnbBhO9CiEf2mV9IZNGl9m472J4ZDSjxEgUWyinqeqf4ni+rpKe FYcbvutEyd1p8lMkBoInybN62HrEc0SmSVv1AC+Ug1fn32Lso9ODnc3L5kQbhkfsvWWH CBph21lmiCuWWUQ5UFEXtNpKY3ru3z9QUObAqQCQLjWr/3982Vc/69LFy4nnx65FtY2p rq3Q== X-Gm-Message-State: APjAAAULDWaLWLnaWmlnounj/Efv9eqF4hCiDkE5umQD7tD9ssgzKqRF AFE7PbqOlMIn8/8ftM4D+7Ip5gcojjr/nr1x859YPDECXKR2gEwGP4WHG0G78RtGuHXMiseI7gS ekVionyknHONSgS/bnJ+IxsMaulBAUbuxmL4efs7wwATC9Cl0S4+3KQBL/g== X-Received: by 2002:aca:c511:: with SMTP id v17mr3651414oif.124.1556066401973; Tue, 23 Apr 2019 17:40:01 -0700 (PDT) X-Received: by 2002:aca:c511:: with SMTP id v17mr3651400oif.124.1556066401613; Tue, 23 Apr 2019 17:40:01 -0700 (PDT) MIME-Version: 1.0 References: <20190417204817.GA28897@xps13.dannf> In-Reply-To: From: dann frazier Date: Tue, 23 Apr 2019 18:39:50 -0600 Message-ID: Subject: Re: [RFC] arm64: swiotlb: cma_alloc error spew To: Robin Murphy Cc: Christoph Hellwig , Marek Szyprowski , iommu@lists.linux-foundation.org, linux-kernel@vger.kernel.org, linux-arm-kernel , Xinwei Kong 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 Tue, Apr 23, 2019 at 12:03 PM dann frazier wrote: > > On Tue, Apr 23, 2019 at 5:32 AM Robin Murphy wrote: > > > > On 17/04/2019 21:48, dann frazier wrote: > > > hey, > > > I'm seeing an issue on a couple of arm64 systems[*] where they spew > > > ~10K "cma: cma_alloc: alloc failed" messages at boot. The errors are > > > non-fatal, and bumping up cma to a large enough size (~128M) gets rid > > > of them - but that seems suboptimal. Bisection shows that this started > > > after commit fafadcd16595 ("swiotlb: don't dip into swiotlb pool for > > > coherent allocations"). It looks like __dma_direct_alloc_pages() > > > is opportunistically using CMA memory but falls back to non-CMA if CMA > > > disabled or unavailable. I've demonstrated that this fallback is > > > indeed returning a valid pointer. So perhaps the issue is really just > > > the warning emission. > > > > The CMA area being full isn't necessarily an ignorable non-problem, > > since it means you won't be able to allocate the kind of large buffers > > for which CMA was intended. The question is, is it actually filling up > > with allocations that deserve to be there, or is this the same as I've > > seen on a log from a ThunderX2 system where it's getting exhausted by > > thousands upon thousands of trivial single page allocations? If it's the > > latter (CONFIG_CMA_DEBUG should help shed some light if necessary), > > Appears so. Here's a histogram of count/size w/ a cma= large enough to > avoid failures: > > $ dmesg | grep "cma: cma_alloc(cma" | sed -r 's/.*count > ([0-9]+)\,.*/\1/' | sort -n | uniq -c > 2062 1 > 32 2 > 266 8 > 2 24 > 4 32 > 256 33 And IIUC, this is also a big culprit. The debugfs bitmap seems to show that the alignment of each of these leaves 31 pages unused, which adds up to 31MB! -dann > 7 64 > 2 128 > 2 1024 > > -dann > > > then > > that does lean towards spending a bit more effort on this idea: > > > > https://lore.kernel.org/lkml/20190327080821.GB20336@lst.de/ > > > > Robin. > > > > > The following naive patch solves the problem for me - just silence the > > > cma errors, since it looks like a soft error. But is there a better > > > approach? > > > > > > [*] APM X-Gene & HiSilicon Hi1620 w/ SMMU disabled > > > > > > diff --git a/kernel/dma/direct.c b/kernel/dma/direct.c > > > index 6310ad01f915b..0324aa606c173 100644 > > > --- a/kernel/dma/direct.c > > > +++ b/kernel/dma/direct.c > > > @@ -112,7 +112,7 @@ struct page *__dma_direct_alloc_pages(struct device *dev, size_t size, > > > /* CMA can be used only in the context which permits sleeping */ > > > if (gfpflags_allow_blocking(gfp)) { > > > page = dma_alloc_from_contiguous(dev, count, page_order, > > > - gfp & __GFP_NOWARN); > > > + true); > > > if (page && !dma_coherent_ok(dev, page_to_phys(page), size)) { > > > dma_release_from_contiguous(dev, page, count); > > > page = NULL; > > > > > > > > > > > >