On Thu, 16 Oct 2025, Lei Li wrote:

> Hi guys,
> I want to know if dm writecache target can handle power-off situation.
> 
> I've read the dm-writecache.c recent days and got confused. It seems
> that dm writecache may lose data if my pc encounter a power-off. Here
> is my thought:
> 1. There is no replay process for dm writecache. Every time
> writecache_ctr() builds a new wc_memory_entry array.
> 2. metadata update in dm-writeback can not guarantee atomic.
> 
> If I missed something?
> 
> Thanks

Hi

It should be safe w.r.t. power-off.

You need to use the FLUSH bio to commit previous writes to the stable 
storage - see writecache_map calling writecache_map_flush. Without the 
FLUSH bio, dm-writecache can lose data, but most disks could lose data in 
the absence of flush too.

struct wc_memory_entry has "seq_count" and there is seq_count in the 
superblock. The function writecache_flush increases the seq_count in the 
superblock and that makes wc_memory_entries valid.

In writecache_resume, there is "if (!writecache_entry_is_committed(wc, 
e))" - if the system is recovering from a crash and the cache entry was 
not fully committed (it has seq_count >= wc->seq_count), it is ignored 
(because it may have been only partially written).

There is no journaling - the driver keeps all the metadata in memory, and 
the seq_count is sufficient to prevent the system from using partially 
written cache blocks in the case of recovery from a crash.

Mikulas


Reply via email to