| ▲ | jeffbee 13 hours ago |
| You mean it converts an expression like `buf[i]` into a baroque sequence of CPU exception paths, potentially involving a trap back into the kernel. |
|
| ▲ | rishabhaiover 12 hours ago | parent [-] |
| I don't fully understand the under the hood mechanics of mmap, but I can sense that you're trying to convey that mmap shouldn't be used a blanket optimization technique as there are tradeoffs in terms of page fault overheads (being at the mercy of OS page cache mechanics) |
| |
| ▲ | StilesCrisis 9 hours ago | parent | next [-] | | Tradeoffs such as "if an I/O error occurs, the program immediately segfaults." Also, I doubt you're I/O bound to the point where mmap noticeably better than read, but I guess it's fine for an experiment. | |
| ▲ | jibal 11 hours ago | parent | prev [-] | | I think he's conveying that he doesn't know what he's talking about. buf[i] generates the same code regardless of whether mmap is being used. The first access to a page will cause a trap that loads the page into memory, but this is also true if the memory is read into. |
|