This is the patch that allows larger bios to snapshots and improve
snapshot performance.
The logic and reason is explained in the patch header.
Note that providing a merge function on a snapshot target doesn't work,
the target merge function doesn't know where the bio will go, thus it
cannot call underlying merge function accurately. Guessing is not
possible, because the merge function must be obeyed.
This patch may also improve CPU consumption a little bit by not providing
a merge function on linear devices, where it is not needed.
Mikulas
---
dm: Don't install merge function if not needed
This patch changes dm to not install merge function when not needed.
Merge functions is installed when the table needs it. It is never
uninstalled --- uninstalling it is not thread-safe.
The reason for this change is this:
The specification for allowed bio size is this:
* a bio containing just one page is always allowed
* if the bio contains more pages, it must conform to queue limits and
the merge function. The bio must not be larger than the size allowed
by the queue's merge function.
The limit set by the "merge" function must be obeyed. If we don't obey
this limit, "md" driver doesn't process the bio and returns an error.
The snapshot target can provide its own merge function, but when this
merge function is called, it is unclear to which location the bio will go.
We would know where the bio will go in case of already reallocated chunk,
but in case of read or write to not-yet-reallocated chunk, it is impossible
to say where this chunk will be eventually reallocated.
"Guessing" where the bio will go is not allowed, because the guess will
eventually go wrong. Incorrect guess could allow too large bio to
be created. When such large bio is passed to "md" driver, the "md" driver
rejects it with an error.
Consequently --- if the snapshot "cow" device has a merge function,
we must not allow bios larger than a page to go to that snapshot.
Therefore, we could allow bios larger than a page and improve snapshot
performance by not setting a merge function for a "cow" device.
The "cow" device is device mapper device, it is usually composed of
one or more linear targets, these targets do not need merge function
if the underlying disk doesn't have a merge function.
This patch introduces this logic:
* the device mapper provides a merge function for its device
if one of the underlying devices have a merge function OR
if one of the targets have nonzero "split_io".
Consequently, if the "cow" device is a linear target and if the underlying disk
doesn't have a merge function, the "cow" device doesn't have a merge function
either. Thus, the snapshot target can allow bios larger than a page.
This patch (together with the previous patch to not copy on full chunk write)
improves performance when writing to ext2 filesystem created on a sparse device
with 8k chunk from 22MB/s (before the patch) to 40MB/s (after the patch).