From patchwork Fri Dec 15 17:55:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Rostedt X-Patchwork-Id: 179500 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:3b04:b0:fb:cd0c:d3e with SMTP id c4csp9464789dys; Fri, 15 Dec 2023 09:59:42 -0800 (PST) X-Google-Smtp-Source: AGHT+IF4leXE0giUAEQLzgvfUcxxb3ntba8cvG9s13GmhPB0DCZqs8ybCYBJBHfPTfn4L8pMjZpv X-Received: by 2002:a05:6a20:639e:b0:190:65d3:779b with SMTP id m30-20020a056a20639e00b0019065d3779bmr10256824pzg.92.1702663182761; Fri, 15 Dec 2023 09:59:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702663182; cv=none; d=google.com; s=arc-20160816; b=D7XeiFJziQddDXo3uBgQOKW4zS1LfoNzQvPAUNMDLzx+diwowjpPztk/jMzl/XbXPu bXkxiQjGx/fgtlVGx8/BYDB4Kmxz8xac9I6tKK80GY4sQOKcaGuor7bnjiRHS3lWSN7V 1/Dkds+IDKk4/GaMg2VtA7CmOiuBHian34ZDXDG5zPlS6aVubbPKTV+cbh/Yx4DE5/hK 3QnrI2C4RQfyZ0TZDlmM4d0A9bdADOfdn799ghdmyuokz0xpNwqTdww0pp2gU12VBbyF 9bEjV2oOXOB2w4OdebIwfEjTVZzmBCSkIzl8EXY2/HLlqaBjhboyS7WyGRYxAsJIcOTm Cw2A== 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=5L2fen0ns4iWt3xKFQktzJJ0HdCsyr7BmRrngeKZuwU=; fh=pL1t9p0RxD5qCgSUniSa3P4+XmpksJYPzX6TE+dndao=; b=x+JtyJlszHFXval560EpDaLt16fQATypc8M/81Esd7F8bv7wNDGfhO6AXG7bIjDIkh Nqj5jIWJoZguw0VisYGC7A1qDOgs8Y1yM6p0rluXUCmaCUkMO44zZcN7gTt2WQjiMsvF PgLfircpbANXSV9t1fZulgqJR/kuHw7Mx0to0fI90d04Cx0qimcLurINy9B8zHeoHUqo eLHnomilZgdLqTX4ZQRgNA5d15kevY8CW2zlO5b24B+JubE/miAYoMSdDVvbqNgRacjf wDBCp4wao+TZpNEaftnC+3e9viENhfrSbqpXZNX8JfbYYe9EhLHys7ulmDICMIIE/PNb UCbw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-1487-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-1487-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 fb4-20020a056a002d8400b006ce64b59391si13202614pfb.110.2023.12.15.09.59.42 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Dec 2023 09:59:42 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-1487-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-1487-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-1487-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 8CABEB2350E for ; Fri, 15 Dec 2023 17:58:38 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id AB6FC59E50; Fri, 15 Dec 2023 17:54:58 +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 B67C647F4B; Fri, 15 Dec 2023 17:54:56 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 97F8EC433C9; Fri, 15 Dec 2023 17:54:56 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.97) (envelope-from ) id 1rECPa-00000002wSn-2fbA; Fri, 15 Dec 2023 12:55:46 -0500 Message-ID: <20231215175546.414002832@goodmis.org> User-Agent: quilt/0.67 Date: Fri, 15 Dec 2023 12:55:13 -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 v4 11/15] ring-buffer: Keep the same size when updating the order References: <20231215175502.106587604@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: 1785371749206814676 X-GMAIL-MSGID: 1785371749206814676 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 695b64fbc1cb..a93dbbcea83d 100644 --- a/kernel/trace/ring_buffer.c +++ b/kernel/trace/ring_buffer.c @@ -5830,7 +5830,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;