@@ -28,6 +28,7 @@
#include <linux/sched.h>
#include <linux/uio.h>
#include <linux/vmstat.h>
+#include <linux/sizes.h>
int dax_clear_blocks(struct inode *inode, sector_t block, long size)
{
@@ -38,24 +39,20 @@ int dax_clear_blocks(struct inode *inode, sector_t block, long size)
do {
void __pmem *addr;
unsigned long pfn;
- long count;
+ long count, sz;
- count = bdev_direct_access(bdev, sector, &addr, &pfn, size);
+ sz = min_t(long, size, SZ_1M);
+ count = bdev_direct_access(bdev, sector, &addr, &pfn, sz);
if (count < 0)
return count;
- BUG_ON(size < count);
- while (count > 0) {
- unsigned pgsz = PAGE_SIZE - offset_in_page(addr);
- if (pgsz > count)
- pgsz = count;
- clear_pmem(addr, pgsz);
- addr += pgsz;
- size -= pgsz;
- count -= pgsz;
- BUG_ON(pgsz & 511);
- sector += pgsz / 512;
- cond_resched();
- }
+ if (count < sz)
+ sz = count;
+ clear_pmem(addr, sz);
+ addr += sz;
+ size -= sz;
+ BUG_ON(sz & 511);
+ sector += sz / 512;
+ cond_resched();
} while (size);
wmb_pmem();