From patchwork Thu Aug 23 06:10:28 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hiroshi Doyu X-Patchwork-Id: 10895 Return-Path: X-Original-To: patchwork@peony.canonical.com Delivered-To: patchwork@peony.canonical.com Received: from fiordland.canonical.com (fiordland.canonical.com [91.189.94.145]) by peony.canonical.com (Postfix) with ESMTP id E07F823FA4 for ; Thu, 23 Aug 2012 06:11:11 +0000 (UTC) Received: from mail-iy0-f180.google.com (mail-iy0-f180.google.com [209.85.210.180]) by fiordland.canonical.com (Postfix) with ESMTP id DB8A9A18F38 for ; Thu, 23 Aug 2012 06:10:57 +0000 (UTC) Received: by mail-iy0-f180.google.com with SMTP id j38so694034iad.11 for ; Wed, 22 Aug 2012 23:11:11 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-forwarded-to:x-forwarded-for:delivered-to:received-spf :x-pgp-universal:from:to:date:message-id:x-mailer:in-reply-to :references:mime-version:cc:subject:x-beenthere:x-mailman-version :precedence:list-id:list-unsubscribe:list-archive:list-post :list-help:list-subscribe:content-type:content-transfer-encoding :sender:errors-to:x-gm-message-state; bh=vF4ddzwLEJnGWjTwDAXl5aTMmji9dqlcFiQxkmNLI2I=; b=kZK5vd1bSxCaK5mPbYQnutbza4oxDZHmJV8TuGAA2wCSgA2vv1QPqeybuANRx08/l6 fii2FE24456qzCvjZxXVgauc5ccXjApBnXTS7gVViB/NbJtXVaN0sm8FMDneNue/At0v JostSnEl/4n8Ohmt5hT8fN/4DmqOIUU1AuKE6tmIMCLfcyHR/KNYoONLGH7dJqTU1t2N GQe/bKaUqEiwTOiaiOLHGhnxoeXz5xQsF229x/taFfvJxFGDNN3i4OHCLBXjoJT5GpEW Qj3dvVbO7TP+YjOCoYLJqxrv8fZDS5gNHZt0DwbRU2ymKf5G4BiBskgls/Zdhydr5klO U5HQ== Received: by 10.50.159.196 with SMTP id xe4mr4686012igb.43.1345702271191; Wed, 22 Aug 2012 23:11:11 -0700 (PDT) X-Forwarded-To: linaro-patchwork@canonical.com X-Forwarded-For: patch@linaro.org linaro-patchwork@canonical.com Delivered-To: patches@linaro.org Received: by 10.50.184.232 with SMTP id ex8csp239285igc; Wed, 22 Aug 2012 23:11:10 -0700 (PDT) Received: by 10.205.118.14 with SMTP id fo14mr69651bkc.130.1345702269561; Wed, 22 Aug 2012 23:11:09 -0700 (PDT) Received: from mombin.canonical.com (mombin.canonical.com. [91.189.95.16]) by mx.google.com with ESMTP id fs16si4104885bkc.49.2012.08.22.23.11.07; Wed, 22 Aug 2012 23:11:09 -0700 (PDT) Received-SPF: neutral (google.com: 91.189.95.16 is neither permitted nor denied by best guess record for domain of linaro-mm-sig-bounces@lists.linaro.org) client-ip=91.189.95.16; Authentication-Results: mx.google.com; spf=neutral (google.com: 91.189.95.16 is neither permitted nor denied by best guess record for domain of linaro-mm-sig-bounces@lists.linaro.org) smtp.mail=linaro-mm-sig-bounces@lists.linaro.org Received: from localhost ([127.0.0.1] helo=mombin.canonical.com) by mombin.canonical.com with esmtp (Exim 4.71) (envelope-from ) id 1T4QdG-0004u1-NH; Thu, 23 Aug 2012 06:11:06 +0000 Received: from hqemgate03.nvidia.com ([216.228.121.140]) by mombin.canonical.com with esmtp (Exim 4.71) (envelope-from ) id 1T4QdE-0004sx-8B for linaro-mm-sig@lists.linaro.org; Thu, 23 Aug 2012 06:11:04 +0000 Received: from hqnvupgp07.nvidia.com (Not Verified[216.228.121.13]) by hqemgate03.nvidia.com id ; Wed, 22 Aug 2012 23:12:11 -0700 Received: from hqemhub01.nvidia.com ([172.17.108.22]) by hqnvupgp07.nvidia.com (PGP Universal service); Wed, 22 Aug 2012 23:05:04 -0700 X-PGP-Universal: processed; by hqnvupgp07.nvidia.com on Wed, 22 Aug 2012 23:05:04 -0700 Received: from hqnvemgw02.nvidia.com (172.16.227.111) by hqemhub01.nvidia.com (172.20.150.30) with Microsoft SMTP Server id 8.3.264.0; Wed, 22 Aug 2012 23:10:57 -0700 Received: from daphne.nvidia.com (Not Verified[172.16.212.96]) by hqnvemgw02.nvidia.com with MailMarshal (v6,7,2,8378) id ; Wed, 22 Aug 2012 23:11:44 -0700 Received: from oreo.Nvidia.com (dhcp-10-21-25-186.nvidia.com [10.21.25.186]) by daphne.nvidia.com (8.13.8+Sun/8.8.8) with ESMTP id q7N6AcIS004834; Wed, 22 Aug 2012 23:10:53 -0700 (PDT) From: Hiroshi Doyu To: Date: Thu, 23 Aug 2012 09:10:28 +0300 Message-ID: <1345702229-9539-4-git-send-email-hdoyu@nvidia.com> X-Mailer: git-send-email 1.7.5.4 In-Reply-To: <1345702229-9539-1-git-send-email-hdoyu@nvidia.com> References: <1345702229-9539-1-git-send-email-hdoyu@nvidia.com> MIME-Version: 1.0 Cc: linux@arm.linux.org.uk, arnd@arndb.de, konrad.wilk@oracle.com, minchan@kernel.org, linux-kernel@vger.kernel.org, linaro-mm-sig@lists.linaro.org, linux-mm@kvack.org, kyungmin.park@samsung.com, pullip.cho@samsung.com, linux-arm-kernel@lists.infradead.org Subject: [Linaro-mm-sig] [v2 3/4] ARM: dma-mapping: Refactor out to introduce __alloc_fill_pages X-BeenThere: linaro-mm-sig@lists.linaro.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: "Unified memory management interest group." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: linaro-mm-sig-bounces@lists.linaro.org Errors-To: linaro-mm-sig-bounces@lists.linaro.org X-Gm-Message-State: ALoCoQnsekt5o3GziiUxlrNIvT2GQvSKIJw4imbuhVLf5Y8oTyrREZmQYaETbZQ8Z2N8WIKEpN4K __alloc_fill_pages() allocates power of 2 page number allocation at most repeatedly. Signed-off-by: Hiroshi Doyu --- arch/arm/mm/dma-mapping.c | 50 ++++++++++++++++++++++++++++++-------------- 1 files changed, 34 insertions(+), 16 deletions(-) diff --git a/arch/arm/mm/dma-mapping.c b/arch/arm/mm/dma-mapping.c index b64475a..7ab016b 100644 --- a/arch/arm/mm/dma-mapping.c +++ b/arch/arm/mm/dma-mapping.c @@ -1022,20 +1022,11 @@ static inline void __free_iova(struct dma_iommu_mapping *mapping, spin_unlock_irqrestore(&mapping->lock, flags); } -static struct page **__iommu_alloc_buffer(struct device *dev, size_t size, gfp_t gfp) +static int __alloc_fill_pages(struct page ***ppages, int count, gfp_t gfp) { - struct page **pages; - int count = size >> PAGE_SHIFT; - int array_size = count * sizeof(struct page *); + struct page **pages = *ppages; int i = 0; - if ((array_size <= PAGE_SIZE) || (gfp & GFP_ATOMIC)) - pages = kzalloc(array_size, gfp); - else - pages = vzalloc(array_size); - if (!pages) - return NULL; - while (count) { int j, order = __fls(count); @@ -1045,22 +1036,49 @@ static struct page **__iommu_alloc_buffer(struct device *dev, size_t size, gfp_t if (!pages[i]) goto error; - if (order) + if (order) { split_page(pages[i], order); - j = 1 << order; - while (--j) - pages[i + j] = pages[i] + j; + j = 1 << order; + while (--j) + pages[i + j] = pages[i] + j; + } __dma_clear_buffer(pages[i], PAGE_SIZE << order); i += 1 << order; count -= 1 << order; } - return pages; + return 0; + error: while (i--) if (pages[i]) __free_pages(pages[i], 0); + return -ENOMEM; +} + +static struct page **__iommu_alloc_buffer(struct device *dev, size_t size, + gfp_t gfp) +{ + struct page **pages; + int count = size >> PAGE_SHIFT; + int array_size = count * sizeof(struct page *); + int err; + + if ((array_size <= PAGE_SIZE) || (gfp & GFP_ATOMIC)) + pages = kzalloc(array_size, gfp); + else + pages = vzalloc(array_size); + if (!pages) + return NULL; + + err = __alloc_fill_pages(&pages, count, gfp); + if (err) + goto error + + return pages; + +error: if ((array_size <= PAGE_SIZE) || (gfp & GFP_ATOMIC)) kfree(pages); else