Received: by 10.223.164.221 with SMTP id h29csp342138wrb; Tue, 31 Oct 2017 20:36:30 -0700 (PDT) X-Google-Smtp-Source: ABhQp+TnkEnMYhgZBmhzTdeBM2owZ+fcg353OOtbC1hNfZSYbMhcjsoQy+nKug4W5/M0uSWbKCpX X-Received: by 10.98.217.214 with SMTP id b83mr4613043pfl.144.1509507390131; Tue, 31 Oct 2017 20:36:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1509507390; cv=none; d=google.com; s=arc-20160816; b=VlGdzViyH/2RDAxeOzfQCvSkGB5XuaYNPMsTeT1TvAkW0VUcprP9tBErqX2e/UwSu6 JutVsGvuHQrT37NQMhI8UPVyTvDSc0T+2HeQcgH8RJkeswkhfH/4ctUYECtUku0VQwMo DEHoirmL6zOBafe2leh3mEl79r6jy669Yiv/D/48cIL37A+u1r9dywzGsiAEnAKN6C8d mGlbTlIi3JsnAla0O7yWprn0u2bN3x9m4vVccqCJSikxuceOT4IbzOE1diiY/MqQn/VV ScRFA4WOhKKNBik5N8qakONrnl4GzzI5PH2yNSPD+96nzVA1uaxzdjV4RmNq3K9DF+0J DUvw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :arc-authentication-results; bh=QaORBHNLliZc9pzhGEEgoYWigBZD+oFZiVzYXbf1EhI=; b=lnwEr+++j8yoRdqb5D+kXTFsBmMsqGtUCXpBDV/kXYeEAG2UDKjkcI/hpwfAH6Wgtk 4U4gDP66zmYZUVXh6FqZXoreOlZxlhl28dS3Q6jGijM7B/dFAOyzqFB5qS2CzQrt6+sj R7K5JuWy/0VXU3CLcTO8CmycPC8+q8HEzTyGyjzV5n+a9aC5qQzUCPio9hSDpSY5jG5F q9c0/5bUKzjphyPt3yD4d6G3b3WinbamuyXsM6dnERxt3qYSlHOqEvA56F8CCoLMlPZB 0+b/BK2qeQ250CP0wR6MYAydnmOwQuV6VCwpgIdsLxkM5fu9yuymB3HpMnkA9yH20pPY 7yng== 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 m20si3297419pgn.40.2017.10.31.20.36.16; Tue, 31 Oct 2017 20:36:30 -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 S1754282AbdKADfc (ORCPT + 99 others); Tue, 31 Oct 2017 23:35:32 -0400 Received: from mga03.intel.com ([134.134.136.65]:12632 "EHLO mga03.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754115AbdKADfb (ORCPT ); Tue, 31 Oct 2017 23:35:31 -0400 Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by orsmga103.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 31 Oct 2017 20:35:30 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.44,326,1505804400"; d="scan'208";a="330370967" Received: from gvt-dell.bj.intel.com (HELO gvt-dell-host.bj.intel.com) ([10.238.154.59]) by fmsmga004.fm.intel.com with ESMTP; 31 Oct 2017 20:35:28 -0700 From: changbin.du@intel.com To: rostedt@goodmis.org, mingo@redhat.com Cc: linux-kernel@vger.kernel.org, Changbin Du Subject: [PATCH v3] tracing: Allocate mask_str buffer dynamically Date: Wed, 1 Nov 2017 11:28:08 +0800 Message-Id: <1509506888-4053-1-git-send-email-changbin.du@intel.com> X-Mailer: git-send-email 2.7.4 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Changbin Du 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. 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. The exact buffer size should be: DIV_ROUND_UP(nr_cpu_ids, 4) + nr_cpu_ids/32 + 2; Example output: ff,ffffffff With this change, the mutext tracing_cpumask_update_lock also can be removed now, which was used to protect mask_str. Signed-off-by: Changbin Du Cc: Steven Rostedt --- v3: - remove tracing_cpumask_update_lock which was used to protect mask_str. (Rostedt) v2: - remove 'static' declaration. - fix buffer size. --- kernel/trace/trace.c | 29 +++++++++-------------------- 1 file changed, 9 insertions(+), 20 deletions(-) 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_fops = { .llseek = seq_lseek, }; -/* - * 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 = file_inode(filp)->i_private; + char *mask_str; int len; - mutex_lock(&tracing_cpumask_update_lock); + /* Bitmap, ',' and two more bytes for the newline and '\0'. */ + len = DIV_ROUND_UP(nr_cpu_ids, 4) + nr_cpu_ids/32 + 2; + mask_str = kmalloc(len, GFP_KERNEL); + if (!mask_str) + return -ENOMEM; - len = snprintf(mask_str, count, "%*pb\n", + len = snprintf(mask_str, len, "%*pb\n", cpumask_pr_args(tr->tracing_cpumask)); if (len >= count) { count = -EINVAL; goto out_err; } - count = simple_read_from_buffer(ubuf, count, ppos, mask_str, NR_CPUS+1); + count = simple_read_from_buffer(ubuf, count, ppos, mask_str, len); out_err: - mutex_unlock(&tracing_cpumask_update_lock); + kfree(mask_str); return count; } @@ -4228,8 +4221,6 @@ tracing_cpumask_write(struct file *filp, const char __user *ubuf, if (err) goto err_unlock; - 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(); cpumask_copy(tr->tracing_cpumask, tracing_cpumask_new); - - mutex_unlock(&tracing_cpumask_update_lock); free_cpumask_var(tracing_cpumask_new); return count; -- 2.7.4 From 1582831225223280587@xxx Wed Nov 01 03:04:46 +0000 2017 X-GM-THRID: 1582228994579987643 X-Gmail-Labels: Inbox,Category Forums