Received: by 10.223.164.221 with SMTP id h29csp321948wrb; Tue, 31 Oct 2017 20:04:46 -0700 (PDT) X-Google-Smtp-Source: ABhQp+TmxAtz+/0RiTuoYUSgxNv11Ub9co1xSe+UEZlts6w4XQJFk1J+2ri0wQ/gVg8Q/6tdSpG+ X-Received: by 10.98.21.86 with SMTP id 83mr4673340pfv.290.1509505486699; Tue, 31 Oct 2017 20:04:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1509505486; cv=none; d=google.com; s=arc-20160816; b=L+l38F7i/MEa2aaml2kK1W7R20Qldz4HABcsz8Z0Jz62zXZv+NW8tvGK7tCkqcoldy 0maHS2tHPcWvQP/xusZo2nVwVkPmFnxTjjkUBF1fMoXA8r+u1+CN3Iv4JJm3ObKfnCd0 vQ1f8s2ZsJ+7A0CBRZU3RaZcGwbccOKzszpVIToUMHs1S110ja4Eb2KpVJFaxuBSecpv zVg+ZscJ03OCYrQw0VSnScmU5dREItaeRG3fElSAZYqo8EuEIlY4Siq/Tg4spD1MGHqA iOr1ywTMGZbAXJ2VnzBd8u4hiwFjpG/nMdf3OhTfcTAKnkU+SzpkfAcwl9sGrF4Ob6wA MEEQ== 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=xxa4e3ftBP3CPYeFkHWM4D1WoNvPpvMQQYJfj+NLSR0=; b=uiJ1tXYHA1C6LnxGpayKh8pOT7bSEaUEdsN9KSCy+cFGdkCU3Y/LuQyvdsMet6OoPY pcn0u7Ch18bZF0QdmqGrrFjZWyYWZIXjdsZYGnQ7leAbknOkIrBptxVwESn6gxrHX5wq ngs+rrQO2jUcP+s94FIcPgkH9BhoPUqIwA55MLZG09leD5GleQo3HVgjkgiqVhXUQSdX y7dprc3Jreok7m7k+CKYjAsgpKKmBdPwJzX4ya2w1XR9lYp+AwPI8fA2kNDGjyMJewoE MAZ8hLdJK7sUSmOvzpo4VcN5eaPo8QDzrUFvDGiOm2jFMAidWFTcnt8qYaWmIDsnOYgC oTmw== 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 u131si3248366pgc.272.2017.10.31.20.04.24; Tue, 31 Oct 2017 20:04:46 -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 S1754091AbdKADDY (ORCPT + 99 others); Tue, 31 Oct 2017 23:03:24 -0400 Received: from mga02.intel.com ([134.134.136.20]:18414 "EHLO mga02.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751390AbdKADDX (ORCPT ); Tue, 31 Oct 2017 23:03:23 -0400 Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga101.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 31 Oct 2017 20:03:22 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.44,326,1505804400"; d="asc'?scan'208";a="1212642980" Received: from gvt-dell.bj.intel.com (HELO intel.com) ([10.238.154.59]) by fmsmga001.fm.intel.com with SMTP; 31 Oct 2017 20:03:20 -0700 Date: Wed, 1 Nov 2017 10:56:15 +0800 From: "Du, Changbin" To: Steven Rostedt Cc: changbin.du@intel.com, mingo@redhat.com, linux-kernel@vger.kernel.org Subject: Re: [PATCH v2] tracing: Allocate mask_str buffer dynamically Message-ID: <20171101025615.GA29285@intel.com> References: <1508948428-4969-1-git-send-email-changbin.du@intel.com> <20171031121958.7c0e3ab4@gandalf.local.home> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="dDRMvlgZJXvWKvBx" Content-Disposition: inline In-Reply-To: <20171031121958.7c0e3ab4@gandalf.local.home> 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 --dDRMvlgZJXvWKvBx Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Hi Rostedt, On Tue, Oct 31, 2017 at 12:19:58PM -0400, Steven Rostedt wrote: > On Thu, 26 Oct 2017 00:20:28 +0800 > changbin.du@intel.com wrote: >=20 > > 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 > > Signed-off-by: Changbin Du > >=20 > > --- > > v2: > > - remove 'static' declaration. > > - fix buffer size. > > --- > > kernel/trace/trace.c | 18 ++++++++++-------- > > 1 file changed, 10 insertions(+), 8 deletions(-) > >=20 > > diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c > > index 752e5da..6b70648 100644 > > --- a/kernel/trace/trace.c > > +++ b/kernel/trace/trace.c > > @@ -4184,31 +4184,33 @@ static const struct file_operations show_traces= _fops =3D { > > */ > > static DEFINE_MUTEX(tracing_cpumask_update_lock); >=20 > The above mutex was used to protect mask_str. >=20 > > =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; > > + char *mask_str; > > int len; > > =20 > > + /* 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; > > + > > mutex_lock(&tracing_cpumask_update_lock); >=20 > This patch can remove the mutex as well, since there's no sharing of > the mask anymore. >=20 > -- Steve > ok, let me remove it in v3. > > =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_CPU= S+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; > > } >=20 --=20 Thanks, Changbin Du --dDRMvlgZJXvWKvBx Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 iQEcBAEBAgAGBQJZ+TfOAAoJEAanuZwLnPNU66IIAImZ+EBNc6kb6Xjg4Ze60gLd /xGKmOW/pZijnD3SEJQVcDStcSNLdLmarhHXWaJ3GdTAS/lZAek+hmDizpjk3Moo InfksG0Qlnm5KO0shpQwqlXE6ZwiEAxXDEptcUK8hdKSyDKbXj8frwy7Ske0zCkQ 3pXP2bYblmH+3adbY5ZcFkxQy0+LN36yhmadclgwlM6hh74/qyt1XbUUXnzH8GUN lQGSWUNO7u8OYLofUCHpbx0XVYHMVPOgNxoO3st7eo//nDHjl82k7MYyq5ysvu+X JSZ3A5a72/KN06os+Bu6g2CGskggBXfmI+uYqaCh3tshwSShvDo604pgzQwB1mA= =eTRk -----END PGP SIGNATURE----- --dDRMvlgZJXvWKvBx-- From 1582790722964332849@xxx Tue Oct 31 16:21:00 +0000 2017 X-GM-THRID: 1582228994579987643 X-Gmail-Labels: Inbox,Category Forums