The lru_cache_disable() call in __alloc_contig_migrate_range() can cause a performance hit. If we can successfully allocate without it that would be preferable. Add a new ACR_FLAGS_LAZY to tell functions to take a lazy path for allocation (I.E. prefer fast-failure over slow-success), and use it to avoid flushing and disabling the LRU cache in __alloc_contig_migrate_range(). This will mean that pages still in the cache are not migrated, and if they're busy will cause the allocation to fail on __test_page_isolated_in_pageblock() and so return -EBUSY. The caller of alloc_contig_frozen_range_noprof() would therefore be expected to re-try without ACR_FLAGS_LAZY. Signed-off-by: Daniel Scally --- include/linux/gfp.h | 1 + mm/page_alloc.c | 12 ++++++++---- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/include/linux/gfp.h b/include/linux/gfp.h index 63a7654c725fcc8854159130ebc106e611c15b23..b0d53ad7885ec726857379eb8a9b999e2350bdb9 100644 --- a/include/linux/gfp.h +++ b/include/linux/gfp.h @@ -386,6 +386,7 @@ extern gfp_t vma_thp_gfp_mask(struct vm_area_struct *vma); typedef unsigned int __bitwise acr_flags_t; #define ACR_FLAGS_NONE ((__force acr_flags_t)0) // ordinary allocation request #define ACR_FLAGS_CMA ((__force acr_flags_t)BIT(0)) // allocate for CMA +#define ACR_FLAGS_LAZY ((__force acr_flags_t)BIT(1)) // take the lazy path /* The below functions must be run on a range from a single zone. */ int alloc_contig_frozen_range_noprof(unsigned long start, unsigned long end, diff --git a/mm/page_alloc.c b/mm/page_alloc.c index aa1ed599c7c6b7ed697e9015b5e024c46b16c28c..fcbe405057d5a5fce816acc706dcb5e5441ac23b 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -7197,7 +7197,8 @@ static void alloc_contig_dump_pages(struct list_head *page_list) /* [start, end) must belong to a single zone. */ static int __alloc_contig_migrate_range(struct compact_control *cc, - unsigned long start, unsigned long end) + unsigned long start, unsigned long end, + acr_flags_t alloc_flags) { /* This function is based on compact_zone() from compaction.c. */ unsigned int nr_reclaimed; @@ -7210,7 +7211,8 @@ static int __alloc_contig_migrate_range(struct compact_control *cc, .reason = MR_CONTIG_RANGE, }; - lru_cache_disable(); + if (!(alloc_flags & ACR_FLAGS_LAZY)) + lru_cache_disable(); while (pfn < end || !list_empty(&cc->migratepages)) { if (fatal_signal_pending(current)) { @@ -7245,7 +7247,9 @@ static int __alloc_contig_migrate_range(struct compact_control *cc, break; } - lru_cache_enable(); + if (!(alloc_flags & ACR_FLAGS_LAZY)) + lru_cache_enable(); + if (ret < 0) { if (!(cc->gfp_mask & __GFP_NOWARN) && ret == -EBUSY) alloc_contig_dump_pages(&cc->migratepages); @@ -7417,7 +7421,7 @@ int alloc_contig_frozen_range_noprof(unsigned long start, unsigned long end, * allocated. So, if we fall through be sure to clear ret so that * -EBUSY is not accidentally used or returned to caller. */ - ret = __alloc_contig_migrate_range(&cc, start, end); + ret = __alloc_contig_migrate_range(&cc, start, end, alloc_flags); if (ret && ret != -EBUSY) goto done; -- 2.43.0