Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp149788pxb; Mon, 8 Feb 2021 18:19:06 -0800 (PST) X-Google-Smtp-Source: ABdhPJwgHuurSnnDTK8TYy4ZPVwKrh1+ug/l8VrfHYIGuGuSG7lG8KXeAQkr21H7KyLH6qCV4OtC X-Received: by 2002:a17:906:84d7:: with SMTP id f23mr21024676ejy.87.1612837146116; Mon, 08 Feb 2021 18:19:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1612837146; cv=none; d=google.com; s=arc-20160816; b=YhJyL/Becm9CgAu+ZIL6Xe2Ol0+HqrrCCdfG1bH8gngdvXhDMeNf4Blp3DAOO5Wshe 5UwuDk9S1PiIyjgcrE/6nGsa0mlXA6V+3DHn7jVd6DKUU3n3ZBvNy3YFdgCoa59fpyEm LL0JblxhAFgZo26gt6zmS9Cci/NjplB8G6cCE5A3JvaW06G2YE5DgL51HUHzlJVEwI5I JO40aZGh6KpSdQqbNAsUuWIWdGDKaVufxt2xEED0xj5ihsKkJ8DLJudANFlPA/qmMzzi 5Q4nAlXMU4BCP73EhmvtHSP/ej8LddZo0ZH3ntqimoE62ql0CS1vmdTNdeRLATNPqRFc zaLw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=Ik38m4IjcFLsdwQI0HpvP26246DHILYTF24fdWKk08Y=; b=OCeFzkRQ/VdYg2V2ev+nY+jDyDNkCsDL77gFZCtPBa4L7Eanv1xtucPm7HoiCvuP01 DoI1MWjeSeZGPN6KiNwscpUmLMLr/HYe24FyTodhVfPB0bf9fIxZsUDeKGEX/rynC1AP 4qS9VuudwmYdwx2eeGGSIXh+D0pUJawrraF2EEUIVHsWKp/MpdyZsDtRIn1nzjYCDqBV My30dFRdqjXFnSMCtix8ZVcb9Z8hKIIdgD5m3PTC8Hnyz8twBNQg+jx0B2cxUjtP/pjn JH1y9quLtrdzp/6dPq1cq2E+SWz+RUu187qI90YB6i9p+Xmznqylm2WT5OeXd6iB8V5K 4MQQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b="tmMXxTh/"; 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=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id p13si12727993ejo.460.2021.02.08.18.18.42; Mon, 08 Feb 2021 18:19:06 -0800 (PST) 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=@gmail.com header.s=20161025 header.b="tmMXxTh/"; 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=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229683AbhBICSD (ORCPT + 99 others); Mon, 8 Feb 2021 21:18:03 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53880 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229544AbhBICSB (ORCPT ); Mon, 8 Feb 2021 21:18:01 -0500 Received: from mail-pg1-x52f.google.com (mail-pg1-x52f.google.com [IPv6:2607:f8b0:4864:20::52f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7D958C061786 for ; Mon, 8 Feb 2021 18:17:21 -0800 (PST) Received: by mail-pg1-x52f.google.com with SMTP id g15so11491789pgu.9 for ; Mon, 08 Feb 2021 18:17:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=Ik38m4IjcFLsdwQI0HpvP26246DHILYTF24fdWKk08Y=; b=tmMXxTh/2F4edrYUOQigogZEfG5mpJje42FVNrAslBy3B7onZFqw4ocOUlaG2fNwd/ +5ZJNj8MfAnBydeOq72rMwSS2QzbDL4LpemyLMO8XMFdMX8C1fpzTF/bKGAKPFk4Nnwd edQTzzW7oSw/4a/pOZFxiACvHSwJEw8eJlrew7YXdCmwNJzngd9WJywg60zvBmDOXjo0 yO2dylbodn/vn/hmpw4Gi+jlwQ8S9doYzqS8aJVkZXaWkasJb54ng2WU2Bx8slSCLUWo NI+SgbYsoYZROOJ9x7uP7Yx9AQhaAFi+TNqnj2GHqOik+o2bsT5JLNV1KIRhPXKW7xsx fBOg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=Ik38m4IjcFLsdwQI0HpvP26246DHILYTF24fdWKk08Y=; b=E8G2ywKDY/dtuXMBZPreye1Vzt34m3D4XR/qaGIQQF+hFB+V39vwtgLm78XjIRmhwj vddzeHvHqiG/3awEdLwQ7McvBE/gg16VWgWAp/CxKocz7mY5ACRuA2wGSVeW4KFq6KFZ 0nbI0LsoNwGfGGTf/pnp1PXS4kCwziCh/LL+OSsE/AfaZkCrUmUmaEdQ2okYHX/yhX2Y ze7YiLyVLFNK9mX2/n8RCx6dN/m5X9hwW8MqDjhhBqJRXGaovZNx9xoDKx3PYjsMAgAb lPsUL7qd8GB5ZRIs+n0lV5sDBGclSaiQFP+WJ9bp0ydiR8UfhplL9i4jWKRPK09Z6MtX 6Atw== X-Gm-Message-State: AOAM532TK00BY4P09wdyGltnH29VQ85/AY8DXQMr5jWBAMYf5okFHp9P XFiQpFrSdqdhXQg+TxJIpPg= X-Received: by 2002:a63:4521:: with SMTP id s33mr17345380pga.16.1612837040883; Mon, 08 Feb 2021 18:17:20 -0800 (PST) Received: from localhost ([2409:10:2e40:5100:6e29:95ff:fe2d:8f34]) by smtp.gmail.com with ESMTPSA id h70sm18654407pfe.70.2021.02.08.18.17.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Feb 2021 18:17:19 -0800 (PST) Date: Tue, 9 Feb 2021 11:17:18 +0900 From: Sergey Senozhatsky To: John Ogness Cc: Petr Mladek , Sergey Senozhatsky , Sergey Senozhatsky , Steven Rostedt , linux-kernel@vger.kernel.org, "J. Avila" Subject: Re: [PATCH] printk: avoid prb_first_valid_seq() where possible Message-ID: References: <20210205141728.18117-1-john.ogness@linutronix.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210205141728.18117-1-john.ogness@linutronix.de> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On (21/02/05 15:23), John Ogness wrote: > If message sizes average larger than expected (more than 32 > characters), the data_ring will wrap before the desc_ring. Once the > data_ring wraps, it will start invalidating descriptors. These > invalid descriptors hang around until they are eventually recycled > when the desc_ring wraps. Readers do not care about invalid > descriptors, but they still need to iterate past them. If the > average message size is much larger than 32 characters, then there > will be many invalid descriptors preceding the valid descriptors. > > The function prb_first_valid_seq() always begins at the oldest > descriptor and searches for the first valid descriptor. This can > be rather expensive for the above scenario. And, in fact, because > of its heavy usage in /dev/kmsg, there have been reports of long > delays and even RCU stalls. > > For code that does not need to search from the oldest record, > replace prb_first_valid_seq() usage with prb_read_valid_*() > functions, which provide a start sequence number to search from. > > Fixes: 896fbe20b4e2333fb55 ("printk: use the lockless ringbuffer") > Reported-by: kernel test robot > Reported-by: J. Avila > Signed-off-by: John Ogness Acked-by: Sergey Senozhatsky > diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c > index 5a95c688621f..035aae771ea1 100644 > --- a/kernel/printk/printk.c > +++ b/kernel/printk/printk.c > @@ -735,9 +735,9 @@ static ssize_t devkmsg_read(struct file *file, char __user *buf, > logbuf_lock_irq(); > } > > - if (user->seq < prb_first_valid_seq(prb)) { > + if (r->info->seq != user->seq) { > /* our last seen message is gone, return error and reset */ > - user->seq = prb_first_valid_seq(prb); Yeah, I can see how this pattern can be expensive, it would have been less obvious and harder to spot had it been something like this valid_seq = prb_first_valid_seq(prb); if (user->seq < valid_seq) { user->seq = valid_seq; ... } Great analysis, John. I wonder if Intel test robot measures all test execution times; I do recall "we saw N% performance improvement after patch P" emails, but not sure if all of the tests are being tracked. -ss