CC: [email protected] CC: [email protected] TO: Mel Gorman <[email protected]> CC: Alexander Lobakin <[email protected]> CC: Andrew Morton <[email protected]> CC: Linux Memory Management List <[email protected]>
tree: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master head: 9ed13a17e38e0537e24d9b507645002bf8d0201f commit: 0f87d9d30f21390dd71114f30e63038980e6eb3f mm/page_alloc: add an array-based interface to the bulk page allocator date: 7 weeks ago :::::: branch date: 12 hours ago :::::: commit date: 7 weeks ago config: x86_64-randconfig-m001-20210618 (attached as .config) compiler: gcc-9 (Debian 9.3.0-22) 9.3.0 If you fix the issue, kindly add following tag as appropriate Reported-by: kernel test robot <[email protected]> Reported-by: Dan Carpenter <[email protected]> smatch warnings: mm/page_alloc.c:5130 __alloc_pages_bulk() error: we previously assumed 'page_array' could be null (see line 5103) vim +/page_array +5130 mm/page_alloc.c 9cd7555875bb09 Mel Gorman 2017-02-24 5008 387ba26fb1cb9b Mel Gorman 2021-04-29 5009 /* 0f87d9d30f2139 Mel Gorman 2021-04-29 5010 * __alloc_pages_bulk - Allocate a number of order-0 pages to a list or array 387ba26fb1cb9b Mel Gorman 2021-04-29 5011 * @gfp: GFP flags for the allocation 387ba26fb1cb9b Mel Gorman 2021-04-29 5012 * @preferred_nid: The preferred NUMA node ID to allocate from 387ba26fb1cb9b Mel Gorman 2021-04-29 5013 * @nodemask: Set of nodes to allocate from, may be NULL 0f87d9d30f2139 Mel Gorman 2021-04-29 5014 * @nr_pages: The number of pages desired on the list or array 0f87d9d30f2139 Mel Gorman 2021-04-29 5015 * @page_list: Optional list to store the allocated pages 0f87d9d30f2139 Mel Gorman 2021-04-29 5016 * @page_array: Optional array to store the pages 387ba26fb1cb9b Mel Gorman 2021-04-29 5017 * 387ba26fb1cb9b Mel Gorman 2021-04-29 5018 * This is a batched version of the page allocator that attempts to 0f87d9d30f2139 Mel Gorman 2021-04-29 5019 * allocate nr_pages quickly. Pages are added to page_list if page_list 0f87d9d30f2139 Mel Gorman 2021-04-29 5020 * is not NULL, otherwise it is assumed that the page_array is valid. 387ba26fb1cb9b Mel Gorman 2021-04-29 5021 * 0f87d9d30f2139 Mel Gorman 2021-04-29 5022 * For lists, nr_pages is the number of pages that should be allocated. 0f87d9d30f2139 Mel Gorman 2021-04-29 5023 * 0f87d9d30f2139 Mel Gorman 2021-04-29 5024 * For arrays, only NULL elements are populated with pages and nr_pages 0f87d9d30f2139 Mel Gorman 2021-04-29 5025 * is the maximum number of pages that will be stored in the array. 0f87d9d30f2139 Mel Gorman 2021-04-29 5026 * 0f87d9d30f2139 Mel Gorman 2021-04-29 5027 * Returns the number of pages on the list or array. 387ba26fb1cb9b Mel Gorman 2021-04-29 5028 */ 387ba26fb1cb9b Mel Gorman 2021-04-29 5029 unsigned long __alloc_pages_bulk(gfp_t gfp, int preferred_nid, 387ba26fb1cb9b Mel Gorman 2021-04-29 5030 nodemask_t *nodemask, int nr_pages, 0f87d9d30f2139 Mel Gorman 2021-04-29 5031 struct list_head *page_list, 0f87d9d30f2139 Mel Gorman 2021-04-29 5032 struct page **page_array) 387ba26fb1cb9b Mel Gorman 2021-04-29 5033 { 387ba26fb1cb9b Mel Gorman 2021-04-29 5034 struct page *page; 387ba26fb1cb9b Mel Gorman 2021-04-29 5035 unsigned long flags; 387ba26fb1cb9b Mel Gorman 2021-04-29 5036 struct zone *zone; 387ba26fb1cb9b Mel Gorman 2021-04-29 5037 struct zoneref *z; 387ba26fb1cb9b Mel Gorman 2021-04-29 5038 struct per_cpu_pages *pcp; 387ba26fb1cb9b Mel Gorman 2021-04-29 5039 struct list_head *pcp_list; 387ba26fb1cb9b Mel Gorman 2021-04-29 5040 struct alloc_context ac; 387ba26fb1cb9b Mel Gorman 2021-04-29 5041 gfp_t alloc_gfp; 387ba26fb1cb9b Mel Gorman 2021-04-29 5042 unsigned int alloc_flags = ALLOC_WMARK_LOW; 0f87d9d30f2139 Mel Gorman 2021-04-29 5043 int nr_populated = 0; 387ba26fb1cb9b Mel Gorman 2021-04-29 5044 387ba26fb1cb9b Mel Gorman 2021-04-29 5045 if (WARN_ON_ONCE(nr_pages <= 0)) 387ba26fb1cb9b Mel Gorman 2021-04-29 5046 return 0; 387ba26fb1cb9b Mel Gorman 2021-04-29 5047 0f87d9d30f2139 Mel Gorman 2021-04-29 5048 /* 0f87d9d30f2139 Mel Gorman 2021-04-29 5049 * Skip populated array elements to determine if any pages need 0f87d9d30f2139 Mel Gorman 2021-04-29 5050 * to be allocated before disabling IRQs. 0f87d9d30f2139 Mel Gorman 2021-04-29 5051 */ 0f87d9d30f2139 Mel Gorman 2021-04-29 5052 while (page_array && page_array[nr_populated] && nr_populated < nr_pages) 0f87d9d30f2139 Mel Gorman 2021-04-29 5053 nr_populated++; 0f87d9d30f2139 Mel Gorman 2021-04-29 5054 387ba26fb1cb9b Mel Gorman 2021-04-29 5055 /* Use the single page allocator for one page. */ 0f87d9d30f2139 Mel Gorman 2021-04-29 5056 if (nr_pages - nr_populated == 1) 387ba26fb1cb9b Mel Gorman 2021-04-29 5057 goto failed; 387ba26fb1cb9b Mel Gorman 2021-04-29 5058 387ba26fb1cb9b Mel Gorman 2021-04-29 5059 /* May set ALLOC_NOFRAGMENT, fragmentation will return 1 page. */ 387ba26fb1cb9b Mel Gorman 2021-04-29 5060 gfp &= gfp_allowed_mask; 387ba26fb1cb9b Mel Gorman 2021-04-29 5061 alloc_gfp = gfp; 387ba26fb1cb9b Mel Gorman 2021-04-29 5062 if (!prepare_alloc_pages(gfp, 0, preferred_nid, nodemask, &ac, &alloc_gfp, &alloc_flags)) 387ba26fb1cb9b Mel Gorman 2021-04-29 5063 return 0; 387ba26fb1cb9b Mel Gorman 2021-04-29 5064 gfp = alloc_gfp; 387ba26fb1cb9b Mel Gorman 2021-04-29 5065 387ba26fb1cb9b Mel Gorman 2021-04-29 5066 /* Find an allowed local zone that meets the low watermark. */ 387ba26fb1cb9b Mel Gorman 2021-04-29 5067 for_each_zone_zonelist_nodemask(zone, z, ac.zonelist, ac.highest_zoneidx, ac.nodemask) { 387ba26fb1cb9b Mel Gorman 2021-04-29 5068 unsigned long mark; 387ba26fb1cb9b Mel Gorman 2021-04-29 5069 387ba26fb1cb9b Mel Gorman 2021-04-29 5070 if (cpusets_enabled() && (alloc_flags & ALLOC_CPUSET) && 387ba26fb1cb9b Mel Gorman 2021-04-29 5071 !__cpuset_zone_allowed(zone, gfp)) { 387ba26fb1cb9b Mel Gorman 2021-04-29 5072 continue; 387ba26fb1cb9b Mel Gorman 2021-04-29 5073 } 387ba26fb1cb9b Mel Gorman 2021-04-29 5074 387ba26fb1cb9b Mel Gorman 2021-04-29 5075 if (nr_online_nodes > 1 && zone != ac.preferred_zoneref->zone && 387ba26fb1cb9b Mel Gorman 2021-04-29 5076 zone_to_nid(zone) != zone_to_nid(ac.preferred_zoneref->zone)) { 387ba26fb1cb9b Mel Gorman 2021-04-29 5077 goto failed; 387ba26fb1cb9b Mel Gorman 2021-04-29 5078 } 387ba26fb1cb9b Mel Gorman 2021-04-29 5079 387ba26fb1cb9b Mel Gorman 2021-04-29 5080 mark = wmark_pages(zone, alloc_flags & ALLOC_WMARK_MASK) + nr_pages; 387ba26fb1cb9b Mel Gorman 2021-04-29 5081 if (zone_watermark_fast(zone, 0, mark, 387ba26fb1cb9b Mel Gorman 2021-04-29 5082 zonelist_zone_idx(ac.preferred_zoneref), 387ba26fb1cb9b Mel Gorman 2021-04-29 5083 alloc_flags, gfp)) { 387ba26fb1cb9b Mel Gorman 2021-04-29 5084 break; 387ba26fb1cb9b Mel Gorman 2021-04-29 5085 } 387ba26fb1cb9b Mel Gorman 2021-04-29 5086 } 387ba26fb1cb9b Mel Gorman 2021-04-29 5087 387ba26fb1cb9b Mel Gorman 2021-04-29 5088 /* 387ba26fb1cb9b Mel Gorman 2021-04-29 5089 * If there are no allowed local zones that meets the watermarks then 387ba26fb1cb9b Mel Gorman 2021-04-29 5090 * try to allocate a single page and reclaim if necessary. 387ba26fb1cb9b Mel Gorman 2021-04-29 5091 */ 387ba26fb1cb9b Mel Gorman 2021-04-29 5092 if (!zone) 387ba26fb1cb9b Mel Gorman 2021-04-29 5093 goto failed; 387ba26fb1cb9b Mel Gorman 2021-04-29 5094 387ba26fb1cb9b Mel Gorman 2021-04-29 5095 /* Attempt the batch allocation */ 387ba26fb1cb9b Mel Gorman 2021-04-29 5096 local_irq_save(flags); 387ba26fb1cb9b Mel Gorman 2021-04-29 5097 pcp = &this_cpu_ptr(zone->pageset)->pcp; 387ba26fb1cb9b Mel Gorman 2021-04-29 5098 pcp_list = &pcp->lists[ac.migratetype]; 387ba26fb1cb9b Mel Gorman 2021-04-29 5099 0f87d9d30f2139 Mel Gorman 2021-04-29 5100 while (nr_populated < nr_pages) { 0f87d9d30f2139 Mel Gorman 2021-04-29 5101 0f87d9d30f2139 Mel Gorman 2021-04-29 5102 /* Skip existing pages */ 0f87d9d30f2139 Mel Gorman 2021-04-29 @5103 if (page_array && page_array[nr_populated]) { 0f87d9d30f2139 Mel Gorman 2021-04-29 5104 nr_populated++; 0f87d9d30f2139 Mel Gorman 2021-04-29 5105 continue; 0f87d9d30f2139 Mel Gorman 2021-04-29 5106 } 0f87d9d30f2139 Mel Gorman 2021-04-29 5107 387ba26fb1cb9b Mel Gorman 2021-04-29 5108 page = __rmqueue_pcplist(zone, ac.migratetype, alloc_flags, 387ba26fb1cb9b Mel Gorman 2021-04-29 5109 pcp, pcp_list); 387ba26fb1cb9b Mel Gorman 2021-04-29 5110 if (!page) { 387ba26fb1cb9b Mel Gorman 2021-04-29 5111 /* Try and get at least one page */ 0f87d9d30f2139 Mel Gorman 2021-04-29 5112 if (!nr_populated) 387ba26fb1cb9b Mel Gorman 2021-04-29 5113 goto failed_irq; 387ba26fb1cb9b Mel Gorman 2021-04-29 5114 break; 387ba26fb1cb9b Mel Gorman 2021-04-29 5115 } 387ba26fb1cb9b Mel Gorman 2021-04-29 5116 387ba26fb1cb9b Mel Gorman 2021-04-29 5117 /* 387ba26fb1cb9b Mel Gorman 2021-04-29 5118 * Ideally this would be batched but the best way to do 387ba26fb1cb9b Mel Gorman 2021-04-29 5119 * that cheaply is to first convert zone_statistics to 387ba26fb1cb9b Mel Gorman 2021-04-29 5120 * be inaccurate per-cpu counter like vm_events to avoid 387ba26fb1cb9b Mel Gorman 2021-04-29 5121 * a RMW cycle then do the accounting with IRQs enabled. 387ba26fb1cb9b Mel Gorman 2021-04-29 5122 */ 387ba26fb1cb9b Mel Gorman 2021-04-29 5123 __count_zid_vm_events(PGALLOC, zone_idx(zone), 1); 387ba26fb1cb9b Mel Gorman 2021-04-29 5124 zone_statistics(ac.preferred_zoneref->zone, zone); 387ba26fb1cb9b Mel Gorman 2021-04-29 5125 387ba26fb1cb9b Mel Gorman 2021-04-29 5126 prep_new_page(page, 0, gfp, 0); 0f87d9d30f2139 Mel Gorman 2021-04-29 5127 if (page_list) 387ba26fb1cb9b Mel Gorman 2021-04-29 5128 list_add(&page->lru, page_list); 0f87d9d30f2139 Mel Gorman 2021-04-29 5129 else 0f87d9d30f2139 Mel Gorman 2021-04-29 @5130 page_array[nr_populated] = page; 0f87d9d30f2139 Mel Gorman 2021-04-29 5131 nr_populated++; 387ba26fb1cb9b Mel Gorman 2021-04-29 5132 } 387ba26fb1cb9b Mel Gorman 2021-04-29 5133 387ba26fb1cb9b Mel Gorman 2021-04-29 5134 local_irq_restore(flags); 387ba26fb1cb9b Mel Gorman 2021-04-29 5135 0f87d9d30f2139 Mel Gorman 2021-04-29 5136 return nr_populated; 387ba26fb1cb9b Mel Gorman 2021-04-29 5137 387ba26fb1cb9b Mel Gorman 2021-04-29 5138 failed_irq: 387ba26fb1cb9b Mel Gorman 2021-04-29 5139 local_irq_restore(flags); 387ba26fb1cb9b Mel Gorman 2021-04-29 5140 387ba26fb1cb9b Mel Gorman 2021-04-29 5141 failed: 387ba26fb1cb9b Mel Gorman 2021-04-29 5142 page = __alloc_pages(gfp, 0, preferred_nid, nodemask); 387ba26fb1cb9b Mel Gorman 2021-04-29 5143 if (page) { 0f87d9d30f2139 Mel Gorman 2021-04-29 5144 if (page_list) 387ba26fb1cb9b Mel Gorman 2021-04-29 5145 list_add(&page->lru, page_list); 0f87d9d30f2139 Mel Gorman 2021-04-29 5146 else 0f87d9d30f2139 Mel Gorman 2021-04-29 5147 page_array[nr_populated] = page; 0f87d9d30f2139 Mel Gorman 2021-04-29 5148 nr_populated++; 387ba26fb1cb9b Mel Gorman 2021-04-29 5149 } 387ba26fb1cb9b Mel Gorman 2021-04-29 5150 0f87d9d30f2139 Mel Gorman 2021-04-29 5151 return nr_populated; 387ba26fb1cb9b Mel Gorman 2021-04-29 5152 } 387ba26fb1cb9b Mel Gorman 2021-04-29 5153 EXPORT_SYMBOL_GPL(__alloc_pages_bulk); 387ba26fb1cb9b Mel Gorman 2021-04-29 5154 --- 0-DAY CI Kernel Test Service, Intel Corporation https://lists.01.org/hyperkitty/list/[email protected]
.config.gz
Description: application/gzip
_______________________________________________ kbuild mailing list -- [email protected] To unsubscribe send an email to [email protected]
