datto / dattobd

kernel module for taking block-level snapshots and incremental backups of Linux block devices
GNU General Public License v2.0
576 stars 122 forks source link

[Question] Does Datto snapshot use COFW? #282

Open Finix1979 opened 2 years ago

Finix1979 commented 2 years ago

I have a question about how to handle write operations in snapshot mode. When the write I/O comes and matches the tracing requirement, Datto clones the IO via bio_make_read_clone and submits it for reading the original data. After reading completion, Datto submits the original write IO and COW file write IO in separate threads.

My question is whether the read IO is necessary if the COW file already contains the required data.

nickchen-cpu commented 2 years ago

Hi

Yes, Dattobd uses COFW.

But its check time is when writing instead of reading as you mentioned.

static int cow_write_current(struct cow_manager *cm, uint64_t block, void *buf){
...
       //if the block mapping already exists return so we don't overwrite it
    if(block_mapping) return 0;
...
}

Trade off:

Finix1979 commented 2 years ago

Thank you @nickchen-cpu If we could check if the write range is already copied or in progress(read io is in flight already) before issuing the read operation, we could avoid this disk IO (copied) or wait until the previous read(in flight). It could be a range tree to record what is already copied to the file, and another range tree records in flight read range.