From patchwork Wed Dec 13 02:19:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Rostedt X-Patchwork-Id: 177755 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp8134070vqy; Tue, 12 Dec 2023 18:20:55 -0800 (PST) X-Google-Smtp-Source: AGHT+IHY4KIRLuPjvOkCxA2ipCjPHqpI4rAEKr7u1vSZ4gbL3BYVlsYsxxu7fBLxshQ4QLUhQAUC X-Received: by 2002:a05:6808:1793:b0:3b2:ef72:f59e with SMTP id bg19-20020a056808179300b003b2ef72f59emr8999142oib.24.1702434055208; Tue, 12 Dec 2023 18:20:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702434055; cv=none; d=google.com; s=arc-20160816; b=yX4CZW5igoIYSZK+Mtx3msWMvY5wX58XaJ1LaPNptEy237NWxvozSl4vUr2/cLfdwD 7pV4rYpIkMs3zGmwhpMWVkvB4m7i7i5B8+PPrj+VlT6QQY6E4tyK0UQ5pHzHzMwiqO0Z YyohNkLfi7RfURbDZHplA3rrIkjXt+gMSYbFmjuCoq8PfuxGH4wCtEjC13ea0HWbz8Dz knQ/ZAKG/1G2l82knqrHOJcn9KZtBwzfE05GXxaEO8T9jH/71v4sUTMvavg1TxcGtKxo aPXn1kOgT9WQtR0t48ymUiPY5BY/j7tsJBUj3CpjArHjtVAsoACh1O3+i0oQdtvCA3Rk 4b5w== 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=ZobDNIVy76n8TCtsWB9gVbVLeKlpwMA0LZQrV6oENA0=; fh=e3UoLP0GGIVG/JuDivUt2G6X10h9sIOfzt1IJTPiLuw=; b=bUWwhAIcfJ8jIg8yr3klH72l2r+IVjCdrNYMUuWj3f3mzVFqHZlYOQ9O0ldITcwdMN 3Yocx+JWegQ8EGXEbCgJNYIT+tgc7zA+i8XNdkt/3oAsmnKpKwUZOais+0X5U9rJmb71 /78lTI8FsWtjRxlnSD61vOmq0SzXt1rkqMT7Q81q97l7mZVzQ6vY70c1O25O5TYGAuDY EDgzNrsUfgYCNam1+f1Xkifro4H6BqV66JhlMDzRMNbPNDAkRxcNdCTbS/oNho2n62Ag fN//L5AA52rQN/bVIGT1RgP8hGBL1AcxNsIqHnYtUhMeahH4Q2iJiY14kz4bRucuFXdq RWHQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from howler.vger.email (howler.vger.email. [2620:137:e000::3:4]) by mx.google.com with ESMTPS id bq15-20020a056a000e0f00b006cef66f8c03si6307765pfb.53.2023.12.12.18.20.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Dec 2023 18:20:55 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) client-ip=2620:137:e000::3:4; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 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 howler.vger.email (Postfix) with ESMTP id DDB348083AF3; Tue, 12 Dec 2023 18:20:35 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1378374AbjLMCTm (ORCPT + 99 others); Tue, 12 Dec 2023 21:19:42 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54412 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1378316AbjLMCTW (ORCPT ); Tue, 12 Dec 2023 21:19:22 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5686BCF for ; Tue, 12 Dec 2023 18:19:28 -0800 (PST) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7EC20C433CA; Wed, 13 Dec 2023 02:19:27 +0000 (UTC) Received: from rostedt by gandalf with local (Exim 4.97) (envelope-from ) id 1rDEr5-00000002TqJ-1VjB; Tue, 12 Dec 2023 21:20:11 -0500 Message-ID: <20231213022011.141490099@goodmis.org> User-Agent: quilt/0.67 Date: Tue, 12 Dec 2023 21:19:25 -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: [PATCH v2 11/15] ring-buffer: Keep the same size when updating the order References: <20231213021914.361709558@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 howler.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 (howler.vger.email [0.0.0.0]); Tue, 12 Dec 2023 18:20:36 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1785131492225215963 X-GMAIL-MSGID: 1785131492225215963 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 2c908b4f3f68..86d3cac2a877 100644 --- a/kernel/trace/ring_buffer.c +++ b/kernel/trace/ring_buffer.c @@ -6039,7 +6039,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;