From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752766AbdECJaZ (ORCPT ); Wed, 3 May 2017 05:30:25 -0400 Received: from smtprelay0064.hostedemail.com ([216.40.44.64]:59375 "EHLO smtprelay.hostedemail.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752242AbdECJaQ (ORCPT ); Wed, 3 May 2017 05:30:16 -0400 X-Session-Marker: 6A6F6540706572636865732E636F6D X-Spam-Summary: 2,0,0,,d41d8cd98f00b204,joe@perches.com,:::::::::::::,RULES_HIT:41:355:379:421:541:599:973:988:989:1260:1277:1311:1313:1314:1345:1359:1373:1437:1515:1516:1518:1534:1542:1593:1594:1711:1730:1747:1777:1792:2194:2198:2199:2200:2393:2559:2562:2689:2693:2828:3138:3139:3140:3141:3142:3355:3622:3865:3866:3867:3868:3870:3871:3872:3874:4321:5007:6691:7903:9010:9108:10004:10400:10848:11026:11232:11473:11658:11914:12043:12296:12533:12740:12760:12895:13161:13229:13439:14096:14097:14659:14721:21080:21433:21451:21627:30054:30091,0,RBL:none,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:,MSBL:0,DNSBL:none,Custom_rules:0:0:0,LFtime:1,LUA_SUMMARY:none X-HE-Tag: cable94_765300b2cdd3d X-Filterd-Recvd-Size: 3592 Message-ID: <1493803811.22125.12.camel@perches.com> Subject: Re: [PATCH] printk: Add best-effort printk() buffering. From: Joe Perches To: Tetsuo Handa , linux-kernel@vger.kernel.org Cc: mingo@redhat.com, peterz@infradead.org, pmladek@suse.com, sergey.senozhatsky@gmail.com, rostedt@goodmis.org Date: Wed, 03 May 2017 02:30:11 -0700 In-Reply-To: <201705031521.EIJ39594.MFtOVOHSFLFOJQ@I-love.SAKURA.ne.jp> References: <1493560477-3016-1-git-send-email-penguin-kernel@I-love.SAKURA.ne.jp> <1493568716.1874.7.camel@perches.com> <201705031521.EIJ39594.MFtOVOHSFLFOJQ@I-love.SAKURA.ne.jp> Content-Type: text/plain; charset="ISO-8859-1" X-Mailer: Evolution 3.22.6-1ubuntu1 Mime-Version: 1.0 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, 2017-05-03 at 15:21 +0900, Tetsuo Handa wrote: > Joe Perches wrote: > > On Sun, 2017-04-30 at 22:54 +0900, Tetsuo Handa wrote: > > > Sometimes we want to printk() multiple lines in a group without being > > > disturbed by concurrent printk() from interrupts and/or other threads. > > > For example, mixed printk() output of multiple thread's dump makes it > > > hard to interpret. > > > > > > This patch introduces fixed-sized statically allocated buffers for > > > buffering printk() output for each thread/context in best effort > > > (i.e. up to PAGE_SIZE bytes, up to 16 concurrent printk() users). > > > > [] > > > diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c > > > > [] > > > +#define MAX_PRINTK_BUFFERS 16 > > > +static struct printk_buffer { > > > + unsigned long context; /* printk_context() */ > > > + unsigned int nested; > > > + unsigned int used; /* Valid bytes in buf[]. */ > > > + char buf[PAGE_SIZE]; > > > +} printk_buffers[MAX_PRINTK_BUFFERS]; > > > > Perhaps these buffers could be acquired by > > alloc_page rather than be static structures and > > the sizeof buf[PAGE_SIZE] should be reduced by > > sizeof(unsigned long) + > > sizeof(unsigned int) + > > sizeof(unsigned int) > > so that struct printk_buffers is exactly > > PAGE_SIZE. > > When should the buffers be allocated? If upon boot, there will be little > difference. If the first time each buffer is needed, we introduce a risk > of failing to allocate memory using alloc_page(GFP_ATOMIC | __GFP_NOWARN) > and a risk of stack overflow during alloc_page() because printk() has to be > prepared for being called from stack-tight situation. This is supposed to be best effort anyway. > Also, while dynamic allocation can allow linked list of the buffer, we > will need to introduce a lock for traversing the list, which might become > more expensive than walking fixed-sized array of the buffer. Shouldn't matter as this is supposed to be best effort and any printk is already quite expensive and not fast-path. > We could avoid list traversal by passing "struct printk_buffer" argument, > but since there are so many functions which expect pr_cont() behavior, > scattering "struct printk_buffer" argument is a big patch. There would be possible to add pid instead. > Thus, I think fixed-sized statically allocated buffers is the most > reasonable choice. Using a CONFIG_ option for controlling how many pages > should be allocated for "struct printk_buffer" might make sense for systems > with little RAM. Simpler, but not better.