aboutsummaryrefslogtreecommitdiffstats
path: root/src/alloc
diff options
context:
space:
mode:
authorlloyd <[email protected]>2011-06-07 13:37:04 +0000
committerlloyd <[email protected]>2011-06-07 13:37:04 +0000
commit100ddd76eba1392901577efe8cc191af9df18712 (patch)
tree93692f843eeb2bbb4008a718d7d86a96699087d1 /src/alloc
parentad7aad3eb232499dfa6b74a66d6aff29c9ceb77c (diff)
Write zeros in 4K blocks
Diffstat (limited to 'src/alloc')
-rw-r--r--src/alloc/alloc_mmap/mmap_mem.cpp16
1 files changed, 9 insertions, 7 deletions
diff --git a/src/alloc/alloc_mmap/mmap_mem.cpp b/src/alloc/alloc_mmap/mmap_mem.cpp
index 78177bcdd..e4b602764 100644
--- a/src/alloc/alloc_mmap/mmap_mem.cpp
+++ b/src/alloc/alloc_mmap/mmap_mem.cpp
@@ -85,20 +85,22 @@ void* MemoryMapping_Allocator::alloc_block(size_t n)
if(file.get_fd() == -1)
throw MemoryMapping_Failed("Could not create file");
- std::vector<byte> zeros(n);
+ std::vector<byte> zeros(4096);
- ssize_t remaining = n;
+ size_t remaining = n;
while(remaining)
{
- ssize_t wrote_here = ::write(file.get_fd(),
- &zeros[0],
- remaining);
+ const size_t write_try = std::min(zeros.size(), remaining);
- if(wrote_here == -1 && errno != EINTR)
+ ssize_t wrote_got = ::write(file.get_fd(),
+ &zeros[0],
+ write_try);
+
+ if(wrote_got == -1 && errno != EINTR)
throw MemoryMapping_Failed("Could not write to file");
- remaining -= wrote_here;
+ remaining -= wrote_got;
}
#ifndef MAP_NOSYNC