Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=198.137.202.133 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795617923; b=xa4kvzqTz8avMH0gg2VG6VdUMSZ4AyZJA5DwZStB6JddmWwJu0J/W4HUtzOUs4bjXGHJ Ba1xklxBNwfDIA0CDc3RxS59VgOPWNQA5MwPI9wTL4A2wPBsat13IjB6LZJDwRq/iZXcv 6e3pFozobRyfxd4DLEIya8W0SMvNHKTQaqcYTXbkIH7kDv4gTKEddc8Be88+odrdpjVx1 MaoFUPjuA+lC9GEu4sgv2LCXH8xKtBBiwlw+xnYAFkpombm22ReN6kfiG0bUs84PGkKy3 65g6e8v6S3+Jv+L2eaZRniravjXOKJsm6n9GAuBjrHcLYNPcoX7yWyOl9zh99CcMAkQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795617923; h=DMARC-Filter:DKIM-Signature:Received:From:To:Cc:Subject:Date: Message-ID:X-Mailer:In-Reply-To:References:MIME-Version: Content-Transfer-Encoding:X-SRS-Rewrite; bh=pZr4gwTs5CGkrDG9wIJNGO7T0+7Z3L4j5ujCxiTF4Ts=; b=H0Bq82i09RSMhPoxzerrnaxe9fFrKr0vunuqtFYVjXse9UajXrBthlK72SjT8BlqBAuy wr71NXpz6ezrtxEkkKeyMCHIcEqLboOU3uWA4JKSdrL8IYsdhZiTYb2VNiWehBYrii3q0 l38ZQTjvzCJau4FWq1uo6uqyPyLi5BUxvcOteEijgfnvA2lzJtdSvwwRuyo7g7WmAykFc ST4ITjyvNnaD8wgNQFFMJCCm7kXUdt6+NDanWuAE/qnJK48IQQcAaJtggba2qujxWCGuC EQKTozPfS2Onk+fvK+POR/tKW4ltFCuFMmjOAGHoE/SLyy26Un7DnpiNjkdsPhEXHRg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=fail header.from=lst.de; spf=none smtp.mailfrom=bombadil.srs.infradead.org; dkim=pass header.d=infradead.org header.i=@infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b="Un1f/kIt"; arc=none smtp.remote-ip=198.137.202.133 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C0EE4606A323 for ; Wed, 25 Nov 2026 14:45:22 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org C0EE4606A323 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=lst.de Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=bombadil.srs.infradead.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=Un1f/kIt DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=pZr4gwTs5CGkrDG9wIJNGO7T0+7Z3L4j5ujCxiTF4Ts=; b=Un1f/kItzYBpuYisZ1c77n98Zj 6dy51BdQDwNuyc03piDiQOWWTqOyGMqYqH10WonsgZbAxMpYWd5Fx7xEeJ0VT3pVEa7JoMqQNn+vE FJS7RI0Yo8b2/5SkZ6FFqlgBU05wd5ER4w6npQNqdiw9fgksEJqSOZ0XJJ3QE9nP2NEWj0DshiA1R jKypPM7UQ1vKov8IuqsBGioNhL/x36FwIJIrVvMjQEPUdcR9DOdaBDNzU5nwjF2UJ2J80AqJfE6FW n2pQ/ISoUepIM02gYhpdzAQQOjmkF1OwP8DVwaYT+W8w8qBnDfq/UrRvrXlUqOI/8w72LAyA9yPuQ wSxm4pkg==; Received: from 2a02-8389-2301-9f00-7ed2-8579-02f4-a961.cable.dynamic.v6.surfer.at ([2a02:8389:2301:9f00:7ed2:8579:2f4:a961] helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.100.1 #2 (Red Hat Linux)) id 1xWEFN-0000000ADx1-3kbn; Wed, 25 Nov 2026 14:45:22 +0000 From: Christoph Hellwig To: Carlos Maiolino Cc: linux-xfs@vger.kernel.org Subject: [PATCH 13/15] xfs: create ophdrs on the fly in xlog_write Date: Wed, 25 Nov 2026 15:42:34 +0100 Message-ID: <20261125144430.728485-14-hch@lst.de> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20261125144430.728485-1-hch@lst.de> References: <20261125144430.728485-1-hch@lst.de> X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Currently each log iovec starts with an xlog_op_header in the CIL buffer. This wastes a little bit of memory, but more importantly makes managing the alignment of the individual log regions a bit annoying. Stop allocating this space now that the opheaders are generated by xlog_write and switch i_len to only account for the actual log region managed by the log item which doesn't include the opheader. Instead the opheader is only included in the low-level space reservation managed by xfs_log_vec_bytes. Signed-off-by: Christoph Hellwig --- fs/xfs/xfs_log.c | 26 +++++++----------- fs/xfs/xfs_log_cil.c | 61 ++++++++++--------------------------------- fs/xfs/xfs_log_priv.h | 7 ++++- 3 files changed, 29 insertions(+), 65 deletions(-) diff --git a/fs/xfs/xfs_log.c b/fs/xfs/xfs_log.c index 0a59cbdcc3cb..58a2fcc7275b 100644 --- a/fs/xfs/xfs_log.c +++ b/fs/xfs/xfs_log.c @@ -835,17 +835,12 @@ xlog_write_unmount_record( struct xlog *log, struct xlog_ticket *ticket) { - struct { - struct xlog_op_header ophdr; - struct xfs_unmount_log_format ulf; - } unmount_rec = { - .ulf = { - .magic = XLOG_UNMOUNT_TYPE, - }, + struct xfs_unmount_log_format ulf = { + .magic = XLOG_UNMOUNT_TYPE, }; struct xfs_log_iovec reg = { - .i_addr = &unmount_rec, - .i_len = sizeof(unmount_rec), + .i_addr = &ulf, + .i_len = sizeof(ulf), .i_type = XLOG_REG_TYPE_UNMOUNT, }; @@ -2016,7 +2011,7 @@ xlog_write_ophdr( ophdr = xlog_write_space_advance(data, sizeof(struct xlog_op_header)); ophdr->oh_tid = cpu_to_be32(data->ticket->t_tid); - ophdr->oh_len = cpu_to_be32(rlen - sizeof(struct xlog_op_header)); + ophdr->oh_len = cpu_to_be32(rlen); ophdr->oh_clientid = XFS_TRANSACTION; ophdr->oh_flags = xlog_ophdr_flag(reg); if (rlen != reg->i_len) @@ -2118,15 +2113,12 @@ xlog_write_region( if (error) return error; } - - rlen = min_t(uint32_t, reg->i_len, xlog_write_space_left(data)); + rlen = min_t(uint32_t, reg->i_len, + xlog_write_space_left(data) - sizeof(struct xlog_op_header)); xlog_write_ophdr(data, reg, rlen); - if (rlen > sizeof(struct xlog_op_header)) { - xlog_write_iovec(data, - reg->i_addr + sizeof(struct xlog_op_header), - rlen - sizeof(struct xlog_op_header)); - } + if (rlen) + xlog_write_iovec(data, reg->i_addr, rlen); /* * If we wrote the whole region, move to the next region. diff --git a/fs/xfs/xfs_log_cil.c b/fs/xfs/xfs_log_cil.c index 20c1d229cc61..541584f7d3b6 100644 --- a/fs/xfs/xfs_log_cil.c +++ b/fs/xfs/xfs_log_cil.c @@ -301,15 +301,14 @@ xlog_cil_alloc_shadow_bufs( * the next one is naturally aligned. We'll need to account for * that slack space here. * - * We also add the xlog_op_header to each region when - * formatting, but that's not accounted to the size of the item - * at this point. Hence we'll need an addition number of bytes - * for each vector to hold an opheader. - * * Then round nbytes up to 64-bit alignment so that the initial * buffer alignment is easy to calculate and verify. + * + * Note that this does not include the per-iovec ophdr, which + * only exists in the iclog buffer, but not the CIL buffer. */ - nbytes = xlog_item_space(niovecs, nbytes); + nbytes = round_up(nbytes + niovecs * sizeof(uint64_t), + sizeof(uint64_t)); /* * The data buffer needs to start 64-bit aligned, so round up @@ -418,17 +417,8 @@ struct xlog_format_buf { * biggest basic data type we put into it. We have already accounted for this * padding when sizing the buffer. * - * However, this padding does not get written into the log, and hence we have to - * track the space used by the log vectors separately to prevent log space hangs - * due to inaccurate accounting (i.e. a leak) of the used log space through the - * CIL context ticket. - * - * We also add space for the xlog_op_header that describes this region in the - * log. This prepends the data region we return to the caller to copy their data - * into, so do all the static initialisation of the ophdr now. Because the ophdr - * is not 8 byte aligned, we have to be careful to ensure that we align the - * start of the buffer such that the region we return to the call is 8 byte - * aligned and packed against the tail of the ophdr. + * However, this padding does not get written into the log, and is not accounted + * for in i_len. */ void * xlog_format_start( @@ -437,23 +427,14 @@ xlog_format_start( { struct xfs_log_vec *lv = lfb->lv; struct xfs_log_iovec *vec = &lv->lv_iovecp[lfb->idx]; - uint32_t len; - void *buf; ASSERT(lfb->idx < lv->lv_niovecs); - len = lv->lv_buf_used + sizeof(struct xlog_op_header); - if (!IS_ALIGNED(len, sizeof(uint64_t))) { - lv->lv_buf_used = round_up(len, sizeof(uint64_t)) - - sizeof(struct xlog_op_header); - } + lv->lv_buf_used = round_up(lv->lv_buf_used, sizeof(uint64_t)); vec->i_type = type; vec->i_addr = lv->lv_buf + lv->lv_buf_used; - - buf = vec->i_addr + sizeof(struct xlog_op_header); - ASSERT(IS_ALIGNED((unsigned long)buf, sizeof(uint64_t))); - return buf; + return vec->i_addr; } void @@ -469,16 +450,11 @@ xlog_format_commit( * Always round up the length to the correct alignment so callers don't * need to know anything about this log vec layout requirement. This * means we have to zero the area the data to be written does not cover. - * This is complicated by fact the payload region is offset into the - * logvec region by the opheader that tracks the payload. */ len = xlog_calc_iovec_len(data_len); - if (len - data_len != 0) { - char *buf = vec->i_addr + sizeof(struct xlog_op_header); + if (len - data_len != 0) + memset(vec->i_addr + data_len, 0, len - data_len); - memset(buf + data_len, 0, len - data_len); - } - len += sizeof(struct xlog_op_header); lv->lv_buf_used += len; vec->i_len = len; @@ -1170,11 +1146,7 @@ xlog_cil_write_commit_record( struct xfs_cil_ctx *ctx) { struct xlog *log = ctx->cil->xc_log; - struct xlog_op_header ophdr = { - }; struct xfs_log_iovec reg = { - .i_addr = &ophdr, - .i_len = sizeof(struct xlog_op_header), .i_type = XLOG_REG_TYPE_COMMIT, }; int error; @@ -1192,7 +1164,6 @@ xlog_cil_write_commit_record( } struct xlog_cil_trans_hdr { - struct xlog_op_header oph[2]; struct xfs_trans_header thdr; struct xfs_log_iovec lhdr[2]; }; @@ -1202,8 +1173,7 @@ struct xlog_cil_trans_hdr { * need to account for the space used by the transaction header here as it is * not accounted for in xlog_write(). * - * This is the only place we write a transaction header, so we also build the - * log opheaders that indicate the start of a log transaction and wrap the + * This is the only place we write a transaction header, so we also wrap the * transaction header. We keep the start record in it's own log vector rather * than compacting them into a single region as this ends up making the logic * in xlog_write() for handling empty opheaders for start, commit and unmount @@ -1222,8 +1192,6 @@ xlog_cil_build_trans_hdr( memset(hdr, 0, sizeof(*hdr)); /* Log start record */ - hdr->lhdr[0].i_addr = &hdr->oph[0]; - hdr->lhdr[0].i_len = sizeof(struct xlog_op_header); hdr->lhdr[0].i_type = XLOG_REG_TYPE_LRHEADER; /* transaction header in host byte order format */ @@ -1232,9 +1200,8 @@ xlog_cil_build_trans_hdr( hdr->thdr.th_tid = tic->t_tid; hdr->thdr.th_num_items = num_iovecs; - hdr->lhdr[1].i_addr = &hdr->oph[1]; - hdr->lhdr[1].i_len = sizeof(struct xlog_op_header) + - sizeof(struct xfs_trans_header); + hdr->lhdr[1].i_addr = &hdr->thdr; + hdr->lhdr[1].i_len = sizeof(struct xfs_trans_header); hdr->lhdr[1].i_type = XLOG_REG_TYPE_TRANSHDR; lvhdr->lv_niovecs = 2; diff --git a/fs/xfs/xfs_log_priv.h b/fs/xfs/xfs_log_priv.h index 2d87f9eae493..2be318c2eacf 100644 --- a/fs/xfs/xfs_log_priv.h +++ b/fs/xfs/xfs_log_priv.h @@ -745,12 +745,17 @@ static inline __be32 *xlog_cycle_data(struct xlog_rec_header *rhead, unsigned i) return &rhead->h_cycle_data[i]; } +static inline unsigned int xfs_log_iovec_bytes(struct xfs_log_iovec *reg) +{ + return sizeof(struct xlog_op_header) + reg->i_len; +} + static inline unsigned int xfs_log_vec_bytes(struct xfs_log_vec *lv) { unsigned int bytes = 0, i; for (i = 0; i < lv->lv_niovecs; i++) - bytes += lv->lv_iovecp[i].i_len; + bytes += xfs_log_iovec_bytes(&lv->lv_iovecp[i]); return bytes; } -- 2.53.0