Closed kcgthb closed 5 years ago
And when the ftruncate()
length is not zero, maybe there could be a way to only copy up the truncated portion of the file? For instance, in the case of a 1GB file truncated to its first 1GB, we may save some time and resources by only copyup'ing the first 1GB of the file, as the remaining 15GB will be thrown away afterwards anyway.
Not possible with ftruncate()
as the file must already be open for writing, so it is already present in the upper layer at this time.
truncate()
is considered a metadata only operation and doesn't perform a copyup, the truncate is performed in the layer where the file resides.
However, there is another case that can be optimized: open(O_TRUNC). Currently a copyup is performed for nothing in that case. I'll fix that!
0cf2beb: open(O_TRUNC)
now skips any copyup of data from lower to upper (the rest of the copyup process is still performed).
Avoid costly copyup operation when the destination file is to be entirely rewritten .
For instance, on
truncate()
/ftruncate()
withlength = 0
, we know that the file will be completely overwritten, so it's not necessary to copyup the old data from the lower layer,as it will be discarded after the copyup anyway,