Commit 1fdcce6e authored by Michal Hocko's avatar Michal Hocko Committed by Linus Torvalds

memremap: add scheduling point to devm_memremap_pages

devm_memremap_pages is initializing struct pages in for_each_device_pfn
and that can take quite some time.  We have even seen a soft lockup
triggering on a non preemptive kernel

  NMI watchdog: BUG: soft lockup - CPU#61 stuck for 22s! [kworker/u641:11:1808]
  RIP: 0010:[<ffffffff8118b6b7>]  [<ffffffff8118b6b7>] devm_memremap_pages+0x327/0x430
  Call Trace:
    pmem_attach_disk+0x2fd/0x3f0 [nd_pmem]
    nvdimm_bus_probe+0x64/0x110 [libnvdimm]
    nd_async_device_register+0xe/0x40 [libnvdimm]

fix this by adding cond_resched every 1024 pages.

Link: default avatarMichal Hocko <>
Reported-by: default avatarJohannes Thumshirn <>
Tested-by: default avatarJohannes Thumshirn <>
Cc: Dan Williams <>
Signed-off-by: default avatarAndrew Morton <>
Signed-off-by: default avatarLinus Torvalds <>
parent 9b6e63cb
...@@ -350,7 +350,7 @@ void *devm_memremap_pages(struct device *dev, struct resource *res, ...@@ -350,7 +350,7 @@ void *devm_memremap_pages(struct device *dev, struct resource *res,
pgprot_t pgprot = PAGE_KERNEL; pgprot_t pgprot = PAGE_KERNEL;
struct dev_pagemap *pgmap; struct dev_pagemap *pgmap;
struct page_map *page_map; struct page_map *page_map;
int error, nid, is_ram; int error, nid, is_ram, i = 0;
align_start = res->start & ~(SECTION_SIZE - 1); align_start = res->start & ~(SECTION_SIZE - 1);
align_size = ALIGN(res->start + resource_size(res), SECTION_SIZE) align_size = ALIGN(res->start + resource_size(res), SECTION_SIZE)
...@@ -448,6 +448,8 @@ void *devm_memremap_pages(struct device *dev, struct resource *res, ...@@ -448,6 +448,8 @@ void *devm_memremap_pages(struct device *dev, struct resource *res,
list_del(&page->lru); list_del(&page->lru);
page->pgmap = pgmap; page->pgmap = pgmap;
percpu_ref_get(ref); percpu_ref_get(ref);
if (!(++i % 1024))
} }
devres_add(dev, page_map); devres_add(dev, page_map);
return __va(res->start); return __va(res->start);
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment