From patchwork Wed Aug 22 10:20:27 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hiroshi Doyu X-Patchwork-Id: 10865 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 2047323E1B for ; Wed, 22 Aug 2012 10:21:01 +0000 (UTC) Received: from mail-gh0-f180.google.com (mail-gh0-f180.google.com [209.85.160.180]) by fiordland.canonical.com (Postfix) with ESMTP id 77D1AA18D27 for ; Wed, 22 Aug 2012 10:20:49 +0000 (UTC) Received: by ghbg10 with SMTP id g10so526508ghb.11 for ; Wed, 22 Aug 2012 03:21:00 -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=RUESkRcKW8fczg5z7FgxH/8ZOihEzPq1zoTWW5mXk4s=; b=U8N6iqQQD3lCnnmbAbuZwZfWMqGIBtBX/4cYWSr5Rg+QJY9z+sze087yhqPAvwnbB8 CHfvflwDyzMkMrdYLfXzpMrhclXCz1lD2VD9XtkE5B9qEo8bGGpsiWwazPZDpx3Wjmqn ILsMAzRoHLEexq9jBX3qruWBfKhGveUu7geqBwJD7FohXCR/CTeOkjlns55Yot7hoEA3 R30DDc5EEvb+y3wyoBplAjHrVHMXxmklp0MIwH8aq5cT6PlsZLapJuqsy9WAYzV9AVh9 m7nQW8rYYJ1tA36PFZQ1OVR7LZn3rqs7vsv0ZMkSTzyrT2M4G9JbtdhNpocjlL0P2mUB 2p+g== Received: by 10.50.10.201 with SMTP id k9mr1532177igb.28.1345630859557; Wed, 22 Aug 2012 03:20:59 -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 ex8csp194231igc; Wed, 22 Aug 2012 03:20:58 -0700 (PDT) Received: by 10.180.91.169 with SMTP id cf9mr5704817wib.1.1345630858272; Wed, 22 Aug 2012 03:20:58 -0700 (PDT) Received: from mombin.canonical.com (mombin.canonical.com. [91.189.95.16]) by mx.google.com with ESMTP id h5si10045310wiz.6.2012.08.22.03.20.57; Wed, 22 Aug 2012 03:20:58 -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 1T483T-0003nF-Ew; Wed, 22 Aug 2012 10:20:55 +0000 Received: from hqemgate04.nvidia.com ([216.228.121.35]) by mombin.canonical.com with esmtp (Exim 4.71) (envelope-from ) id 1T483R-0003mk-N9 for linaro-mm-sig@lists.linaro.org; Wed, 22 Aug 2012 10:20:54 +0000 Received: from hqnvupgp07.nvidia.com (Not Verified[216.228.121.13]) by hqemgate04.nvidia.com id ; Wed, 22 Aug 2012 03:20:05 -0700 Received: from hqemhub02.nvidia.com ([172.17.108.22]) by hqnvupgp07.nvidia.com (PGP Universal service); Wed, 22 Aug 2012 03:14:53 -0700 X-PGP-Universal: processed; by hqnvupgp07.nvidia.com on Wed, 22 Aug 2012 03:14:53 -0700 Received: from hqnvemgw01.nvidia.com (172.20.150.20) by hqemhub02.nvidia.com (172.20.150.31) with Microsoft SMTP Server id 8.3.264.0; Wed, 22 Aug 2012 03:20:43 -0700 Received: from daphne.nvidia.com (Not Verified[172.16.212.96]) by hqnvemgw01.nvidia.com with MailMarshal (v6,7,2,8378) id ; Wed, 22 Aug 2012 03:20: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 q7MAKWep027973; Wed, 22 Aug 2012 03:20:40 -0700 (PDT) From: Hiroshi Doyu To: Marek Szyprowski Date: Wed, 22 Aug 2012 13:20:27 +0300 Message-ID: <1345630830-9586-2-git-send-email-hdoyu@nvidia.com> X-Mailer: git-send-email 1.7.5.4 In-Reply-To: <1345630830-9586-1-git-send-email-hdoyu@nvidia.com> References: <1345630830-9586-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" , "linux-arm-kernel@lists.infradead.org" Subject: [Linaro-mm-sig] [RFC 1/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: ALoCoQn2/1QsNvuRs+I8B1lHpyLTkgibYq4runBZQXVKVDbltWRiNUpFCmaa6rXRBFVxbkQv2j/B __alloc_fill_pages() allocates power of 2 page number allocation at most repeatedly. Signed-off-by: Hiroshi Doyu --- arch/arm/mm/dma-mapping.c | 40 ++++++++++++++++++++++++++++------------ 1 files changed, 28 insertions(+), 12 deletions(-) diff --git a/arch/arm/mm/dma-mapping.c b/arch/arm/mm/dma-mapping.c index 7dc61ed..aec0c06 100644 --- a/arch/arm/mm/dma-mapping.c +++ b/arch/arm/mm/dma-mapping.c @@ -988,19 +988,10 @@ 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 *); int i = 0; - - if (array_size <= PAGE_SIZE) - pages = kzalloc(array_size, gfp); - else - pages = vzalloc(array_size); - if (!pages) - return NULL; + struct page **pages = *ppages; while (count) { int j, order = __fls(count); @@ -1022,11 +1013,36 @@ static struct page **__iommu_alloc_buffer(struct device *dev, size_t size, gfp_t 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) + 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) kfree(pages); else