6 ms·
From the mouth of Linus: https://marc.info/?l=linux-kernel&m=95496636207616&w=2 https://marc.info/?l=linux-kernel&m=95496636207616&w=2 It’s a bit old, but it
by lrossi 6y ago
From the mouth of Linus:
https://marc.info/?l=linux-kernel&m=95496636207616&w=2 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.
- beagle3 6y agoLMDB (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.
- nabla9 6y agoYes. 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; }