From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.0 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 020ACC10F03 for ; Wed, 24 Apr 2019 00:40:09 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id C535E218D2 for ; Wed, 24 Apr 2019 00:40:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728921AbfDXAkF (ORCPT ); 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-Google-Smtp-Source: APXvYqx0e4WJRVNRiguNI1//zAUIEyYuWcBl6vnE7VQGMLKBvKc3t094QzmR2EGAhr9F72Gg81zS4S+vG7/HUzW4SJk= 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; > > > > > > > > > > > > From mboxrd@z Thu Jan 1 00:00:00 1970 From: dann frazier Subject: Re: [RFC] arm64: swiotlb: cma_alloc error spew Date: Tue, 23 Apr 2019 18:39:50 -0600 Message-ID: References: <20190417204817.GA28897@xps13.dannf> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: iommu-bounces-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org Errors-To: iommu-bounces-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org To: Robin Murphy Cc: linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org, iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org, Xinwei Kong , Christoph Hellwig , linux-arm-kernel List-Id: iommu@lists.linux-foundation.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-jcswGhMUV9g@public.gmane.org/ > > > > 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; > > > > > > > > > > > > From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.0 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B5D1AC10F03 for ; Wed, 24 Apr 2019 00:40:07 +0000 (UTC) Received: from mail.linuxfoundation.org (mail.linuxfoundation.org [140.211.169.12]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 68586218D2 for ; Wed, 24 Apr 2019 00:40:07 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 68586218D2 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=canonical.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=iommu-bounces@lists.linux-foundation.org Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id 29B51ED0; Wed, 24 Apr 2019 00:40:07 +0000 (UTC) Received: from smtp1.linuxfoundation.org (smtp1.linux-foundation.org [172.17.192.35]) by mail.linuxfoundation.org (Postfix) with ESMTPS id 4F5BDECD for ; Wed, 24 Apr 2019 00:40:06 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from youngberry.canonical.com (youngberry.canonical.com [91.189.89.112]) by smtp1.linuxfoundation.org (Postfix) with ESMTP id A2B1374A for ; Wed, 24 Apr 2019 00:40:05 +0000 (UTC) Received: from mail-ot1-f70.google.com ([209.85.210.70]) by youngberry.canonical.com with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.76) (envelope-from ) id 1hJ5xD-0004c6-5n for iommu@lists.linux-foundation.org; Wed, 24 Apr 2019 00:40:03 +0000 Received: by mail-ot1-f70.google.com with SMTP id a2so9954496otk.13 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=M6SDP5pj5oRYDEQHFKNVHEwqIHoVlblSmrSi/CGle0ImCJpBqzql3zXovBIlq7PPnt aLQsrKlYy6kC8uOuYEbj0Zw1+f5la2oDo5QVEtXgVopdVVEwJxF75hd75kzQ1amPa/qz b2y0J2VGjkXARnq6sRN8CollN5E8u/d+LDEcBLpD7HeyYzbkAamaAMG4wqktGZaNM112 qGv5jgr24lIpA8x3DngofLPzmQQcWZEbdUwfdlJFaZe6WOJZ3tblRKsQDjOpb4wIawCo lUuN6cllEtK3nQcRrCd65VHnXIHxK4PmX3J/C5a19fxdYQH/Ggla801HLmdkLrS4Rh3p gndg== X-Gm-Message-State: APjAAAW6DthzPx8NHC3M2L+H5Y4Vsqy++VPQM8h4jd4fZG/7ua4ge8fQ jVG5Ip2M3gzu8OFLw4sW7dNDTnPOEgR3MeG0LyDeLGsVmryjkJT2FSmXr6OTWLf+BBxuRqVwl3e rjQ8ZpiAcdWTrFSO3TQrX5DFBwaYcQp3LqL+smk59JqRb5rHaIyUYxjpS9y9P3AA= X-Received: by 2002:aca:c511:: with SMTP id v17mr3651418oif.124.1556066401975; Tue, 23 Apr 2019 17:40:01 -0700 (PDT) X-Google-Smtp-Source: APXvYqx0e4WJRVNRiguNI1//zAUIEyYuWcBl6vnE7VQGMLKBvKc3t094QzmR2EGAhr9F72Gg81zS4S+vG7/HUzW4SJk= 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: linux-kernel@vger.kernel.org, iommu@lists.linux-foundation.org, Xinwei Kong , Christoph Hellwig , linux-arm-kernel X-BeenThere: iommu@lists.linux-foundation.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: Development issues for Linux IOMMU support List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit Sender: iommu-bounces@lists.linux-foundation.org Errors-To: iommu-bounces@lists.linux-foundation.org Message-ID: <20190424003950.zwzJDXu2-Iz3jorSuwOJSaQqNJ9pboFgVD64akBhISg@z> 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; > > > > > > > > > > > > _______________________________________________ iommu mailing list iommu@lists.linux-foundation.org https://lists.linuxfoundation.org/mailman/listinfo/iommu From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.0 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SPF_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D7918C10F03 for ; Wed, 24 Apr 2019 00:40:24 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id A4635217D9 for ; Wed, 24 Apr 2019 00:40:24 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="uLbX1TaT" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org A4635217D9 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=canonical.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+infradead-linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:To:Subject:Message-ID:Date:From: In-Reply-To:References:MIME-Version:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=EdRyyU0QXrclCpSyGeirVDplhbSnVXQtu17B2/HBqrs=; b=uLbX1TaTzxK8Q1 t+4Hbv2lXgJDEn6eRN9rWyJxHm1OiwPHkrY2VLuQOThHKdIatO6tiZB/PIZuv4gFoK3pE6RwEfRFz QhGnR7I/AZwN4zdamBi6Kkz9yyrMgw+7Rd+HXs4QwTpyOIn1yyMoWpgQ+MkO4OOGkbgPmrhtyiC5q ORUpCPFRIgqHNFqyQRw5t2Hi0NqivQEWxIWPVTKyJ0N5sgrlZVIY5iOy6qKmez2HAtxOjxD+fdCOp TXYolnic+KuJB4znh+aakd4z81npU7jz61Nq+VW+OHY86Srj3YmtM15kJleS9GHsbX0RIXUNSO9F+ eXPxaKz3wYi4caJpZJvg==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1hJ5xN-0000vk-Qo; Wed, 24 Apr 2019 00:40:13 +0000 Received: from youngberry.canonical.com ([91.189.89.112]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1hJ5xJ-0000Ez-Hf for linux-arm-kernel@lists.infradead.org; Wed, 24 Apr 2019 00:40:11 +0000 Received: from mail-oi1-f199.google.com ([209.85.167.199]) by youngberry.canonical.com with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.76) (envelope-from ) id 1hJ5xD-0004c4-4k for linux-arm-kernel@lists.infradead.org; Wed, 24 Apr 2019 00:40:03 +0000 Received: by mail-oi1-f199.google.com with SMTP id i203so6848559oih.16 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=fhghqEPkV7eUFxWDT2V4KrQsYJk+TIzSoICKEjeoI+6o0RnDf0scbnmvsgl1WHZhQT 0O1zS9pJcGaaj2xYH6/jOvnfmSMOpl1fU7a5zbkLU3mtGoouBeZhlFLT4/p8b+po4ayN 2gj0JQ8YWDDrTB8a9SH7CKUm9drgZn2T+86QlUomuxDeHTQUyNpmKD8W4sOj/bBMECzv vWFOQULyPEMjz+JF9NN7WWD5Y/n15KCJNbLTlynMgsjyA2v1A/iQcBbbljkzdGDZCgmG pOHpqm1wmNZV+OTgyzyZIAFXsCmODlFSiE4HYlGMlH415bv0I/fNSW9e+jqdW2veCzMa ZSzw== X-Gm-Message-State: APjAAAUpb7QqSLSg/z1l/u9LYEcGzxIY5qkeTViERQkJ8jEXFhquIuGF b3M1tlBCQi5AEcauHYR/HUd+d+EyPTKuGL9ffe0XPHuGKIqbT/ZV7XAeF1ryE5oAkbY19jJY/E9 X9vi9iv6ntDgnwIGz9kQBOAi49qhgAqZuRKxxMEILT33DyWTvbsSaU83xBmUbqqla1VVE X-Received: by 2002:aca:c511:: with SMTP id v17mr3651413oif.124.1556066401972; Tue, 23 Apr 2019 17:40:01 -0700 (PDT) X-Google-Smtp-Source: APXvYqx0e4WJRVNRiguNI1//zAUIEyYuWcBl6vnE7VQGMLKBvKc3t094QzmR2EGAhr9F72Gg81zS4S+vG7/HUzW4SJk= 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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190423_174010_241078_3DA967BA X-CRM114-Status: GOOD ( 25.06 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-kernel@vger.kernel.org, iommu@lists.linux-foundation.org, Xinwei Kong , Christoph Hellwig , linux-arm-kernel , Marek Szyprowski Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+infradead-linux-arm-kernel=archiver.kernel.org@lists.infradead.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; > > > > > > > > > > > > _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel