diff options
author | Damien Zammit <damien@zamaudio.com> | 2021-12-26 22:38:57 +1100 |
---|---|---|
committer | Samuel Thibault <samuel.thibault@ens-lyon.org> | 2021-12-27 15:50:56 +0100 |
commit | e5762c52ca54b349468df3fcb74a289feb138c2a (patch) | |
tree | 590adeaeee8dc926c2648259831d6c4f6d592a6d /rumpdisk | |
parent | 83ac2b3d67afc9895a80e813118569e2a73236ab (diff) | |
download | hurd-e5762c52ca54b349468df3fcb74a289feb138c2a.tar.gz hurd-e5762c52ca54b349468df3fcb74a289feb138c2a.tar.bz2 hurd-e5762c52ca54b349468df3fcb74a289feb138c2a.zip |
rumpdisk: Fault-in the memory pages
This ensures memory pages are allocated before written to.
Message-Id: <20211226113857.150525-6-damien@zamaudio.com>
Diffstat (limited to 'rumpdisk')
-rw-r--r-- | rumpdisk/block-rump.c | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/rumpdisk/block-rump.c b/rumpdisk/block-rump.c index a586a6e0..ce64abde 100644 --- a/rumpdisk/block-rump.c +++ b/rumpdisk/block-rump.c @@ -284,10 +284,18 @@ rumpdisk_device_write (void *d, mach_port_t reply_port, { struct block_data *bd = d; ssize_t written; + volatile uint8_t dummy_read; + int pagesize = sysconf (_SC_PAGE_SIZE); + int npages = (count + pagesize - 1) / pagesize; + int i; if ((bd->mode & D_WRITE) == 0) return D_INVALID_OPERATION; + /* Fault-in the memory pages by reading a single byte of each */ + for (i = 0; i < npages; i++) + dummy_read = ((volatile uint8_t *)data)[i * pagesize]; + written = rump_sys_pwrite (bd->rump_fd, (const void *)data, (size_t)count, (off_t)bn * bd->block_size); vm_deallocate (mach_task_self (), (vm_address_t) data, count); @@ -313,6 +321,7 @@ rumpdisk_device_read (void *d, mach_port_t reply_port, vm_address_t buf; int pagesize = sysconf (_SC_PAGE_SIZE); int npages = (count + pagesize - 1) / pagesize; + int i; ssize_t err; kern_return_t ret; @@ -327,8 +336,9 @@ rumpdisk_device_read (void *d, mach_port_t reply_port, if (ret != KERN_SUCCESS) return ENOMEM; - /* Ensure physical allocation. */ - memset (buf, 0, npages * pagesize); + /* Ensure physical allocation by writing a single byte of each */ + for (i = 0; i < npages; i++) + ((uint8_t *)buf)[i * pagesize] = 0; err = rump_sys_pread (bd->rump_fd, (void *)buf, (size_t)count, (off_t)bn * bd->block_size); if (err < 0) |