Was going through the implementation of
embed.FS and started wondering about the lack of
WriteTo - specifically about the implications in case the embedded data is not present in memory e.g. because it got evicted due to memory pressure - or simply due to outright not fitting in memory. Won’t this tie Ps up while the data is faulted in, with no way for the scheduler to park the offending Gs?
Obviously, WriteTo wouldn't solve this problem above for all cases (e.g. all cases in which the WriteTo implementation is unable to bypass the userspace copy) although it should help significantly when it does (e.g. in case of embedded static files to be served over plain HTTP). Or maybe reads from embed.FS instances could try to opportunistically madvise(MADV_WILLNEED) and yield if mincore returns that the pages are not (yet) resident in memory? Or the scheduler/sysmon should be taught how to handle that case (e.g. with userfaultfd on Linux)?