Received: by 10.223.164.221 with SMTP id h29csp1816764wrb; Wed, 25 Oct 2017 07:17:04 -0700 (PDT) X-Google-Smtp-Source: ABhQp+TM0Y063mB23AQ5MHi/nKn+YfIla8FxbwZDH/dbs/xdwiNcptVF4GmhDOs9Wnhc+NuVXlWR X-Received: by 10.101.93.12 with SMTP id e12mr2157702pgr.214.1508941024671; Wed, 25 Oct 2017 07:17:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1508941024; cv=none; d=google.com; s=arc-20160816; b=rvZIkgfuK/9XtVyed4bp+ZrAkbjxZrAO8vegAF1D09OgRSJ7Mp/lXuN/ZkVeHwlpwn zma8S0oRaO4V8XSp6RtmN/b0GADMHW7aFZ4k800Ac6y+ZVESOFeadqytjdkoFl501zqW PQdHboSO0Fak3Ckxm2ve1ZSol0PL6qv2sp8U8qWD0QsBv23pcXiQ3GlfjwxAEwb8eNiO mfKtJkq50wK7H1+B4N+881bJa03MdPk5HVCTUzqfIZ0wrvDkXw40bBt+YjRhH2XBw1Fe 1eGm0bPYwqVWa/8SfrmcF/Si6MlDT2LByXnfSBo62DB8RkhDqhJU6KYCcvCj2MIZ6Egu rGlg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:arc-authentication-results; bh=K50jqiIpESGtky2yHdzz0C9SXrv+RC8fIZ56LKf+L4c=; b=PorKPQASuWpopGS8sKYNbAQ/aHPm0PNhPl6bFq1Rb0cmiqKgR0/R9jECz4MG6OGXGD mhlMp2BH7dg25mNvNLOIq6OeiKVowAeHVoWugIljZLv5Qsh/aNZMrHTi/sqshvwm//3E rVXGOHEuRpFD6RItr7P8Pea+tM4z9Gz2cfqhBFpqZaHA2Enu53fpYs0A1Ht5u9lJWnIb LUU7Lc+zWrFOTsXz5fYXhIY/UQhGC9qo920XwEcyX64L/mT484CxYhkoIePPLB2wp3Lg RJDjouODc/GrwaYGkHTyarPH/DWWyuJ3Kp+CQyI0h6g/6R2lQxyrZr6vHd/zPfe8+OaK YK/A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g59si1648388plb.95.2017.10.25.07.16.47; Wed, 25 Oct 2017 07:17:04 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751945AbdJYOQA (ORCPT + 99 others); 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 Received: from orsmga003.jf.intel.com ([10.7.209.27]) by orsmga104.jf.intel.com with ESMTP; 25 Oct 2017 07:15:58 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.43,431,1503385200"; d="asc'?scan'208";a="1029235049" Received: from gvt-dell.bj.intel.com (HELO intel.com) ([10.238.154.59]) by orsmga003.jf.intel.com with SMTP; 25 Oct 2017 07:15:56 -0700 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 Precedence: bulk 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-- From 1582228994579987643@xxx Wed Oct 25 11:32:34 +0000 2017 X-GM-THRID: 1582228994579987643 X-Gmail-Labels: Inbox,Category Forums