Skip to content

Commit c5057b8

Browse files
JasonXingkawasaki
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. Reviewed-by: Yushan Zhou <[email protected]> Reviewed-by: Masami Hiramatsu (Google) <[email protected]> Signed-off-by: Jason Xing <[email protected]>
1 parent 5206c68 commit c5057b8

2 files changed

Lines changed: 13 additions & 10 deletions

File tree

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
@@ -304,6 +304,7 @@ static void __relay_reset(struct rchan_buf *buf, unsigned int init)
304304
buf->data = buf->start;
305305
buf->offset = 0;
306306
buf->stats.full_count = 0;
307+
buf->stats.big_count = 0;
307308

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

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

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

0 commit comments

Comments
 (0)