Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932260AbcCGTug (ORCPT ); Mon, 7 Mar 2016 14:50:36 -0500 Received: from [65.55.169.141] ([65.55.169.141]:17184 "EHLO na01-bl2-obe.outbound.protection.outlook.com" rhost-flags-FAIL-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1753329AbcCGTuG (ORCPT ); Mon, 7 Mar 2016 14:50:06 -0500 Authentication-Results: linux.com; dkim=none (message not signed) header.d=none;linux.com; dmarc=none action=none header.from=hpe.com; Message-ID: <56DDDACF.6000702@hpe.com> Date: Mon, 7 Mar 2016 14:47:27 -0500 From: Waiman Long User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:10.0.12) Gecko/20130109 Thunderbird/10.0.12 MIME-Version: 1.0 To: Christoph Lameter CC: Tejun Heo , Dave Chinner , , , Ingo Molnar , Peter Zijlstra , Scott J Norton , Douglas Hatch Subject: Re: [RFC PATCH 1/2] percpu_counter: Allow falling back to global counter on large system References: <1457146299-1601-1-git-send-email-Waiman.Long@hpe.com> <1457146299-1601-2-git-send-email-Waiman.Long@hpe.com> In-Reply-To: Content-Type: text/plain; charset="ISO-8859-1"; format=flowed Content-Transfer-Encoding: 7bit X-Originating-IP: [72.71.243.134] X-ClientProxiedBy: BY1PR15CA0002.namprd15.prod.outlook.com (25.162.17.140) To TU4PR84MB0319.NAMPRD84.PROD.OUTLOOK.COM (25.162.186.29) X-MS-Office365-Filtering-Correlation-Id: 6023dd7e-bc79-485d-0602-08d346c1573a X-Microsoft-Exchange-Diagnostics: 1;TU4PR84MB0319;2:RZhJox8jJy5kC3Dv9l/JrgGwGIERq7bGQnwKNCwlW4ectK2RdGpnqTgRUnEDYR06piceb4ON2U0sgkZkEZDWFuI6WDqMelmZOoE2IVW8APvrOpnq2TudH4wCtpce0SmlioUVocLf3wEvLucK+jFbL9ChX4z8QSmcbkeNZM2r5Tmvrx5fg8ZhrMpJzM8GDO2k;3:N/217uw8y/opxQowPrkkQeAvB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q3MTAQ7Xy3b35wmWGOQe1UUN8VsSPnpueH0PZFXBpsYlFxLlHonYGcpbcaPZuDfHsu9MgfvGFMPCtNp4VkajG49yVFw7TYtH5x5T7mQxRqREtOL1Go4M9jBnn+DLVazr1y7A6fc61jklc9EWT2IaUrYPRu/ATzKde0otT6BjoPakmLnpiCe4V2hcVsFr6gBSZm3Fk X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(601004)(2401047)(5005006)(8121501046)(10201501046)(3002001);SRVR:TU4PR84MB0319;BCL:0;PCL:0;RULEID:;SRVR:TU4PR84MB0319; X-Forefront-PRVS: 087474FBFA X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10019020)(4630300001)(6009001)(6049001)(24454002)(479174004)(377454003)(23756003)(33656002)(2906002)(1096002)(59896002)(36756003)(2950100001)(230700001)(42186005)(6116002)(3846002)(4326007)(586003)(117156001)(189998001)(40100003)(77096005)(87976001)(92566002)(66066001)(47776003)(110136002)(65956001)(80316001)(83506001)(87266999)(81166005)(50466002)(5004730100002)(65816999)(5008740100001)(4001350100001)(50986999)(76176999)(86362001)(54356999)(7059030)(217873001);DIR:OUT;SFP:1102;SCL:1;SRVR:TU4PR84MB0319;H:[192.168.142.128];FPR:;SPF:None;MLV:sfv;LANG:en; X-Microsoft-Exchange-Diagnostics: =?iso-8859-1?Q?1;TU4PR84MB0319;23:DsLLkw34shLilj+nQV84uYSu662F8gX+Rk2U6Fs?= =?iso-8859-1?Q?5nMf2cr38PvzZDr8slnjGXztb/j/xL0oOSsTUUyPafpJ/0bBN/ERX1cifh?= =?iso-8859-1?Q?7yYGXRuOb5J7exfpw0rrGOGkNLvW5nY/B9ArbE15IyfVqT6RCWfaJwoLUP?= =?iso-8859-1?Q?aCqKQeegM1qFiB/zZEodJ5gHqeWI/HxqGNA7WYXPtLeMvWlPkdCGh1jkUA?= =?iso-8859-1?Q?NcYGeFnKI7EN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359pBQTP?= =?iso-8859-1?Q?kF0t7vFxTECEuXLEm3DjBlMJStTAK+OG2z2GwXxHqkcMKjbDpBZDtpSDcE?= =?iso-8859-1?Q?xZQO2fBbKE5?= X-Microsoft-Exchange-Diagnostics: 1;TU4PR84MB0319;5:ONcBWfXkaFCpJlrziWYTAIXX8oLUuuSJhtvMCKrTpbJcJpNQBe1fIdftwIvo0Gd+2N5Uu9fttGMhptbaqrGw3jNRtS9z9TIagqHqhL791dgKF5jlJw44hXCvtXgF4abM5D9Gr42msvr8FjxGu1JEww==;24:vLtQ9kIm/CTebhyboCP7I+RpA/LY0Gmnxwveu1ZAokdBCfTk0vXNxt6m/gEid6EknNQ8oVd0WGfcYuv7peHIyhMRSB432j82xw06o8i8YbM= SpamDiagnosticOutput: 1:23 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: hpe.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Mar 2016 19:47:37.6048 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: TU4PR84MB0319 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1989 Lines: 44 On 03/07/2016 01:24 PM, Christoph Lameter wrote: > On Fri, 4 Mar 2016, Waiman Long wrote: > >> This patch provides a mechanism to selectively degenerate per-cpu >> counters to global counters at per-cpu counter initialization time. The >> following new API is added: >> >> percpu_counter_set_limit(struct percpu_counter *fbc, >> u32 percpu_limit) >> >> The function should be called after percpu_counter_set(). It will >> compare the total limit (nr_cpu * percpu_limit) against the current >> counter value. If the limit is not smaller, it will disable per-cpu >> counter and use only the global counter instead. At run time, when >> the counter value grows past the total limit, per-cpu counter will >> be enabled again. > Hmmm... That is requiring manual setting of a limit. Would it not be > possible to completely automatize the switch over? F.e. one could > keep a cpumask of processors that use the per cpu counters. The limit is usually the batch size used or a multiple of it. > Then in the fastpath if the current cpu is a member increment the per cpu > counter. If not do the spinlock thing. If there is contention add the > cpu to the cpumask and use the per cpu counters. Thus automatically > scaling for the processors on which frequent increments are operating. That is an interesting idea. I will do some prototyping and see how it goes. One of the downside that I see is the increase in the size of the percpu_counter structure. > Then regularly (once per minute or so) degenerate the counter by folding > the per cpu diffs into the global count and zapping the cpumask. Actually, I think we need 2 cpumasks - one for deciding to use global or percpu count and another one for which percpu counts are used as it is not safe to change a per-cpu count other than your own one. > If the cpumask is empty you can use the global count. Otherwise you just > need to add up the counters of the cpus set in the cpumask. Cheers, Longman