Skip to content

Commit 0b27796

Browse files
committed
libnvdimm, pmem: disable dax flushing when pmem is fronting a volatile region
The pmem driver attaches to both persistent and volatile memory ranges advertised by the ACPI NFIT. When the region is volatile it is redundant to spend cycles flushing caches at fsync(). Check if the hosting region is volatile and do not set dax_write_cache() if it is. Cc: Jan Kara <jack@suse.cz> Cc: Jeff Moyer <jmoyer@redhat.com> Cc: Christoph Hellwig <hch@lst.de> Cc: Matthew Wilcox <mawilcox@microsoft.com> Cc: Ross Zwisler <ross.zwisler@linux.intel.com> Signed-off-by: Dan Williams <dan.j.williams@intel.com>
1 parent 6e0c90d commit 0b27796

3 files changed

Lines changed: 15 additions & 5 deletions

File tree

‎drivers/nvdimm/pmem.c‎

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -284,10 +284,10 @@ static int pmem_attach_disk(struct device *dev,
284284
struct nd_namespace_io *nsio = to_nd_namespace_io(&ndns->dev);
285285
struct nd_region *nd_region = to_nd_region(dev->parent);
286286
struct vmem_altmap __altmap, *altmap = NULL;
287+
int nid = dev_to_node(dev), fua, wbc;
287288
struct resource *res = &nsio->res;
288289
struct nd_pfn *nd_pfn = NULL;
289290
struct dax_device *dax_dev;
290-
int nid = dev_to_node(dev);
291291
struct nd_pfn_sb *pfn_sb;
292292
struct pmem_device *pmem;
293293
struct resource pfn_res;
@@ -314,9 +314,12 @@ static int pmem_attach_disk(struct device *dev,
314314
dev_set_drvdata(dev, pmem);
315315
pmem->phys_addr = res->start;
316316
pmem->size = resource_size(res);
317-
if (!IS_ENABLED(CONFIG_ARCH_HAS_UACCESS_FLUSHCACHE)
318-
|| nvdimm_has_flush(nd_region) < 0)
317+
fua = nvdimm_has_flush(nd_region);
318+
if (!IS_ENABLED(CONFIG_ARCH_HAS_UACCESS_FLUSHCACHE) || fua < 0) {
319319
dev_warn(dev, "unable to guarantee persistence of writes\n");
320+
fua = 0;
321+
}
322+
wbc = nvdimm_has_cache(nd_region);
320323

321324
if (!devm_request_mem_region(dev, res->start, resource_size(res),
322325
dev_name(&ndns->dev))) {
@@ -360,7 +363,7 @@ static int pmem_attach_disk(struct device *dev,
360363
return PTR_ERR(addr);
361364
pmem->virt_addr = addr;
362365

363-
blk_queue_write_cache(q, true, true);
366+
blk_queue_write_cache(q, wbc, fua);
364367
blk_queue_make_request(q, pmem_make_request);
365368
blk_queue_physical_block_size(q, PAGE_SIZE);
366369
blk_queue_max_hw_sectors(q, UINT_MAX);
@@ -390,7 +393,7 @@ static int pmem_attach_disk(struct device *dev,
390393
put_disk(disk);
391394
return -ENOMEM;
392395
}
393-
dax_write_cache(dax_dev, true);
396+
dax_write_cache(dax_dev, wbc);
394397
pmem->dax_dev = dax_dev;
395398

396399
gendev = disk_to_dev(disk);

‎drivers/nvdimm/region_devs.c‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1060,6 +1060,12 @@ int nvdimm_has_flush(struct nd_region *nd_region)
10601060
}
10611061
EXPORT_SYMBOL_GPL(nvdimm_has_flush);
10621062

1063+
int nvdimm_has_cache(struct nd_region *nd_region)
1064+
{
1065+
return is_nd_pmem(&nd_region->dev);
1066+
}
1067+
EXPORT_SYMBOL_GPL(nvdimm_has_cache);
1068+
10631069
void __exit nd_region_devs_exit(void)
10641070
{
10651071
ida_destroy(&region_ida);

‎include/linux/libnvdimm.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,4 +165,5 @@ void nd_region_release_lane(struct nd_region *nd_region, unsigned int lane);
165165
u64 nd_fletcher64(void *addr, size_t len, bool le);
166166
void nvdimm_flush(struct nd_region *nd_region);
167167
int nvdimm_has_flush(struct nd_region *nd_region);
168+
int nvdimm_has_cache(struct nd_region *nd_region);
168169
#endif /* __LIBNVDIMM_H__ */

0 commit comments

Comments
 (0)