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=-8.7 required=3.0 tests=DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,DKIM_VALID,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT 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 40FF1C43381 for ; Tue, 26 Mar 2019 23:02:42 +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 0F26E2075D for ; Tue, 26 Mar 2019 23:02:42 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="GptpbGU1"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="ZRq94w4D" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 0F26E2075D Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.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:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=bVYjpiKTpsKqb1AkUnToKy8iAzxSdJkCto6TAZ0Fs/M=; b=GptpbGU12GpPxKFk1CXhNVKfb7 qe7q1lOFMATdvVggxYV8DTb6nwTeRJDKZLKQ2VCOrwnu50o0y9e8U05RVzwq1paw6i5mAMabRuLNq sQHJoxZF/UeBaXm7RDtrE1K6ADAL11s0AZbPlCfNNGgYB6Bni8+itPY9DBKBiAhp87ZVO+VNm5AKL 2oSKy3hbcFwOOATJVQ0YFZcTCwuRgGtBBS+EnMfpm7OY0v6VuXIT0llclDzP2wraNg0QEeFM8xCDP 86QGuuxGKZoF1hStHP87V5xo6kquVVdI2NZmt6tsp0w478WL2dCbNQwJoRRS17fY9t2PTzXR4flUl Snx/I2Xg==; 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 1h8v5b-0002Pm-Iz; Tue, 26 Mar 2019 23:02:39 +0000 Received: from mail-pl1-x641.google.com ([2607:f8b0:4864:20::641]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1h8v4m-0001NK-Dz for linux-arm-kernel@lists.infradead.org; Tue, 26 Mar 2019 23:01:57 +0000 Received: by mail-pl1-x641.google.com with SMTP id b11so2327184plr.7 for ; Tue, 26 Mar 2019 16:01:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=xR2fAcbi08dJ1U/q08SNwZuhqDiyYfroDhLUIQLycmU=; b=ZRq94w4D00wfNmDhagQEuvIFMFs73QFUr4is3xAUxVycvb9Y4QfKSVGYSVqHIdt4yQ /Dg3bO579AdlV+OYj3yo9UWqEhUG2d+MERdzs6xApqiar8ax+iAaWGF9YKpAa3lW053O 95zfD6T0qswCMW8aetPrWFBPj7IIIsQf2CKRNfVE4t3uNWR2KpDHEYIO2ysR2EOtCGc2 TzgVe7Wuk2KHilHsftLjOXWwSIo9M+PyvGBVkgrAl4ZUEhwjELhGmgNoCaXHM4jJkgXK 6duRfiQPShZOqYsMlFVck0R1vog0+PP8ldK6Sl3xRJj6ucVg5hMr82WuURjijkU8PFyZ ClEQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=xR2fAcbi08dJ1U/q08SNwZuhqDiyYfroDhLUIQLycmU=; b=MNqDX2X9n7Q3uC3jEmGcTX+jZMTuTMQkjnP/a8/Z8GLEI1AbDh7tZEJNc3fMrloNvL v4o5mFaqI6HXQcTbgxZz0qB1du84E2c1BkVKIeevpY+mXGNbLIzkLzBnHYGhZzFCuu5d 7IV1gEAuFX5uryHRbnbMbf2d30ToRo8dG3V8heWgWcjSUtsO+T2HiINIRmWx8TuqoYou DZaiRItm+1ZSCGoRjqWMFRAF20Vrt6nrvQKT+/FJNfZdys6mdOTea19Ak7bynUnxrh4j JYiMj6V0Sx3HOywibP2ahFgMDINHAfuy86bStg1PqNzTwdgsTlqxZdXMkax6GtKRVOQz g5vA== X-Gm-Message-State: APjAAAXa49UMoW9zTpp8lD7C6tqcdemMf6E9SvBgKRsBu2zejTHdiZX6 5JU5Cd2g9nxgj6Xwhq9CN7M= X-Google-Smtp-Source: APXvYqw95qvrcdsbOKMlAJtssFXpn2KopvmCCHiGiW9jB5JdCv75GEFUp4aJ6ghruPJ0/CYlo+WAZA== X-Received: by 2002:a17:902:be04:: with SMTP id r4mr20181970pls.218.1553641304557; Tue, 26 Mar 2019 16:01:44 -0700 (PDT) Received: from Asurada-Nvidia.nvidia.com (thunderhill.nvidia.com. [216.228.112.22]) by smtp.gmail.com with ESMTPSA id n24sm43832587pfi.123.2019.03.26.16.01.43 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 26 Mar 2019 16:01:44 -0700 (PDT) From: Nicolin Chen To: hch@lst.de, robin.murphy@arm.com Subject: [PATCH v2 RFC/RFT 5/5] dma-contiguous: Do not allocate a single page from CMA area Date: Tue, 26 Mar 2019 16:01:31 -0700 Message-Id: <20190326230131.16275-6-nicoleotsuka@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190326230131.16275-1-nicoleotsuka@gmail.com> References: <20190326230131.16275-1-nicoleotsuka@gmail.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190326_160148_901879_A9DF22B4 X-CRM114-Status: GOOD ( 14.79 ) 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: tony@atomide.com, catalin.marinas@arm.com, joro@8bytes.org, will.deacon@arm.com, linux@armlinux.org.uk, iommu@lists.linux-foundation.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, m.szyprowski@samsung.com MIME-Version: 1.0 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 The addresses within a single page are always contiguous, so it's not so necessary to always allocate one single page from CMA area. Since the CMA area has a limited predefined size of space, it may run out of space in heavy use cases, where there might be quite a lot CMA pages being allocated for single pages. However, there is also a concern that a device might care where a page comes from -- it might expect the page from CMA area and act differently if the page doesn't. This patch tries to skip of one-page size allocations and returns NULL so as to let callers allocate normal pages unless the device has its own CMA area. This would save resources from the CMA area for more CMA allocations. And it'd also reduce CMA fragmentations resulted from trivial allocations. Signed-off-by: Nicolin Chen --- kernel/dma/contiguous.c | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/kernel/dma/contiguous.c b/kernel/dma/contiguous.c index b2a87905846d..09074bd04793 100644 --- a/kernel/dma/contiguous.c +++ b/kernel/dma/contiguous.c @@ -186,16 +186,32 @@ int __init dma_contiguous_reserve_area(phys_addr_t size, phys_addr_t base, * * This function allocates memory buffer for specified device. It uses * device specific contiguous memory area if available or the default - * global one. Requires architecture specific dev_get_cma_area() helper - * function. + * global one. + * + * However, it skips one-page size of allocations from the global area. + * As the addresses within one page are always contiguous, so there is + * no need to waste CMA pages for that kind; it also helps reduce the + * fragmentations in the CMA area. So a caller should be the rebounder + * in such case to allocate a normal page upon NULL return value. + * + * Requires architecture specific dev_get_cma_area() helper function. */ struct page *dma_alloc_from_contiguous(struct device *dev, size_t count, unsigned int align, bool no_warn) { + struct cma *cma; + if (align > CONFIG_CMA_ALIGNMENT) align = CONFIG_CMA_ALIGNMENT; - return cma_alloc(dev_get_cma_area(dev), count, align, no_warn); + if (dev && dev->cma_area) + cma = dev->cma_area; + else if (count > 1) + cma = dma_contiguous_default_area; + else + return NULL; + + return cma_alloc(cma, count, align, no_warn); } /** -- 2.17.1 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel