From: Petr Mladek <pmladek@suse.com>
To: John Ogness <john.ogness@linutronix.de>
Cc: Sergey Senozhatsky <senozhatsky@chromium.org>,
Steven Rostedt <rostedt@goodmis.org>,
Thomas Gleixner <tglx@linutronix.de>,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH printk v4 7/8 v2] printk: use printk_buffers for devkmsg
Date: Fri, 6 Jan 2023 11:39:15 +0100 [thread overview]
Message-ID: <Y7f6U8+Kk3VoF5Dk@alley> (raw)
In-Reply-To: <87cz7tch2n.fsf@jogness.linutronix.de>
On Thu 2023-01-05 13:22:16, John Ogness wrote:
> Replace the buffers in struct devkmsg_user with a struct
> printk_buffers. This reduces the number of buffers to track.
>
> As a side-effect, @text_buf was 8kB large, even though it only
> needed to be the max size of a ringbuffer record. By switching to
> struct printk_buffers, ~7kB less memory is allocated when opening
> /dev/kmsg.
>
> And since struct printk_buffers will be used now, reduce duplicate
> code by calling printk_get_next_message() to handle the record
> reading and formatting.
> Signed-off-by: John Ogness <john.ogness@linutronix.de>
> ---
> kernel/printk/printk.c | 40 ++++++++++++++++------------------------
> 1 file changed, 16 insertions(+), 24 deletions(-)
>
> diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
> index 4fb7d29fb05d..32996b0c5d03 100644
> --- a/kernel/printk/printk.c
> +++ b/kernel/printk/printk.c
> @@ -695,16 +695,14 @@ static ssize_t msg_print_ext_body(char *buf, size_t size,
> return len;
> }
>
> +static bool printk_get_next_message(struct printk_message *pmsg, u64 seq, bool is_extended);
> +
> /* /dev/kmsg - userspace message inject/listen interface */
> struct devkmsg_user {
> atomic64_t seq;
> struct ratelimit_state rs;
> struct mutex lock;
> - char buf[CONSOLE_EXT_LOG_MAX];
> -
> - struct printk_info info;
> - char text_buf[CONSOLE_EXT_LOG_MAX];
> - struct printk_record record;
> + struct printk_buffers pbufs;
> };
>
> static __printf(3, 4) __cold
> @@ -786,8 +784,10 @@ static ssize_t devkmsg_read(struct file *file, char __user *buf,
> size_t count, loff_t *ppos)
> {
> struct devkmsg_user *user = file->private_data;
> - struct printk_record *r = &user->record;
> - size_t len;
> + char *outbuf = &user->pbufs.outbuf[0];
> + struct printk_message pmsg = {
> + .pbufs = &user->pbufs,
> + };
> ssize_t ret;
>
> if (!user)
> @@ -797,7 +797,7 @@ static ssize_t devkmsg_read(struct file *file, char __user *buf,
> if (ret)
> return ret;
>
> - if (!prb_read_valid(prb, atomic64_read(&user->seq), r)) {
> + while (!printk_get_next_message(&pmsg, atomic64_read(&user->seq), true)) {
A problem is that printk_get_next_message() does not format the
message when it shoud get supressed on the console.
I would solve it be adding a parameter to printk_get_next_message() that
will tell whether to suppress or not, e.g. @can_suppress.
> if (file->f_flags & O_NONBLOCK) {
> ret = -EAGAIN;
> goto out;
> @@ -814,36 +814,31 @@ static ssize_t devkmsg_read(struct file *file, char __user *buf,
> * This pairs with __wake_up_klogd:A.
> */
> ret = wait_event_interruptible(log_wait,
> - prb_read_valid(prb,
> - atomic64_read(&user->seq), r)); /* LMM(devkmsg_read:A) */
> + prb_read_valid(prb, atomic64_read(&user->seq),
> + NULL)); /* LMM(devkmsg_read:A) */
The above change from "if" to "while" could be avoided if we use
printk_get_next_message() here as well. It looks slightly more
strightfoward to me. Or do I miss something, please?
> if (ret)
> goto out;
> }
>
Otherwise, I like this change. It simplifies the code.
Best Regards,
Petr
next prev parent reply other threads:[~2023-01-06 10:39 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-01-05 10:37 [PATCH printk v4 0/8] printk: cleanup buffer handling John Ogness
2023-01-05 10:37 ` [PATCH printk v4 1/8] printk: move size limit macros into internal.h John Ogness
2023-01-05 14:48 ` Petr Mladek
2023-01-05 10:37 ` [PATCH printk v4 2/8] console: Use BIT() macros for @flags values John Ogness
2023-01-05 10:37 ` [PATCH printk v4 3/8] console: Document struct console John Ogness
2023-01-05 10:37 ` [PATCH printk v4 4/8] printk: introduce struct printk_buffers John Ogness
2023-01-05 15:06 ` Petr Mladek
2023-01-05 10:37 ` [PATCH printk v4 5/8] printk: introduce printk_get_next_message() and printk_message John Ogness
2023-01-05 15:24 ` Petr Mladek
2023-01-05 10:37 ` [PATCH printk v4 6/8] printk: introduce console_prepend_dropped() for dropped messages John Ogness
2023-01-05 16:17 ` Petr Mladek
2023-01-05 16:35 ` John Ogness
2023-01-06 9:34 ` Petr Mladek
2023-01-05 10:37 ` [PATCH printk v4 7/8] printk: use printk_buffers for devkmsg John Ogness
2023-01-05 12:14 ` John Ogness
2023-01-05 12:16 ` [PATCH printk v4 7/8 v2] " John Ogness
2023-01-06 10:39 ` Petr Mladek [this message]
2023-01-08 21:11 ` John Ogness
2023-01-05 10:37 ` [PATCH printk v4 8/8] printk: adjust string limit macros John Ogness
2023-01-06 11:11 ` Petr Mladek
2023-01-06 11:21 ` [PATCH printk v4 0/8] printk: cleanup buffer handling Petr Mladek
2023-01-07 8:18 ` John Ogness
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=Y7f6U8+Kk3VoF5Dk@alley \
--to=pmladek@suse.com \
--cc=john.ogness@linutronix.de \
--cc=linux-kernel@vger.kernel.org \
--cc=rostedt@goodmis.org \
--cc=senozhatsky@chromium.org \
--cc=tglx@linutronix.de \
/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
all inboxes | Powered by JetHome®