2 ms·
"On its face, readfile() adds nothing new; an application can obtain the same result with calls to openat(), read(), and close(). But it reduces the number of s
by tyingq 7y ago
"On its face, readfile() adds nothing new; an application can obtain the same result with calls to openat(), read(), and close(). But it reduces the number of system calls required from three to one"
A little surprised they didn't also roll in an optional lseek() offset in case you wanted a specific area of the file. Then it would roll 4 syscalls into 1. The somewhat similar sendfile() accepts an offset.
- masklinn 7y agoIf you look at the thread, readfile() would be pretty specifically for extremely short files e.g. procfs and sysfs. It would not be intended as a convenience API for slurping an entire file but as a performance API for very short reads (straight open(); read(); close() where the syscall overhead is enormous). The implementation(s) by Greg Kroah-Hartman don't even bother looping until read returns empty or the buffer is full.
- tyingq 7y agoSure, but it would be simple to add, and perhaps then useful for lots of small reads from bigger files. Or things like /proc/pid/mem.