From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752601AbbEAUBD (ORCPT ); Fri, 1 May 2015 16:01:03 -0400 Received: from mail-db3on0080.outbound.protection.outlook.com ([157.55.234.80]:4544 "EHLO emea01-db3-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752526AbbEAUBB (ORCPT ); Fri, 1 May 2015 16:01:01 -0400 Authentication-Results: spf=fail (sender IP is 12.216.194.146) smtp.mailfrom=ezchip.com; ezchip.com; dkim=none (message not signed) header.d=none; From: Chris Metcalf To: Frederic Weisbecker , Andrew Morton , Thomas Gleixner , "Peter Zijlstra" , CC: Chris Metcalf Subject: [PATCH] smpboot: dynamically allocate the cpumask Date: Fri, 1 May 2015 16:00:47 -0400 Message-ID: <1430510447-17296-1-git-send-email-cmetcalf@ezchip.com> X-Mailer: git-send-email 2.1.2 In-Reply-To: <20150501085356.GA14149@lerouge> X-EOPAttributedMessage: 0 X-Forefront-Antispam-Report: CIP:12.216.194.146;CTRY:US;IPV:NLI;EFV:NLI;SFV:NSPM;SFS:(10009020)(6009001)(339900001)(189002)(199003)(19580395003)(6806004)(87936001)(85426001)(47776003)(50226001)(50986999)(50466002)(19580405001)(36756003)(46102003)(2950100001)(106466001)(92566002)(48376002)(42186005)(5001770100001)(33646002)(229853001)(86362001)(62966003)(104016003)(77156002)(107886002)(5001960100002)(105606002)(4001430100001);DIR:OUT;SFP:1101;SCL:1;SRVR:VI1PR02MB0781;H:ld-1.internal.tilera.com;FPR:;SPF:Fail;MLV:sfv;MX:1;A:1;LANG:en; MIME-Version: 1.0 Content-Type: text/plain X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:VI1PR02MB0781; X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(601004)(5005006)(3002001);SRVR:VI1PR02MB0781;BCL:0;PCL:0;RULEID:;SRVR:VI1PR02MB0781; X-Forefront-PRVS: 0563F2E8B7 X-OriginatorOrg: ezchip.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 May 2015 20:00:56.8530 (UTC) X-MS-Exchange-CrossTenant-Id: 0fc16e0a-3cd3-4092-8b2f-0a42cff122c3 X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=0fc16e0a-3cd3-4092-8b2f-0a42cff122c3;Ip=[12.216.194.146];Helo=[ld-1.internal.tilera.com] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR02MB0781 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Frederic Weisbecker observed that we'd be better off to dynamically allocate the cpumask associated with smpboot threads to save memory. Signed-off-by: Chris Metcalf --- (Dropped a bunch of people off the cc's) I figured since Andrew had already taken the previous v10 patchset into the -mm tree, it was better to just submit this as a followup patch. I can also argue that since it doesn't fix a bug per se, just improves memory usage, it seems OK to have as a follow-on patch. That said, I can respin a v11 patch 1/3 instead to give a new single patch for smpboot; Andrew, just let me know if you'd prefer that. include/linux/smpboot.h | 2 +- kernel/smpboot.c | 12 ++++++++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/include/linux/smpboot.h b/include/linux/smpboot.h index 7c42153edfac..da3c593f9845 100644 --- a/include/linux/smpboot.h +++ b/include/linux/smpboot.h @@ -43,7 +43,7 @@ struct smp_hotplug_thread { void (*park)(unsigned int cpu); void (*unpark)(unsigned int cpu); void (*pre_unpark)(unsigned int cpu); - struct cpumask cpumask; + cpumask_var_t cpumask; bool selfparking; const char *thread_comm; }; diff --git a/kernel/smpboot.c b/kernel/smpboot.c index 209750ab7031..5e46c2a75d59 100644 --- a/kernel/smpboot.c +++ b/kernel/smpboot.c @@ -232,7 +232,7 @@ void smpboot_unpark_threads(unsigned int cpu) mutex_lock(&smpboot_threads_lock); list_for_each_entry(cur, &hotplug_threads, list) - if (cpumask_test_cpu(cpu, &cur->cpumask)) + if (cpumask_test_cpu(cpu, cur->cpumask)) smpboot_unpark_thread(cur, cpu); mutex_unlock(&smpboot_threads_lock); } @@ -260,7 +260,7 @@ static void smpboot_destroy_threads(struct smp_hotplug_thread *ht) unsigned int cpu; /* Unpark any threads that were voluntarily parked. */ - for_each_cpu_not(cpu, &ht->cpumask) { + for_each_cpu_not(cpu, ht->cpumask) { if (cpu_online(cpu)) { struct task_struct *tsk = *per_cpu_ptr(ht->store, cpu); if (tsk) @@ -291,7 +291,10 @@ int smpboot_register_percpu_thread(struct smp_hotplug_thread *plug_thread) unsigned int cpu; int ret = 0; - cpumask_copy(&plug_thread->cpumask, cpu_possible_mask); + if (!alloc_cpumask_var(&plug_thread->cpumask, GFP_KERNEL)) + return -ENOMEM; + cpumask_copy(plug_thread->cpumask, cpu_possible_mask); + get_online_cpus(); mutex_lock(&smpboot_threads_lock); for_each_online_cpu(cpu) { @@ -324,6 +327,7 @@ void smpboot_unregister_percpu_thread(struct smp_hotplug_thread *plug_thread) smpboot_destroy_threads(plug_thread); mutex_unlock(&smpboot_threads_lock); put_online_cpus(); + free_cpumask_var(plug_thread->cpumask); } EXPORT_SYMBOL_GPL(smpboot_unregister_percpu_thread); @@ -338,7 +342,7 @@ EXPORT_SYMBOL_GPL(smpboot_unregister_percpu_thread); int smpboot_update_cpumask_percpu_thread(struct smp_hotplug_thread *plug_thread, const struct cpumask *new) { - struct cpumask *old = &plug_thread->cpumask; + struct cpumask *old = plug_thread->cpumask; cpumask_var_t tmp; unsigned int cpu; -- 2.1.2