From patchwork Tue Mar 26 22:49:59 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolin Chen X-Patchwork-Id: 10872289 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 3706F14DE for ; Tue, 26 Mar 2019 22:52:12 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1FC0528BB9 for ; Tue, 26 Mar 2019 22:52:12 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 135FC28D6A; Tue, 26 Mar 2019 22:52:12 +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 AD66028BB9 for ; Tue, 26 Mar 2019 22:52:11 +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=TPlrNg3ElWKKq1KPIBbGSk3QbG FzRWnmRWW4zVrhelzAd310Pl15XbvmtLjJSvDtGZY/LIKKvSRmN4ZtR5MDV4+5bLG6YdynbVlq9PW uFFYMDYUwhWyvUJ4bBtLSUuDa2f4i3AKlx4BfGHuO+bkRRc8T+0TxhKNTf+ToQieQYyWJ9faBz7zQ AP8j9gTTCVBEeZMjxRinecSnugp4Jl08cj8SbP4ix5PQ83if1Ie8za5FGfGL3FIzMBEy9xkypLsT2 8hC1LQzs5HhLKcDeuu0S8tM8c3wja08UU5R0D4vzz/CXANrtYtdUHIRbASF5+HClJf120mQP9a0zX PXsVOLwg==; 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 1h8uvM-0006Li-BX; Tue, 26 Mar 2019 22:52:04 +0000 Received: from mail-pg1-x541.google.com ([2607:f8b0:4864:20::541]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1h8uta-00050Q-NY for linux-arm-kernel@lists.infradead.org; Tue, 26 Mar 2019 22:50:19 +0000 Received: by mail-pg1-x541.google.com with SMTP id y3so8930038pgk.12 for ; Tue, 26 Mar 2019 15:50:14 -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=msqo3md2sAcMz6GQ64ybELtPm5q20Ot5oUTlPMh0Oebc+foeYulBl+nKNO+5O8wfNN vW16df9fGdyuriIUKnQzh2QYAeA2NtXWiMTYY+q48kxmviKbNHreRXftpGksrMXG7iZL xrgiynkXN3R9uy2J7m5IzKws0dim0cKbybsejXhNsybr6ijdzXzF6gN/iQa6uWoB8Hs0 RSfkbCu4hjBD+mwvaLcyn34KRjI2U61I3efqFXgsrueWydJ7PlRtBsC0AGC7+Sq+vU99 ZBAHmbX4usg6pB4SNPZaDPE3cFZrd7DNIvHLDkiH3zhnypGs9A64vtHDD1RUuKZRLnvw U9Vg== 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=nJ4ojTIW/33YhB4uanN5lG/qtEFCoXdkHaolK8MxU/X8Kc0RutWgElYDrKpVx7uXZG cfzgHseWaghCy7nWGrcKA1Oa4zibNnZpZaT7otN8SMpi6Ex7KNqiNxaoAvOp1j2tve9b //MpWuZ77EPRRJZB5mkzZpEbBWAVrIGpSKoxjBLXtHZox14mfU0dJEiRdb19CxNc5x7V +LcdDKO9cvxBmmZGns4pu+qm/HmDzPeCNq+yhcawH1XOTXEj+g/Grm37o8l4XHBKVsir jSMxX2lElAHk5hDKtyZGAk/V6GA3LugnwHRUmx3pchqtGOTlB02vuXpT2EwmtHcUY0Er OS3g== X-Gm-Message-State: APjAAAVirCgj+i670gydsRrGEPsBprOFHV2q3f90q7qwkF4HLY4PWLmZ JAy9WvjxrIhehUhIsH9WZAM= X-Google-Smtp-Source: APXvYqxZpKGQj6dfGYHbCUIDZUHCWq8Wq5nlbTjsOZ9r7c3obGfooVatp/mh5wpzMEIihl6DSdIuGw== X-Received: by 2002:a63:6949:: with SMTP id e70mr31096833pgc.89.1553640613149; Tue, 26 Mar 2019 15:50:13 -0700 (PDT) Received: from Asurada-Nvidia.nvidia.com (thunderhill.nvidia.com. [216.228.112.22]) by smtp.gmail.com with ESMTPSA id 8sm56937368pfs.50.2019.03.26.15.50.12 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 26 Mar 2019 15:50:12 -0700 (PDT) From: Nicolin Chen To: hch@lst.de, robin.murphy@arm.com Subject: [PATCH RFC/RFT 5/5] dma-contiguous: Do not allocate a single page from CMA area Date: Tue, 26 Mar 2019 15:49:59 -0700 Message-Id: <20190326224959.9656-6-nicoleotsuka@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190326224959.9656-1-nicoleotsuka@gmail.com> References: <20190326224959.9656-1-nicoleotsuka@gmail.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190326_155015_063762_2CC91811 X-CRM114-Status: GOOD ( 14.47 ) 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); } /**