]> git.karo-electronics.de Git - linux-beck.git/commitdiff
ARM: 8337/1: mm: Do not invoke OOM for higher order IOMMU DMA allocations
authorTomasz Figa <tfiga@chromium.org>
Wed, 1 Apr 2015 06:26:33 +0000 (07:26 +0100)
committerRussell King <rmk+kernel@arm.linux.org.uk>
Thu, 2 Apr 2015 08:58:25 +0000 (09:58 +0100)
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 <tfiga@chromium.org>
Reviewed-by: Doug Anderson <dianders@chromium.org>
Acked-by: David Rientjes <rientjes@google.com>
Acked-by: Marek Szyprowski <m.szyprowski@samsung.com>
Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>
arch/arm/mm/dma-mapping.c

index c27447653903f1134594fe309dc885285ea43bb3..f9941cd689e971422b13706922a99199772f4e95 100644 (file)
@@ -1135,13 +1135,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);