On Fri, Jul 31, 2020 at 12:05:58PM +1000, Dave Chinner wrote: > On Fri, Jul 31, 2020 at 12:45:17AM +0100, Matthew Wilcox wrote: > > Essentially, we do as you thought > > it worked, we read the entire page (or at least the portion of it that > > isn't going to be overwritten. Once all the bytes have been transferred, > > we can mark the page Uptodate. We'll need to wait for the transfer to > > happen if the write overlaps a block boundary, but we do that right now. > > Right, we can do that, but it would be an entire page read, I think, > because I see little point int doing two small IOs with a seek in > between them when a single IO will do the entire thing much faster > that two small IOs and put less IOP load on the disk. We still have > to think about impact of IOs on spinning disks, unfortunately... Heh, maybe don't read the existing code because we actually do that today if, say, you have a write that spans bytes 800-3000 of a 4kB page. Worse, we wait for each one individually before submitting the next, so the drive doesn't even get the chance to see that we're doing read-seek-read. I think we can profitably skip reading portions of the page if the write overlaps either the beginning or end of the page, but it's not worth breaking up an I/O for skipping reading 2-3kB. The readahead window expands up to 256kB, so clearly we are comfortable with doing potentially-unnecessary reads of at least that much. I start to wonder about whether it might be worth skipping part of the page if you do a 1MB write to the middle of a 2MB page, but the THP patchset doesn't even try to allocate large pages in the write path yet, so the question remains moot today.