From mboxrd@z Thu Jan 1 00:00:00 1970 From: Akinobu Mita Subject: [PATCH 2/2] intel-iommu: don't unnecessarily call dma_alloc_from_contiguous() Date: Mon, 29 Sep 2014 00:52:04 +0900 Message-ID: <1411919524-3666-2-git-send-email-akinobu.mita@gmail.com> References: <1411919524-3666-1-git-send-email-akinobu.mita@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <1411919524-3666-1-git-send-email-akinobu.mita-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: iommu-bounces-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org Errors-To: iommu-bounces-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org To: linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org, akpm-de/tnXTf+JLsfHDXvbKv3WD2FQJk+8+b@public.gmane.org Cc: Andi Kleen , Peter Hurley , Yinghai Lu , x86-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org, Akinobu Mita , iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org, Ingo Molnar , "H. Peter Anvin" , Thomas Gleixner , David Woodhouse List-Id: iommu@lists.linux-foundation.org If CONFIG_DMA_CMA is enabled, intel_alloc_coherent() tries to allocate memory region by dma_alloc_from_contiguous() before trying to use alloc_pages(). This wastes CMA region by small DMA-coherent buffers which can be allocated by alloc_pages(). And it also causes performance degradation, as this is trying to drive _all_ dma mapping allocations through a _very_ small window, reported by Peter Hurley. This fixes it by trying to allocate by alloc_pages() first in intel_alloc_coherent() as dma_alloc_from_contiguous should be called only for huge allocation. Signed-off-by: Akinobu Mita Reported-by: Peter Hurley Cc: Peter Hurley Cc: Marek Szyprowski Cc: Konrad Rzeszutek Wilk Cc: David Woodhouse Cc: Don Dutile Cc: Thomas Gleixner Cc: Ingo Molnar Cc: "H. Peter Anvin" Cc: Andi Kleen Cc: Yinghai Lu Cc: x86-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org Cc: iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org --- drivers/iommu/intel-iommu.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/drivers/iommu/intel-iommu.c b/drivers/iommu/intel-iommu.c index 3441615..f9794fa 100644 --- a/drivers/iommu/intel-iommu.c +++ b/drivers/iommu/intel-iommu.c @@ -3250,7 +3250,8 @@ static void *intel_alloc_coherent(struct device *dev, size_t size, flags |= GFP_DMA32; } - if (flags & __GFP_WAIT) { + page = alloc_pages(flags | __GFP_NOWARN, order); + if (!page && (flags & __GFP_WAIT)) { unsigned int count = size >> PAGE_SHIFT; page = dma_alloc_from_contiguous(dev, count, order); @@ -3261,10 +3262,10 @@ static void *intel_alloc_coherent(struct device *dev, size_t size, } } - if (!page) - page = alloc_pages(flags, order); - if (!page) + if (!page) { + warn_alloc_failed(flags, order, NULL); return NULL; + } memset(page_address(page), 0, size); *dma_handle = __intel_map_single(dev, page_to_phys(page), size, -- 1.9.1