From patchwork Mon Mar 16 08:12:05 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tomasz Figa X-Patchwork-Id: 6015921 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 15C8ABF90F for ; Mon, 16 Mar 2015 08:14:58 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 296B820304 for ; Mon, 16 Mar 2015 08:14:57 +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 56A56202FE for ; Mon, 16 Mar 2015 08:14:56 +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 1YXQ8i-0003jH-7V; Mon, 16 Mar 2015 08:12:44 +0000 Received: from mail-pa0-x230.google.com ([2607:f8b0:400e:c03::230]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1YXQ8c-0003bc-Ez for linux-arm-kernel@lists.infradead.org; Mon, 16 Mar 2015 08:12:39 +0000 Received: by pabyw6 with SMTP id yw6so58023500pab.2 for ; Mon, 16 Mar 2015 01:12:16 -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=+iGN4c2WdYpMuxsmaV/Fyt7izK5hYBliEyk5H4Wa0Ik=; b=LjueHnNhwi0eEBNiAlUR8BJTj8dpcno+KZG3XDgDYx/9Ok2SBbehnF4ET6bwhYPvot meMOpECknbgcCRCBE6swpffFAeSfmprEV+GpvKOTQzHjqcf1KoyVHv++qqQnMWXESOPa x4E3aQdpEO/K+PSAzSeHcOxpOUrjn6VXLPG4o= 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=+iGN4c2WdYpMuxsmaV/Fyt7izK5hYBliEyk5H4Wa0Ik=; b=LSDh/ZAMv19aSsXfYaYJDLNNxfyvB9KaYDtq7VQA1libxFVZex6Qdwp2w6l4kdeD4u fJzeVndQblhes08DL4KP77TP80XCRNyDOoKrTI5+zIhQDHiyLab0cTZGUzKVjtE5qAVI zNLwciAgWn6DN7UlVcKnzAlzLCA+4pvtm6k90T0nUGUsbmS1sPY9xhUCplgLrY90JCH4 aMGBFGgMKhcOcJiFolkcjeD1htMXf4crExDDH0gc+7PfIspbHSx4+wC3ZAScpRC8zQPH nIFs2/a+O7pMUZBIUlIeq1NEsVYHS+JMBSp70yd6mH6OrpntTKwlsfGmDjC9EVOnyvlv 8DRw== X-Gm-Message-State: ALoCoQnx9Yi3QkQFjDHO3SIA2nqh3qlGD++HpvPK5pfMwWa7GsVnPuN12RXw/ez86Nf4OQ8+WSqo X-Received: by 10.70.136.202 with SMTP id qc10mr132990068pdb.117.1426493536770; Mon, 16 Mar 2015 01:12:16 -0700 (PDT) Received: from basement.tok.corp.google.com ([172.23.69.229]) by mx.google.com with ESMTPSA id uf4sm15912748pac.9.2015.03.16.01.12.13 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 16 Mar 2015 01:12:16 -0700 (PDT) From: Tomasz Figa To: linux-arm-kernel@lists.infradead.org Subject: [PATCH] ARM: mm: Do not invoke OOM for higher order IOMMU DMA allocations Date: Mon, 16 Mar 2015 17:12:05 +0900 Message-Id: <1426493525-25502-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-20150316_011238_559202_681EAE51 X-CRM114-Status: GOOD ( 17.05 ) X-Spam-Score: -0.8 (/) Cc: Laurent Pinchart , Laura Abbott , Will Deacon , linux-kernel@vger.kernel.org, Douglas Anderson , Santosh Shilimkar , 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 positive orders and only if that fails doing OOMable order 0 allocation as a fall back. Signed-off-by: Tomasz Figa --- arch/arm/mm/dma-mapping.c | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/arch/arm/mm/dma-mapping.c b/arch/arm/mm/dma-mapping.c index 83cd5ac..f081e9e 100644 --- a/arch/arm/mm/dma-mapping.c +++ b/arch/arm/mm/dma-mapping.c @@ -1145,18 +1145,31 @@ static struct page **__iommu_alloc_buffer(struct device *dev, size_t size, } /* - * IOMMU can map any pages, so himem can also be used here + * IOMMU can map any pages, so himem can also be used here. + * We do not want OOM killer to be invoked as long as we can fall back + * to single pages, so we use __GFP_NORETRY for positive orders. */ - gfp |= __GFP_NOWARN | __GFP_HIGHMEM; + gfp |= __GFP_NOWARN | __GFP_HIGHMEM | __GFP_NORETRY; while (count) { - int j, order = __fls(count); + int j, order; - pages[i] = alloc_pages(gfp, order); - while (!pages[i] && order) - pages[i] = alloc_pages(gfp, --order); - if (!pages[i]) - goto error; + for (order = __fls(count); order; --order) { + /* Will not trigger OOM. */ + pages[i] = alloc_pages(gfp, order); + if (pages[i]) + break; + } + + if (!pages[i]) { + /* + * Fall back to single page allocation. + * Might invoke OOM killer as last resort. + */ + pages[i] = alloc_pages(gfp & ~__GFP_NORETRY, 0); + if (!pages[i]) + goto error; + } if (order) { split_page(pages[i], order);