Received: by 2002:a05:7412:3b8b:b0:fc:a2b0:25d7 with SMTP id nd11csp2747010rdb; Mon, 12 Feb 2024 15:39:33 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCU9CYt3xi1XHX77EoAmm5LZmDy46g84iCc9hppAUGOeT2U5qlmbaa4A7YydUthZDxsmSHshRwLZrbkkpXctlGL40tNindvcrrL457zpIA== X-Google-Smtp-Source: AGHT+IG28kj1gfVRT5XHti8tNCRhyf5lDoAzuY0tylbBTuRY+QeoJWAcDdRWKBxN0quwv6o9Uq5d X-Received: by 2002:a17:906:1691:b0:a3c:c213:e920 with SMTP id s17-20020a170906169100b00a3cc213e920mr2010759ejd.64.1707781172968; Mon, 12 Feb 2024 15:39:32 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707781172; cv=pass; d=google.com; s=arc-20160816; b=GR1QQWE8+tERvjvG+kol+qF+bm4zv4KYLimardXfbKjSfQGjhrS0l28bmFWXrDSX6O QwLDXO5aJbBNpqqACXc7MZGjN9TPxfO4BXtxbaOUrLLYpxysz/JMnlALWEixaBERxkev gfJcuPVFgaTs0DWf6fHnBXXjZiJ6JZqWY9VxPBBFprNzKlsnDac0zGFyA6lQjBt9lC5q wRxN0S9W8ogeZHybAeaxxbTWHfB0IAtugn3ND/r+uqHbX+wtMcBU5AsV5Gecj4JHLqsE 26M1M3UPAHj6R7aSuou9ym4Iq7qlTtOXL4GrCnfbj9uU1xhG6yIf+itZ81WSsVtwPtIY ZYtg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:list-unsubscribe:list-subscribe:list-id:precedence :user-agent:content-transfer-encoding:references:in-reply-to:date:cc :to:from:subject:message-id:dkim-signature; bh=FnEc996vgRnzo1q7VyxyIhbro5goYOgIkrj/kqaENfA=; fh=C9CLaGHO9imiQeIw77LXsDlz6Mr4dsOov6gHlk96ZS0=; b=r0hlaC3uqK/oJchTeXAI94fU2R0mPySFzPOHVrrXct1TQwBWj/NBIXyyax+lQ0eIuR eAcYLYMMrqwLlAExxnoN+ZuQr57Wo5hYIFyooTV97NqEVE+9mgoE5vXilg52ZB3lVXwT sn3yS7NiQi99f+Ff1+JEmFYLGcX+s3XasU0Qs4+x0n/0P4B2dqRAi28w3QOOyEu4+qAV 0FZfQC1V8ppZ4HzUt2Jpz/dETAGKHm4MTt62fG5vaAS9GHnzvqICjYVH2y1QtsRUOwR7 p0avdttVu1ur6oKxKUBZuFzbClVz7Y01/5KdNcOxXFv7Mz2Gnx0vt21PaNJeW12JbBbq FGJQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=gaCKnN3a; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-62551-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-62551-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com X-Forwarded-Encrypted: i=2; AJvYcCWBMtRWGi2C7iPhc3kwizKHn2tIRlns2/y/bTQOCMtmpCAYsVlffqXsiVe3pBAbm73NuygyQoLVilpkEPQOm676U05qjFzXtCDs1yZpNw== Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id bl8-20020a170906c24800b00a385b289b4csi654792ejb.752.2024.02.12.15.39.32 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Feb 2024 15:39:32 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-62551-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=gaCKnN3a; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-62551-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-62551-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com 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 am.mirrors.kernel.org (Postfix) with ESMTPS id B095D1F23A9E for ; Mon, 12 Feb 2024 23:39:32 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3712251C29; Mon, 12 Feb 2024 23:39:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="gaCKnN3a" Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.11]) (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 B2F4350268; Mon, 12 Feb 2024 23:39:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.11 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707781147; cv=none; b=HFSKSA/Mp6jVGt2iWBm66pZjnLfteBfTgFhrk2ubh8FAkBuclgxHBw9SY4o3BxKVKIJJ93tdIkKSaLFah4cdvTCwVSS87t9sMSBNKwIPQ601aO6pRS3UPhv6OC6nexH+uQWxCxmzjw3F36xDYkcWRaDEeDhugQ5xKzQlVxXENW4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707781147; c=relaxed/simple; bh=QPAWSIbAkGzPHg0gCvchvrpX63qIMyVQwVrLpDY0n+c=; h=Message-ID:Subject:From:To:Cc:Date:In-Reply-To:References: Content-Type:MIME-Version; b=fk9zfJ7QYmqacUYHjgUV7yFgq0fmWVYcY9zJvUL9bZzacnqzStDoe+SbLhCkGO7GPaVwRLG3yEjJDmYUIJHZn9IahwnssxTJmuzNpg2PNQgnFrTgXwQ+zRcWNdB+ZW+/gVc0pWxQz3ECK96dBp0xIph1E2SmPTjj4alZVSAH+0c= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=none smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=gaCKnN3a; arc=none smtp.client-ip=198.175.65.11 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1707781146; x=1739317146; h=message-id:subject:from:to:cc:date:in-reply-to: references:content-transfer-encoding:mime-version; bh=QPAWSIbAkGzPHg0gCvchvrpX63qIMyVQwVrLpDY0n+c=; b=gaCKnN3aIXi8iyK5YygR7BBoJNHbLA2Eti0Y1xg+mxJKXifJLKdKt+ih cmVITmm9D41H3uuKe2NZHUolus6pRvu1kJMLW/4KglSPrDOOV2AeZQGZ0 fDGcFRCoPlswSwgkZkfXM+yp3B5X5X1vPVtcKmXWwbQ51U8n5RRp4amIG GVWSyxwT49QhJNNRmcli6HKF6gxSDgGB/ZIYoYGBryhhit73Y75TEHO0y A8dNNFj5h+Uktd1YkIdxlZ52W2YyTmyOo4TCRrjvuC2SOtotznYZSgTQz IADCzDilj3qmNbydXdV5UmJjONSemYxecMlOPnfshwDHXdWS4yUvrXdel A==; X-IronPort-AV: E=McAfee;i="6600,9927,10982"; a="12332444" X-IronPort-AV: E=Sophos;i="6.06,155,1705392000"; d="scan'208";a="12332444" Received: from fmviesa007.fm.intel.com ([10.60.135.147]) by orvoesa103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Feb 2024 15:39:05 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.06,155,1705392000"; d="scan'208";a="2682509" Received: from sparrish-mobl1.amr.corp.intel.com (HELO [10.209.29.247]) ([10.209.29.247]) by fmviesa007-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Feb 2024 15:39:04 -0800 Message-ID: Subject: Re: [PATCH] tracing: Have saved_cmdlines arrays all in one allocation From: Tim Chen To: Steven Rostedt , LKML , Linux Trace Kernel Cc: Masami Hiramatsu , Mathieu Desnoyers , Mark Rutland , Vincent Donnefort , Sven Schnelle , Mete Durlu Date: Mon, 12 Feb 2024 15:39:03 -0800 In-Reply-To: <20240212180941.379c419b@gandalf.local.home> References: <20240212180941.379c419b@gandalf.local.home> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.44.4 (3.44.4-2.fc36) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 On Mon, 2024-02-12 at 18:09 -0500, Steven Rostedt wrote: > From: "Steven Rostedt (Google)" >=20 > The saved_cmdlines have three arrays for mapping PIDs to COMMs: >=20 > - map_pid_to_cmdline[] > - map_cmdline_to_pid[] > - saved_cmdlines >=20 > 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. >=20 > 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. >=20 > 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. This patch does make better use of the extra space and make the previous change better. Reviewed-by: Tim Chen =20 >=20 > Link: https://lore.kernel.org/linux-trace-kernel/20240212174011.068211d9@= gandalf.local.home/ >=20 > Signed-off-by: Steven Rostedt (Google) > --- > kernel/trace/trace_sched_switch.c | 13 ++++--------- > 1 file changed, 4 insertions(+), 9 deletions(-) >=20 > 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_cmdline= s_buffer(unsigned int val) > int order; > =20 > /* Figure out how much is needed to hold the given number of cmdlines *= / > - orig_size =3D sizeof(*s) + val * TASK_COMM_LEN; > + orig_size =3D sizeof(*s) + val * (TASK_COMM_LEN + sizeof(int)); Strictly speaking, *map_cmdline_to_pid is unsigned int so it is more consis= tent to use sizeof(unsigned) in line above. But I'm nitpicking and I'm fine to leave it as is. > order =3D get_order(orig_size); > size =3D 1 << (order + PAGE_SHIFT); > page =3D alloc_pages(GFP_KERNEL, order); > @@ -212,16 +212,11 @@ static struct saved_cmdlines_buffer *allocate_cmdli= nes_buffer(unsigned int val) > memset(s, 0, sizeof(*s)); > =20 > /* Round up to actual allocation */ > - val =3D (size - sizeof(*s)) / TASK_COMM_LEN; > + val =3D (size - sizeof(*s)) / (TASK_COMM_LEN + sizeof(int)); > s->cmdline_num =3D val; > =20 > - s->map_cmdline_to_pid =3D 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 =3D (unsigned *)&s->saved_cmdlines[val * TASK_COM= M_LEN]; > =20 > s->cmdline_idx =3D 0; > memset(&s->map_pid_to_cmdline, NO_CMDLINE_MAP,