From patchwork Mon Mar 23 07:27:00 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tomasz Figa X-Patchwork-Id: 6070801 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 847CABF90F for ; Mon, 23 Mar 2015 07:29:47 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 962252020F for ; Mon, 23 Mar 2015 07:29:46 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id BD5D3201FE for ; Mon, 23 Mar 2015 07:29:45 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1YZwlu-00047y-Ip; Mon, 23 Mar 2015 07:27:38 +0000 Received: from mail-pa0-x236.google.com ([2607:f8b0:400e:c03::236]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1YZwls-000433-DW for linux-arm-kernel@lists.infradead.org; Mon, 23 Mar 2015 07:27:37 +0000 Received: by pagv19 with SMTP id v19so7968415pag.2 for ; Mon, 23 Mar 2015 00:27:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id; bh=s/SB4XPuXCudV1QzojzcxUjHrtZ6urrKRYT1q/tYvU0=; b=IRKJdV5Bbj2vzkULWYzzbAESuVqrII7CmsueHqzLJFKV+tE2ydNPsJXVwpSjTC35nS 2QVW63HNdjQKCyjP6FBryBs7HBKBWUjiUEWlpyZJGxRxSg/jCJRFj8SqpuOz1h3u5bZ/ kLF0d7V3M7t/2MYlYkjKyTEohhMDqnyuPucvk= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=s/SB4XPuXCudV1QzojzcxUjHrtZ6urrKRYT1q/tYvU0=; b=ETAjgpsZMkuPGxJt9Wjn//YxCjo4vd/Wq0PGjhQFLnCWMhJQ9cBd8tWj+SDAD55emt ec0YFiBSgyHLAGy6bqKm+HOrRl8MnoO+HxtsuEKoOJRnJvlMmIfdCrT2YoHBraQ67QxO D1FcRNTryZ/asKPFX9Owm92fQ/6735J9R3JINxaPnAC4LMUwD7Mcix6miU5D3t25kR5G n0N5H5xv2INlbF8vDyRL5NV6UmQfpqalQN2b5oEht+8S5VmZYXLMEy7CBxhUFq0xX1ia grIYso3J7hVGHS8Aom2MiksB356+XXbBlLa5eQbQRTnontY2MCgB8XD96sqA0hT8pK5x 8Y2g== X-Gm-Message-State: ALoCoQkHw4zDEsg9eWXSaCWP3ZgV441i31MdHauMPZSeAAobS1Mofeu/O6TpBH+KIlPDPK+24oTE X-Received: by 10.66.90.134 with SMTP id bw6mr1564695pab.131.1427095634868; Mon, 23 Mar 2015 00:27:14 -0700 (PDT) Received: from basement.tok.corp.google.com ([172.23.69.229]) by mx.google.com with ESMTPSA id hp6sm6276737pbc.71.2015.03.23.00.27.11 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 23 Mar 2015 00:27:14 -0700 (PDT) From: Tomasz Figa To: linux-arm-kernel@lists.infradead.org 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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20150323_002736_523276_E3A8ED76 X-CRM114-Status: GOOD ( 16.32 ) X-Spam-Score: -0.8 (/) Cc: Laurent Pinchart , Laura Abbott , David Rientjes , Will Deacon , linux-kernel@vger.kernel.org, Douglas Anderson , Ritesh Harjani , Carlo Caione , Russell King , Andrew Morton , Tomasz Figa , Sonny Rao , Marek Szyprowski X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-4.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED, T_DKIM_INVALID, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 Reviewed-by: Doug Anderson Acked-by: David Rientjes Acked-by: Marek Szyprowski --- 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);