Skip to content

Commit f605a26

Browse files
rhvgoyaldjbw
authored andcommitted
dax, pmem: Add a dax operation zero_page_range
Add a dax operation zero_page_range, to zero a page. This will also clear any known poison in the page being zeroed. As of now, zeroing of one page is allowed in a single call. There are no callers which are trying to zero more than a page in a single call. Once we grow the callers which zero more than a page in single call, we can add that support. Primary reason for not doing that yet is that this will add little complexity in dm implementation where a range might be spanning multiple underlying targets and one will have to split the range into multiple sub ranges and call zero_page_range() on individual targets. Suggested-by: Christoph Hellwig <[email protected]> Signed-off-by: Vivek Goyal <[email protected]> Reviewed-by: Pankaj Gupta <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Dan Williams <[email protected]>
1 parent 5d64efe commit f605a26

File tree

3 files changed

+35
-0
lines changed

3 files changed

+35
-0
lines changed

drivers/dax/super.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,26 @@ size_t dax_copy_to_iter(struct dax_device *dax_dev, pgoff_t pgoff, void *addr,
344344
}
345345
EXPORT_SYMBOL_GPL(dax_copy_to_iter);
346346

347+
int dax_zero_page_range(struct dax_device *dax_dev, pgoff_t pgoff,
348+
size_t nr_pages)
349+
{
350+
if (!dax_alive(dax_dev))
351+
return -ENXIO;
352+
353+
if (!dax_dev->ops->zero_page_range)
354+
return -EOPNOTSUPP;
355+
/*
356+
* There are no callers that want to zero more than one page as of now.
357+
* Once users are there, this check can be removed after the
358+
* device mapper code has been updated to split ranges across targets.
359+
*/
360+
if (nr_pages != 1)
361+
return -EIO;
362+
363+
return dax_dev->ops->zero_page_range(dax_dev, pgoff, nr_pages);
364+
}
365+
EXPORT_SYMBOL_GPL(dax_zero_page_range);
366+
347367
#ifdef CONFIG_ARCH_HAS_PMEM_API
348368
void arch_wb_cache_pmem(void *addr, size_t size);
349369
void dax_flush(struct dax_device *dax_dev, void *addr, size_t size)

drivers/nvdimm/pmem.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,16 @@ static const struct block_device_operations pmem_fops = {
282282
.revalidate_disk = nvdimm_revalidate_disk,
283283
};
284284

285+
static int pmem_dax_zero_page_range(struct dax_device *dax_dev, pgoff_t pgoff,
286+
size_t nr_pages)
287+
{
288+
struct pmem_device *pmem = dax_get_private(dax_dev);
289+
290+
return blk_status_to_errno(pmem_do_write(pmem, ZERO_PAGE(0), 0,
291+
PFN_PHYS(pgoff) >> SECTOR_SHIFT,
292+
PAGE_SIZE));
293+
}
294+
285295
static long pmem_dax_direct_access(struct dax_device *dax_dev,
286296
pgoff_t pgoff, long nr_pages, void **kaddr, pfn_t *pfn)
287297
{
@@ -313,6 +323,7 @@ static const struct dax_operations pmem_dax_ops = {
313323
.dax_supported = generic_fsdax_supported,
314324
.copy_from_iter = pmem_copy_from_iter,
315325
.copy_to_iter = pmem_copy_to_iter,
326+
.zero_page_range = pmem_dax_zero_page_range,
316327
};
317328

318329
static const struct attribute_group *pmem_attribute_groups[] = {

include/linux/dax.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ struct dax_operations {
3434
/* copy_to_iter: required operation for fs-dax direct-i/o */
3535
size_t (*copy_to_iter)(struct dax_device *, pgoff_t, void *, size_t,
3636
struct iov_iter *);
37+
/* zero_page_range: required operation. Zero page range */
38+
int (*zero_page_range)(struct dax_device *, pgoff_t, size_t);
3739
};
3840

3941
extern struct attribute_group dax_attribute_group;
@@ -199,6 +201,8 @@ size_t dax_copy_from_iter(struct dax_device *dax_dev, pgoff_t pgoff, void *addr,
199201
size_t bytes, struct iov_iter *i);
200202
size_t dax_copy_to_iter(struct dax_device *dax_dev, pgoff_t pgoff, void *addr,
201203
size_t bytes, struct iov_iter *i);
204+
int dax_zero_page_range(struct dax_device *dax_dev, pgoff_t pgoff,
205+
size_t nr_pages);
202206
void dax_flush(struct dax_device *dax_dev, void *addr, size_t size);
203207

204208
ssize_t dax_iomap_rw(struct kiocb *iocb, struct iov_iter *iter,

0 commit comments

Comments
 (0)