mmap text file

Valdis.Kletnieks at vt.edu Valdis.Kletnieks at vt.edu
Tue Mar 31 13:53:26 EDT 2015


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.

> }
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 848 bytes
Desc: not available
Url : http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20150331/1f73156a/attachment.bin 


More information about the Kernelnewbies mailing list