From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752202AbbCWH1R (ORCPT ); Mon, 23 Mar 2015 03:27:17 -0400 Received: from mail-pa0-f46.google.com ([209.85.220.46]:33508 "EHLO mail-pa0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751853AbbCWH1P (ORCPT ); Mon, 23 Mar 2015 03:27:15 -0400 From: Tomasz Figa To: linux-arm-kernel@lists.infradead.org Cc: linux-kernel@vger.kernel.org, Russell King , Marek Szyprowski , Will Deacon , Andrew Morton , Laura Abbott , Ritesh Harjani , Carlo Caione , Laurent Pinchart , Douglas Anderson , Sonny Rao , David Rientjes , Tomasz Figa Subject: [PATCH v2] ARM: mm: Do not invoke OOM for higher order IOMMU DMA allocations Date: Mon, 23 Mar 2015 16:27:00 +0900 Message-Id: <1427095620-20994-1-git-send-email-tfiga@chromium.org> X-Mailer: git-send-email 2.2.0.rc0.207.ga3a616c Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org IOMMU should be able to use single pages as well as bigger blocks, so if higher order allocations fail, we should not affect state of the system, with events such as OOM killer, but rather fall back to order 0 allocations. This patch changes the behavior of ARM IOMMU DMA allocator to use __GFP_NORETRY, which bypasses OOM invocation, for orders higher than zero and, only if that fails, fall back to normal order 0 allocation which might invoke OOM killer. Signed-off-by: Tomasz Figa --- arch/arm/mm/dma-mapping.c | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) Changes since v1: (https://patchwork.kernel.org/patch/6015921/) - do not clear __GFP_NORETRY, as it might come from the caller, - s/positive order/order higher than 0/. diff --git a/arch/arm/mm/dma-mapping.c b/arch/arm/mm/dma-mapping.c index 83cd5ac..3f1ac51 100644 --- a/arch/arm/mm/dma-mapping.c +++ b/arch/arm/mm/dma-mapping.c @@ -1150,13 +1150,28 @@ static struct page **__iommu_alloc_buffer(struct device *dev, size_t size, gfp |= __GFP_NOWARN | __GFP_HIGHMEM; while (count) { - int j, order = __fls(count); + int j, order; + + for (order = __fls(count); order > 0; --order) { + /* + * We do not want OOM killer to be invoked as long + * as we can fall back to single pages, so we force + * __GFP_NORETRY for orders higher than zero. + */ + pages[i] = alloc_pages(gfp | __GFP_NORETRY, order); + if (pages[i]) + break; + } - pages[i] = alloc_pages(gfp, order); - while (!pages[i] && order) - pages[i] = alloc_pages(gfp, --order); - if (!pages[i]) - goto error; + if (!pages[i]) { + /* + * Fall back to single page allocation. + * Might invoke OOM killer as last resort. + */ + pages[i] = alloc_pages(gfp, 0); + if (!pages[i]) + goto error; + } if (order) { split_page(pages[i], order); -- 2.2.0.rc0.207.ga3a616c