diff for duplicates of <5731D453.8050104@suse.cz> diff --git a/a/1.txt b/N1/1.txt index f5e9c2f..6073788 100644 --- a/a/1.txt +++ b/N1/1.txt @@ -19,3 +19,124 @@ patch 03/13 but it's simple to resolve. Thanks ----8<---- +>From 68f09f1d4381c7451238b4575557580380d8bf30 Mon Sep 17 00:00:00 2001 +From: Vlastimil Babka <vbabka@suse.cz> +Date: Fri, 29 Apr 2016 11:51:17 +0200 +Subject: [RFC 02/13] mm, page_alloc: set alloc_flags only once in slowpath + +In __alloc_pages_slowpath(), alloc_flags doesn't change after it's initialized, +so move the initialization above the retry: label. Also make the comment above +the initialization more descriptive. + +The only exception in the alloc_flags being constant is ALLOC_NO_WATERMARKS, +which may change due to TIF_MEMDIE being set on the allocating thread. We can +fix this, and make the code simpler and a bit more effective at the same time, +by moving the part that determines ALLOC_NO_WATERMARKS from +gfp_to_alloc_flags() to gfp_pfmemalloc_allowed(). This means we don't have to +mask out ALLOC_NO_WATERMARKS in several places in __alloc_pages_slowpath() +anymore. The only test for the flag can instead call gfp_pfmemalloc_allowed(). + +Signed-off-by: Vlastimil Babka <vbabka@suse.cz> +--- + mm/page_alloc.c | 49 ++++++++++++++++++++++++------------------------- + 1 file changed, 24 insertions(+), 25 deletions(-) + +diff --git a/mm/page_alloc.c b/mm/page_alloc.c +index a50184ec6ca0..1b58facf4b5e 100644 +--- a/mm/page_alloc.c ++++ b/mm/page_alloc.c +@@ -3216,8 +3216,7 @@ __alloc_pages_direct_compact(gfp_t gfp_mask, unsigned int order, + */ + count_vm_event(COMPACTSTALL); + +- page = get_page_from_freelist(gfp_mask, order, +- alloc_flags & ~ALLOC_NO_WATERMARKS, ac); ++ page = get_page_from_freelist(gfp_mask, order, alloc_flags, ac); + + if (page) { + struct zone *zone = page_zone(page); +@@ -3366,8 +3365,7 @@ __alloc_pages_direct_reclaim(gfp_t gfp_mask, unsigned int order, + return NULL; + + retry: +- page = get_page_from_freelist(gfp_mask, order, +- alloc_flags & ~ALLOC_NO_WATERMARKS, ac); ++ page = get_page_from_freelist(gfp_mask, order, alloc_flags, ac); + + /* + * If an allocation failed after direct reclaim, it could be because +@@ -3425,16 +3423,6 @@ gfp_to_alloc_flags(gfp_t gfp_mask) + } else if (unlikely(rt_task(current)) && !in_interrupt()) + alloc_flags |= ALLOC_HARDER; + +- if (likely(!(gfp_mask & __GFP_NOMEMALLOC))) { +- if (gfp_mask & __GFP_MEMALLOC) +- alloc_flags |= ALLOC_NO_WATERMARKS; +- else if (in_serving_softirq() && (current->flags & PF_MEMALLOC)) +- alloc_flags |= ALLOC_NO_WATERMARKS; +- else if (!in_interrupt() && +- ((current->flags & PF_MEMALLOC) || +- unlikely(test_thread_flag(TIF_MEMDIE)))) +- alloc_flags |= ALLOC_NO_WATERMARKS; +- } + #ifdef CONFIG_CMA + if (gfpflags_to_migratetype(gfp_mask) == MIGRATE_MOVABLE) + alloc_flags |= ALLOC_CMA; +@@ -3444,7 +3432,19 @@ gfp_to_alloc_flags(gfp_t gfp_mask) + + bool gfp_pfmemalloc_allowed(gfp_t gfp_mask) + { +- return !!(gfp_to_alloc_flags(gfp_mask) & ALLOC_NO_WATERMARKS); ++ if (unlikely(gfp_mask & __GFP_NOMEMALLOC)) ++ return false; ++ ++ if (gfp_mask & __GFP_MEMALLOC) ++ return true; ++ if (in_serving_softirq() && (current->flags & PF_MEMALLOC)) ++ return true; ++ if (!in_interrupt() && ++ ((current->flags & PF_MEMALLOC) || ++ unlikely(test_thread_flag(TIF_MEMDIE)))) ++ return true; ++ ++ return false; + } + + static inline bool is_thp_gfp_mask(gfp_t gfp_mask) +@@ -3579,25 +3579,24 @@ __alloc_pages_slowpath(gfp_t gfp_mask, unsigned int order, + (__GFP_ATOMIC|__GFP_DIRECT_RECLAIM))) + gfp_mask &= ~__GFP_ATOMIC; + +-retry: +- if (gfp_mask & __GFP_KSWAPD_RECLAIM) +- wake_all_kswapds(order, ac); +- + /* +- * OK, we're below the kswapd watermark and have kicked background +- * reclaim. Now things get more complex, so set up alloc_flags according +- * to how we want to proceed. ++ * The fast path uses conservative alloc_flags to succeed only until ++ * kswapd needs to be woken up, and to avoid the cost of setting up ++ * alloc_flags precisely. So we do that now. + */ + alloc_flags = gfp_to_alloc_flags(gfp_mask); + ++retry: ++ if (gfp_mask & __GFP_KSWAPD_RECLAIM) ++ wake_all_kswapds(order, ac); ++ + /* This is the last chance, in general, before the goto nopage. */ +- page = get_page_from_freelist(gfp_mask, order, +- alloc_flags & ~ALLOC_NO_WATERMARKS, ac); ++ page = get_page_from_freelist(gfp_mask, order, alloc_flags, ac); + if (page) + goto got_pg; + + /* Allocate without watermarks if the context allows */ +- if (alloc_flags & ALLOC_NO_WATERMARKS) { ++ if (gfp_pfmemalloc_allowed(gfp_mask)) { + /* + * Ignore mempolicies if ALLOC_NO_WATERMARKS on the grounds + * the allocation is high priority and these type of +-- +2.8.2 diff --git a/a/content_digest b/N1/content_digest index c9325b7..d983228 100644 --- a/a/content_digest +++ b/N1/content_digest @@ -37,6 +37,127 @@ "\n" "Thanks\n" "\n" - ----8<---- + "----8<----\n" + ">From 68f09f1d4381c7451238b4575557580380d8bf30 Mon Sep 17 00:00:00 2001\n" + "From: Vlastimil Babka <vbabka@suse.cz>\n" + "Date: Fri, 29 Apr 2016 11:51:17 +0200\n" + "Subject: [RFC 02/13] mm, page_alloc: set alloc_flags only once in slowpath\n" + "\n" + "In __alloc_pages_slowpath(), alloc_flags doesn't change after it's initialized,\n" + "so move the initialization above the retry: label. Also make the comment above\n" + "the initialization more descriptive.\n" + "\n" + "The only exception in the alloc_flags being constant is ALLOC_NO_WATERMARKS,\n" + "which may change due to TIF_MEMDIE being set on the allocating thread. We can\n" + "fix this, and make the code simpler and a bit more effective at the same time,\n" + "by moving the part that determines ALLOC_NO_WATERMARKS from\n" + "gfp_to_alloc_flags() to gfp_pfmemalloc_allowed(). This means we don't have to\n" + "mask out ALLOC_NO_WATERMARKS in several places in __alloc_pages_slowpath()\n" + "anymore. The only test for the flag can instead call gfp_pfmemalloc_allowed().\n" + "\n" + "Signed-off-by: Vlastimil Babka <vbabka@suse.cz>\n" + "---\n" + " mm/page_alloc.c | 49 ++++++++++++++++++++++++-------------------------\n" + " 1 file changed, 24 insertions(+), 25 deletions(-)\n" + "\n" + "diff --git a/mm/page_alloc.c b/mm/page_alloc.c\n" + "index a50184ec6ca0..1b58facf4b5e 100644\n" + "--- a/mm/page_alloc.c\n" + "+++ b/mm/page_alloc.c\n" + "@@ -3216,8 +3216,7 @@ __alloc_pages_direct_compact(gfp_t gfp_mask, unsigned int order,\n" + " \t */\n" + " \tcount_vm_event(COMPACTSTALL);\n" + " \n" + "-\tpage = get_page_from_freelist(gfp_mask, order,\n" + "-\t\t\t\t\talloc_flags & ~ALLOC_NO_WATERMARKS, ac);\n" + "+\tpage = get_page_from_freelist(gfp_mask, order, alloc_flags, ac);\n" + " \n" + " \tif (page) {\n" + " \t\tstruct zone *zone = page_zone(page);\n" + "@@ -3366,8 +3365,7 @@ __alloc_pages_direct_reclaim(gfp_t gfp_mask, unsigned int order,\n" + " \t\treturn NULL;\n" + " \n" + " retry:\n" + "-\tpage = get_page_from_freelist(gfp_mask, order,\n" + "-\t\t\t\t\talloc_flags & ~ALLOC_NO_WATERMARKS, ac);\n" + "+\tpage = get_page_from_freelist(gfp_mask, order, alloc_flags, ac);\n" + " \n" + " \t/*\n" + " \t * If an allocation failed after direct reclaim, it could be because\n" + "@@ -3425,16 +3423,6 @@ gfp_to_alloc_flags(gfp_t gfp_mask)\n" + " \t} else if (unlikely(rt_task(current)) && !in_interrupt())\n" + " \t\talloc_flags |= ALLOC_HARDER;\n" + " \n" + "-\tif (likely(!(gfp_mask & __GFP_NOMEMALLOC))) {\n" + "-\t\tif (gfp_mask & __GFP_MEMALLOC)\n" + "-\t\t\talloc_flags |= ALLOC_NO_WATERMARKS;\n" + "-\t\telse if (in_serving_softirq() && (current->flags & PF_MEMALLOC))\n" + "-\t\t\talloc_flags |= ALLOC_NO_WATERMARKS;\n" + "-\t\telse if (!in_interrupt() &&\n" + "-\t\t\t\t((current->flags & PF_MEMALLOC) ||\n" + "-\t\t\t\t unlikely(test_thread_flag(TIF_MEMDIE))))\n" + "-\t\t\talloc_flags |= ALLOC_NO_WATERMARKS;\n" + "-\t}\n" + " #ifdef CONFIG_CMA\n" + " \tif (gfpflags_to_migratetype(gfp_mask) == MIGRATE_MOVABLE)\n" + " \t\talloc_flags |= ALLOC_CMA;\n" + "@@ -3444,7 +3432,19 @@ gfp_to_alloc_flags(gfp_t gfp_mask)\n" + " \n" + " bool gfp_pfmemalloc_allowed(gfp_t gfp_mask)\n" + " {\n" + "-\treturn !!(gfp_to_alloc_flags(gfp_mask) & ALLOC_NO_WATERMARKS);\n" + "+\tif (unlikely(gfp_mask & __GFP_NOMEMALLOC))\n" + "+\t\treturn false;\n" + "+\n" + "+\tif (gfp_mask & __GFP_MEMALLOC)\n" + "+\t\treturn true;\n" + "+\tif (in_serving_softirq() && (current->flags & PF_MEMALLOC))\n" + "+\t\treturn true;\n" + "+\tif (!in_interrupt() &&\n" + "+\t\t\t((current->flags & PF_MEMALLOC) ||\n" + "+\t\t\t unlikely(test_thread_flag(TIF_MEMDIE))))\n" + "+\t\treturn true;\n" + "+\n" + "+\treturn false;\n" + " }\n" + " \n" + " static inline bool is_thp_gfp_mask(gfp_t gfp_mask)\n" + "@@ -3579,25 +3579,24 @@ __alloc_pages_slowpath(gfp_t gfp_mask, unsigned int order,\n" + " \t\t\t\t(__GFP_ATOMIC|__GFP_DIRECT_RECLAIM)))\n" + " \t\tgfp_mask &= ~__GFP_ATOMIC;\n" + " \n" + "-retry:\n" + "-\tif (gfp_mask & __GFP_KSWAPD_RECLAIM)\n" + "-\t\twake_all_kswapds(order, ac);\n" + "-\n" + " \t/*\n" + "-\t * OK, we're below the kswapd watermark and have kicked background\n" + "-\t * reclaim. Now things get more complex, so set up alloc_flags according\n" + "-\t * to how we want to proceed.\n" + "+\t * The fast path uses conservative alloc_flags to succeed only until\n" + "+\t * kswapd needs to be woken up, and to avoid the cost of setting up\n" + "+\t * alloc_flags precisely. So we do that now.\n" + " \t */\n" + " \talloc_flags = gfp_to_alloc_flags(gfp_mask);\n" + " \n" + "+retry:\n" + "+\tif (gfp_mask & __GFP_KSWAPD_RECLAIM)\n" + "+\t\twake_all_kswapds(order, ac);\n" + "+\n" + " \t/* This is the last chance, in general, before the goto nopage. */\n" + "-\tpage = get_page_from_freelist(gfp_mask, order,\n" + "-\t\t\t\talloc_flags & ~ALLOC_NO_WATERMARKS, ac);\n" + "+\tpage = get_page_from_freelist(gfp_mask, order, alloc_flags, ac);\n" + " \tif (page)\n" + " \t\tgoto got_pg;\n" + " \n" + " \t/* Allocate without watermarks if the context allows */\n" + "-\tif (alloc_flags & ALLOC_NO_WATERMARKS) {\n" + "+\tif (gfp_pfmemalloc_allowed(gfp_mask)) {\n" + " \t\t/*\n" + " \t\t * Ignore mempolicies if ALLOC_NO_WATERMARKS on the grounds\n" + " \t\t * the allocation is high priority and these type of\n" + "-- \n" + 2.8.2 -5bf1139b5e813cd1f9dbe85837bd5bf416355618fb63b6af6d60344eaa364538 +fa7a7ec7a5cc3ca62872bb08c8c72ae6a0c99755784e177d238d8b3f78fcddf9
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.