From patchwork Thu Dec 21 16:10:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Rostedt X-Patchwork-Id: 182343 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:2483:b0:fb:cd0c:d3e with SMTP id q3csp518690dyi; Thu, 21 Dec 2023 08:14:32 -0800 (PST) X-Google-Smtp-Source: AGHT+IHZWQzddN8BuXVDxlRQnXxXafEgVysQWOqghYgPeUJBl3pbxfnevZOSAgocguzZaAloCQxT X-Received: by 2002:a05:6e02:1ba9:b0:35c:e98f:c591 with SMTP id n9-20020a056e021ba900b0035ce98fc591mr21667599ili.3.1703175271720; Thu, 21 Dec 2023 08:14:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703175271; cv=none; d=google.com; s=arc-20160816; b=FDS3Bzp7x7P+a5hEgbOqHceL5auW8gHKCAX5XthKRmMjI7Ze1gNmCVzBUOnRpw0xhi /rpLUT5bnTho66uJx+cesdEen31NTMzw9UuIe1IHfgBTrfLWwTVzT0rkgV8TqOpjAXFy nWBOMSNs/Lwuuf8quhFHvNIoDgQDuH6qVhZ2V7jgP8f52pLB/oj6j8yZGY6bNaO0PRiW VJVcLTBOPR7F4+sZjGqwn8GOmB92iFJzF47CI8ybXvu7ve7raMQpZ1oq5n2o9piQ5/NE rNDSaCRDSzyg4yWI364OIAnCPzkXng8CVCkIBWjDyp0Ee/n54zyJSa0eHczoBa+GGa6M Krvg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:list-unsubscribe:list-subscribe:list-id:precedence :references:subject:cc:to:from:date:user-agent:message-id; bh=LivDZpjGlV656DTtofl9jUnIAaYu2QkVpB94alOxgAg=; fh=e3UoLP0GGIVG/JuDivUt2G6X10h9sIOfzt1IJTPiLuw=; b=C6h0EVXoh3Nc+tB5G5pJQjO8ymcIKhDWZzC0rbw2wwosrwg6nobkytbZCu7Iuht1EN Hbqwas7PVfrXMgQtKZiyXzJPPkhUhW/E5Fg0VQ3sEjOGSmlleBwfUly5D26ekyWdV+Jl mHC9fAIYUFuA0RmIVn3EPIDRbhIX1NIPRZIgryex+1vKhiixr145y8DERRJdWgvGz/+T xzOeyTjRGh5UJ8W7r1Oyh36K4pqYeG2ZNwhzvtthJjsL9cXDciDlJ0nYhnoeJTgLcbWO sWCS6BXddcGKe0iq7Clm9QvpoE1cBueTX3T6x7Np86PJBVL+cz91/GIspHZREPeFjAOw Wflg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-8735-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-8735-ouuuleilei=gmail.com@vger.kernel.org" Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id h33-20020a63f921000000b005cd8b9dc455si1758352pgi.567.2023.12.21.08.14.31 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Dec 2023 08:14:31 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-8735-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-8735-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-8735-ouuuleilei=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 94E41B22B17 for ; Thu, 21 Dec 2023 16:13:15 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 8161C6EB77; Thu, 21 Dec 2023 16:10:03 +0000 (UTC) X-Original-To: linux-kernel@vger.kernel.org Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BCE00634E3 for ; Thu, 21 Dec 2023 16:10:01 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9AA6FC433B9; Thu, 21 Dec 2023 16:10:01 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.97) (envelope-from ) id 1rGLdZ-000000041LZ-2YYa; Thu, 21 Dec 2023 11:11:05 -0500 Message-ID: <20231221161105.389855512@goodmis.org> User-Agent: quilt/0.67 Date: Thu, 21 Dec 2023 11:10:35 -0500 From: Steven Rostedt To: linux-kernel@vger.kernel.org Cc: Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Andrew Morton , Tzvetomir Stoyanov , Vincent Donnefort , Kent Overstreet Subject: [for-next][PATCH 11/16] ring-buffer: Keep the same size when updating the order References: <20231221161024.478795180@goodmis.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1785908713434020816 X-GMAIL-MSGID: 1785908713434020816 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. Link: https://lore.kernel.org/linux-trace-kernel/20231219185630.649397785@goodmis.org Cc: Masami Hiramatsu Cc: Mark Rutland Cc: Mathieu Desnoyers Cc: Andrew Morton Cc: Tzvetomir Stoyanov Cc: Vincent Donnefort Cc: Kent Overstreet Fixes: f9b94daa542a ("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 fdcd171b09b5..23ead7602da0 100644 --- a/kernel/trace/ring_buffer.c +++ b/kernel/trace/ring_buffer.c @@ -5897,7 +5897,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;