From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from YT3PR01CU008.outbound.protection.outlook.com (mail-canadacentralazon11020084.outbound.protection.outlook.com [52.101.189.84]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6EBC02135BA for ; Thu, 12 Dec 2024 14:06:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.189.84 ARC-Seal:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734012383; cv=fail; b=HNBsYDixTwAChoY8Zm6tQRpmANPcaWJGnkevVhwyzdbKoxCnu1YMYeguAxJy7no3VzF7JUrOH7f4iENjINnYYmW6mmzRi/Av++aL9gMed8+LyshaumdpTigkF0XT6dlaZr4e+s6ZRGE0s0g9d2XeNZ+0L4vDmZ9+i1TVfDd2rlk= ARC-Message-Signature:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734012383; c=relaxed/simple; bh=VuMun1BWKcnnuecK8MhnFypkykLZXsCZxy+hh3XHEbA=; h=Message-ID:Date:Subject:To:Cc:References:From:In-Reply-To: Content-Type:MIME-Version; b=Ja8IFXkMdC+WaKvVBJI8OrV7Hs5OUhpnldMq9FzeBNE7Q2YOwov6WuX+BO5WTKn/kEinbwDzInesA4Ssn/J5RwIByoZtiVFPjdJbdq32Diq3igqdTo2VeP90H1FFGBeat8HsJfj49IIUtSdylG6DSqDyH8JTm52Ly5MMcEoPFAU= ARC-Authentication-Results:i=2; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=efficios.com; spf=pass smtp.mailfrom=efficios.com; dkim=pass (2048-bit key) header.d=efficios.com header.i=@efficios.com header.b=bxc5O3cB; arc=fail smtp.client-ip=52.101.189.84 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=efficios.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=efficios.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=efficios.com header.i=@efficios.com header.b="bxc5O3cB" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=FSYwVhso/xrdxF4UCRkih53FPP3yiAnvOkR7Vu1SiqfsclcExIXDONzt4QVr/B5kNjxsBuDOl8gtxeqA93+iXOVrHFRPva+NPe+GNOlR/FOcChq+3I6cp87dj3gzMQ+Ai8uXe7NWmrm7l1YwQr1C8ingQ6wrWiWbHGmwewtSl6sqC8xiBhlgNVmynYEolzu8bRarMDAaUqo8pWU360OvDBMiuZOM73PzBViJhI5TDoNMiXu1QSCZi9awd8ovYa4GBaR0Acoyt6ajwkJCgzOw+UGjBZInTws/Wvx2WYXbnWTV37eO5SmBJfzZsQ6bHRr6zCChImfinCsXneN2+WheBQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=mAwvFj+qCxH6pTOYnmEflphz/zzKPoqZTUehhuYgkJw=; b=BZXA4BVGN8PM5W9GGLncQ0GUeD4pdFY7zNb2qJUdTAzpcu4Y+SeU6eZnaP0ydwNACvv+Gd8TEjR9/PgIihrLspRLC2ASwtonQZK/qLXnsGrIscng+UI5cy1OU1j0b3kYm0NYhOAqNTt6kmVZmZ7X5uAUC+QXbvZPW5tGS/9SXYcQsdMGycEu8SXh9mGDmM+OCSKN1Il3h04jWEYazSfjuyg6WPtZzw+zJxZ4IIAhyZkuwMXDariK7qUL7oYKE3v19T0EV9Y9DXS5zdUYC4mrCUlsuE6HL44jikSIx7lUHnh+BqWk/vKK4ueQq1jCtxjNCm7OCZLpOR2UCc3Upjis4g== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=efficios.com; dmarc=pass action=none header.from=efficios.com; dkim=pass header.d=efficios.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=efficios.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=mAwvFj+qCxH6pTOYnmEflphz/zzKPoqZTUehhuYgkJw=; b=bxc5O3cBYEBcE7mUNx+zGCOLhnlDhNvuOIRHo1uPsOn7SVbIJ3aj3JeuGYnx/fWqV2r5uPDbsG1IkGcPD0+4L4kK6S+Cj1oQLK2+jK3ngxRXDADTeWdiEFXsMIjK5jgk+s3hb7nXCTKAjuHT6biUmHYAEYK2Fgdip0I+FEYD4G+gM6u3rnlDWSwAON6Q4jhoX7sH7rzqbuecFKsgd352yFp0dvTCypu0RTF1pZKyjnvEKXj4Noem17SB5hRuxt0RdRYX0PSNwgVHSMHiYQ0d9EoCZdg6iZDmzCwNFvJ8V/1ip9oTV3H/gXXug7buGoavr4M+p5rsphlyewROGr59zg== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=efficios.com; Received: from YT2PR01MB9175.CANPRD01.PROD.OUTLOOK.COM (2603:10b6:b01:be::5) by YQBPR0101MB6085.CANPRD01.PROD.OUTLOOK.COM (2603:10b6:c01:31::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8251.17; Thu, 12 Dec 2024 14:06:13 +0000 Received: from YT2PR01MB9175.CANPRD01.PROD.OUTLOOK.COM ([fe80::50f1:2e3f:a5dd:5b4]) by YT2PR01MB9175.CANPRD01.PROD.OUTLOOK.COM ([fe80::50f1:2e3f:a5dd:5b4%5]) with mapi id 15.20.8251.015; Thu, 12 Dec 2024 14:06:13 +0000 Message-ID: <4b0956f1-2b81-468c-b162-0f8013d60761@efficios.com> Date: Thu, 12 Dec 2024 09:06:11 -0500 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] sched: Move task_mm_cid_work to mm delayed work To: Gabriele Monaco , linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: Juri Lelli , Vincent Guittot , Ingo Molnar , Peter Zijlstra , Andrew Morton , Mel Gorman References: <20241205083110.180134-2-gmonaco@redhat.com> <4c067b75e06aadd34eff5b60fc7c59967aa30809.camel@redhat.com> <5ba975e2-06b9-4b98-bece-d601b19a06db@efficios.com> <445b4203-940d-4817-bd45-9da757f22450@efficios.com> <481a7b7716cf4eb2d592b08558d297d343d9aa25.camel@redhat.com> <1f4a8928-8450-48e2-bf40-e75967240d79@efficios.com> <7c4d0c6800a4bd7a5cf4928e28d59fb469c944b9.camel@redhat.com> <7e9082361b5b98f1824301c92cde929725db0db6.camel@redhat.com> From: Mathieu Desnoyers Content-Language: en-US In-Reply-To: <7e9082361b5b98f1824301c92cde929725db0db6.camel@redhat.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-ClientProxiedBy: YQBPR0101CA0278.CANPRD01.PROD.OUTLOOK.COM (2603:10b6:c01:68::12) To YT2PR01MB9175.CANPRD01.PROD.OUTLOOK.COM (2603:10b6:b01:be::5) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: YT2PR01MB9175:EE_|YQBPR0101MB6085:EE_ X-MS-Office365-Filtering-Correlation-Id: 3c0bcc90-2eb2-4ff3-05cc-08dd1ab622ff X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|366016|1800799024; X-Microsoft-Antispam-Message-Info: =?utf-8?B?QnJqTk9HYk82UjExN3hKSVRtejRhcUd3K0drT0FoOUlwY3Z5SUFQbGg0Y3NI?= =?utf-8?B?Skpnd21PSUVDOGJ5RE0rOHZza1dodDg4Tmt3QzNHU2J6TFRhQjlpbDVvSDU1?= =?ut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IvL1gzTzVlalVx?= =?utf-8?B?eCt3MVE2TDFLbzgwWTVER2FJRk85MmRWaHhsUjA1Yzh4c3lYdXp4YUVlL2Ji?= =?utf-8?B?TG9GMTF5YURlbG5JdmNKTEpJcmZIRUU0dUM4VURIaURBS2JGU1RBSmxNTGxz?= =?utf-8?B?c1NvYWFSR0dQMENJYWprcHg0UHJSSFBuMExrZVpYbTNpRnZlUGY0VndLd0o0?= =?utf-8?B?TEtJaGYvZ0FyeEw4NmF1dXl2WEZKUjU1QXRZWDh0ZlBFY3JYeGFKZWZVeDJl?= =?utf-8?B?cFV3VzB0dFNDVkE2Q3lTbU1kMTBnY3VSZUxhYi9RNVhndmFqY2Iyczg0NGpY?= =?utf-8?B?bzAwRmcrWGpIdUdmU2tiNHR4NjJYcEJZbndTRGUzRld2bnhXYklSUWxVR2Rq?= =?utf-8?B?R2ZpTjVRVE1GMTFBTnE2YmUvaWVPMmdud3hZZTJFdy9XbXpWVmlFK3VvNGoy?= =?utf-8?Q?MYYtDmMQKy7TeEiwNY4lHUs=3D?= X-OriginatorOrg: efficios.com X-MS-Exchange-CrossTenant-Network-Message-Id: 3c0bcc90-2eb2-4ff3-05cc-08dd1ab622ff X-MS-Exchange-CrossTenant-AuthSource: YT2PR01MB9175.CANPRD01.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Dec 2024 14:06:13.1125 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4f278736-4ab6-415c-957e-1f55336bd31e X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 9u3EaVHBAd/Z4z+pUSe3Yv40cyiy0bdoO0f6ArnEx/kpBOyyRZQ/5eJK7kfCw+0d2o/yT1U0pKMFlbhFC/JcK+9xD4yp9sh+HnQuB7d5m70= X-MS-Exchange-Transport-CrossTenantHeadersStamped: YQBPR0101MB6085 On 2024-12-12 06:09, Gabriele Monaco wrote: > > On Wed, 2024-12-11 at 12:07 -0500, Mathieu Desnoyers wrote: >>> Here's where I'm in doubt, is a compact map more desirable than >>> reusing >>> the same mm_cids for cache locality? >> >> This is a tradeoff between: >> >> A) Preserving cache locality after a transition from many threads to >> few >>     threads, or after reducing the hamming weight of the allowed cpu >> mask. >> >> B) Making the mm_cid guarantees wrt nr threads and allowed cpu mask >> easy >>     to document and understand. >> >> C) Allowing applications to eventually react to mm_cid compaction >> after >>     reduction of the nr threads or allowed cpu mask, making the >> tracking >>     of mm_cid compaction easier by shrinking it back towards 0 or >> not. >> >> D) Making sure applications that periodically reduce and then >> increase >>     again the nr threads or allowed cpu mask still benefit from good >>     cache locality with mm_cid. >> >> >>> If not, should we perhaps ignore the recent_cid if it's larger than >>> the >>> map weight? >>> It seems the only way the recent_cid is unset is with migrations, >>> but >>> I'm not sure if forcing one would make the test vain as the cid >>> could >>> be dropped outside of task_mm_cid_work. >>> >>> What do you think? >> >> Can you try this patch ? (compile-tested only) >> >> commit 500649e03c5c28443f431829732c580750657326 >> Author: Mathieu Desnoyers >> Date:   Wed Dec 11 11:53:01 2024 -0500 >> >>      sched: shrink mm_cid allocation with nr thread/affinity >> >> diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h >> index 76f5f53a645f..b92e79770a93 100644 >> --- a/kernel/sched/sched.h >> +++ b/kernel/sched/sched.h >> @@ -3657,10 +3657,24 @@ static inline int __mm_cid_try_get(struct >> task_struct *t, struct mm_struct *mm) >>   { >>    struct cpumask *cidmask = mm_cidmask(mm); >>    struct mm_cid __percpu *pcpu_cid = mm->pcpu_cid; >> - int cid = __this_cpu_read(pcpu_cid->recent_cid); >> + int cid, max_nr_cid, allowed_max_nr_cid; >> >> + /* >> + * After shrinking the number of threads or reducing the number >> + * of allowed cpus, reduce the value of max_nr_cid so expansion >> + * of cid allocation will preserve cache locality if the number >> + * of threads or allowed cpus increase again. >> + */ >> + max_nr_cid = atomic_read(&mm->max_nr_cid); >> + while ((allowed_max_nr_cid = min_t(int, READ_ONCE(mm- >>> nr_cpus_allowed), atomic_read(&mm->mm_users))), >> + max_nr_cid > allowed_max_nr_cid) { >> + if (atomic_try_cmpxchg(&mm->max_nr_cid, &max_nr_cid, >> allowed_max_nr_cid)) >> + break; >> + } >>    /* Try to re-use recent cid. This improves cache locality. */ >> - if (!mm_cid_is_unset(cid) && !cpumask_test_and_set_cpu(cid, >> cidmask)) >> + cid = __this_cpu_read(pcpu_cid->recent_cid); >> + if (!mm_cid_is_unset(cid) && cid < max_nr_cid && >> +     !cpumask_test_and_set_cpu(cid, cidmask)) >>    return cid; >>    /* >>    * Expand cid allocation if the maximum number of concurrency >> @@ -3668,12 +3682,11 @@ static inline int __mm_cid_try_get(struct >> task_struct *t, struct mm_struct *mm) >>    * and number of threads. Expanding cid allocation as much as >>    * possible improves cache locality. >>    */ >> - cid = atomic_read(&mm->max_nr_cid); >> - while (cid < READ_ONCE(mm->nr_cpus_allowed) && cid < >> atomic_read(&mm->mm_users)) { >> - if (!atomic_try_cmpxchg(&mm->max_nr_cid, &cid, cid + 1)) >> + while (max_nr_cid < allowed_max_nr_cid) { >> + if (!atomic_try_cmpxchg(&mm->max_nr_cid, &max_nr_cid, max_nr_cid + >> 1)) >>    continue; >> - if (!cpumask_test_and_set_cpu(cid, cidmask)) >> - return cid; >> + if (!cpumask_test_and_set_cpu(max_nr_cid, cidmask)) >> + return max_nr_cid; >>    } >>    /* >>    * Find the first available concurrency id. > > Thanks for the patch, it seems much more robust than my simple > condition on the weight. It passes the test (both versions) we > previously discussed and doesn't seem to interfere with the general > rseq functionality as checked by the other selftests. Great! > I'm not sure if I should run more tests on this one. The other thing I'd be interested in is to see if those patches introduce any performance regression (e.g. the will-it-scale tests). If you have spare cycles to try this out, that would be good, else we can let the test bots complain. > I will come up with a V2 shortly and attach some performance > evaluations. OK > > Do you want to keep your patch separate or do I submit it together with > V2? Let me prepare a proper patch with commit message, and then feel free to add it into your series, so it benefits from your testing. Thanks, Mathieu > > Thanks, > Gabriele > -- Mathieu Desnoyers EfficiOS Inc. https://www.efficios.com