Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp3083231ybt; Mon, 29 Jun 2020 14:55:16 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwgcfkywtjWZSE/7gQVuRAvRtGz/dkYpSd+doTnLCCb5lso3XGQn2zAta68TCvGqWyMuvST X-Received: by 2002:a05:6402:1b0e:: with SMTP id by14mr19176450edb.266.1593467716421; Mon, 29 Jun 2020 14:55:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1593467716; cv=none; d=google.com; s=arc-20160816; b=Pl7KVSyhflk7Vbky0wihP9O/+HvgQtDaTCspe3qubOLOYzjVEnNDH2uIvyQt76qCcY Q54cpMbnJ21XDOSaiKx68k3rsOOPBRTyLJFnCxtSdhZvQLY6kIz5aNPJJv7PErB9cnof 6+BSkrwKpKsWshRjS24cqEtTfDk0YDR7LsxwmWMnD9aP9IvJ6KlwhXlma4jp4XyOqa1i 1rfRfzkdoFAjY6atos1EA/e+X5RkcAvNHVV7BMpjhb4H4yejgR1Xh9nPMFHVZpa+qP/C jhHaxeGcHIvDaT9mYKC6tUuJnL0gMn2bfvY7y9FchJ6p3dRojtb9l+WvnKqF90Ku+brG fyTg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:message-id:in-reply-to:date :references:subject:cc:to:dkim-signature:dkim-signature:from; bh=siVZWIEnwE41C7ZxHsZfQ8/Re56UAlzQKcSRDT+JiwE=; b=T32E1VD6DvIyhZZH7z0tdFWvlU6KTNt+l3MLb/OtjJJXxZooRuqmBUaF2LVG5eqnOs /u6MFFiUZpHidR7qIpsM2cUR6VNxSKR99c/zvcnqJr6V8hHG8A7LROFeGpJA08uT6tzx UPsQWGuMa7Y2YOP9rfwaKGOkO3DwYGYV2xcW6u9NIBPQhZ3x4PVe9twNiffZWqHOZB09 vU8cTHxbDwAGGlnDq8uwR3nba1FsJatbbhgctVCCOj/7CWHzp+5O8wNfTspohhY1qtTG etXjSaWfaF0xK8AF84MJ3CzuTEM+A9RjlgQbpDSg67C6ITVQ8Vk1vowD7lywm+ctLFlk Wp9w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=IKXYGJmt; dkim=neutral (no key) header.i=@vger.kernel.org; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id n19si523078ejb.704.2020.06.29.14.54.53; Mon, 29 Jun 2020 14:55:16 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=IKXYGJmt; dkim=neutral (no key) header.i=@vger.kernel.org; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2404109AbgF2Vvt (ORCPT + 99 others); Mon, 29 Jun 2020 17:51:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40980 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2404569AbgF2Vvo (ORCPT ); Mon, 29 Jun 2020 17:51:44 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D1C73C061755 for ; Mon, 29 Jun 2020 14:51:44 -0700 (PDT) From: John Ogness DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1593467502; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=siVZWIEnwE41C7ZxHsZfQ8/Re56UAlzQKcSRDT+JiwE=; b=IKXYGJmt9+3Ei4t1+Bz9jNVCq5EyBhJN4FxcPlnhlriH3eqv1MsTGz+xRnHdHDt0MdwjAZ GgC/iiIB5osdzoNnLhSWN8WopSY5+H2icQKjzEAsbVzPTQEvwT7j3BiGUke+vmxAisBCVf ncxdG+J5IclAPaNTpWyACqalFl+HvjJ18ehxf14FR5l9si8QVQiNGyyhqKcCaRzp+bSlCe 3HfQdz2WnIxanWg9QdWnbTdRRUl9QUALzpFJOp88k2eTtqHX97GFc/zeFuG8FQcH+itufC GKq9M863SUY4Byx3DH2OO1kBh+nuTCBoYmmih+2F1/feVSJ0c4MP5ERnCyZ7uw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1593467502; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=siVZWIEnwE41C7ZxHsZfQ8/Re56UAlzQKcSRDT+JiwE=; b=5bCsnwV2vmOJbIXbrSqZo66YzWmyOSG5xc215ieN3Sqv6ET2KdOCpBcPMjC/fZH1IV3ZcL GMnrZcN4JNSoE9AA== To: Petr Mladek Cc: Peter Zijlstra , Sergey Senozhatsky , Sergey Senozhatsky , Steven Rostedt , Linus Torvalds , Greg Kroah-Hartman , Andrea Parri , Thomas Gleixner , Paul McKenney , kexec@lists.infradead.org, linux-kernel@vger.kernel.org Subject: Re: syslog size unread: was: [PATCH v3 3/3] printk: use the lockless ringbuffer References: <20200618144919.9806-1-john.ogness@linutronix.de> <20200618144919.9806-4-john.ogness@linutronix.de> <20200625152042.GI8444@alley> Date: Mon, 29 Jun 2020 23:51:40 +0200 In-Reply-To: <20200625152042.GI8444@alley> (Petr Mladek's message of "Thu, 25 Jun 2020 17:20:42 +0200") Message-ID: <87k0zp8rrn.fsf@jogness.linutronix.de> MIME-Version: 1.0 Content-Type: text/plain Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2020-06-25, Petr Mladek wrote: > On Thu 2020-06-18 16:55:19, John Ogness wrote: >> --- a/kernel/printk/printk.c >> +++ b/kernel/printk/printk.c >> @@ -1609,11 +1633,15 @@ int do_syslog(int type, char __user *buf, int len, int source) >> break; >> /* Number of chars in the log buffer */ >> case SYSLOG_ACTION_SIZE_UNREAD: >> + if (source != SYSLOG_FROM_PROC) { >> + text = kmalloc(LOG_LINE_MAX + PREFIX_MAX, GFP_KERNEL); >> + if (!text) >> + return -ENOMEM; > > The buffer is needed only to count lines to count the size of added > prefixes. Could we use the new prb_read_valid_info() that allows to > get the number of lines without actually reading the buffer? Yes! For the next version I introduce a macro to iterate just the meta data: #define prb_for_each_info(from, rb, s, i, lc) \ for ((s) = from; prb_read_valid_info(rb, s, i, lc); (s) = (i)->seq + 1) This can be used in all 3 locations where prb_count_lines() is used. In all three places, there is no need to be copying the data. And for SYSLOG_ACTION_SIZE_UNREAD, there is no need for the record and kmalloc'd buffer. This also means that prb_count_lines() will become a private static helper of the ringbuffer. John Ogness