All of lore.kernel.org
 help / color / mirror / Atom feed
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 v1 4/5] relayfs: support a counter tracking if data is too big to write
Date: Mon, 12 May 2025 10:49:34 +0800	[thread overview]
Message-ID: <20250512024935.64704-5-kerneljasonxing@gmail.com> (raw)
In-Reply-To: <20250512024935.64704-1-kerneljasonxing@gmail.com>

From: Jason Xing <kernelxing@tencent.com>

It doesn't really matter to let the user/admin know what the last too
big value is. Just record how many times this case is triggered.

Also solve the 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 previous racy condition because
in terms of the global structure, it is likely to happen when a few of
per-cpu buffers encounter the too big data case.

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        | 19 +++++++++++--------
 2 files changed, 14 insertions(+), 10 deletions(-)

diff --git a/include/linux/relay.h b/include/linux/relay.h
index 7a442c4cbead..0f5f6ff17824 100644
--- a/include/linux/relay.h
+++ b/include/linux/relay.h
@@ -33,8 +33,9 @@
  */
 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,
 	RELAY_DUMP_MASK = (RELAY_DUMP_LAST - 1) | RELAY_DUMP_LAST
 };
 
@@ -43,6 +44,7 @@ enum {
 struct rchan_buf_error_stats
 {
 	unsigned int full;		/* counter for buffer full */
+	unsigned int big;		/* counter for too big to write */
 };
 
 /*
@@ -82,7 +84,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 0e675a77285c..27f7e701724f 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 = 0;
+	buf->stats.big = 0;
 
 	for (i = 0; i < buf->chan->n_subbufs; i++)
 		buf->padding[i] = 0;
@@ -712,7 +713,7 @@ size_t relay_switch_subbuf(struct rchan_buf *buf, size_t length)
 	return length;
 
 toobig:
-	buf->chan->last_toobig = length;
+	buf->stats.big++;
 	return 0;
 }
 EXPORT_SYMBOL_GPL(relay_switch_subbuf);
@@ -772,11 +773,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);
@@ -819,7 +815,7 @@ EXPORT_SYMBOL_GPL(relay_flush);
  */
 void relay_dump(struct rchan *chan, char *buf, int len, int flags)
 {
-	unsigned int i, full_counter = 0;
+	unsigned int i, full_counter = 0, big_counter = 0;
 	struct rchan_buf *rbuf;
 	int offset = 0;
 
@@ -832,15 +828,22 @@ void relay_dump(struct rchan *chan, char *buf, int len, int flags)
 	if (chan->is_global) {
 		rbuf = *per_cpu_ptr(chan->buf, 0);
 		full_counter = rbuf->stats.full;
+		big_counter = rbuf->stats.big;
 	} else {
 		for_each_possible_cpu(i) {
-			if ((rbuf = *per_cpu_ptr(chan->buf, i)))
+			if ((rbuf = *per_cpu_ptr(chan->buf, i))) {
 				full_counter += rbuf->stats.full;
+				big_counter += rbuf->stats.big;
+			}
+		}
 	}
 
 	if (flags & RELAY_DUMP_BUF_FULL)
 		offset += snprintf(buf, sizeof(unsigned int), "%u", full_counter);
 
+	if (flags & RELAY_DUMP_WRT_BIG)
+		offset += snprintf(buf, sizeof(unsigned int), "%u", big_counter);
+
 	snprintf(buf + offset, 1, "\n");
 }
 EXPORT_SYMBOL_GPL(relay_dump);
-- 
2.43.5


  parent reply	other threads:[~2025-05-12  2:49 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-05-12  2:49 [PATCH v1 0/5] relayfs: misc changes Jason Xing
2025-05-12  2:49 ` [PATCH v1 1/5] relayfs: support a counter tracking if per-cpu buffers is full Jason Xing
2025-05-13  0:51   ` Andrew Morton
2025-05-13  1:37     ` Jason Xing
2025-05-12  2:49 ` [PATCH v1 2/5] relayfs: introduce dump of relayfs statistics function Jason Xing
2025-05-13  0:51   ` Andrew Morton
2025-05-13  1:48     ` Jason Xing
2025-05-13  2:04       ` Andrew Morton
2025-05-13  2:26         ` Jason Xing
2025-05-13  3:41           ` Andrew Morton
2025-05-13  3:48             ` Jason Xing
2025-05-13  9:58   ` Masami Hiramatsu
2025-05-13 10:32     ` Jason Xing
2025-05-13 13:22       ` Masami Hiramatsu
2025-05-13 13:46         ` Jason Xing
2025-05-14  1:29           ` Masami Hiramatsu
2025-05-14  2:06             ` Jason Xing
2025-05-12  2:49 ` [PATCH v1 3/5] blktrace: use rbuf->stats.full as a drop indicator in relayfs Jason Xing
2025-05-12  2:49 ` Jason Xing [this message]
2025-05-12  2:49 ` [PATCH v1 5/5] relayfs: uniformally use possible cpu iteration Jason Xing
2025-05-13  0:52   ` Andrew Morton
2025-05-13  2:03     ` Jason Xing
2025-05-13  3:21       ` Andrew Morton
2025-05-13  3:25         ` Jason Xing
2025-05-13  5:52     ` Jason Xing

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=20250512024935.64704-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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.