#3223·seastar

Why does sanitize_iovecs trim to the aligned size?

Author: travisdownsCreated Jan 28, 2026Updated Sep 10, 2026

sanitize_iovecs caps the number of io vectors at IOV_MAX, which makes sense.

Then, however, it trims the tail of the vectors to ensure alignment of the total size. Why does it do that? Is it there to "fix up" after the IOV_MAX resize (they were added in the same commit, the commit only refers to the IOV part)?

Every vector must have an aligned length for vectorized writes, so the total is always aligned by construction, so I can't see the point of this (I may be missing something).

size_t sanitize_iovecs(std::vector<iovec>& iov, size_t disk_alignment) noexcept {
    if (iov.size() > IOV_MAX) {
        iov.resize(IOV_MAX);
    }
    auto length = iovec_len(iov);
    while (auto rest = length & (disk_alignment - 1)) {
        if (iov.back().iov_len <= rest) {
            length -= iov.back().iov_len;
            iov.pop_back();
        } else {
            iov.back().iov_len -= rest;
            length -= rest;
        }
    }
    return length;
}