From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751326AbdKTNku (ORCPT ); Mon, 20 Nov 2017 08:40:50 -0500 Received: from mga05.intel.com ([192.55.52.43]:19689 "EHLO mga05.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751252AbdKTNks (ORCPT ); Mon, 20 Nov 2017 08:40:48 -0500 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.44,427,1505804400"; d="asc'?scan'208";a="177999974" Date: Mon, 20 Nov 2017 21:33:23 +0800 From: "Du, Changbin" To: changbin.du@intel.com Cc: rostedt@goodmis.org, mingo@redhat.com, linux-kernel@vger.kernel.org Subject: Re: [PATCH v3] tracing: Allocate mask_str buffer dynamically Message-ID: <20171120133322.q2sf2duf6kgirqo4@intel.com> References: <1509506888-4053-1-git-send-email-changbin.du@intel.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="4hbysko4cc2cwcud" Content-Disposition: inline In-Reply-To: <1509506888-4053-1-git-send-email-changbin.du@intel.com> User-Agent: NeoMutt/20171027-42-ad8712 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org --4hbysko4cc2cwcud Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Hi Steven, Have you picked up this patch or need more polish? Thanks. On Wed, Nov 01, 2017 at 11:28:08AM +0800, changbin.du@intel.com wrote: > From: Changbin Du >=20 > The default NR_CPUS can be very large, but actual possible nr_cpu_ids > usually is very small. For my x86 distribution, the NR_CPUS is 8192 and > nr_cpu_ids is 4. About 2 pages are wasted. >=20 > Most machines don't have so many CPUs, so define a array with NR_CPUS > just wastes memory. So let's allocate the buffer dynamically when need. >=20 > The exact buffer size should be: > DIV_ROUND_UP(nr_cpu_ids, 4) + nr_cpu_ids/32 + 2; >=20 > Example output: > ff,ffffffff >=20 > With this change, the mutext tracing_cpumask_update_lock also can be > removed now, which was used to protect mask_str. >=20 > Signed-off-by: Changbin Du > Cc: Steven Rostedt >=20 > --- > v3: > - remove tracing_cpumask_update_lock which was used to protect mask_str= =2E (Rostedt) > v2: > - remove 'static' declaration. > - fix buffer size. > --- > kernel/trace/trace.c | 29 +++++++++-------------------- > 1 file changed, 9 insertions(+), 20 deletions(-) >=20 > diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c > index 752e5da..5d2ec80 100644 > --- a/kernel/trace/trace.c > +++ b/kernel/trace/trace.c > @@ -4178,37 +4178,30 @@ static const struct file_operations show_traces_f= ops =3D { > .llseek =3D seq_lseek, > }; > =20 > -/* > - * The tracer itself will not take this lock, but still we want > - * to provide a consistent cpumask to user-space: > - */ > -static DEFINE_MUTEX(tracing_cpumask_update_lock); > - > -/* > - * Temporary storage for the character representation of the > - * CPU bitmask (and one more byte for the newline): > - */ > -static char mask_str[NR_CPUS + 1]; > - > static ssize_t > tracing_cpumask_read(struct file *filp, char __user *ubuf, > size_t count, loff_t *ppos) > { > struct trace_array *tr =3D file_inode(filp)->i_private; > + char *mask_str; > int len; > =20 > - mutex_lock(&tracing_cpumask_update_lock); > + /* Bitmap, ',' and two more bytes for the newline and '\0'. */ > + len =3D DIV_ROUND_UP(nr_cpu_ids, 4) + nr_cpu_ids/32 + 2; > + mask_str =3D kmalloc(len, GFP_KERNEL); > + if (!mask_str) > + return -ENOMEM; > =20 > - len =3D snprintf(mask_str, count, "%*pb\n", > + len =3D snprintf(mask_str, len, "%*pb\n", > cpumask_pr_args(tr->tracing_cpumask)); > if (len >=3D count) { > count =3D -EINVAL; > goto out_err; > } > - count =3D simple_read_from_buffer(ubuf, count, ppos, mask_str, NR_CPUS+= 1); > + count =3D simple_read_from_buffer(ubuf, count, ppos, mask_str, len); > =20 > out_err: > - mutex_unlock(&tracing_cpumask_update_lock); > + kfree(mask_str); > =20 > return count; > } > @@ -4228,8 +4221,6 @@ tracing_cpumask_write(struct file *filp, const char= __user *ubuf, > if (err) > goto err_unlock; > =20 > - mutex_lock(&tracing_cpumask_update_lock); > - > local_irq_disable(); > arch_spin_lock(&tr->max_lock); > for_each_tracing_cpu(cpu) { > @@ -4252,8 +4243,6 @@ tracing_cpumask_write(struct file *filp, const char= __user *ubuf, > local_irq_enable(); > =20 > cpumask_copy(tr->tracing_cpumask, tracing_cpumask_new); > - > - mutex_unlock(&tracing_cpumask_update_lock); > free_cpumask_var(tracing_cpumask_new); > =20 > return count; > --=20 > 2.7.4 >=20 --=20 Thanks, Changbin Du --4hbysko4cc2cwcud Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 iQEcBAEBAgAGBQJaEtmiAAoJEAanuZwLnPNU7uoIAK0IV+ZsOzvtIAi75nVwCFol op3Xr/8Zgr9mZLD83EKvoiKQHP9tepuGgmw5+QqnDnScx6DrtofQZCpL7GoosUuV 3ET2ulCvfRkVoKqJYS9sa4yo2M9QtYGI9E20E0xFkQ8IIguJ3PAn7LdjH5Z/5Oo1 hJu8odAUld8DTNx7QDIHGSWhWo0j7MgTC1qpgaWr2ZrgUE1DOgoo09eedqwFvx+F FjU2vUFKoFSVWrwY6hexZzhsmDwPHVzuCa4c8G8/nFWfw6ZskoXSecZwy2GdPCh8 BHb+S9Np3p/E290JuiHTkY53J5U1d5t8JATvN/BH066eo/keb3zcUXJkSALvMrQ= =PS5A -----END PGP SIGNATURE----- --4hbysko4cc2cwcud--