From patchwork Wed Mar 1 12:19:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Raghavendra K T X-Patchwork-Id: 13155894 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 79948C64ED6 for ; Wed, 1 Mar 2023 12:20:24 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0E0B76B0072; Wed, 1 Mar 2023 07:20:24 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 090586B0073; Wed, 1 Mar 2023 07:20:24 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E4B366B0074; Wed, 1 Mar 2023 07:20:23 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id D1E4B6B0072 for ; Wed, 1 Mar 2023 07:20:23 -0500 (EST) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 936801C6145 for ; Wed, 1 Mar 2023 12:20:23 +0000 (UTC) X-FDA: 80520237126.06.F5826B7 Received: from NAM04-MW2-obe.outbound.protection.outlook.com (mail-mw2nam04on2055.outbound.protection.outlook.com [40.107.101.55]) by imf26.hostedemail.com (Postfix) with ESMTP id 94A0E14001A for ; Wed, 1 Mar 2023 12:20:20 +0000 (UTC) Authentication-Results: imf26.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b=DorsG1lS; spf=pass (imf26.hostedemail.com: domain of Raghavendra.KodsaraThimmappa@amd.com designates 40.107.101.55 as permitted sender) smtp.mailfrom=Raghavendra.KodsaraThimmappa@amd.com; arc=pass ("microsoft.com:s=arcselector9901:i=1"); dmarc=pass (policy=quarantine) header.from=amd.com ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1677673220; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=FK+nIUdqOR9KEr8+cJsJk2w1QgWI/Up4YGCy/MVVpRs=; b=QQpGpzf8Dyaf6/wmE64sA+0FECOZq6whrIa3hJDni8ki/njauaYQ32G85jkEuwdqehQpJs kYHkAFbULBwWxnEqeXrh7Dw1WoOXkehsKGhBwSl70ckRjbdy/j4h3qmjLUJewp2Rd0j7qh Y9iYUBRF/adBg/LizfUCIV+20xI9jPo= ARC-Authentication-Results: i=2; imf26.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b=DorsG1lS; spf=pass (imf26.hostedemail.com: domain of Raghavendra.KodsaraThimmappa@amd.com designates 40.107.101.55 as permitted sender) smtp.mailfrom=Raghavendra.KodsaraThimmappa@amd.com; arc=pass ("microsoft.com:s=arcselector9901:i=1"); dmarc=pass (policy=quarantine) header.from=amd.com ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1677673220; a=rsa-sha256; cv=pass; b=nxisFgkaj5xaHKx2ZQhv9kYKjqg/jcFRuJrFh8oBlihUpddX155+gTg2jPM8jhqY85k6+x UKOlBWp6noMeqeqOM8vrJTFspRyxy2MKqKR/nW9AoPQjbsTlKKf7ZTQsU4sTIy1P3wZukR euTmlJ0LfZWETrdIajF7eVzZTmXKnDg= ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=JMjTV+TFmvtj2TTkF5kFKMCp2CLRJXO6xI+DJZyAxoOoPf+D4YPTzj+K9Fi+pvEPt38LD9N/u9Avl4/LFd67XW7r1BGYKyKseaSBxE5WQvUFm5sPSbk55rZmQ/d3xBVULY9FB3Tzh0QSz8yJYnDvG1DGlEQ0lx/obMYo56pleAccASa0SxH98cOx/iJg160Gp9ZKt90avyZclMdqEZdHkEJQytt3gAOVPc6QwHosXU0JwdArB3AG0mygYJ4+cFYCppZlTa13aYSVv61we0R3MptToTXtFRtevHhRCVwNmVm6ht+klLrVi+tSLYmM0NNisA6dGuWARqeGuljfVhhGXQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; 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=FK+nIUdqOR9KEr8+cJsJk2w1QgWI/Up4YGCy/MVVpRs=; b=lCKaZu1onHhJc0OyStm1wfCYqz/k9I3a49UiN78wYm4Ho0tYZqSwEZIGpmxJG2hq8IcHfNAO0QoFxLladWer/W/tPSQQpQ6UQaX4Dh7gaXppqHJguyNb/jrRVa1IG1vt6H0LNr044odLiyAzsSqeFdvYf23QebXsYeRuV+wenZkfdNnMzP/z8SB0A2wShD31k/IlENxVN2tg0X1FJV5c1pf7+q3uzCndzjQvY3DAxdvdUS7sU5N6MdP3qpffBmmGGUqZWHzgWaAffiHNtDQK6akPJoupQ+NsYIyUNhmU3GXv3OybnFUAk7JpdsgomzfvhIygFNclZlwdiV4mnlWc0w== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=vger.kernel.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=FK+nIUdqOR9KEr8+cJsJk2w1QgWI/Up4YGCy/MVVpRs=; b=DorsG1lS6n3Vzi/nbCIk5QBI+CtmmHJlvkOV1pNGEk7WpenhLjnwDg83iAvoAZlenhEAChef8oqMleWWydaOZ5Lv8VdKiIQoQKQn1vNCU5CmXVg+WWyIOgWOU4KEbXNMvBB4zap+dPYJyRaVXEI9Vr+CO8bz6xJcx/GtZiugW/A= Received: from DM6PR12CA0033.namprd12.prod.outlook.com (2603:10b6:5:1c0::46) by CH2PR12MB4037.namprd12.prod.outlook.com (2603:10b6:610:7a::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6134.30; Wed, 1 Mar 2023 12:20:17 +0000 Received: from DS1PEPF0000E638.namprd02.prod.outlook.com (2603:10b6:5:1c0:cafe::84) by DM6PR12CA0033.outlook.office365.com (2603:10b6:5:1c0::46) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6156.18 via Frontend Transport; Wed, 1 Mar 2023 12:20:17 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by DS1PEPF0000E638.mail.protection.outlook.com (10.167.17.70) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6156.12 via Frontend Transport; Wed, 1 Mar 2023 12:20:17 +0000 Received: from BLR-L-RKODSARA.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.34; Wed, 1 Mar 2023 06:20:13 -0600 From: Raghavendra K T To: , CC: Ingo Molnar , Peter Zijlstra , "Mel Gorman" , Andrew Morton , "David Hildenbrand" , , Bharata B Rao , Disha Talreja , Mel Gorman , Raghavendra K T Subject: [PATCH REBASE V3 1/4] sched/numa: Apply the scan delay to every new vma Date: Wed, 1 Mar 2023 17:49:00 +0530 Message-ID: <7a6fbba87c8b51e67efd3e74285bb4cb311a16ca.1677672277.git.raghavendra.kt@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS1PEPF0000E638:EE_|CH2PR12MB4037:EE_ X-MS-Office365-Filtering-Correlation-Id: 06abf500-d09c-41ef-e142-08db1a4f51b5 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: iCupr+U8pqM+HeB3EUDY8aiPF6whw0HnzU8F27CU2ulVAlOYYITuzkjld6vRGzY3Il4+sTK9J1kiGU/WniRBRczzLw38vqSfi2zAqTPmtD0fMEb8vCdvO8zY4lq4yXfHLBi8XIqtGhJPZ6P0ts2o67QgHx9YI8/9y2rEVIK/p+00Lrdl46feVc3ckEFPkInLWixYZMDh+Mkd8S+AYXmMH4Baq0J3WEdqTG+p5jqDZJS/r2UUYbJ/GBPXhszzT4KgAHsynFlO5ItZwrXYGDwjLXm1Yf3cgUDxWQ6BIj0oRpM8MMPk+S0sy8tflCpI81qfvD1lHDBkhStmDnojzulO1gZbUV0yJN0ubEusMqOLHq1F4Ixx3xY8ygnXMtMci6HVfGIA5UQV9j5t4/SeVCI5ryyohL56S9R9i0cy1w5PlxzpCLB7bq2mUeN8tkLe8hiwxyhfLFTZFZMG1ix2LTXli3TPtIbfLxRrNiPeMHuV3F0QSRIw3pTbwkKellR7NQp4MISsYoN614MH7VaG11LqoMZ7ufCCZGYRJgo4tL0YSzdWdIkpfBjv7Qa/dXJGZ/Q1KKD2ONAvkGktgl/EdYiBqWIzCdOQObEZeDos8JLevk5Tvb7keXvxwbObWM8IthUnI7pNfkkzh7RO8xhA5R3U20iGgIXtWz9kg8nOq3iFSH7glqo35CmWHo1OghHNajRxRw9pk0A/ASgoKDbSkpZum2+vpyScX8laZ5td22HwPm75l/jf+iL+zW0m1/JUunxL X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230025)(4636009)(396003)(376002)(136003)(39860400002)(346002)(451199018)(40470700004)(36840700001)(46966006)(356005)(36860700001)(81166007)(82740400003)(36756003)(7696005)(41300700001)(2906002)(40480700001)(5660300002)(8676002)(4326008)(8936002)(82310400005)(70206006)(40460700003)(70586007)(2616005)(16526019)(336012)(186003)(47076005)(83380400001)(26005)(426003)(110136005)(478600001)(316002)(54906003)(6666004)(36900700001)(2101003);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Mar 2023 12:20:17.7888 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 06abf500-d09c-41ef-e142-08db1a4f51b5 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: DS1PEPF0000E638.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH2PR12MB4037 X-Rspamd-Queue-Id: 94A0E14001A X-Stat-Signature: 34tgb6d9xo717mjrx88ymhdbuuhcyszt X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1677673220-241331 X-HE-Meta: U2FsdGVkX19L69aPu+45AodEQbvTzF7GTCO5g7vES06OALqyhvcNPJcQss+jFbn42BDNXDDHSdFBFntVHx+o8hSlKhZKgDYyt3tSmw2ypPfYMMpMsi80sbZJpRmOohd1uL1RnWGiihftlqGbtTA9z6Dq25q6/FfRTYqRL2vUYcGtDSYywYsZtQPqJe3SEZRWNy/VDdvM7gvAAo9FwLmB55k0SgVicUvtjjsJrJ4NdVvCupro/HNUThIjyfzW2NLm22AHuk3WZqSpyK3cTvFtaSUaI/dbYwX7PYD6QTOsP2l/q9uA+DG/ORjMAROqk70Zjv+xygcXg6Syv/wztB7er+j+HTM98d7vZrge/X5MLuOgUWa6b6r1714p7Bn9vU6bWaj67A0pYYBNFKOw2Sk3S/GwFPdY372aXqR8HxSyoxTo0SJ/KrL5Q7uUAfqv0pq0lR0C1Fv8TnPrVJmiDYiDaC+6fiY0nOoSj9iJn2eBjxjFgvOA1ACcdXl2gP9lq8DWNFxIEQIXy/P0ZgdEgsL52KQ9S8OtDhsj66YfIA2Kx/TaX7Kyfxa6+Mt9xir+y/NY9J99Ig4PCFdTMbJ8SbrY3+WV0bZhGjCk15AGXg/hoLfK6awSLwLRBr0ak+yCelOCp920RGKEB+7HJwEw37b59y2eSx72Yy9v7Y12UOF+dxTasG1ktRmwYlVmYyW47MgwrLwhQPR/3V6/SG0pw/3Y4bqqCjEInyjHcpaOKA6D7/gB7Bptnl/SIVZz6+L2X3nityo7NRa4fuk58WLBWJu+N2zpU6zcsQ5eakxWQk2eqGkuDN+rielQvkaB3qLMHRsGJiHs2HA864vgDYxTFR2RTjxc2W2J8B2q2CZpkroW3RRXPjyqUQ7SAHkizH26nJOH+RgfF0Pwzkm+4GwECOLeaoqn1+P0SUHhSRGXgNmRWe55p5KDsv9ELtrRJLmEqUgCZ+doVlme12p0m3aGsr4 PI9EKfrh Is34OXSrMW2UCyHZA+CYH5jZMVEHXfFWAS5JR+N6OldI+u55845INUPjbHTUqtTcjCOE4YsVjOZooA3chedVEHvIgZ7njpo/wPMOC2ONtLHG8YYGJrIzh2yyjyQch7HRE1R7sb4koH89iGtHake5nR3AHVIOdNDwTXqFegJccdU0fCMbFbDiMAu0JA3J3NJI8GhqsoxNzE4BnL9YSEyZFbGTij0N87SZz6byoNYUmwpYEIJlBN6aYe19xvRSae5Awv8WV2etaisCbYEYQr9qh4+yW1MU2+oEw3yK5pv7pGDKoFmsXGWI33z1phdSf1A4Akvfq53PA7pMhglDLz4QGZMaK6LFz/7EU7MFz5iYfHIFLT2xSXzUlZj0DT+Ulgh6JH5opHkyepUUDSH7BwpIepxcTvs5xRvwt+4qor1ToTwPGn/iB4BlYlw0Z5VkMvLhYwA68XNemOl+TMjO0zHIpbOF7SDVxLkFzbA5U6yA7RI1t2aFUftZq0d3SORTuokK1mSi+qf5MWlFT8QHNZkxC+7KI5a+4A7izWtzkmqnYLK9a9xfzG5xjwb6nmgNtjLttcf6RiAD+teYTBBc= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: From: Mel Gorman Currently whenever a new task is created we wait for sysctl_numa_balancing_scan_delay to avoid unnessary scanning overhead. Extend the same logic to new or very short-lived VMAs. (Raghavendra: Add initialization in vm_area_dup()) Signed-off-by: Mel Gorman Signed-off-by: Raghavendra K T --- include/linux/mm.h | 16 ++++++++++++++++ include/linux/mm_types.h | 7 +++++++ kernel/fork.c | 2 ++ kernel/sched/fair.c | 19 +++++++++++++++++++ 4 files changed, 44 insertions(+) diff --git a/include/linux/mm.h b/include/linux/mm.h index 3d4bb18dfcb7..2cce434a5e55 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -29,6 +29,7 @@ #include #include #include +#include struct mempolicy; struct anon_vma; @@ -626,6 +627,20 @@ struct vm_operations_struct { unsigned long addr); }; +#ifdef CONFIG_NUMA_BALANCING +static inline void vma_numab_state_init(struct vm_area_struct *vma) +{ + vma->numab_state = NULL; +} +static inline void vma_numab_state_free(struct vm_area_struct *vma) +{ + kfree(vma->numab_state); +} +#else +static inline void vma_numab_state_init(struct vm_area_struct *vma) {} +static inline void vma_numab_state_free(struct vm_area_struct *vma) {} +#endif /* CONFIG_NUMA_BALANCING */ + #ifdef CONFIG_PER_VMA_LOCK /* * Try to read-lock a vma. The function is allowed to occasionally yield false @@ -727,6 +742,7 @@ static inline void vma_init(struct vm_area_struct *vma, struct mm_struct *mm) vma->vm_ops = &dummy_vm_ops; INIT_LIST_HEAD(&vma->anon_vma_chain); vma_mark_detached(vma, false); + vma_numab_state_init(vma); } /* Use when VMA is not part of the VMA tree and needs no locking */ diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h index 89bbf7d8a312..1cea78f60011 100644 --- a/include/linux/mm_types.h +++ b/include/linux/mm_types.h @@ -475,6 +475,10 @@ struct vma_lock { struct rw_semaphore lock; }; +struct vma_numab_state { + unsigned long next_scan; +}; + /* * This struct describes a virtual memory area. There is one of these * per VM-area/task. A VM area is any part of the process virtual memory @@ -565,6 +569,9 @@ struct vm_area_struct { #endif #ifdef CONFIG_NUMA struct mempolicy *vm_policy; /* NUMA policy for the VMA */ +#endif +#ifdef CONFIG_NUMA_BALANCING + struct vma_numab_state *numab_state; /* NUMA Balancing state */ #endif struct vm_userfaultfd_ctx vm_userfaultfd_ctx; } __randomize_layout; diff --git a/kernel/fork.c b/kernel/fork.c index 75792157f51a..305f963359dc 100644 --- a/kernel/fork.c +++ b/kernel/fork.c @@ -516,6 +516,7 @@ struct vm_area_struct *vm_area_dup(struct vm_area_struct *orig) return NULL; } INIT_LIST_HEAD(&new->anon_vma_chain); + vma_numab_state_init(new); dup_anon_vma_name(orig, new); return new; @@ -523,6 +524,7 @@ struct vm_area_struct *vm_area_dup(struct vm_area_struct *orig) void __vm_area_free(struct vm_area_struct *vma) { + vma_numab_state_free(vma); free_anon_vma_name(vma); vma_lock_free(vma); kmem_cache_free(vm_area_cachep, vma); diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c index 7a1b1f855b96..7c2bbc8d618b 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -3027,6 +3027,25 @@ static void task_numa_work(struct callback_head *work) if (!vma_is_accessible(vma)) continue; + /* Initialise new per-VMA NUMAB state. */ + if (!vma->numab_state) { + vma->numab_state = kzalloc(sizeof(struct vma_numab_state), + GFP_KERNEL); + if (!vma->numab_state) + continue; + + vma->numab_state->next_scan = now + + msecs_to_jiffies(sysctl_numa_balancing_scan_delay); + } + + /* + * Scanning the VMA's of short lived tasks add more overhead. So + * delay the scan for new VMAs. + */ + if (mm->numa_scan_seq && time_before(jiffies, + vma->numab_state->next_scan)) + continue; + do { start = max(start, vma->vm_start); end = ALIGN(start + (pages << PAGE_SHIFT), HPAGE_SIZE); From patchwork Wed Mar 1 12:19:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Raghavendra K T X-Patchwork-Id: 13155895 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id D9F77C64EC7 for ; Wed, 1 Mar 2023 12:20:28 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 747706B0073; Wed, 1 Mar 2023 07:20:28 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 6F6D76B0074; Wed, 1 Mar 2023 07:20:28 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 597A56B007B; Wed, 1 Mar 2023 07:20:28 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 4BFA76B0073 for ; Wed, 1 Mar 2023 07:20:28 -0500 (EST) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 1D909140799 for ; Wed, 1 Mar 2023 12:20:28 +0000 (UTC) X-FDA: 80520237336.28.37608F4 Received: from NAM12-DM6-obe.outbound.protection.outlook.com (mail-dm6nam12on2062.outbound.protection.outlook.com [40.107.243.62]) by imf10.hostedemail.com (Postfix) with ESMTP id 269C3C0021 for ; Wed, 1 Mar 2023 12:20:24 +0000 (UTC) Authentication-Results: imf10.hostedemail.com; dkim=none; arc=pass ("microsoft.com:s=arcselector9901:i=1"); dmarc=pass (policy=quarantine) header.from=amd.com; spf=pass (imf10.hostedemail.com: domain of Raghavendra.KodsaraThimmappa@amd.com designates 40.107.243.62 as permitted sender) smtp.mailfrom=Raghavendra.KodsaraThimmappa@amd.com ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1677673225; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=tDXLvwqwbuijg3/rtfuFEB9A4LWMIALLerkzU7QFDYQ=; b=TaADVNXz+xVgqS+HVfCC3MhW+qCx1tsH3v0YZAXfd3HtKTsb2SYUfuLl0YgAKdWXAcuFMD jZdB9vfe5v9uqjWBILmPv3dW+4P+ML0/L/kw2S5l70mEqf0t0mriSYVXld2L0ENGUstz75 VjThXJ2h071AJlq3ukZXLW9V5Mg/aQ0= ARC-Authentication-Results: i=2; imf10.hostedemail.com; dkim=none; arc=pass ("microsoft.com:s=arcselector9901:i=1"); dmarc=pass (policy=quarantine) header.from=amd.com; spf=pass (imf10.hostedemail.com: domain of Raghavendra.KodsaraThimmappa@amd.com designates 40.107.243.62 as permitted sender) smtp.mailfrom=Raghavendra.KodsaraThimmappa@amd.com ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1677673225; a=rsa-sha256; cv=pass; b=1zTDTmZddljZWKSh2m043BaTBoVRVs/G3PFSISfcBdwYhpDVCQ3LiYtg3RZZvwtzy2UsYj h5Shjx7LkbaNipNxilhQAvNrcK5Gw0Wwhnk2yL6wq0PYcEpVYQwe5mYdomrXlAe9QmW799 PUB46mQvcBAllyFgbFztycJZzdiHp+w= ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=W4RYe5igQgDx6XoYSk8vvpQnT+8q7nILPJlTyjK4L+GCQE0Z4LlD0azRWYVEXO+rA0olLi1tmF3m1Gz/YM72DFGbdWxdkQy1zQrjDGt/t2bezpPRp92orT8B6lSfVKZinjwbifHOrtKNbdccUFgdwetVhRHmhC48A4s4MGPv3KGZDwrACr5yuRJ0H1ZQwsq9fQi7KSil+fO5z1sZkY7ayrFJCuZk5RwHKGLYXIJAmUv9rN3diIEQdfqizB5/aXLQ/Kz5zs3D3lsnzsKUEilwheD/zE4MV8kayqHgk8WgkV5NZkH1WBZtrALuxLxO3vi7ZW4rDn8Dc6XY/fVvNnXI1A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; 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=tDXLvwqwbuijg3/rtfuFEB9A4LWMIALLerkzU7QFDYQ=; b=i90zdrBaRfCBGPWdhPv5vU9U0jKSY1tPL6ll3qyu3f6nwS0IHR7Elrxa5GCnaAduMuf60dx3RDm1QnDpc4q0p4DvGLi6/S2CxCKDhxjGeMx7028VDkepNZPBNC2CMWYDX3K8zB5oE0sv2K+eQ7UR4Xb4qKgYqDzyYzjFuwvWAZeR15obO82/DvsrLl4VfQviI6C26gr0QNJTw7oTGF2e6njSLF6H+QtI7qhg4eRQoQE6WJObeUf58vpo/TVdr2bNhWzzaZJzlO3A8Y2sPvPX4N+tVEEHL/XtnPv0aeqR+k3yy5SdZZIdQeEvPtni3AwyhxNYI3he8/yItZb8/s4ZSQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=vger.kernel.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none Received: from DS7PR05CA0034.namprd05.prod.outlook.com (2603:10b6:8:2f::35) by IA0PR12MB8713.namprd12.prod.outlook.com (2603:10b6:208:48e::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6156.18; Wed, 1 Mar 2023 12:20:22 +0000 Received: from DS1PEPF0000E639.namprd02.prod.outlook.com (2603:10b6:8:2f:cafe::61) by DS7PR05CA0034.outlook.office365.com (2603:10b6:8:2f::35) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6156.18 via Frontend Transport; Wed, 1 Mar 2023 12:20:21 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by DS1PEPF0000E639.mail.protection.outlook.com (10.167.17.71) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6156.12 via Frontend Transport; Wed, 1 Mar 2023 12:20:21 +0000 Received: from BLR-L-RKODSARA.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.34; Wed, 1 Mar 2023 06:20:17 -0600 From: Raghavendra K T To: , CC: Ingo Molnar , Peter Zijlstra , "Mel Gorman" , Andrew Morton , "David Hildenbrand" , , Bharata B Rao , Disha Talreja , Raghavendra K T Subject: [PATCH REBASE V3 2/4] sched/numa: Enhance vma scanning logic Date: Wed, 1 Mar 2023 17:49:01 +0530 Message-ID: <092f03105c7c1d3450f4636b1ea350407f07640e.1677672277.git.raghavendra.kt@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS1PEPF0000E639:EE_|IA0PR12MB8713:EE_ X-MS-Office365-Filtering-Correlation-Id: 712bc024-5db1-408b-d395-08db1a4f541a X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: jXySr1HB2yOBeR3bu2An4Dyr08vgaUZ1V+3NDTwfz722UW6rd5AMRXtFJhKIBVnBhAFvtd44ABYIuTYag4YuU5YdrHahrhn8VfvqfMsRd7Uh2dVYux9vTBLPRUo/GGYAjUjtLKbaKWM2qmYhlA5QRekpX/qwMyr1fBzu3kAjOg9Z5kNITWhyZ0BKtoV5/3GHzLih2MLU9RMLj/hf2I16aqjPl7vVZODsqMGV+5w1ggkO8/nOqg+WBxv+LEXmGLVSz3oKlnL1nPIH3MMZlSp7KIPSG6+aCG7nkQEWqRar5IpjnQ3+TaY7INUgrJBXum2vwy5W7nBL5xOczKXUiAuDXjGaq6Xs14IO29fTKP5cRgjVS7CZH30E6iqzwe3+q8/i1PhohotB/OYcCHLkZZ8LcVkFGcSXHYF7VwBbo2fpHdr2bQOmuFNkEPz8k6yluFj4rN+eKnxVs/QpLEsqpsGsQ4S0kMvTyXCfFaSO5eD+PjQaNF7eOkWe3oy1Ez1HNOT9BwRpKRdQLhi1s+OMPQwM/+FjZfQH9dcsJ9o+ZPfkRGMtU0newVIWS78Sz1WL5rRIAraT8ulEcnaWbJulShb2Hirjzp6WWnYY6w2OzqOitTsKrzg5vki6GiSY36T1ZGe0dYzhbF7TknY2mgyTKWb924SesFSePpjuOM3sdbBl4FSZ8OOyNxcBq4RM5cboDBQpVJBng9P5pl2LLY/O8zXyMNYixGONZQh8B2CQuvnMKRwsFcrbfDLdCNGVEeDNOfvg X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230025)(4636009)(346002)(39860400002)(136003)(376002)(396003)(451199018)(40470700004)(36840700001)(46966006)(36756003)(41300700001)(40480700001)(5660300002)(8936002)(4326008)(8676002)(2906002)(356005)(36860700001)(82740400003)(81166007)(6666004)(7696005)(478600001)(316002)(54906003)(70586007)(82310400005)(70206006)(83380400001)(110136005)(426003)(47076005)(2616005)(40460700003)(186003)(336012)(16526019)(26005)(2101003)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Mar 2023 12:20:21.6183 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 712bc024-5db1-408b-d395-08db1a4f541a X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: DS1PEPF0000E639.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA0PR12MB8713 X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 269C3C0021 X-Stat-Signature: gcgcgathdjxot5ctt6rduh8w6fa5murg X-Rspam-User: X-HE-Tag: 1677673224-687487 X-HE-Meta: U2FsdGVkX18CmOqoa/jRDkf/AFnYn2BRvbUkTGIz7Nkmn//DLXHUCCAeaH0YiXNnwdNig/yEVmsMF4kpMJAMo+8Eo6mOxtJWnDLk+n26INtj8IoJ1AkToJ3OlsC4SnfGmkjxQwlnv/yIogSZerrl8KEw75JJ5oCzbLug6iot7bVNxkCgQ3RImT4f1O9IEQCY8RSg0TLbgN8C0z4iBwmqyTi53LvZHGIPd4oTvqK0/0ykU/V46mNDiX5+p+duvoZbXzJH6gCA7LiWWMona91QqHSL1vxfkLsbnWkv6iUA2FaEd45MaY/cpzmr4UY2CwjC9vUqJ55N/a2o6uPDy6ZuYF+gIJ4Qw+5bluoxdjrwVuxxqyTzW7OKBA4aCpLAnXY+WZFBItj1gBB0ubZDyaq+lMKxAFuHmsGFxHa7yTxIWVYpXdsatnozFQC/wYFZDA3jSEsbMDm5jTb2o79IMLpyBH3IvuNqUxWT9qfSgzJ8tiv+i0IKaJPzKBPOyi3Td7F9ZED5NZsP3wlrO00wRISxSbJbQ6s7IF5DFfMwnev5BbPYtoWWmBpHv0U3MQqueif6MaadkLMdrVd0G9z1swbg9gPEo20PapUcrluX4GmFbg/D6Z3PLXN6WxShLWuhV6DtvOtzA6Az1IJqTHvzsT/YvIps1NLjxApZTDyHx5yhkhZXBLU1eJ3sUo/KMXT2sIJI+acImrfWZ8kDQG4XiQfgIsHBMtsz7bUdoNrdtW6LcawwUzVs+PAmXlM3PHq9X9xDAO3eqfg/s6/rAK00CBjOm1o9qbFztXECDbyf+taH9vxXounAfvSAZvec3smMuYvg5IuTL9SpyfWRP8606P5PmhNcN1WyTOzXWWMlpTNsFJw0KfCuLOben8/dx4tyhnQW5z2jhVUQMi1fsAle5pVYUioLUspr6cpcot5E7893Sp0+4wm+rR9C3qRDMAxGwONB482Fn0oh9jbLyissbBl g1NXrCvE tObsuiF2DktWUiYXM4ZNPHK2abYgV2e54OSGIuEZ0Y+amXESc+MwgNY9bsdHnivVBRmyDuNukY7a2b9bNuIysd9Gtowd8+uypJwa5h1VmJHsRkaT7fcNVo3VCz85dogvniuJSrWmx3pioEwf+tHif2n3Sap16Yp2ZpkGvOlO26CzoY66giqGlFMKUBRxVx9EEqJjE21p66Sbg7FyyG9ZA8JnnBgEsJDyct6Js3Lnm0+XyBXV99NbhrXzAoI7KBS08zSNyb4bAmKU9WI2ac/ee1SMsYToIRyID4BfzLr5P2Bmv4u2/3dHFRM/hCwahGtlTGvu3UUU6KgI5J3g0nyrruDV+v5l7fWG9xqDySYyHjyb2ICbpNmw5hJ+WXbNjugdpAqB0VTXCdoBbaJnBfZCSMDbkofb0JCk18dDxAmy6UkruEM72JqEKRcM9bs8Eq5euWDwhbmpHQd5EIWHXcxM8gbH4nMbjjXTSjKsP7SG2DqVZmOrRBjP41dHHSsRwVKtFZdmhNhNkHm73NyRt7oX7bt7V4aTX/3ENDq3ASmgEjx/HJulCesrRfY0dog== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: During the Numa scanning make sure only relevant vmas of the tasks are scanned. Before: All the tasks of a process participate in scanning the vma even if they do not access vma in it's lifespan. Now: Except cases of first few unconditional scans, if a process do not touch vma (exluding false positive cases of PID collisions) tasks no longer scan all vma Logic used: 1) 6 bits of PID used to mark active bit in vma numab status during fault to remember PIDs accessing vma. (Thanks Mel) 2) Subsequently in scan path, vma scanning is skipped if current PID had not accessed vma. 3) First two times we do allow unconditional scan to preserve earlier behaviour of scanning. Acknowledgement to Bharata B Rao for initial patch to store pid information and Peter Zijlstra (Usage of test and set bit) Suggested-by: Mel Gorman Signed-off-by: Raghavendra K T --- include/linux/mm.h | 14 ++++++++++++++ include/linux/mm_types.h | 1 + kernel/sched/fair.c | 19 +++++++++++++++++++ mm/memory.c | 3 +++ 4 files changed, 37 insertions(+) diff --git a/include/linux/mm.h b/include/linux/mm.h index 2cce434a5e55..b7e4484af05b 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -1666,6 +1666,16 @@ static inline int xchg_page_access_time(struct page *page, int time) last_time = page_cpupid_xchg_last(page, time >> PAGE_ACCESS_TIME_BUCKETS); return last_time << PAGE_ACCESS_TIME_BUCKETS; } + +static inline void vma_set_access_pid_bit(struct vm_area_struct *vma) +{ + unsigned int pid_bit; + + pid_bit = current->pid % BITS_PER_LONG; + if (vma->numab_state && !test_bit(pid_bit, &vma->numab_state->access_pids)) { + __set_bit(pid_bit, &vma->numab_state->access_pids); + } +} #else /* !CONFIG_NUMA_BALANCING */ static inline int page_cpupid_xchg_last(struct page *page, int cpupid) { @@ -1715,6 +1725,10 @@ static inline bool cpupid_match_pid(struct task_struct *task, int cpupid) { return false; } + +static inline void vma_set_access_pid_bit(struct vm_area_struct *vma) +{ +} #endif /* CONFIG_NUMA_BALANCING */ #if defined(CONFIG_KASAN_SW_TAGS) || defined(CONFIG_KASAN_HW_TAGS) diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h index 1cea78f60011..df4e0bc66d17 100644 --- a/include/linux/mm_types.h +++ b/include/linux/mm_types.h @@ -477,6 +477,7 @@ struct vma_lock { struct vma_numab_state { unsigned long next_scan; + unsigned long access_pids; }; /* diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c index 7c2bbc8d618b..9443ae9db028 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -2928,6 +2928,21 @@ static void reset_ptenuma_scan(struct task_struct *p) p->mm->numa_scan_offset = 0; } +static bool vma_is_accessed(struct vm_area_struct *vma) +{ + /* + * Allow unconditional access first two times, so that all the (pages) + * of VMAs get prot_none fault introduced irrespective of accesses. + * This is also done to avoid any side effect of task scanning + * amplifying the unfairness of disjoint set of VMAs' access. + */ + if (READ_ONCE(current->mm->numa_scan_seq) < 2) + return true; + + return test_bit(current->pid % BITS_PER_LONG, + &vma->numab_state->access_pids); +} + /* * The expensive part of numa migration is done from task_work context. * Triggered from task_tick_numa(). @@ -3046,6 +3061,10 @@ static void task_numa_work(struct callback_head *work) vma->numab_state->next_scan)) continue; + /* Do not scan the VMA if task has not accessed */ + if (!vma_is_accessed(vma)) + continue; + do { start = max(start, vma->vm_start); end = ALIGN(start + (pages << PAGE_SHIFT), HPAGE_SIZE); diff --git a/mm/memory.c b/mm/memory.c index 255b2f4fdd4a..8fac837cde9e 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -4647,6 +4647,9 @@ int numa_migrate_prep(struct page *page, struct vm_area_struct *vma, { get_page(page); + /* Record the current PID acceesing VMA */ + vma_set_access_pid_bit(vma); + count_vm_numa_event(NUMA_HINT_FAULTS); if (page_nid == numa_node_id()) { count_vm_numa_event(NUMA_HINT_FAULTS_LOCAL); From patchwork Wed Mar 1 12:19:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Raghavendra K T X-Patchwork-Id: 13155896 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 742F5C64EC7 for ; Wed, 1 Mar 2023 12:20:50 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E73736B007B; Wed, 1 Mar 2023 07:20:49 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id E22406B007D; Wed, 1 Mar 2023 07:20:49 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CC3C76B007E; Wed, 1 Mar 2023 07:20:49 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id BC57D6B007B for ; Wed, 1 Mar 2023 07:20:49 -0500 (EST) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 969D6AADA2 for ; Wed, 1 Mar 2023 12:20:49 +0000 (UTC) X-FDA: 80520238218.20.FA66BE5 Received: from NAM12-DM6-obe.outbound.protection.outlook.com (mail-dm6nam12on2063.outbound.protection.outlook.com [40.107.243.63]) by imf04.hostedemail.com (Postfix) with ESMTP id ADF424001F for ; Wed, 1 Mar 2023 12:20:46 +0000 (UTC) Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b=5umNEK01; spf=pass (imf04.hostedemail.com: domain of Raghavendra.KodsaraThimmappa@amd.com designates 40.107.243.63 as permitted sender) smtp.mailfrom=Raghavendra.KodsaraThimmappa@amd.com; dmarc=pass (policy=quarantine) header.from=amd.com; arc=pass ("microsoft.com:s=arcselector9901:i=1") ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1677673246; a=rsa-sha256; cv=pass; b=t9r6GO1Byc4w3yur+0fiQNQA0OZBjNSMC/w7PFZegAKO+X04Y96FkcuincanM9sqXyR4FG GbTGGHOFvCVhBGQzIg/M2342Pvp4ZZ/WhsETgSgJU8D6b5POafjm15pAFYHIH9j9u6uVqf PN2j4fDrojvnhRNIuWsxhcY8YC537oU= ARC-Authentication-Results: i=2; imf04.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b=5umNEK01; spf=pass (imf04.hostedemail.com: domain of Raghavendra.KodsaraThimmappa@amd.com designates 40.107.243.63 as permitted sender) smtp.mailfrom=Raghavendra.KodsaraThimmappa@amd.com; dmarc=pass (policy=quarantine) header.from=amd.com; arc=pass ("microsoft.com:s=arcselector9901:i=1") ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1677673246; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=xrS+mOKGYPTmQ3CQudaB16CCkEM1wtpv0h3WebetnPQ=; b=gk6Q5Y4RKfHCQtlJgHBiNWcgClN7NTsdIbGM21u7YyBAzGg6RRv/q4kAKzDvsklAG8RRCE O++phduJ+QTNTIv34TvqBfaHPTZ9TFWh5e/aNMaGVkOD0SDurSUxDgHgkIjDljOhTTl95O 8ymvsD0dxNt02Yj4j49xkxBDExI0PP8= ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Mqoo0HZGFpi6Imiu1dqsn+DBThFJ5hXlMoh2capuWFEXB0hjZ5nDdhgLMVtMOcs/3h15w9GxHC75GllCk5yWzJttnjdsOXddB9LcSwz50WGWa3xvaOaWUGcYtEetzns2Dqm7V/+xLz35J7VgkmM4DXW2b/UEDcWer8DOHn1HzpgRbPl3A2afnbeM46vSpeo2xBn18KwoFvGIRXgCM+rXBPGOcRhxhNC3FZ8ebQHVEGKr9OOKfIZKQyAOTP8/wy8CPfdfIEK7gPVoqeBHCoSSrnzNAWiLH1lUGEXsXPJBxU71Hk1Zowl5lhDh0mGfWrfXpQwqnl5qSXKWKvWMM7cubw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; 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=xrS+mOKGYPTmQ3CQudaB16CCkEM1wtpv0h3WebetnPQ=; b=Od6gmgFPln3BousDU++1kCDiFhLGIRf9jAe5ZCZqFHNgQ/npZcEi8A99gFBB2l45UDRMLcBtuTGNUnTSZhfDI6EpiJU1WnjhJeg8pyvgfL90pKwFcBMWpv8tXRH8NNYryqQScyH2j3lSf8SLOP63ms8pZLa5rIMqhcTyZX6UcI8uYexoNEa7pp86M6Q2wkZxL+5sXhpvs14zt3U/Wzl/x0BqRIhs4CUyzVaJBaYH5kLH2bZK7970BEDkXAnD/Pk1Xdz7O4terGP+KRV2UTwbjoGMtKGfs5Dh9CHwgTwjPGLTRzgVROFELhMvqr5DeQRnS51Cr2ky+yvqSSCS6hyo2w== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=vger.kernel.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=xrS+mOKGYPTmQ3CQudaB16CCkEM1wtpv0h3WebetnPQ=; b=5umNEK01ubL4TqDe0KGq3pBYTj3dqnjI20JqKkCMEKIRauU93AWVsTei6ub0h6rlWDHn3BbklSEwm3EO+phP60dJMIpZGrM9/6uvJcifnimP8JNSB43LJXRs2FguIGkATqghRtT3XdfeQnOpJfQ7oZ7rv7nbrmB3hRg2qsyU5vI= Received: from DM6PR12CA0015.namprd12.prod.outlook.com (2603:10b6:5:1c0::28) by CH2PR12MB4151.namprd12.prod.outlook.com (2603:10b6:610:78::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6134.30; Wed, 1 Mar 2023 12:20:44 +0000 Received: from DS1PEPF0000E638.namprd02.prod.outlook.com (2603:10b6:5:1c0:cafe::b0) by DM6PR12CA0015.outlook.office365.com (2603:10b6:5:1c0::28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6156.18 via Frontend Transport; Wed, 1 Mar 2023 12:20:44 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by DS1PEPF0000E638.mail.protection.outlook.com (10.167.17.70) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6156.12 via Frontend Transport; Wed, 1 Mar 2023 12:20:44 +0000 Received: from BLR-L-RKODSARA.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.34; Wed, 1 Mar 2023 06:20:21 -0600 From: Raghavendra K T To: , CC: Ingo Molnar , Peter Zijlstra , "Mel Gorman" , Andrew Morton , "David Hildenbrand" , , Bharata B Rao , Disha Talreja , Raghavendra K T Subject: [PATCH REBASE V3 3/4] sched/numa: implement access PID reset logic Date: Wed, 1 Mar 2023 17:49:02 +0530 Message-ID: X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS1PEPF0000E638:EE_|CH2PR12MB4151:EE_ X-MS-Office365-Filtering-Correlation-Id: b7e09335-fc40-4582-bdfc-08db1a4f615d X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: tXzauHiLKryFz7iS8anZQ6eCS15J9HLyopJZ4G0CzLso9TG21vYXFzTkhOzZkyAJs21g79dhf4PzUk4BKGD+7fhjIu5M4MFwFOJagCpB7VSxiMOTuu1QaXpbMJsk88oPYIi/5HtEtClgyr3gRxY/xY+aw77V/dRv8qlCR4ZrLluX3E22MPjGEbIri2JiuQSaT+LC9a5PJ+ZP+IeTAZFCvqBaVvZGS1uOAaVqvt5SFfNbuWFEqJaQx394jXym4DsaWCrhGsTrFn3Z+yPzfbRVJGQfcXudbZ1vhpfbmQPCcXktmpoa5/IH7yt3SqpyS8Nx4FG95pRFPGhai7mRHkNXd4w572caOTLueIQ31k+UIwoUz4ZVG5+E8WV6JQY8c75lUL+FrijbVtBOQEEIJGibi0kZsMse8Mk/WfIYRnkZQNJv54CTMRzzgqXVtQ5nnY1B/y8H4oca/iHNoay0kXYFAqbS4twz/QVMocpQLQmNGKhkVtO/+l9o8z/dkhjm0TzWYgmTPiRUO9zPiXVUsKqIxvwmdggMsudzYDDH/nsdJMijhXXxXjEko6O3hEXzH3QQZOEmLv3q59Ju/yU+D0EBiVmdA9dWePBVvSdXRA9QM3hNAmE7BbaqzZ0Fg1PyPz92XgHlqKcygBRB6dkd7rjCOXuANNTWe5CQtlJvBle+LfaCGpoq8aBqwvPB7vK260fvOb6bJEoxh6pI9W7FxgLTYtL3RxDvQdNrZCIKUvlr0KZz0kSUCK+wToU/Vdjv6LuW X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230025)(4636009)(39860400002)(346002)(376002)(136003)(396003)(451199018)(46966006)(36840700001)(40470700004)(316002)(54906003)(83380400001)(40480700001)(426003)(47076005)(336012)(2616005)(356005)(82310400005)(82740400003)(81166007)(36860700001)(7696005)(478600001)(36756003)(26005)(16526019)(6666004)(186003)(110136005)(40460700003)(2906002)(41300700001)(5660300002)(8936002)(8676002)(4326008)(70206006)(70586007)(36900700001)(2101003);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Mar 2023 12:20:44.0547 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: b7e09335-fc40-4582-bdfc-08db1a4f615d X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: DS1PEPF0000E638.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH2PR12MB4151 X-Rspam-User: X-Rspamd-Queue-Id: ADF424001F X-Rspamd-Server: rspam01 X-Stat-Signature: wrddbd44nnsgb5poyi7kn9wzu6facmuh X-HE-Tag: 1677673246-283710 X-HE-Meta: U2FsdGVkX1/UeUvqKe5vqj40+dgUfvVOgEafdRKd9fEw2N5GKc2xLNXwkIiEe9x9wCeLsSYIVPNugc5oW4Vgfb3I+SgbFTxeN6q9lEXC2V84AUAq36sSQF6d+riky35inuimRgB6lI3m7HJmyK4ETRaVndPZtYQktVf4yUgxHkIz2SFlS0us1evydex42DJxn5W0dSrQzoAAnWEHJ69SiAUdWWECQ9dCZYQ2xZhhGDRQV85yLEp17F7QL67fonu9dUGmEj6dxnm2qKbtHidkydom00EMv5jWKfJf6RxfZD8S5Vs24OwRoNxmomcdh7TZS4FwLi3h9DZfpCmD3rHPlriKVNdijpc+LymAPW0t1RSwqEpdfpxF4FP5iQwhX/T/9/SV/eb+jkh0nWMZ5k+zLkCjk4MNxpK+ZkNHN42y74guzu0VYBE9nXlYXeJflExEbDi9Q7hMehIHyk+O2vklHX5uTpfYWL/8UU8/9AAt0idIa0HJvEdrnp3h9/KKsClA4WTjKpXUAgnp7mGaokPLkTfBr09zLMv2QhdfVoXz49aQHz2ZlNNEEBJC7dlRi6KzfDIxekZxbo22x0MRZ+vKAV3Axluazt07L+JomAqJx59UEL/O2kT3lg9PC5Zwdc52DBbDZ4GgChqFEQDa1TrivGxeOQ0KqkrmzZcen/aBcUlbxDhp367cM/UZln894DhspBEkqhpDIhdRe7WATnj0ABzKca3mO173kmDEXpnYWkv8Tef+9sEcwEZgUw0/JftuZdIAi3IzntbqjoQWOL1ewDq8mihdbtguNxDCV70FuK8KVIae01ZF/MC+wN9Z8qlfto2CyXo92QPHxSMtPlpqZuWCJUBgUOKcCXDa8sHSFegge+tMww3gwdP8gF/DVrol8ACs5REqRSlXCQZ0dqPHZkLYZZLbaiUGmBWxPgIGzv80Mbuo7S0kyGJDcin1Wr9vIE89Vi+T+jnijCobLCV b2lAiAYN +pNOBjxZCAJ29dMLD+rOqC8s+8n4FT2zKoUvO4mOWKR5xqcUtpsg8ahtrmedGmxnicZRQ72yBq2dWkv2Kyetznid4bAG1vzA7rcHWzbpucSWkDOTDTFf1ylZKyZdBxc4HfRRJaNIsQfkpkqBdkuEUTGtOsgB6GVqjVnxNJeGo9p+hTxdJZxVKzQSo6y59nsg//EmSJ/tWLoptdHxT7nTj+yvKoWCdGTdsc5Zfrsvla7gXo5chZZIS/V3lHhiBXym4m8RB7/1ZuEov8g6OnusW5mrRrGMjCm26LupCO+v88CoL+wmi7TMMrjtvHkiImoX4NwQgvngxKLML4U5g5fyuYkXsX0seRixtiyoIubtpreXBbVWTwB2nIOP5REdvKdCXtMP5ssT+m28/V/BCLABK4C69CVCrT9lDSV8kSwXO5ldSW4t2RVfJUniSnDpoeW8BhuaZrukeKNugYlshQ/lC+ajtWj/8UltavlTd03jFFlxQU4mTBOtKqF8WEYuvQDQ5hwwujq+V3+fDcwRQAaaLs9kem8l/Plmbdy63bNwAgxSOjoF1NZzgLB+FJ0HqQ2I6i8FKYYWjGH0nAA4= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: This helps to ensure, only recently accessed PIDs scan the VMAs. Current implementation: (idea supported by PeterZ) 1. Accessing PID information is maintained in two windows. access_pids[1] being newest. 2. Reset old access PID info i.e. access_pid[0] every (4 * sysctl_numa_balancing_scan_delay) interval after initial scan delay period expires. The above interval seemed to be experimentally optimum since it avoids frequent reset of access info as well as helps clearing the old access info regularly. The reset logic is implemented in scan path. Suggested-by: Mel Gorman Signed-off-by: Raghavendra K T --- include/linux/mm.h | 4 ++-- include/linux/mm_types.h | 3 ++- kernel/sched/fair.c | 23 +++++++++++++++++++++-- 3 files changed, 25 insertions(+), 5 deletions(-) diff --git a/include/linux/mm.h b/include/linux/mm.h index b7e4484af05b..5232ebb34145 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -1672,8 +1672,8 @@ static inline void vma_set_access_pid_bit(struct vm_area_struct *vma) unsigned int pid_bit; pid_bit = current->pid % BITS_PER_LONG; - if (vma->numab_state && !test_bit(pid_bit, &vma->numab_state->access_pids)) { - __set_bit(pid_bit, &vma->numab_state->access_pids); + if (vma->numab_state && !test_bit(pid_bit, &vma->numab_state->access_pids[1])) { + __set_bit(pid_bit, &vma->numab_state->access_pids[1]); } } #else /* !CONFIG_NUMA_BALANCING */ diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h index df4e0bc66d17..e17bdd10dc15 100644 --- a/include/linux/mm_types.h +++ b/include/linux/mm_types.h @@ -477,7 +477,8 @@ struct vma_lock { struct vma_numab_state { unsigned long next_scan; - unsigned long access_pids; + unsigned long next_pid_reset; + unsigned long access_pids[2]; }; /* diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c index 9443ae9db028..a93e7a33281f 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -2930,6 +2930,7 @@ static void reset_ptenuma_scan(struct task_struct *p) static bool vma_is_accessed(struct vm_area_struct *vma) { + unsigned long pids; /* * Allow unconditional access first two times, so that all the (pages) * of VMAs get prot_none fault introduced irrespective of accesses. @@ -2939,10 +2940,12 @@ static bool vma_is_accessed(struct vm_area_struct *vma) if (READ_ONCE(current->mm->numa_scan_seq) < 2) return true; - return test_bit(current->pid % BITS_PER_LONG, - &vma->numab_state->access_pids); + pids = vma->numab_state->access_pids[0] | vma->numab_state->access_pids[1]; + return test_bit(current->pid % BITS_PER_LONG, &pids); } +#define VMA_PID_RESET_PERIOD (4 * sysctl_numa_balancing_scan_delay) + /* * The expensive part of numa migration is done from task_work context. * Triggered from task_tick_numa(). @@ -3051,6 +3054,10 @@ static void task_numa_work(struct callback_head *work) vma->numab_state->next_scan = now + msecs_to_jiffies(sysctl_numa_balancing_scan_delay); + + /* Reset happens after 4 times scan delay of scan start */ + vma->numab_state->next_pid_reset = vma->numab_state->next_scan + + msecs_to_jiffies(VMA_PID_RESET_PERIOD); } /* @@ -3065,6 +3072,18 @@ static void task_numa_work(struct callback_head *work) if (!vma_is_accessed(vma)) continue; + /* + * RESET access PIDs regularly for old VMAs. Resetting after checking + * vma for recent access to avoid clearing PID info before access.. + */ + if (mm->numa_scan_seq && + time_after(jiffies, vma->numab_state->next_pid_reset)) { + vma->numab_state->next_pid_reset = vma->numab_state->next_pid_reset + + msecs_to_jiffies(VMA_PID_RESET_PERIOD); + vma->numab_state->access_pids[0] = READ_ONCE(vma->numab_state->access_pids[1]); + vma->numab_state->access_pids[1] = 0; + } + do { start = max(start, vma->vm_start); end = ALIGN(start + (pages << PAGE_SHIFT), HPAGE_SIZE); From patchwork Wed Mar 1 12:19:03 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Raghavendra K T X-Patchwork-Id: 13155897 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3B748C64EC7 for ; Wed, 1 Mar 2023 12:20:54 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C9E186B007D; Wed, 1 Mar 2023 07:20:53 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id C4DFF6B007E; Wed, 1 Mar 2023 07:20:53 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id AEF736B0080; Wed, 1 Mar 2023 07:20:53 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id A16036B007D for ; Wed, 1 Mar 2023 07:20:53 -0500 (EST) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 7AE8D40755 for ; Wed, 1 Mar 2023 12:20:53 +0000 (UTC) X-FDA: 80520238386.15.47E2A30 Received: from NAM04-BN8-obe.outbound.protection.outlook.com (mail-bn8nam04on2072.outbound.protection.outlook.com [40.107.100.72]) by imf06.hostedemail.com (Postfix) with ESMTP id 7BEC218001B for ; Wed, 1 Mar 2023 12:20:50 +0000 (UTC) Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b=Rmu06Bt7; dmarc=pass (policy=quarantine) header.from=amd.com; spf=pass (imf06.hostedemail.com: domain of Raghavendra.KodsaraThimmappa@amd.com designates 40.107.100.72 as permitted sender) smtp.mailfrom=Raghavendra.KodsaraThimmappa@amd.com; arc=pass ("microsoft.com:s=arcselector9901:i=1") ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1677673250; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=sdMpUlZfRBZwN1PTr9bWybieMaYFtQSQWlJlEbRQxwM=; b=YAAVhIQAcawbaD6Sb45lGPrsYTWgasottNA0gPuZZ7B34iSGwvblhtvcwaGZHaQyGZ5FRH kWvqPfbvhQA/v8qs5l6hAvpkMLGpAtpNlmUaLdYMk/M9xfKPu4dYFnTXXJpiFU7bGyhXH7 zZ4HIXecJtodgcM6YW6YpJnYjtZ0+fY= ARC-Authentication-Results: i=2; imf06.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b=Rmu06Bt7; dmarc=pass (policy=quarantine) header.from=amd.com; spf=pass (imf06.hostedemail.com: domain of Raghavendra.KodsaraThimmappa@amd.com designates 40.107.100.72 as permitted sender) smtp.mailfrom=Raghavendra.KodsaraThimmappa@amd.com; arc=pass ("microsoft.com:s=arcselector9901:i=1") ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1677673250; a=rsa-sha256; cv=pass; b=XaB0xpkaGHK1Xuost7+JAI52xoyh+2qLmIGNdGsXoJ7RJQt0SF92NpgIC4TkL5UJfz0OKE U2dlZs0tAyGU7Bly+zVCE2J3JBS8EIAE6dtu8UX/UWqYJedVQ0/7rRTdyz8dBSLJeV3Znx IUfCArkuPHynLOxHISKn3cctAYBX6/g= ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=DNsf2aPvzoqczlB90Yj+spHLDgev4xcv6HC55MvCqhRylyXp2qgDxvP18fgiiqWnwLeHVBwOaahTvlKU5kOoo0jIAYwVdCMrsz9Z/aC7gbuEmhsNie+YiOAmeoEHV6stD+I7DXjAtOKw/7kzS5rPyXktkMCHUSbirjfSWgdd0W+cFKS1h7GLJZimP4JSyh7ap3xpmSDs/6hgdOvWsCPqeexWvJwOvtJy49yzyssUCWIO6+ykfblfrs6Y+njXNUFXpqm4JdAt8eyvypBTo6Ws9YevD05BDdA5eDiHnF2Ap9RHs8Gbq6at5aobENx9MJl2TYutKOQpsKmUsysW/8HAAw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; 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=sdMpUlZfRBZwN1PTr9bWybieMaYFtQSQWlJlEbRQxwM=; b=Il1NgZgeQJomduZG1nMQ9UAZWNx9ONTvWC2bYSB5myEAXonE7hy7JKQ5Oh7223WLALq/PT3V30m5BYSD9QrR+M64n7jjT4CRT5iLAfOKguWMM29wBMqEYPQElQknGaIgnaPDxazkx5oBOTzwj2NSZMw2c0BQEEaf45ZK5TM7TuvQyxBjzV/yUkD7XGmTUPwSluZxX1oxMWF/FIS9591SUN0tYeDfZTwiZNdbgVJ48KrNf8gWKuuAihMd8dqJUeArULufEFcGv8im6ov3ThQ1HPCv68udYIxT2M14i39UW8BPt7bu/pBmXOi5beQdX93qzPqTpNu0hTgWtdlNm5UJFQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=vger.kernel.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=sdMpUlZfRBZwN1PTr9bWybieMaYFtQSQWlJlEbRQxwM=; b=Rmu06Bt7FLjf++7Rt11aqHe8g5V+xIFq83p6OfQjsIR4lxpnzj+S6Tkh+F+Ek5Ls5S2/N30nl2K0Bv30mup/B8RJJwX6YesvwCKKpFT+JgEG5XML4dxDd6ylqNUdRCzVIbOu9gk6Ed6iQbw2J2ev7QUstF9iNeeORE4foxTTupE= Received: from DS7PR06CA0046.namprd06.prod.outlook.com (2603:10b6:8:54::13) by DS0PR12MB7803.namprd12.prod.outlook.com (2603:10b6:8:144::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6134.29; Wed, 1 Mar 2023 12:20:45 +0000 Received: from DS1PEPF0000E63C.namprd02.prod.outlook.com (2603:10b6:8:54:cafe::ae) by DS7PR06CA0046.outlook.office365.com (2603:10b6:8:54::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6156.18 via Frontend Transport; Wed, 1 Mar 2023 12:20:45 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by DS1PEPF0000E63C.mail.protection.outlook.com (10.167.17.74) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6156.12 via Frontend Transport; Wed, 1 Mar 2023 12:20:45 +0000 Received: from BLR-L-RKODSARA.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.34; Wed, 1 Mar 2023 06:20:41 -0600 From: Raghavendra K T To: , CC: Ingo Molnar , Peter Zijlstra , "Mel Gorman" , Andrew Morton , "David Hildenbrand" , , Bharata B Rao , Disha Talreja , Raghavendra K T Subject: [PATCH REBASE V3 4/4] sched/numa: Use hash_32 to mix up PIDs accessing VMA Date: Wed, 1 Mar 2023 17:49:03 +0530 Message-ID: X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS1PEPF0000E63C:EE_|DS0PR12MB7803:EE_ X-MS-Office365-Filtering-Correlation-Id: 8772a753-7205-425b-4101-08db1a4f61f1 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: ZUyQQgl9aFxV85LK8rx/q3JVAvv44lxplMSP7vlD54/pLOEIAmeCypYMOtR5c3crYehAU79/0IRA62FD/kUlh0HL0jGuyL1GKpcd3rYtmGRN3wJo4vIIn995Tdf84b5Y5hMWqVNBC5sIy8cFBej3IjmCDW7XNzKbKdXwz1IGRxRBUg/Cq0dv0+FLV7thVIjp1Pd07jM6lTk0guTdVG5HrBZuyw+urR/qh606yuSgkj1VqPEhKlQBQzGRxncVmXwgCNcNtihcsRKhYBhuLUaXJhtzQsSq4PWge/vcgr8o51btB7rtm8NEcCmDvfEO54gemZNDEyfmO4i+UNhsDRKeCsxHJyuufD0ud7TcQ4GDYK7RlWxge7A3mpP4Vldgx0qwWl4eLnQDIM8EKPjUKtZR7Lh2rUF4B8pf6kiEvg0+6qYkFDD6uZ3UU2yQgnvBP02637n1RWUBcomC28/duUZkvn7lfuqNwgfUNwfkrNf5x2SOpLXGfQpoDxzSiYa/Vintub8Dn+X2CU9BszrVtwMky9h8p068r1JM/Rc1lPndjYsMwFBakEFt4IA183CAa1Y/UOvJZlRlAdchFJION4wuGEhfLePgFoCEzbFDp3OSoInqL+wJwb4W+IatFzJmMI/8hfSuOBS4U4M9/eyYtw3HQmOfZ4W58Q1Ng2m8FmV7oCyPgvF74OYzSZx9NiB/88m3t4GVOtu8GUZ1lPEbOxmR6ew9VdbFUI69vr+NHl6iRhrCninftSZXpel5K/UibrWS X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230025)(4636009)(376002)(396003)(346002)(136003)(39860400002)(451199018)(46966006)(36840700001)(40470700004)(47076005)(186003)(16526019)(36860700001)(26005)(82310400005)(426003)(6666004)(40460700003)(83380400001)(81166007)(40480700001)(82740400003)(356005)(36756003)(336012)(2616005)(4326008)(8676002)(70206006)(2906002)(8936002)(5660300002)(70586007)(7696005)(41300700001)(110136005)(316002)(54906003)(478600001)(36900700001)(2101003);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Mar 2023 12:20:45.0215 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 8772a753-7205-425b-4101-08db1a4f61f1 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: DS1PEPF0000E63C.namprd02.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS0PR12MB7803 X-Rspamd-Queue-Id: 7BEC218001B X-Rspamd-Server: rspam09 X-Rspam-User: X-Stat-Signature: j7huacwygi5zy4ephxycbrfj43aaer6m X-HE-Tag: 1677673250-238026 X-HE-Meta: U2FsdGVkX1/Dzah0UaPsGbqjUtjiSs3bjm85dvnjyNhqbp6TzsE7D6FLRmmu0Sa03xLFlvdcYiMLqQNuK5kp95RwIMEYv766gFHXFPadw6RLGllYAmVHBC192PJA75XPxi4H3YKUL7DfT5NGvMREUoKGhg0W38g86unqedHSjztqMtvkzAdl7Qi3VILJgN/J7uOcg9M8MCRt7fiRgHL65O0yZ4Wl52jpj3U+wulbfQj9id1Gv5hCHJvmJ3qa2GgLjwgxEXE7zgXekbEeECVlFbelOwu5Xd+248rAE9rkgUNT9FtNpMumFisFyt88B1PuzWZThf10cB1I7zgPeRqcF+lt6IO34GaVzKt1F5RneMO0I60rok6nrwOpc+3x5AEi71doiGYgerZL9H5wQhdHr0L5wXPHsT8JUmeB0bG8hPrEcXdbZhNUwWVM2Zsug+cnXpmDnQE+eFjuVokG9hBVQUdzXwzssm+1UuulVMqpwFl/5w7j1GJBe3knfNwlvPSYjsOYjmoy8RAQ2WdYWHG/3OUs2LZssRQPNVJqYoy16JwDE+pWWyxwHkOeChLmrIWXuM7ZttU++IGJ8r3Bn9/apWiBKBjDpcPpoJHBnBL2nq8I8lHp52+gFiSYo+/XBF+nx7Rbb4KGJlQVCotGvp+GlAQ076qMa5SrfFpiGDMppNh2cKnPIRH8zQWIOWMUDkneY5jyWi0NHq2brlsXwpz9UpBZrLPjvBapVIpBp8NP3k5HdTVN8UU1Rh8Ruiji8TEfMUst7W4yaFEm1McnQZ0yvnZI72cQVxbc7j1evP+UCrsXAkuGo3ne4uwM/5o9igQ+qlpTi4RVUyHAmJL5ToXLSLKRBj37Y5UrCBmKBFx9BmWUTJc/BhjokvwUOafY/4tkBGJryY+fYn4424TZqQR6TL6ObL0YHQapyAqXCR91HQdM5yTVDKdsWaSYbWy8ipAs0MP+h/VmaqGIUhx4Gm3 IQ4XtmpE LNAzT3P5zmePe+Qn/TJcferQDgmIcLcitZT3IZzhuU9B+2o+NqZgTBeITp8lQ3RVoe5qV77hckqaliijmyg1y5XHq4qsGIlk6c3dNoFnDl/rlZ9hPqGrzmgtkmmh5c3EhJkq/+KPrJV4qOsu9vHNSbcuEOl9Exxndnq/bmEx+MElCUxp+uxRxq9HqWTIu0kIiIHR3tY5PzzgAtVJy77+SxmFhckJRtB6KM+IWCDFn/k6qNVLRIcXY5exksTUWz6hv8Yaj3jwTkrbqcavZQxaRwyp+ZBUwlSspHWi1fwMkKWirx0K/JaBm+LuaVqRfFO89raL9G9leoM4xhkF9KscBNmXsp+sTN6Cjh0NoRjU/TEeAyiHhHsEsTJmO+Je0maFv5VLAm/IwSvJkB47lL0nN/3WLtIw0BbbRKPNcOi8xAMJ9nkwLBvBuINDKopjrdbXRJY1tZnB98ZEdNjz9Wl3psZeZFGM57midpfj6kem/M/Y7vYtCwQ9Vj5Bgsh5XWFb3Ab+HjrH4TKKQLieMnkx+NcvPhC0JhRZ5AGsmomVAVQg3DjV4pa35GQ7vHJ0Rle9kSLgi/UN3YnFvx2ZoP4yZxL2MnLS1Mtj0/3+V5fSauXpcaB9tcXfvKtLmhw== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: before: last 6 bits of PID is used as index to store information about tasks accessing VMA's. after: hash_32 is used to take of cases where tasks are created over a period of time, and thus improve collision probability. Result: The patch series overall improving autonuma cost. Kernbench around more than 5% improvement and system time in mmtest autonuma showed more than 80% improvement Suggested-by: Peter Zijlstra Signed-off-by: Raghavendra K T --- include/linux/mm.h | 2 +- kernel/sched/fair.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/include/linux/mm.h b/include/linux/mm.h index 5232ebb34145..1b9be34a24fb 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -1671,7 +1671,7 @@ static inline void vma_set_access_pid_bit(struct vm_area_struct *vma) { unsigned int pid_bit; - pid_bit = current->pid % BITS_PER_LONG; + pid_bit = hash_32(current->pid, ilog2(BITS_PER_LONG)); if (vma->numab_state && !test_bit(pid_bit, &vma->numab_state->access_pids[1])) { __set_bit(pid_bit, &vma->numab_state->access_pids[1]); } diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c index a93e7a33281f..8592941dd565 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -2941,7 +2941,7 @@ static bool vma_is_accessed(struct vm_area_struct *vma) return true; pids = vma->numab_state->access_pids[0] | vma->numab_state->access_pids[1]; - return test_bit(current->pid % BITS_PER_LONG, &pids); + return test_bit(hash_32(current->pid, ilog2(BITS_PER_LONG)), &pids); } #define VMA_PID_RESET_PERIOD (4 * sysctl_numa_balancing_scan_delay)