From patchwork Tue Mar 26 23:01:31 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolin Chen X-Patchwork-Id: 10872303 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 1865314DE for ; Tue, 26 Mar 2019 23:02:45 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 07FEB28D92 for ; Tue, 26 Mar 2019 23:02:45 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id F034028DA0; Tue, 26 Mar 2019 23:02:44 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,DKIM_VALID,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 5C65528D92 for ; Tue, 26 Mar 2019 23:02:44 +0000 (UTC) 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 1h8v5c-0002Pm-BW; Tue, 26 Mar 2019 23:02:40 +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 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP 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); } /**