From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751950AbdJYOQA (ORCPT ); Wed, 25 Oct 2017 10:16:00 -0400 Received: from mga06.intel.com ([134.134.136.31]:46845 "EHLO mga06.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750823AbdJYOP7 (ORCPT ); Wed, 25 Oct 2017 10:15:59 -0400 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.43,431,1503385200"; d="asc'?scan'208";a="1029235049" Date: Wed, 25 Oct 2017 22:08:58 +0800 From: "Du, Changbin" To: changbin.du@intel.com Cc: rostedt@goodmis.org, mingo@redhat.com, linux-kernel@vger.kernel.org Subject: Re: [PATCH] tracing: Allocate mask_str buffer dynamically Message-ID: <20171025140858.GA24679@intel.com> References: <1508930676-8861-1-git-send-email-changbin.du@intel.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="J/dobhs11T7y2rNN" Content-Disposition: inline In-Reply-To: <1508930676-8861-1-git-send-email-changbin.du@intel.com> User-Agent: Mutt/1.5.24 (2015-08-30) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org --J/dobhs11T7y2rNN Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Wed, Oct 25, 2017 at 07:24:36PM +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 > Signed-off-by: Changbin Du > --- > kernel/trace/trace.c | 15 ++++++++------- > 1 file changed, 8 insertions(+), 7 deletions(-) >=20 > diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c > index 752e5da..d1b3f11 100644 > --- a/kernel/trace/trace.c > +++ b/kernel/trace/trace.c > @@ -4184,19 +4184,18 @@ static const struct file_operations show_traces_f= ops =3D { > */ > static DEFINE_MUTEX(tracing_cpumask_update_lock); > =20 > -/* > - * 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; > + static char *mask_str; ah, need remove 'static'. > int len; > =20 > + mask_str =3D kmalloc(nr_cpu_ids + 1, GFP_KERNEL); > + if (!mask_str) > + return -ENOMEM; > + > mutex_lock(&tracing_cpumask_update_lock); > =20 > len =3D snprintf(mask_str, count, "%*pb\n", > @@ -4205,10 +4204,12 @@ tracing_cpumask_read(struct file *filp, char __us= er *ubuf, > 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, nr_cpu_ids+1); > =20 > out_err: > mutex_unlock(&tracing_cpumask_update_lock); > + kfree(mask_str); > =20 > return count; > } > --=20 > 2.7.4 >=20 --=20 Thanks, Changbin Du --J/dobhs11T7y2rNN Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 iQEcBAEBAgAGBQJZ8Jr6AAoJEAanuZwLnPNUgWsIALlk1H0crdeGfTy5/oOqnBRo wHP/xk7K+NQG4XX7AZbsiun/Cn4WV6yz2DT9Z6cabs/tOvz0aai/YtgMZxzsBHuu 85nKe1pcjKV5y94A1Nd+eY+ORbjo+zA0Ot+3Cggwx3f/Ny9oqlzwSz9rE5hGGMFM aYP60chuX0RT8GNrmXINS1KMVR+CZvIYsPmsDbzOMivyYpOC0p2mRnXdCUwXwGQ6 nBm/Vn238fmW9lv1Uvn0pDzC7hOlAqOEFUeqCMuWCi8/QKKbYCUhja09s5iL9nz3 ZVaTqi6UV4QVS8XrI/NKB7M/orFowemO8zaEVEN/uepjFcQKy/aunVWv5L+Fzb4= =ADYq -----END PGP SIGNATURE----- --J/dobhs11T7y2rNN--