Received: by 10.223.164.202 with SMTP id h10csp3824601wrb; Mon, 20 Nov 2017 05:42:21 -0800 (PST) X-Google-Smtp-Source: AGs4zMZv6c9Rq+6Kiz/7YpnJZO5q9Uhm2oEdTe3AQQf3FQo5Jg14agQa5gf4nsB+7G9uCFoOtFfj X-Received: by 10.98.237.20 with SMTP id u20mr11354452pfh.237.1511185341723; Mon, 20 Nov 2017 05:42:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1511185341; cv=none; d=google.com; s=arc-20160816; b=bPdpdkXfQAerK+3ObkZbgVimijY5hiFHfZMYqnIppT8GBDkYVuZpQdy/rJTz1Tb+ST W6QBqmcq/E5T2pHI34j3yrhlWOqkEHWES/F1WnlvFld6PYzpTVdkTPgtdrOVCl0y9Wao szFn2PxyoGhI4rST5UPCmAEhptLJAClCipVZCDEXxQ1ZrWc/PYbFIZi19ZePNot6mcFE 1QwpIb9NYaNb+b0a3Yjv9R3O9iL5h+2hhmAv7tMsYdpfHE6AGEENblbkJ9/jKhbGUP73 iUqcmo2+dfHm4eC7i6VMfbfWz2VqfJ2/nvSUTM8Zk/qI3mZkLyaiMxcwg37fIYFvqRN7 BHvg== 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=tRD2x+Cflp0Loq4Rk0KhJKkTUyz1tO65g8yZ8EduMec=; b=di4iUTgIrCW5+ZeazqgjBS67TadnJBaVTWysSla1wgwn1YRZj8o31DgaDiYiQ07tQq Zro3OZaQ8+7L07FsIWOee+YbVNlPxb/Lwz9ig656vs5jyVA4v49YbWS6nQdAxFIDNvbN bvwy6blhxo4qEC8TS5fZQd+86N/keDaqSDlj/DL2aLeKKIihoZQ+bHjH1ZaBuB3efqpc dmTbQMW+LyymPz5coGZolAHrDtTrXeLiTmExjGjsOZChLLBmZGchp4aGc10MvA/qQYZ1 7h88sEFqI6fd81BussRPUp4THnooZuiEo2JivaOsZ/qEAv6lOHVXscZjp0GO/wV/qETq pdSQ== 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 g8si8154516pgr.127.2017.11.20.05.42.11; Mon, 20 Nov 2017 05:42:21 -0800 (PST) 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 S1751322AbdKTNku (ORCPT + 66 others); 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 Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by fmsmga105.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 20 Nov 2017 05:40:48 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.44,427,1505804400"; d="asc'?scan'208";a="177999974" Received: from gvt-dell.bj.intel.com (HELO intel.com) ([10.238.154.59]) by fmsmga005.fm.intel.com with SMTP; 20 Nov 2017 05:40:46 -0800 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 Precedence: bulk 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-- From 1582833221112816694@xxx Wed Nov 01 03:36:30 +0000 2017 X-GM-THRID: 1582228994579987643 X-Gmail-Labels: Inbox,Category Forums