AsiaBSDCon 2026

logstor: A Log-structured virtual storage
2026-03-21 , Room B

Logstor uses the idea from log-structured file system to build a virtual disk on top of a physical disk. It is a virtual disk so its size can be larger then the underlying physical disk. It’s log-structured so it treats the underlying disk as a log and transforms the write requests from upper layer file system to log append operations. Since the random write operations are transformed to log append, the random write operations are transformed to sequential write operations.

Logstor is implemented by using FreeBSD’s GEOM mechanism. This is the second version of this program. The differences with the previous version are:
* The previous version runs in user-level and this version runs in kernel.
* Remove garbage collection and replace it with Stale Sector Recycle (SSR).
* Add new logstor commands snapshot and rollback.

Garbage collection is required if the underlying storage device is flash memory since flash memory does not support write operation, it only supports erase and program operations. But garbage collection is a costly operation. If the underlying storage device is hard disk, we can use a more efficient way to recycle sectors by using Stale Sector Recycle (SSR). In SSR, the program just searches for any stale sectors on the disk and overwrites it with new data.

Below I will use block to mean virtual block and sector to mean physical sector. Logstor is a virtual disk so it must record the block address to sector address mapping (forward mapping) for every virtual block. In order to know if a sector is stale, it also needs to record the sector to block address mapping (reverse mapping) for every physical sector on the disk. For reverse mapping, logstor divides the disk into segments and the last sector of each segment is used to store the reverse mapping. For forward mapping, it is not stored at fixed locations on the disk. Just like the regular data, the forward mapping information are also appended to the end of the log. I implemented a customized simple file system in logstor to store the forward mapping information. This simple file system has a buffer cache so only the recently used file data are cached in memory.

The new commands supported by logstor are snapshot and rollback. Snapshot is used to take a snapshot of the virtual disk so that later a rollback command can revert the virtual disk back to its previous snapshot. In order to support these commands, logstor must maintain 4 forward mapping files. They are current, snapshot, previous and newsnap mapping files. Whenever a block is written to the disk, its forward mapping information is always recorded in current mapping file.

When a snapshot command is received, logstor will do the following things:
* Move current mapping to previous mapping so that we don’t need to freeze the virtual disk while doing snapshot.
* Merge previous mapping and snapshot mapping to newsnapt mapping.
* Move newsnap mapping to snapshot mapping.
* Delete previous mapping.

When a rollback command is received, logstor just simply deletes current mapping file so that all the blocks in the current mapping become stale sectors. To delete a mapping in the simple file system is very easy. We don’t need to find all the sectors of that file. We only set the root sector of that file to null then all the sectors for that mapping file become stale. Those stale sectors will then be recycled by SSR.

Wuyang Chung is currently working as a freelancer. Previously, Chung worked at Industrial Technology Research Institute as a Windows CE system integrator. After that he worked in ALi as a firmware engineer. His last work was in Hewlett-Packard Taiwan branch as a system software engineer and worked on writing test programs and helping to analyze product issues detected by those test programs.