From: Jason Xing <kerneljasonxing@gmail.com>
To: axboe@kernel.dk, rostedt@goodmis.org, mhiramat@kernel.org,
mathieu.desnoyers@efficios.com, akpm@linux-foundation.org
Cc: linux-kernel@vger.kernel.org, linux-block@vger.kernel.org,
linux-trace-kernel@vger.kernel.org,
Jason Xing <kernelxing@tencent.com>,
Yushan Zhou <katrinzhou@tencent.com>
Subject: [PATCH v2 4/4] relayfs: support a counter tracking if data is too big to write
Date: Thu, 15 May 2025 14:16:43 +0800 [thread overview]
Message-ID: <20250515061643.31472-5-kerneljasonxing@gmail.com> (raw)
In-Reply-To: <20250515061643.31472-1-kerneljasonxing@gmail.com>
From: Jason Xing <kernelxing@tencent.com>
It really doesn't matter if the user/admin knows what the last too
big value is. Record how many times this case is triggered would be
helpful.
Solve the existing issue where relay_reset() doesn't restore
the value.
Store the counter in the per-cpu buffer structure instead of the global
buffer structure. It also solves the racy condition which is likely
to happen when a few of per-cpu buffers encounter the too big data case
and then access the global field last_toobig without lock protection.
Remove the printk in relay_close() since kernel module can directly call
relay_dump() as they want.
Reviewed-by: Yushan Zhou <katrinzhou@tencent.com>
Signed-off-by: Jason Xing <kernelxing@tencent.com>
---
include/linux/relay.h | 5 +++--
kernel/relay.c | 12 ++++++------
2 files changed, 9 insertions(+), 8 deletions(-)
diff --git a/include/linux/relay.h b/include/linux/relay.h
index 3fb285716e34..08c1888c9c1a 100644
--- a/include/linux/relay.h
+++ b/include/linux/relay.h
@@ -33,13 +33,15 @@
*/
enum {
RELAY_DUMP_BUF_FULL = (1 << 0),
+ RELAY_DUMP_WRT_BIG = (1 << 1),
- RELAY_DUMP_LAST = RELAY_DUMP_BUF_FULL,
+ RELAY_DUMP_LAST = RELAY_DUMP_WRT_BIG,
};
struct rchan_buf_stats
{
unsigned int full_count; /* counter for buffer full */
+ unsigned int big_count; /* counter for too big to write */
};
/*
@@ -79,7 +81,6 @@ struct rchan
const struct rchan_callbacks *cb; /* client callbacks */
struct kref kref; /* channel refcount */
void *private_data; /* for user-defined data */
- size_t last_toobig; /* tried to log event > subbuf size */
struct rchan_buf * __percpu *buf; /* per-cpu channel buffers */
int is_global; /* One global buffer ? */
struct list_head list; /* for channel list */
diff --git a/kernel/relay.c b/kernel/relay.c
index f47fc750e559..f4d1dcac164a 100644
--- a/kernel/relay.c
+++ b/kernel/relay.c
@@ -304,6 +304,7 @@ static void __relay_reset(struct rchan_buf *buf, unsigned int init)
buf->data = buf->start;
buf->offset = 0;
buf->stats.full_count = 0;
+ buf->stats.big_count = 0;
for (i = 0; i < buf->chan->n_subbufs; i++)
buf->padding[i] = 0;
@@ -603,7 +604,7 @@ size_t relay_switch_subbuf(struct rchan_buf *buf, size_t length)
return length;
toobig:
- buf->chan->last_toobig = length;
+ buf->stats.big_count++;
return 0;
}
EXPORT_SYMBOL_GPL(relay_switch_subbuf);
@@ -663,11 +664,6 @@ void relay_close(struct rchan *chan)
if ((buf = *per_cpu_ptr(chan->buf, i)))
relay_close_buf(buf);
- if (chan->last_toobig)
- printk(KERN_WARNING "relay: one or more items not logged "
- "[item size (%zd) > sub-buffer size (%zd)]\n",
- chan->last_toobig, chan->subbuf_size);
-
list_del(&chan->list);
kref_put(&chan->kref, relay_destroy_channel);
mutex_unlock(&relay_channels_mutex);
@@ -720,11 +716,15 @@ size_t relay_dump(struct rchan *chan, int flags)
rbuf = *per_cpu_ptr(chan->buf, 0);
if (flags & RELAY_DUMP_BUF_FULL)
count = rbuf->stats.full_count;
+ else if (flags & RELAY_DUMP_WRT_BIG)
+ count = rbuf->stats.big_count;
} else {
for_each_online_cpu(i) {
if ((rbuf = *per_cpu_ptr(chan->buf, i)))
if (flags & RELAY_DUMP_BUF_FULL)
count += rbuf->stats.full_count;
+ else if (flags & RELAY_DUMP_WRT_BIG)
+ count += rbuf->stats.big_count;
}
}
--
2.43.5
prev parent reply other threads:[~2025-05-15 6:17 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-05-15 6:16 [PATCH v2 0/4] relayfs: misc changes Jason Xing
2025-05-15 6:16 ` [PATCH v2 1/4] relayfs: support a counter tracking if per-cpu buffers is full Jason Xing
2025-05-15 18:17 ` Jens Axboe
2025-05-15 6:16 ` [PATCH v2 2/4] relayfs: introduce dump of relayfs statistics function Jason Xing
2025-05-15 18:19 ` Jens Axboe
2025-05-15 23:24 ` Jason Xing
2025-05-16 2:08 ` Masami Hiramatsu
2025-05-16 2:32 ` Jason Xing
2025-05-16 4:37 ` Christoph Hellwig
2025-05-16 5:02 ` Jason Xing
2025-05-16 5:06 ` Christoph Hellwig
2025-05-16 5:44 ` Jason Xing
2025-05-15 6:16 ` [PATCH v2 3/4] blktrace: use rbuf->stats.full as a drop indicator in relayfs Jason Xing
2025-05-15 18:19 ` Jens Axboe
2025-05-15 18:21 ` Jens Axboe
2025-05-15 23:26 ` Jason Xing
2025-05-15 6:16 ` Jason Xing [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250515061643.31472-5-kerneljasonxing@gmail.com \
--to=kerneljasonxing@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=axboe@kernel.dk \
--cc=katrinzhou@tencent.com \
--cc=kernelxing@tencent.com \
--cc=linux-block@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-trace-kernel@vger.kernel.org \
--cc=mathieu.desnoyers@efficios.com \
--cc=mhiramat@kernel.org \
--cc=rostedt@goodmis.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).