stanford-rc / fuse-migratefs

Filesystem overlay for transparent, distributed migration of active data across separate storage systems.
GNU General Public License v3.0
40 stars 10 forks source link

Optimize open(O_TRUNC) #2

Closed kcgthb closed 5 years ago

kcgthb commented 5 years ago

Avoid costly copyup operation when the destination file is to be entirely rewritten .

For instance, on truncate()/ftruncate() with length = 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,

kcgthb commented 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.

thiell commented 5 years ago

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!

thiell commented 5 years ago

0cf2beb: open(O_TRUNC) now skips any copyup of data from lower to upper (the rest of the copyup process is still performed).