Received: by 2002:a05:7412:3b8b:b0:fc:a2b0:25d7 with SMTP id nd11csp2759577rdb; Mon, 12 Feb 2024 16:13:02 -0800 (PST) X-Google-Smtp-Source: AGHT+IGOjY8Mjr4cD02zf32GywWh7tD751ocfLGQORileygy3yZlzH8XL6pDhbN12ANpuhcRKODp X-Received: by 2002:a0d:d2c1:0:b0:5ff:a9bc:3893 with SMTP id u184-20020a0dd2c1000000b005ffa9bc3893mr4742647ywd.12.1707783182371; Mon, 12 Feb 2024 16:13:02 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707783182; cv=pass; d=google.com; s=arc-20160816; b=gfy3JA6l3FmudN5ovmXi8d+c2hqvTH4NBzhAJZXktqlqgV2dLvztP/Is5bl/JoolcW h/Vxq9fjd7TuKBv0nJPORyvd397hV4Zob3VE0txWeeAANcBw2vVk53NTi+QrrwdDqyQj NIBe0AXtSacev4MhRThiEvQ6dt39vqwZs/jz9+QOjeEGZcgxSCb57gWQzbnayO3qO8kG /LZa11mqD4gMkK+0w+3iBrSpHEZzXw1ne/S4V2Hcv7CW4o2XCRcYA1CD7KyDxRtdcBvi cp/3h017SphvWDTcTxna/Hzd2nsvorMI09l3m0UanXt9s1us491zgROqDKVv0emodpqF kPJg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :subject:cc:to:from:date; bh=XF4NjUO0W/ZCDwamIbffZJGWwu1IZ6Q7U6Vio8XTBDc=; fh=bY9eQPbrJ6R3V+AsYRdSLiTpgXa4bWKSwk0DdjQE50Q=; b=AkiWv9NFVxkvutVqkfktTmLUJtVkHo2ysb2mYxbsHGqTLw9AyxmBQCrIHKZNqW1jp4 ZpX/I+j0p3MSuMIs06JXl9ysflBBrLESPqQPNN6rNK5pjQZZS9S9G8PPQryhpoeZ+DK5 pXn0HTHIXjR+ZxdcQGFxYhrznC6/qBelrTACAIwgPKB6DfcPLZj9FT0ZjFB9ik7VQNPP EIkslBGC8JjL5o7InDFgd+3LIn5UtqCC7sEl9sfjfz5ebZ6Jg7GIqFP5nF8JHvNAo0ZE wf3BcXODw7p50UOglTmFe553+pckLS7GWX/6Hpn0uF/JRr0Dwat6Vw+kJzIqP9376u1q LPAw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-62563-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-62563-linux.lists.archive=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=2; AJvYcCWeADnoIKA7HDvzv9YSvocU3eDlfXi33yawbYVfeoM6onpTE++W/w0J6BWc5vxaeGxud1Kbc3J1HF93lau9DC0c7UIfdIIyvcHvPMASOA== Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id z6-20020ae9e606000000b007859f7b7c69si6894587qkf.584.2024.02.12.16.13.02 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Feb 2024 16:13:02 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-62563-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-62563-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-62563-linux.lists.archive=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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 21FFE1C2334D for ; Tue, 13 Feb 2024 00:13:02 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 4E1C65660; Tue, 13 Feb 2024 00:12:55 +0000 (UTC) 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 CB4CA4C64; Tue, 13 Feb 2024 00:12:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707783174; cv=none; b=PWU21QAeUOo1w0GhTXlVC8SPn42jdG3qraUfeE7N+NwERPQI05HuvVWHSxAQDG3yAz+lIMfL0bx6lTzJF4JHEoy4HHB+cpbbZoGD0Rl9TAfBSoRggWAbBFgKezDcMNmT4t3nJV5b8wDP8uo41zCKeK7QhBaBjh/UvZak8EqZeOM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707783174; c=relaxed/simple; bh=snpDxC/p4DzWPM0PkZK4dv4AVgd2kVSFn1TwirwJ8sI=; h=Date:From:To:Cc:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=prao1NMHHAIUNhTWXpB7ZkCcoeXfcrRvCmZSjfa68reM8yDbqb4bmN0LGt2y3UO8ZYRuWYuDZ0XqPDO4ryv1tRzHyM/J5pVaNK86zIyOHerdKA1q6qhDX5/mpBrsddjEivJ9zVTaH16/TFCRCnBbEC1rG+61nOE2KHLwe6kSBPc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 389C3C433C7; Tue, 13 Feb 2024 00:12:53 +0000 (UTC) Date: Mon, 12 Feb 2024 19:13:36 -0500 From: Steven Rostedt To: Tim Chen Cc: LKML , Linux Trace Kernel , Masami Hiramatsu , Mathieu Desnoyers , Mark Rutland , Vincent Donnefort , Sven Schnelle , Mete Durlu Subject: Re: [PATCH] tracing: Have saved_cmdlines arrays all in one allocation Message-ID: <20240212191336.5c502f78@gandalf.local.home> In-Reply-To: References: <20240212180941.379c419b@gandalf.local.home> X-Mailer: Claws Mail 3.19.1 (GTK+ 2.24.33; x86_64-pc-linux-gnu) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit On Mon, 12 Feb 2024 15:39:03 -0800 Tim Chen wrote: > > diff --git a/kernel/trace/trace_sched_switch.c b/kernel/trace/trace_sched_switch.c > > index e4fbcc3bede5..210c74dcd016 100644 > > --- a/kernel/trace/trace_sched_switch.c > > +++ b/kernel/trace/trace_sched_switch.c > > @@ -201,7 +201,7 @@ static struct saved_cmdlines_buffer *allocate_cmdlines_buffer(unsigned int val) > > int order; > > > > /* Figure out how much is needed to hold the given number of cmdlines */ > > - orig_size = sizeof(*s) + val * TASK_COMM_LEN; > > + orig_size = sizeof(*s) + val * (TASK_COMM_LEN + sizeof(int)); > > Strictly speaking, *map_cmdline_to_pid is unsigned int so it is more consistent > to use sizeof(unsigned) in line above. But I'm nitpicking and I'm fine to > leave it as is. I was thinking about making that into a macro as it is used in two places. /* Holds the size of a cmdline and pid element */ #define SAVED_CMDLINE_MAP_ELEMENT_SIZE(s) \ (TASK_COMM_LEN + sizeof((s)->map_cmdline_to_pid[0])) orig_size = sizeof(*s) + val * SAVED_CMDLINE_MAP_ELEMENT_SIZE(s); > > > order = get_order(orig_size); > > size = 1 << (order + PAGE_SHIFT); > > page = alloc_pages(GFP_KERNEL, order); > > @@ -212,16 +212,11 @@ static struct saved_cmdlines_buffer *allocate_cmdlines_buffer(unsigned int val) > > memset(s, 0, sizeof(*s)); > > > > /* Round up to actual allocation */ > > - val = (size - sizeof(*s)) / TASK_COMM_LEN; > > + val = (size - sizeof(*s)) / (TASK_COMM_LEN + sizeof(int)); val = (size - sizeof(*s)) / SAVED_CMDLINE_MAP_ELEMENT_SIZE(s); -- Steve > > s->cmdline_num = val; > > > > - s->map_cmdline_to_pid = kmalloc_array(val, > > - sizeof(*s->map_cmdline_to_pid), > > - GFP_KERNEL); > > - if (!s->map_cmdline_to_pid) { > > - free_saved_cmdlines_buffer(s); > > - return NULL; > > - } > > + /* Place map_cmdline_to_pid array right after saved_cmdlines */ > > + s->map_cmdline_to_pid = (unsigned *)&s->saved_cmdlines[val * TASK_COMM_LEN]; > > > > s->cmdline_idx = 0; > > memset(&s->map_pid_to_cmdline, NO_CMDLINE_MAP,