Skip to content

Commit 19f3cb6

Browse files
JasonXingakpm00
authored andcommitted
relayfs: support a counter tracking if data is too big to write
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_stats() as they want. Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: Jason Xing <[email protected]> Reviewed-by: Yushan Zhou <[email protected]> Reviewed-by: Masami Hiramatsu (Google) <[email protected]> Cc: Jens Axboe <[email protected]> Cc: Mathieu Desnoyers <[email protected]> Cc: Steven Rostedt <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent 7f21738 commit 19f3cb6

File tree

2 files changed

+13
-10
lines changed

2 files changed

+13
-10
lines changed

include/linux/relay.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,15 @@
3333
*/
3434
enum {
3535
RELAY_STATS_BUF_FULL = (1 << 0),
36+
RELAY_STATS_WRT_BIG = (1 << 1),
3637

37-
RELAY_STATS_LAST = RELAY_STATS_BUF_FULL,
38+
RELAY_STATS_LAST = RELAY_STATS_WRT_BIG,
3839
};
3940

4041
struct rchan_buf_stats
4142
{
4243
unsigned int full_count; /* counter for buffer full */
44+
unsigned int big_count; /* counter for too big to write */
4345
};
4446

4547
/*
@@ -79,7 +81,6 @@ struct rchan
7981
const struct rchan_callbacks *cb; /* client callbacks */
8082
struct kref kref; /* channel refcount */
8183
void *private_data; /* for user-defined data */
82-
size_t last_toobig; /* tried to log event > subbuf size */
8384
struct rchan_buf * __percpu *buf; /* per-cpu channel buffers */
8485
int is_global; /* One global buffer ? */
8586
struct list_head list; /* for channel list */

kernel/relay.c

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,7 @@ static void __relay_reset(struct rchan_buf *buf, unsigned int init)
303303
buf->data = buf->start;
304304
buf->offset = 0;
305305
buf->stats.full_count = 0;
306+
buf->stats.big_count = 0;
306307

307308
for (i = 0; i < buf->chan->n_subbufs; i++)
308309
buf->padding[i] = 0;
@@ -602,7 +603,7 @@ size_t relay_switch_subbuf(struct rchan_buf *buf, size_t length)
602603
return length;
603604

604605
toobig:
605-
buf->chan->last_toobig = length;
606+
buf->stats.big_count++;
606607
return 0;
607608
}
608609
EXPORT_SYMBOL_GPL(relay_switch_subbuf);
@@ -662,11 +663,6 @@ void relay_close(struct rchan *chan)
662663
if ((buf = *per_cpu_ptr(chan->buf, i)))
663664
relay_close_buf(buf);
664665

665-
if (chan->last_toobig)
666-
printk(KERN_WARNING "relay: one or more items not logged "
667-
"[item size (%zd) > sub-buffer size (%zd)]\n",
668-
chan->last_toobig, chan->subbuf_size);
669-
670666
list_del(&chan->list);
671667
kref_put(&chan->kref, relay_destroy_channel);
672668
mutex_unlock(&relay_channels_mutex);
@@ -719,11 +715,17 @@ size_t relay_stats(struct rchan *chan, int flags)
719715
rbuf = *per_cpu_ptr(chan->buf, 0);
720716
if (flags & RELAY_STATS_BUF_FULL)
721717
count = rbuf->stats.full_count;
718+
else if (flags & RELAY_STATS_WRT_BIG)
719+
count = rbuf->stats.big_count;
722720
} else {
723721
for_each_online_cpu(i) {
724722
rbuf = *per_cpu_ptr(chan->buf, i);
725-
if (rbuf && flags & RELAY_STATS_BUF_FULL)
726-
count += rbuf->stats.full_count;
723+
if (rbuf) {
724+
if (flags & RELAY_STATS_BUF_FULL)
725+
count += rbuf->stats.full_count;
726+
else if (flags & RELAY_STATS_WRT_BIG)
727+
count += rbuf->stats.big_count;
728+
}
727729
}
728730
}
729731

0 commit comments

Comments
 (0)