Hi, I am trying to achieve faster file writes using mmap. so I am trying the follwowing: /* open file */ while (loop) { /* get the current file size of output file */ filesize = lseek(outfd, 0, SEEK_END); /* Increase file size */ ftruncate(outfd, (off_t)filesize + (off_t)buf.size); /* mmap destination file */ if((dest = mmap(0, buf.size, PROT_WRITE, MAP_SHARED, outfd, filesize)) == (void *) -1) { printf( "Error mapping ouput file: %s: %d, %d\n", argv[1], i, filesize); perror("MMAP Failed\n"); goto error; } memcpy(dest, src, size); munmap(dest); } I am able to only mmap it once next time it fails to mmap, any pointers why it fails ? Regards, --Sagar
On Tue, 31 Mar 2015 17:11:33 +0530, Ssagarr Patil said:
Hi,
while (loop) { /* get the current file size of output file */ filesize = lseek(outfd, 0, SEEK_END);
/* Increase file size */ ftruncate(outfd, (off_t)filesize + (off_t)buf.size
Are you sure you want to do these two *every time* through the loop?
/* mmap destination file */ if((dest = mmap(0, buf.size, PROT_WRITE, MAP_SHARED, outfd, filesize)) == (void *) -1) {
Similarly here - usually the *entire* file gets mmap'ed. Also, what did perror() output? (probably nothing, since you stuck a printf in front of it, which probably reset errno on you).
memcpy(dest, src, size); munmap(dest);
You're not going to achieve faster throughput by adding to the syscall overhead.
}
Hi Valdis,
On Tue, 31 Mar 2015 17:11:33 +0530, Ssagarr Patil said:
Hi,
while (loop) { /* get the current file size of output file */ filesize = lseek(outfd, 0, SEEK_END);
/* Increase file size */ ftruncate(outfd, (off_t)filesize + (off_t)buf.size
Are you sure you want to do these two *every time* through the loop?
/* mmap destination file */ if((dest = mmap(0, buf.size, PROT_WRITE, MAP_SHARED, outfd, filesize)) == (void *) -1) {
Similarly here - usually the *entire* file gets mmap'ed.
Also, what did perror() output? (probably nothing, since you stuck a printf in front of it, which probably reset errno on you).
memcpy(dest, src, size); munmap(dest);
You're not going to achieve faster throughput by adding to the syscall overhead.
any pointers on avoiding syscall this then ? Regards, Sagar
participants (2)
-
Ssagarr Patil -
Valdis.Kletnieks@vt.edu