Received: by 2002:a05:7412:3b8b:b0:fc:a2b0:25d7 with SMTP id nd11csp2745979rdb; Mon, 12 Feb 2024 15:36:29 -0800 (PST) X-Google-Smtp-Source: AGHT+IHiXmzMaJdlQgnDdfxcbNlj3SQdpumugYZe0edlFQZBkFfmDYlaG9fPst3Ja4b72AxvHeWt X-Received: by 2002:a17:90a:7786:b0:297:2abd:cf54 with SMTP id v6-20020a17090a778600b002972abdcf54mr1275469pjk.5.1707780988960; Mon, 12 Feb 2024 15:36:28 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707780988; cv=pass; d=google.com; s=arc-20160816; b=Vtbh+sFzRSHy2p99BJLNaKzGmIsNTpslxzlTwItnWGE57Jo1/739z9ofmnjuJmiYh5 VBsdOko+tvc3khgj2w3YA7Xa6NkzNaW5kICwIFetH282BkTzkMd5pN3hL4uJMwOI09X+ qo/iWnT74GalTqvTAy3ADOCyBF21rLWBtu4NHhzbGjk9s2MTUHGrtj96xNF33LY0qAGi wH7k/qg0LdOHKzEJdY6b7ONX0k/wUNeeRW6j7SAGDTDH32hpwGibSQrfqyvKnP7G+KVz usI11bX1B9pboRF3OLjX3J46sdLo8zAU6U98L9eG2wCLmArKJJr2ZymY/ghoaPkaQoN2 7ylw== 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:dkim-signature; bh=f3so58thmdKKXrnnXJn/KN/nuP9KCjhbMrZuiSFizXY=; fh=Kd4arek8Ixc/shQjbRm3ohEQoIaTyrMUDYgcIJgeEPo=; b=n75ieaQLlYR9J11b/sASDZaDCaqGIYvVsut0lHcarrF0I21T/Li4vgF4DtQ3FN0EpI 1MB9oB2BvgYYfzneTgbZHakJAX0N6XvhHgxwLsSirXLUWhEXb3sy7J6SSS1KFNBly12t pO86mcBQoefGSbkc2IEjbKrtWrw2Rgdztl4yrn71+c4OgBPyMoUkeOwKi+xaUyz6EuGl cs17dkueJbtaVzDVSu8BTSANvBZo3NWN95xUVf54enMSDNG9SDWx4kUFVA/Q5xWMxDJ4 /EYRjMERtuZiRUBXYtb8QbA255W19ykHf9WX3OudZYLLxs4V6KbppG2bfiY3nzWNnfYr sfAQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=FceIkvCk; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-62542-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-62542-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org X-Forwarded-Encrypted: i=2; AJvYcCUvHwCw4kG6Tr56DRz84mtT0OHQxVQVhQy7GOgUSC7RDio3f7Ot6/3hROFu6Cq6rUMmw6NygrZAieueCZ3p4rLDDNeGdpMO3Vz42qFNMQ== Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id m6-20020a170902db0600b001d76a542180si953466plx.541.2024.02.12.15.36.28 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Feb 2024 15:36:28 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-62542-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=FceIkvCk; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-62542-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-62542-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=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 AB3AAB23694 for ; Mon, 12 Feb 2024 23:36:26 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 4EF8D4F8BD; Mon, 12 Feb 2024 23:36:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="FceIkvCk" 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 7248C4F611; Mon, 12 Feb 2024 23:36:18 +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=1707780978; cv=none; b=IHVCINJtCsJHD+HZdC8Xf/H5WwHM7utNZJ+q6DgTHh0cm5gG3bxi1k0Mx/ncDcZAePMW6/00noLS3CQGZZTybXGVMyOjQnjip97V2xRCOAaj0QjuyPSZ+fuVjYM79NbpQABLe3Yyx5LIwFz4vMDy1rlycrlMzOQGYDD5peBTPx8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707780978; c=relaxed/simple; bh=wDhcWRCmEINJ3bjI2gAhFxFaF9zFLEJA9Bnbfrz58rU=; h=Date:From:To:Cc:Subject:Message-Id:In-Reply-To:References: Mime-Version:Content-Type; b=VDbT2CMjHtEYvYbxdeM4POxg45zTdWAmrb2YKx59SEV76Fjjqe44ubuFAKm1ADHezDai4kN+bqnOjPMSy/l1HyqIkUtBFAgG4YSykMgjdJIwG+/e89M71ffevDxafP1uUEoQIwaIxYcCE/D7nLD5RI08Qw6RrjqltFlnrzxhOPU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=FceIkvCk; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8C8E9C433F1; Mon, 12 Feb 2024 23:36:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1707780978; bh=wDhcWRCmEINJ3bjI2gAhFxFaF9zFLEJA9Bnbfrz58rU=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=FceIkvCkZfBR1eVZ2W3IXtAEwIPYWgKiGc2uwItboGq0WDB99rK4iYaAH2SgQ+Mmk yrc2eudriIYcZlbqlaG4PuzpxM8Mlqpd4Tx8kcEiKTyaicwNh/Oj9PHW++l90d/D4h axhVRgiTJWQly8JHcHxGt+gs9oYd4lLOTovVOO+6SSaLYwO9cCzvQwpJITuA2YxK3+ xvVqmPQTyxop7UG8BFQ6pIsGRLwjf/ZiJ8TaAsaMGCD3nEVtSDEuYo4lmOtk9PWbjK Ic6lDDwflWP8tluLU5EOSp7JO94Mx5N+tXwfwMe4PzV42JXkxEVAwclfbSxmvSkon6 gz+TPCjPUIIUw== Date: Tue, 13 Feb 2024 08:36:13 +0900 From: Masami Hiramatsu (Google) To: Steven Rostedt Cc: LKML , Linux Trace Kernel , Masami Hiramatsu , Mathieu Desnoyers , Mark Rutland , Tim Chen , Vincent Donnefort , Sven Schnelle , Mete Durlu Subject: Re: [PATCH] tracing: Have saved_cmdlines arrays all in one allocation Message-Id: <20240213083613.dc8e7ad487988542a6890b2c@kernel.org> In-Reply-To: <20240212180941.379c419b@gandalf.local.home> References: <20240212180941.379c419b@gandalf.local.home> X-Mailer: Sylpheed 3.7.0 (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 18:09:41 -0500 Steven Rostedt wrote: > From: "Steven Rostedt (Google)" > > The saved_cmdlines have three arrays for mapping PIDs to COMMs: > > - map_pid_to_cmdline[] > - map_cmdline_to_pid[] > - saved_cmdlines > > The map_pid_to_cmdline[] is PID_MAX_DEFAULT in size and holds the index > into the other arrays. The map_cmdline_to_pid[] is a mapping back to the > full pid as it can be larger than PID_MAX_DEFAULT. And the > saved_cmdlines[] just holds the COMMs associated to the pids. > > Currently the map_pid_to_cmdline[] and saved_cmdlines[] are allocated > together (in reality the saved_cmdlines is just in the memory of the > rounding of the allocation of the structure as it is always allocated in > powers of two). The map_cmdline_to_pid[] array is allocated separately. > > Since the rounding to a power of two is rather large (it allows for 8000 > elements in saved_cmdlines), also include the map_cmdline_to_pid[] array. > (This drops it to 6000 by default, which is still plenty for most use > cases). This saves even more memory as the map_cmdline_to_pid[] array > doesn't need to be allocated. > > Link: https://lore.kernel.org/linux-trace-kernel/20240212174011.068211d9@gandalf.local.home/ > Looks good to me. Acked-by: Masami Hiramatsu (Google) Thank you, > Signed-off-by: Steven Rostedt (Google) > --- > kernel/trace/trace_sched_switch.c | 13 ++++--------- > 1 file changed, 4 insertions(+), 9 deletions(-) > > 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)); > 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)); > 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, > -- > 2.43.0 > -- Masami Hiramatsu (Google)