Rewriting the GNU Coreutils in Rust
Rewriting the GNU Coreutils in Rust
Posted Jun 9, 2021 3:46 UTC (Wed) by NYKevin (subscriber, #129325)In reply to: Rewriting the GNU Coreutils in Rust by Paf
Parent article: Rewriting the GNU Coreutils in Rust
Would it be legal/advisable for sendfile to actually be implemented by doing that (with write, not fwrite), in cases where the file to read is mmap'able? Or does that break some sort of "don't alloc buffers in userspace without userspace explicitly asking for it" rule? I can't imagine that any reasonable implementation of malloc would care, but I'm sure there's some ridiculous use case where you go trawling through /proc/self/maps and do something clever with it.
Alternative #2: What if you could mmap file A, somehow tell the kernel that "this mmap now belongs to file B," and then unmap it? I'm guessing that you can't do the second step, though. AFAIK, there's currently no such thing as filesystem-to-memory-to-filesystem COW, so you'd have to fault everything into memory, at which point this is clearly a terrible idea (for large files, anyway).
Posted Jun 9, 2021 13:51 UTC (Wed)
by Paf (subscriber, #91811)
[Link] (1 responses)
You can do things like mmap in the kernel; in general you can kind of do ... whatever. But a lot of it is ugly or weird (using syscall type functionality within the kernel is prone to weird reentrancy issues), or requires allocating big blobs of memory in the kernel.
Things like COW for page cache memory would be ... weird. It gets in to areas I’m not familiar with, but I would think faulting, etc, might be a problem.
(Also, I misremembered above - send file is *always* via a pipe.)
Posted Jun 9, 2021 13:58 UTC (Wed)
by Sesse (subscriber, #53779)
[Link]
Rewriting the GNU Coreutils in Rust
Rewriting the GNU Coreutils in Rust