Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

From the mouth of Linus:

https://marc.info/?l=linux-kernel&m=95496636207616&w=2

It’s a bit old, but it should still apply. I remember that in general he was annoyed when seeing people recommend mmap instead of read/write for basic I/O usecases.

In general, it’s almost always better to use the specialized API (read, write etc.) instead of reinventing the wheel on your own.



Yes. If you do lots of sequential/local reads you can reduce the number of context switches dramatically if you do something like:

    /* to reduce context switch */

    int bsize = 16*BUFSIZ;

    int fopen_bsize(char * filename) {
        int fp = fopen(filename, "r");        
        setvbuf(fp, NULL, _IOFBF, bsize);
        return fp;
    }


LMDB (and its modern fork MDBX), and kdb+/shakti make incredibly good use of mmap - I suspect it is possible to get similar performance from read(), but probably at 10x the implementation complexity.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: