From patchwork Sun Dec 10 03:54:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Rostedt X-Patchwork-Id: 176273 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp6353953vqy; Sat, 9 Dec 2023 20:05:07 -0800 (PST) X-Google-Smtp-Source: AGHT+IHyjHAKCUJYCMwK67nzkJ1nzPGSB5PYXa3KWXSsZycrxYVrwEiIRAJGOdTFzFbmFFoq1HYY X-Received: by 2002:a05:6358:881:b0:170:6fc7:c2f2 with SMTP id m1-20020a056358088100b001706fc7c2f2mr2622339rwj.14.1702181107266; Sat, 09 Dec 2023 20:05:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702181107; cv=none; d=google.com; s=arc-20160816; b=cLnjFE2itKMejFW+oVXhslcbSDFVMHveSMm1ccbSGrD/L8itugBGKHwSobRYRpNUUp JSLyJ0R7JUrYyVbVAsyUblqfpRBLh2AGmLe/P94UNux3sggOlIZdqVflfI6j6+yEWJ7W UVii4HYBHAPrVOZRgGD/KWkZsOgTTbVd4GWN8mHjSAbGbW+D8NwGELM2t/8yRsyoXfLV 29StroHCW+BhpHngpXFYr/NFWhvIMBVBcDxHof8qQxcdtL+7TOMAQlukYl2oArUjBONj JdRLJuwhw4LkudNkdK63EgGA6g+ZC6fDLR5hzw/DykqZ+G1gcWbzc1Oqg9HOQgVKAeto no9A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:subject:cc:to:from:date :user-agent:message-id; bh=aLoh1AYSen0LPPbCUh5hXSD2eWDg4oW1oxI+b1cyCsI=; fh=pL1t9p0RxD5qCgSUniSa3P4+XmpksJYPzX6TE+dndao=; b=N3gePS+tudXx4+O542kxdkpdimU9xSM8V/Ou+1UG3nYguD8E0ckV7Dx7z+aGAkX4Oo tsK5Ztkn1QJd1Fr9eAYbwENvqCd4HMrTbkOjt5OHqQGZhh6+TUUrbPOf4nstK+Au1dA0 6q9VO40ducmzL/JMrtmXI37CBJF4QxtoWtHUefls8T75NqvORB771QXhFoRgqSQlAf54 tBZsLFvxRYKJBKTgnplH8jYOO+ee4zdBBeYFK1lEABvaboykwO6kLgikuBdj5S3Fjebj sxN0lhydI8Du5mXu5SMV/XD3RHJDASre2Jqrr6ltVTqJgrOrFzhdIeDT6sl5xB14Y1YZ XksA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from morse.vger.email (morse.vger.email. [23.128.96.31]) by mx.google.com with ESMTPS id x16-20020a634a10000000b005b96d038729si2960122pga.728.2023.12.09.20.05.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 09 Dec 2023 20:05:07 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) client-ip=23.128.96.31; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by morse.vger.email (Postfix) with ESMTP id EB69880659B7; Sat, 9 Dec 2023 20:05:04 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231487AbjLJEEz (ORCPT + 99 others); Sat, 9 Dec 2023 23:04:55 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33258 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231503AbjLJEEI (ORCPT ); Sat, 9 Dec 2023 23:04:08 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0F70FB4 for ; Sat, 9 Dec 2023 20:04:15 -0800 (PST) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B4A1BC433C7; Sun, 10 Dec 2023 04:04:14 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.97) (envelope-from ) id 1rCB3j-000000021Qm-2g3H; Sat, 09 Dec 2023 23:04:51 -0500 Message-ID: <20231210040451.424991712@goodmis.org> User-Agent: quilt/0.67 Date: Sat, 09 Dec 2023 22:54:15 -0500 From: Steven Rostedt To: linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org Cc: Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Andrew Morton , Tzvetomir Stoyanov , Vincent Donnefort , Kent Overstreet Subject: [PATCH 11/14] ring-buffer: Keep the same size when updating the order References: <20231210035404.053677508@goodmis.org> MIME-Version: 1.0 X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on morse.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (morse.vger.email [0.0.0.0]); Sat, 09 Dec 2023 20:05:05 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1784866256919688391 X-GMAIL-MSGID: 1784866256919688391 From: "Steven Rostedt (Google)" The function ring_buffer_subbuf_order_set() just updated the sub-buffers to the new size, but this also changes the size of the buffer in doing so. As the size is determined by nr_pages * subbuf_size. If the subbuf_size is increased without decreasing the nr_pages, this causes the total size of the buffer to increase. This broke the latency tracers as the snapshot needs to be the same size as the main buffer. The size of the snapshot buffer is only expanded when needed, and because the order is still the same, the size becomes out of sync with the main buffer, as the main buffer increased in size without the tracing system knowing. Calculate the nr_pages to allocate with the new subbuf_size to be buffer_size / new_subbuf_size. Fixes: TBD ("ring-buffer: Set new size of the ring buffer sub page") Signed-off-by: Steven Rostedt (Google) --- kernel/trace/ring_buffer.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/kernel/trace/ring_buffer.c b/kernel/trace/ring_buffer.c index 9725aab1b5eb..4726deccd997 100644 --- a/kernel/trace/ring_buffer.c +++ b/kernel/trace/ring_buffer.c @@ -6030,7 +6030,10 @@ int ring_buffer_subbuf_order_set(struct trace_buffer *buffer, int order) if (!cpumask_test_cpu(cpu, buffer->cpumask)) continue; - nr_pages = buffer->buffers[cpu]->nr_pages; + /* Update the number of pages to match the new size */ + nr_pages = old_size * buffer->buffers[cpu]->nr_pages; + nr_pages = DIV_ROUND_UP(nr_pages, buffer->subbuf_size); + cpu_buffers[cpu] = rb_allocate_cpu_buffer(buffer, nr_pages, cpu); if (!cpu_buffers[cpu]) { err = -ENOMEM;