From patchwork Tue Feb 28 04:50:19 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: 13154412 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 2658CC64ED6 for ; Tue, 28 Feb 2023 04:51:45 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 870756B0075; Mon, 27 Feb 2023 23:51:44 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 801956B0078; Mon, 27 Feb 2023 23:51:44 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 671756B007B; Mon, 27 Feb 2023 23:51:44 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 51AEA6B0075 for ; Mon, 27 Feb 2023 23:51:44 -0500 (EST) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 20EF2C1038 for ; Tue, 28 Feb 2023 04:51:44 +0000 (UTC) X-FDA: 80515477728.06.F759F85 Received: from NAM12-MW2-obe.outbound.protection.outlook.com (mail-mw2nam12on2082.outbound.protection.outlook.com [40.107.244.82]) by imf05.hostedemail.com (Postfix) with ESMTP id 132C7100009 for ; Tue, 28 Feb 2023 04:51:40 +0000 (UTC) Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b=fedlaKWw; spf=pass (imf05.hostedemail.com: domain of Raghavendra.KodsaraThimmappa@amd.com designates 40.107.244.82 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=1677559901; 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=q6pRaeAm2S0aSVYFRoe0W0nrXqMgPX0/7nNuAYxeMTY=; b=K0ttIorNgRj8DtbqJ8m4K/aZVDG3kagbNm8QgwA1h/pAtrgc8Yctc2U0WshpUv/knIsPIg TBbfNuwbSsxYqbj32aULz2ra9BCETUse4C3BFK66b5SC2ft3glH/R6eA25AfV6NwlojoHR olHFflZsyax5MEmCtNbyIyawjJMnDQM= ARC-Authentication-Results: i=2; imf05.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b=fedlaKWw; spf=pass (imf05.hostedemail.com: domain of Raghavendra.KodsaraThimmappa@amd.com designates 40.107.244.82 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=1677559901; a=rsa-sha256; cv=pass; b=ifuVD0W+/IK2veHTHsCA8uEvOU/2MAB+s2Ev/YoS4g5dhFSGh7s4DzrfloUFYgEmOATHKx jxTGgGFOKX8lr8GQBIDlPynSeuSoU22gJNqXPxy/1rbXTMUqALNs+KS5lozLJC0RkBTvyS pVwnBhDBDb0tb3ZHH/+wKTpe8Vv6A10= ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=nZShD4lpYv+i0nK6bWP4Ouj/0xHZwo7ROlnxQNmDlVhr0Ra+SDIG9RH2mNr9s95r7BkAHcOflFXDpZUiGB/Kla/97Sh06CuRGTkDBkGv7R5JVP0+AUEkQXGdFAXXVdg2h1kjFP27wb06a6AEgoVDI//A7OBx0g4sPkvIDuZ8CJkwhLWym/DvzadW7nvTa3eXvY4IkGB9bMZj9NCYkTATu2DvjHTIxhdrBCtAW64hOpjHf06AHKhnhzoQ8LpSUXD2667qrDbe0U3cm4sTlGHQVqV8wmmXmdccFACMnG5CCT/RkQziZxtZwHpOELgPFajudcM7HAzhnIb+J5v/agyp1g== 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=q6pRaeAm2S0aSVYFRoe0W0nrXqMgPX0/7nNuAYxeMTY=; b=ImwK5qFbqn//e9r+1Gdi04FB5wWuxD6FIrvBM8sPXD+YrIGj2ywQ7ueZQMoY2gpZ+LLubyKd/1npWBo8ysHWtOuoya2WcVxzw7TBDs2R8WZ8pSpeGtntn5ljcfst2WhHzQQfCGSwKEl2lDbBimEvyRwwwRFyJljQhymoWuXF8l53c1By6e1pRB19IKaVtfm9FhKCBNMBqYHmzdxCcYFLv8bC0ZPn48aconEZtOlMqq/ksxET0TOkqKPY7MwbB2qfg81oofU8OIQ6ndKlJLC8MxzoD/6L92/A1qRLq6zsghn/7jR7A/cYaPjIAYSTXIGIPOt9VOgicBm0HFime6FPsw== 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=q6pRaeAm2S0aSVYFRoe0W0nrXqMgPX0/7nNuAYxeMTY=; b=fedlaKWwRNK/HB4XfJ0pgVUC1wmXCTxAVSK+aAA3ZsMNF5+s3dwtR223ihxAxSvt6lXTdANSDyZ0FuCoLLupd+rQvq334rK/hIbyMfLurZ9w1QjBe8yw/v0sS1SX99po5z7N8T5MjcajNMr8SIQIDlxngCvAbene1e2lutESl18= Received: from MW4PR03CA0328.namprd03.prod.outlook.com (2603:10b6:303:dd::33) by SA1PR12MB5660.namprd12.prod.outlook.com (2603:10b6:806:238::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6134.27; Tue, 28 Feb 2023 04:51:36 +0000 Received: from CO1NAM11FT040.eop-nam11.prod.protection.outlook.com (2603:10b6:303:dd:cafe::b1) by MW4PR03CA0328.outlook.office365.com (2603:10b6:303:dd::33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6134.29 via Frontend Transport; Tue, 28 Feb 2023 04:51:36 +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 CO1NAM11FT040.mail.protection.outlook.com (10.13.174.140) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6156.17 via Frontend Transport; Tue, 28 Feb 2023 04:51:35 +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; Mon, 27 Feb 2023 22:51:29 -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 V3 1/4] sched/numa: Apply the scan delay to every new vma Date: Tue, 28 Feb 2023 10:20:19 +0530 Message-ID: <85e573d315109507fccf8e1b0906d90cb2039cc8.1677557481.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: CO1NAM11FT040:EE_|SA1PR12MB5660:EE_ X-MS-Office365-Filtering-Correlation-Id: 02e3038c-2630-4515-c1c6-08db194778a2 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 4x14G/ew6qo47jZ0L8C9jCWb3wfSsBKO9vcz4k6DNaFSxjLL3lw/B0+edEe1dnATi0lgxvHD5NmVjogZFzacp2AKtQ/vgdr03IXtgHlbDhi1XGxk/eH+JWC+RVObAWQTzPrqoYO8XB9ARO6E30rOsFip7tDcFfPHATnRKhirn+pFwUu9ePLo8yVznsqAh1kdaKHMbjMbI8bD4AyD9QLyl7VSxfPF5zzZsEChe4jN6Rc3f6Qa7hvPjVQkbIprVdaIGUUdRWCDH98sOI1tOK5DDlD0T9FZKqLtnZsNIcpQqqFO6X9vQKop156mdVrW1v4AoBg0424qK9M2yZmxuR2vhrEK9JWUdeFf8DCrSt252TdCiWUcab4IL/r2eeHmHXvugXM4/9/VeM6Ch4Nor+Zd9BE6nlJVA3NwjkjXJYZvz6pwHcoPv41fm7nSMZdhfO350vYvrog/LxYduSqmhYckRyu9olyMPVv51iUS242sdwwxjCXY3kz6RUj4onCE5AfFRmd1ZPkzPtgkwycMEvgqBSWpFyUq4YZjHuui+H9/ZFj9kVDL6EowSkk57bXnioPfNcIKWTSG1/Ox3CZPJTMsD7KlyIhKk/CZyQZ1CnUPmwaxoQpWR9ww3TYdem4Vm9zeipiYp2IF8f9pR+Fm2HRi7terUtP7dtzG6oT/II4VHKRjckRsTOqGR54YRSZndUsHBNSb61P45aM5BxbfddJfLfn6rht2I0wR2w1zItecvx5yUknFp/SbN1RIca3SPHpP 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)(39860400002)(346002)(136003)(451199018)(40470700004)(46966006)(36840700001)(8936002)(5660300002)(41300700001)(70586007)(8676002)(4326008)(70206006)(2906002)(110136005)(316002)(54906003)(478600001)(7696005)(6666004)(36860700001)(426003)(47076005)(82310400005)(26005)(186003)(16526019)(2616005)(336012)(36756003)(83380400001)(356005)(82740400003)(81166007)(40460700003)(40480700001)(2101003)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Feb 2023 04:51:35.8955 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 02e3038c-2630-4515-c1c6-08db194778a2 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: CO1NAM11FT040.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA1PR12MB5660 X-Rspamd-Queue-Id: 132C7100009 X-Stat-Signature: ofs4z6jmbkehrouqx3nrrs6quodnwx7d X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1677559900-255639 X-HE-Meta: U2FsdGVkX19WhSSxRkQiRteMa+cobpf2KyiK0aznMyIg+RtuX85EwyiokBPyIbbDInQojp/fLX4Yc2jbZ/TM8XyfZ+83BXgnDiIBgvbpBHkjajcTCJbXTkiCJhTaZkZc9A043yP7xRKXqJvC67LF0Lfd/uU+k6YQP4XFHsFacpl9uMwMUp4KSZmo8t2CHLCYBdheMhYrVDgIs0R+hUh94Cu7cQ7ZSWibUtbm7a+h5ZEtfY+Iun1rHPOqBjoRybzgz1V02/aoziT7FUovUOK6Tp71X3S6A/cnGRwLSFrO4g0NKtiaxB/WY6ayCNDqF8Iwr25NhftBatyNEh4tlOuFheEmDP1ibxp8iHHLOpxVfjOOo2T3h/1+Lr2hqMw1uyro7fsFjEHevw4gj1KO6+9g8Tc2sPsO7iPinCtdWJd9y172RGxj6fL3VxaTf87jHiRkTLcAEdzQ0mOigjTxQFnFlqw8D0o7cQJWsXOJOj+TqAji3YlmBsG4MIPOO2C3PDwPJ5ZmGe78CSA19TyA5BXd4oTBZFF2DaS6bYFZmY4AWrbAKFNKJWB5VeGUoHy5tHEhPqyWfTC60C7zJn1tsCRm7Tm30eeDgkRRAKzjXFtMNSUE3GRYUQsQpd3RyXfT93dPM+4lvMMrCZ8dqBOSuKm7apAp3sXRyKxShmaGJI2I4vnLyqHntFKbIjVY51NIktKTB3NHMYhYTcu3wuWqHNry5q2jMOPZpRG2+WI9ljQfeoMkSMze7AI50mB7J4ypqlQbXQ0G59WWhOlrW9Z64u9WrhT4bU/8kKLda4RZgvVCJBPRrGgPr98i3WE9pQx6+XG3KXN2NJdxjDhpmdxwnKVgyNwdRY8Tu3MFsu98y0ISFoX+aZPVSbhSYGUosZeNqExe8/napiJbeYAAHprnsKsa1B12OA+zHG3CtGAKrpPZiRfB22eP71S3mQGPTYx57aD21M/pnMF9pKvNVK9naZ/ CmYLl3XH F127nFoRg8/27vwJl5dBOXYiBWs7BW1eFSUTWihDBoBJTBwspvEXfco3DxCWPtj2CuayKUT7pyot9zX0NtWe+SE7dItA1Zr66HKiYmLvs+16UuLbIFZmUuYPBoVHwJ5+/PuZjClq2slCMRME8pFN2MuQSU6o01L6AI4uZJSBIxNzRZmsVIdgOYD7UAtny46OEaLkV+9UXFhq+LVmh9qiZolLYWYVtPjyYGLkbKyDP7PxIWhQ8ngXLkNCqE7mhByxfqLDdvdbsIglPwmpVqiQnT65Vh+VnxnFonI5ybu7TW71EdOpf1LMzwj37vLx23VeSP8DFwCIhPLc63TnExtz1zceU9Cc357FdiN6ssjQnAxzl+fp9B0GPdhvB6AfQXwQb9i+k1xBeRwKkqaLoYCQ0zMOhSd0RtTK8wbpXw9fn+B0QPn6WPbF/Bds4C1dCIEfUGRxq8nb1Kx+DfW8wmNpz3OiNn9D2nlidxEoj6ippj/w7cHTWs6pP3G0Erv/EbHuRi/urhLRfJAgU+8H9bz24l1LgG+Rz6O4CDbEt1t7pd337hy3EP6wx4/f6i6pEwlWms9J96Ac5bMZB/qs= 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 974ccca609d2..41cc8997d4e5 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -29,6 +29,7 @@ #include #include #include +#include struct mempolicy; struct anon_vma; @@ -611,6 +612,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 */ + static inline void vma_init(struct vm_area_struct *vma, struct mm_struct *mm) { static const struct vm_operations_struct dummy_vm_ops = {}; @@ -619,6 +634,7 @@ static inline void vma_init(struct vm_area_struct *vma, struct mm_struct *mm) vma->vm_mm = mm; vma->vm_ops = &dummy_vm_ops; INIT_LIST_HEAD(&vma->anon_vma_chain); + vma_numab_state_init(vma); } static inline void vma_set_anonymous(struct vm_area_struct *vma) diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h index 500e536796ca..a4a1093870d3 100644 --- a/include/linux/mm_types.h +++ b/include/linux/mm_types.h @@ -435,6 +435,10 @@ struct anon_vma_name { char name[]; }; +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 @@ -504,6 +508,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 08969f5aa38d..6c19a3305990 100644 --- a/kernel/fork.c +++ b/kernel/fork.c @@ -474,6 +474,7 @@ struct vm_area_struct *vm_area_dup(struct vm_area_struct *orig) */ *new = data_race(*orig); INIT_LIST_HEAD(&new->anon_vma_chain); + vma_numab_state_init(new); dup_anon_vma_name(orig, new); } return new; @@ -481,6 +482,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); kmem_cache_free(vm_area_cachep, vma); } diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c index e4a0b8bd941c..e39c36e71cec 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -3015,6 +3015,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 Tue Feb 28 04:50:20 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: 13154413 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 D53C7C6FA8E for ; Tue, 28 Feb 2023 04:51:47 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6C21E6B007B; Mon, 27 Feb 2023 23:51:47 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 64ACF6B007D; Mon, 27 Feb 2023 23:51:47 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4C57E6B007E; Mon, 27 Feb 2023 23:51:47 -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 3699C6B007B for ; Mon, 27 Feb 2023 23:51:47 -0500 (EST) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 050B81410FC for ; Tue, 28 Feb 2023 04:51:46 +0000 (UTC) X-FDA: 80515477854.26.D0EDFB7 Received: from NAM04-MW2-obe.outbound.protection.outlook.com (mail-mw2nam04on2072.outbound.protection.outlook.com [40.107.101.72]) by imf21.hostedemail.com (Postfix) with ESMTP id EC9041C0006 for ; Tue, 28 Feb 2023 04:51:43 +0000 (UTC) Authentication-Results: imf21.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b=QJ17y+Gv; spf=pass (imf21.hostedemail.com: domain of Raghavendra.KodsaraThimmappa@amd.com designates 40.107.101.72 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=1677559904; 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=8uk+B5aAIEoEtArS6ZbOd9S+1f2u55Ig79YNUgY/D0U=; b=NEkof+xUmywYFjT6hBjNPxdJyvG6ttjQS/CRS4k8Y5mECGnmz+dDAsI3rBxXzNEQO8QuN3 9DsZ8+B913iDjm3QjcHAysdTIsPlxxANmAG172xJo4coySy9e9XAa24nscPFApniZYsU3t P6shtI7jHXrLZ8rLdhZOHTqpNYl/h2o= ARC-Authentication-Results: i=2; imf21.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b=QJ17y+Gv; spf=pass (imf21.hostedemail.com: domain of Raghavendra.KodsaraThimmappa@amd.com designates 40.107.101.72 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=1677559904; a=rsa-sha256; cv=pass; b=8HQUirVxzO+WVjwGbbU6tHceqp90hsP1UmP8m9fbF/8//B1ZPZGmGb1mbFb5Yl1qSDhUoj 96PwCcmI0NN/JJEoXsroC6aIy8OvY1oLBLCEIsE+FnzQLkhlY1Rm4eE0HxhO20XFZiteHT 1HeY8YbEcN4pZCDtkfYvSaYkA+etvO8= ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ghAqonIqz7BbwH9VhodpgROfavqUfG1YsyLYxl/PiZakQ4LqM2fqG4tJgKEe3HEZi7c9hU9NRgY0m836MEo7axZd1Md8i8D4387VVsWRT5dwvk/tOAok6Ku0KyHPmX00mH8rZ+Jl6fMypx5NxW6kAjM96rTccFXEOc46BgxrdGqnLH1d+jWQkaUb/qegB5VoF6Cf8Fte+aNLdVFla8M/O8mKtmJY18oCXpcQf+w7JRv95TSuBAjVdS27Ig0bYQyKZcD3m+dsW0aGqrpaLEte1HgLVQjaLGj5eLnTKQ2V9yaT2ZHmsR2c1/lX1XjGpCB4k5SHjtk2JuKWWPPm5EETTA== 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=8uk+B5aAIEoEtArS6ZbOd9S+1f2u55Ig79YNUgY/D0U=; b=CYa4gzwEQgyXKabCm9s71bt7iXc44bBjdUBnMeZYlE9/lWI2UQ0xCZOfVzgXVNn3dFQhZHN+AS3CNHf0Pi6GT+qv5AGGPCO/DKgPZHOIjlNYHyOFR8cFVrFwJ5QYamFXEJR+SoTdyRy2vIAXSmvhsynrEWVy7KJ9nYbbP7nlJGLgtZ0NDbLgeuLEB/R6OTdDBXmsc90dlu4F8S6F/xqx8zstYctnk+Q0hsJgoUDuhKtELSQrLcZF4M3aokvpyfkDdNAM4lpjGksIqVkaNxvJyAtK7KOZdgUwrIGTPiqH5pPwACHpb6zxzcwjqpimCh/F6RdgttA1U5H/BiRAExsIkg== 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=8uk+B5aAIEoEtArS6ZbOd9S+1f2u55Ig79YNUgY/D0U=; b=QJ17y+GvfSnSPPZH3oqZ2nYtM/HSKbJk6sMgjivB8bkAKxJU3BNoG6rberOzk2t1bsSGuobtKFQbufjLnNKwINGRVSBquZIt7EVY0IutOZv95Y5dvJ4mtBhDPZngqzplyD4nDvp69ZuAM5yzqa7Blvzs8vfuisjtI0xUDiG86Aw= Received: from MW4PR03CA0323.namprd03.prod.outlook.com (2603:10b6:303:dd::28) by CY8PR12MB7363.namprd12.prod.outlook.com (2603:10b6:930:51::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6134.29; Tue, 28 Feb 2023 04:51:41 +0000 Received: from CO1NAM11FT040.eop-nam11.prod.protection.outlook.com (2603:10b6:303:dd:cafe::eb) by MW4PR03CA0323.outlook.office365.com (2603:10b6:303:dd::28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6134.29 via Frontend Transport; Tue, 28 Feb 2023 04:51:41 +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 CO1NAM11FT040.mail.protection.outlook.com (10.13.174.140) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6156.17 via Frontend Transport; Tue, 28 Feb 2023 04:51:40 +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; Mon, 27 Feb 2023 22:51:34 -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 V3 2/4] sched/numa: Enhance vma scanning logic Date: Tue, 28 Feb 2023 10:20:20 +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: CO1NAM11FT040:EE_|CY8PR12MB7363:EE_ X-MS-Office365-Filtering-Correlation-Id: 42f6652f-98e9-48d2-9a56-08db19477ba9 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: o+PHmVvHK+CkANAn3yHvYQPV1SW4XB/dSatLsMTIRN3mqu13xl3Dc7thz43dMDwpxorEeYvQEiW9qLjl7jM5xCK3+Dp8YT1PUbqvil/5QAgU5MuXvLvVO9lMv/EcdNkCjz0oIT5AM4LqMadJn2+1/+qEmFOBSsOKcRMehtyKYjJk654EBxotZADEaFSbGAZKhrGuyyJMrlgTdORpj3JtDpL/4fhRKiulVc5METEUtgm3p9U8ZwqYyDLpnfVhvIpklzJQ0bNqGfCJRv+dXycgNeUIQ5lpibADfgHPXxnYcOawowhQAZxkn56d0KvYhSMnpay4F70Hp4OjPfZKT0dXfokjN/LgTt1iu5amvjj0B7aRM4Zwo+t9TOy1s86/RvQUH1EEFdFJ83I2Ox6bJHTbetnXwFbJXxkw4ZZrQpF4VEAJyjyMYAcvVGpxJmNcmDgtIh+0Y/AutcdJY9x4tencEApe4aKfMd3dszQLFG/mLUwxGwfDgqYK0dCUtRYnmguDFFIUKWdxjXe0M6q3CdicM11zc8ilgrxRLggOW/6JGs2Ixkf6TOUHi5BHeLLjdB2npCBnTK88g9VgOXSs0mGc7bIeGNvUoOvMBPmgDgXVBCtA0cFtYE76Lwo/SO8HmuYCZcNzXEQru7C5b+LMqsUYTRTwsKYOzipOLRozQ3R/N6hDFZzwMOYDKbUuHVihghGxsIqHkflezfVidBon75IFuT307g+7DgtYn/EeRSHrjdLM81HSSiz7N1xoHwkBqpFT 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)(136003)(39860400002)(346002)(396003)(451199018)(40470700004)(46966006)(36840700001)(54906003)(16526019)(186003)(26005)(356005)(316002)(40480700001)(36756003)(478600001)(5660300002)(7696005)(2906002)(40460700003)(8936002)(6666004)(110136005)(426003)(47076005)(36860700001)(70206006)(83380400001)(8676002)(4326008)(82310400005)(2616005)(70586007)(336012)(81166007)(82740400003)(41300700001)(36900700001)(2101003);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Feb 2023 04:51:40.9736 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 42f6652f-98e9-48d2-9a56-08db19477ba9 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: CO1NAM11FT040.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY8PR12MB7363 X-Rspam-User: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: EC9041C0006 X-Stat-Signature: 4yxjqf9y9jphiyjummuqree8wdexybmy X-HE-Tag: 1677559903-76204 X-HE-Meta: U2FsdGVkX19dD3BnM3ZInfpxFD5Qo+gk7NJbIl5M7ckIkpkLxxk2XFCWhgyVRRL4odKD2pOro4A9F6uP6FsycFXVr4fZ3/78CD/yU0rE+jfWSvVNdtX1jlK/5SSPMIwnyoeoY3UOsiVDU3y0HcHaXvh9t2ex9W3s3VEfl4CHsrtFEPb3bYf/yx7Jsd1HAIZx821zHSKqJhWkXiaho1RTSVHcnrdskDVVJaLVNE3L/Hbc3WMv3Igr9nlnY2elnvfJRbA4q5r+KNtCsHb17Dldugx0bUCQH4dn0iCVIPT00JG4ksL++aI4Jz9S3p6eSXLnIWOI9UNw8zBZ3Q0G/1ptOIqxxCKxCBrXGJ19nGElEiOFuv1+Hiq7SuuX5WiFlTUQlzR7blDfpemdPV8PL59I6lwYokEVPqxqsBQy8oFIrV1q28WM6QQeotYoCBKtQd7FV6pZ8QyiJB7HeXmXVVoTgF/7nNVTHNFQszCM3n3nHmnzqfcnDj0QiCEfGZ0uTagKiHGF+eSOA+0BjZav608VXt6FE/jeV/anesOp0LEvzBp6qhsFM98LR8WTtJvjmzyhBoU3lL6M3RfPlc9hMcDeVMwAzXr1J9Q/7Ee8f97O3RpqbJj++kV96fz2rbDUiugK3+46YlNRcW+B5HRgi7G1g3+NcEzafsr6oHwg04rFfpJFVU00NK4RbbcEe+A0IDj6KqUCv0ChwUeb/I8/wq0/O+Wb2k0lkTKmKCrR41AxbMr56sytlEuEnwvd1kEDomdbeqxv3CszQlRSGUL2L0lWlbEXK8JMq3pLeXUmT4GHMvu3V+JGUjSYMdFz+6FbX6dLi/8sjqsKqNXSZcopTwWoWdYqLcoZI2Bn71nPr/2XK1dzQ63bPRyDFs9J1QhS4ub2pOB5f8HomUneVGpB8zC+5nmmSMSecP554eitq/BbSIF496nFPyn36h72GgegMoub6W06vGjuwKkWdCoTeh8 FsHvGJ+k /I/5shiyGLoaCTvvV4RQXDCXEywgq9wG1v9S5EmIVPNGFKMmYHfF1vyQkPKbu/IoyqQs4gGUnzO5OoO7qrCT1xxQ5e4fTvbq1cvqv0hBIMfW/OB2eQ6FaFTEIspDDNq1Fk0bRHb+1JrCWs4SeZX6OLXbESHEF6Q6n+NUMQhDoM9DxgwyIhNlgo2flCJnk7QzUwbJx4c+p4+L5N4saOgquBKgcTD+oU5C8e9bmr5x2n/qXz4X5T+w7HKf2aJ1v3HaEIFH2XAJkpENs6PUDQwQANub//liUVJyTPMnyG7pz1Efn3aHGa0BVg46gye0A4jAtTH049HfMfcjv0RSOvQKjnQ6a2fuCACnZ5fk7er0H/U85c4y/2FoslTYzhJ720D+FeGkZqxGJc5Euug9Cx5RFErBJX0VNcuPTf0yToi9GavWSTuYseFLZLrc/i+5hKPNzx5qQcKELiNODOQa4j7BwU+c+D5nnY0fHabIL4SkdoIOa+ol4kYXjgW8RMzluy6m3jL7SL6/JSpRxLX9cVFVJvakaN7NBxcSRbNNSMKcKJ+kQoUtiJX2oS7DD2LLpLujqansVqrOAeVo6vBegot+Bg9bJeYmTBpGA8HhY0u50Yhs4KP2IB8eWCtsrjB+jTjOyq96p 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 41cc8997d4e5..097680aaca1e 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -1388,6 +1388,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) { @@ -1437,6 +1447,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 a4a1093870d3..582523e73546 100644 --- a/include/linux/mm_types.h +++ b/include/linux/mm_types.h @@ -437,6 +437,7 @@ struct anon_vma_name { 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 e39c36e71cec..05490cb2d5c6 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -2916,6 +2916,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(). @@ -3034,6 +3049,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 8c8420934d60..150c03a3419c 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -4698,6 +4698,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 Tue Feb 28 04:50:21 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: 13154415 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 286CAC64EC7 for ; Tue, 28 Feb 2023 04:52:11 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3C8E06B007E; Mon, 27 Feb 2023 23:52:10 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 319F86B0082; Mon, 27 Feb 2023 23:52:10 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 07E5D6B0080; Mon, 27 Feb 2023 23:52:10 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id DD8836B007E for ; Mon, 27 Feb 2023 23:52:09 -0500 (EST) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id A9B2EA1103 for ; Tue, 28 Feb 2023 04:52:09 +0000 (UTC) X-FDA: 80515478778.23.BA180D3 Received: from NAM12-MW2-obe.outbound.protection.outlook.com (mail-mw2nam12on2079.outbound.protection.outlook.com [40.107.244.79]) by imf01.hostedemail.com (Postfix) with ESMTP id B201640010 for ; Tue, 28 Feb 2023 04:52:06 +0000 (UTC) Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b=hdLjdHcO; spf=pass (imf01.hostedemail.com: domain of Raghavendra.KodsaraThimmappa@amd.com designates 40.107.244.79 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=1677559926; 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=eoXFYLxyn89pEiIdnnebivPOBHzu3rBSGjAxsggIL6A=; b=n90nrvHaVWe1NL5wTY19Ee36YMzERK2zwIUz91HjK9vJAZMBp/bO41Nfzmczosyzt+IyQG 4AilmO1XgTHdaC9aax59qpXe4PM5Fh1trb0qa0hfRje6+kuHfNmndkPPnGGQyzPlukq6BV eDerj86GeMuaq/NgtglVN7TSW/L9TjY= ARC-Authentication-Results: i=2; imf01.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b=hdLjdHcO; spf=pass (imf01.hostedemail.com: domain of Raghavendra.KodsaraThimmappa@amd.com designates 40.107.244.79 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=1677559926; a=rsa-sha256; cv=pass; b=fg8KoWl/1pT0oS9NBB/tHMJI8UEf46ue0LGMHmUCAfkznATAzOfNcNCU9zqkMy2HgkHc8s BdxJphvxHoHcW6bUcI6O/lTbNRqOwnRvApJ9M4lSntmsY42gO/VCq/nrhPKsC1tcyXLhz8 MWnFsK8Ws/uHZke/0rvzfFT6o8hXZPE= ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=YhIJBb1o2KENT2cFgBVVAqBzcLiF//tadsiqIxoVaLNr3j+M4h3Xhg9+0McGZNmjEj4V3RmuNmC0i+SpKhfk78WAj/38lmNBEg69mP24JrsRi9rqp0yB/WFOcctYMrhr1AjZsMxWcyKSGbrPNvHfAfyjndCr4izO7KA/ad3+Qtm3OgAjnNxWn9Qw2hhOzQZq1AtnUn1vdu2V6AaTFWNbAalGhuYS7+OYycFCTaQo9exz1rscJQm9+ICYIRPdi7uIFNoHCUX6RMPSlwTex3QsAQTotKRDMK0BmJLMPY+FZ3f5MjFE/Fte5jVRKrDVWvEivA8UXF5d33twI4IxH7nqxg== 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=eoXFYLxyn89pEiIdnnebivPOBHzu3rBSGjAxsggIL6A=; b=Rgui38NGuBKMkYHTTfoH6E5OSayQhOU91fhfxZz0TCDouyc/r3m/Y90PmF4NurswCLICsBZPsTARxcpk70JJzfXwovkeji9Y1m/G9VP8RMKJaeAPUWTUn9y+MGj3E7AbcBHtYK2i2s+gOzOMLp4mTV5RScYYQjQIgMiCj78SUdMph8cU/hBTxCpQZwKYKTG+FdbFdMip6dI925YpPtMLyHzq9Ts1aUYRycxU0oAhrPoy+fbBFiEhW2/4as2Wchc3jppih8El8u7IENTpIBn9w89R/t3Mo3AfHnnLCMdukAuLAAgA0M+wUOEy0N3magRsvGJ5QFzDXGiPa+XnNUk3sw== 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=eoXFYLxyn89pEiIdnnebivPOBHzu3rBSGjAxsggIL6A=; b=hdLjdHcOZ2KzIrR/7d57EsMSmNTqUxJkHLSnfzRBV8P2OOFlSlTNZhIiNIeFLUge15w2+8yaCyD2ZZDu8GVQ24vaOCpAOxzoh8cJZOfc6/vrVrT9lcbW8diQB8PtRdG7E6D3SJRAT0ZHVyk6Tfgy43+CALqfZNP6DkN8XuyD5Xw= Received: from MW4PR04CA0124.namprd04.prod.outlook.com (2603:10b6:303:84::9) by IA0PR12MB8373.namprd12.prod.outlook.com (2603:10b6:208:40d::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6134.25; Tue, 28 Feb 2023 04:52:03 +0000 Received: from CO1NAM11FT058.eop-nam11.prod.protection.outlook.com (2603:10b6:303:84:cafe::4e) by MW4PR04CA0124.outlook.office365.com (2603:10b6:303:84::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6134.30 via Frontend Transport; Tue, 28 Feb 2023 04:52:03 +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 CO1NAM11FT058.mail.protection.outlook.com (10.13.174.164) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6156.12 via Frontend Transport; Tue, 28 Feb 2023 04:52:02 +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; Mon, 27 Feb 2023 22:51:38 -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 V3 3/4] sched/numa: implement access PID reset logic Date: Tue, 28 Feb 2023 10:20:21 +0530 Message-ID: <235721608c912cc6c8983c22f11b145606d360d5.1677557481.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: CO1NAM11FT058:EE_|IA0PR12MB8373:EE_ X-MS-Office365-Filtering-Correlation-Id: b6a639e2-0ff8-41db-ad18-08db194788c2 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: DwYGdgEPyZA8HRJd2TXs8HjbIve82CeXVpa/xJSvAgokHVojS/mAUcWqUzzC1kSVQpv/Mn00baOum6QInWtRbmVVck6BuDTZjPa+SO6W9KxVZDjiYi50Rb8fH65/bnTUIhIrLut8UHhwO1COYbqpgw6/IVHVa0or7m3fOdXBNnGCyQk0kYh02fBGsvjom0i0XuLsJw4lmaS4mZp7oPLy6R5fgpJX3A+hOFETqeIC+pNLhKTdf5tkbxW/bxW9iIIxbyTCEcHe5EfMFksEJFBYvbsijn7bCqRM2+t/ooZ96kMPyQBAk8AU4TRukOes5EXENGmfhWG6Vr6IXQAlGldpdY617A9RvjnzfJAjETrLzGE/PXu7rmAi6GqkAB7J4TDVZhxAU2UTPPeg+mPTdhlks/FcfL8FlLC3dSGt6AxQ+kf0S4QQWpfsshRFJQ3G/NUBN4XIZj9NWqFkJBy0xpGOKVEdczksKpqjOIaZnxe3W1DmOXb8r2s54htKJXKWaXHVJWo+B2It9p/n6tEUe90UZOUZeObSpW2jxQ9/+EI1PORotJ2mSSkVi27xYPTJo5H73dy63l/itX6v8i1DJ5eHHjxihwJUajL2Si6cZaII4uEl/g+LAmAmrmTpKcdVbxrEtV2PoQernkBTHXEpNp/lsyiCYXIftaTE/rVLcjL9MgXKEx+E507xw3pX5OoP3G0BcVPF2qjO4AW500YPCz7xkk8eD1E1p+6BSIQcMXrZTuEQIUD56gy0DbVxYUgoYvAl 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)(396003)(376002)(136003)(451199018)(36840700001)(46966006)(40470700004)(110136005)(316002)(83380400001)(36756003)(82310400005)(54906003)(16526019)(40460700003)(8676002)(36860700001)(5660300002)(2906002)(4326008)(70586007)(41300700001)(70206006)(478600001)(426003)(2616005)(6666004)(26005)(47076005)(186003)(40480700001)(336012)(7696005)(81166007)(356005)(8936002)(82740400003)(36900700001)(2101003);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Feb 2023 04:52:02.9483 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: b6a639e2-0ff8-41db-ad18-08db194788c2 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: CO1NAM11FT058.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA0PR12MB8373 X-Rspamd-Queue-Id: B201640010 X-Stat-Signature: w4z7feg9wan6hhjcbsfgz7mqfnwmu3ga X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1677559926-992190 X-HE-Meta: U2FsdGVkX19tl3iB2GCrabbwxDJ+n7Z+eqALcmCzOpVOXZ5ybe8rWksWrFMPpmhyxALSkCZYV7XfeEbnG3hpi6XFKKaUwzmMJqCwMA+Gw601g6juJcsNtTSY61OLWA4xEwg2f9Uz7DQdPL+wc9iGEm/wgBVkLHyTry0siblHbny8H0fAEbjooqUoaJIf2KfxdTMYeuAm3lpq4sNj42Q0Y72vn1l+QsEui5jv+Bd9mgD0YgGWxOPKuf8NrdiVSXC6PUXINSNXQLb8pXxu68zx2XqRgOWU0RGF/DjCniOWxvxnl5ppM6cB088ihjbHBbDgmILSxjbR+L4i4faWsfpIIxr168lp/FEOiLO6iiEe0BDnu8cp8rS02Y8pgGJi1LXGo2yk9Ghh60fGJoq/Lwf51eZE3dqgucV/FleD3yyNls8YwMjjx1J9+xX2avmEA7vygum8mFOd6tkgvpkMtR0xBJOscxJ9jXxklqTksVzetILeUr0b2SeZBr4Q7E63aBVnPQbJ5I27O1AnZFL1zAdJu/9IjbHK32XbMfvJWTvIfbJ9CdXGaRnmhIka4jwHdBpofRAXFtRe7ZjeaKINkTFHlzRlomDl8ziNBrSfIZcLGywgiqMEHXMQnALaeYZRENUneV+zcN28h1mO4kGZMcOQfbhujmKWdRjASbPaRMjUldia+OXCQJpiCfGUtBFUqBSNqFZsjoZ2yTfCzaf9FWuXK/Le6eBCmzrLMwCJlsvUfXwGLU3wlQpLaotEjQgDcLgaWUwraiEsXxQjA8qIPjCmKMS9aHHYsk+hXXwGrDlzb/Mh/D9rgWRU3Tq4EccUttrDF2cZ95PgZn8vHBRbi63l3K3gnBVhiY3sTy9WzWF6vVshmYokfo9VQh6rnSpf/6WN25jO/2DjQ1hSzd9tymsdtoEEt6/enxkR8kuiwRLLSUvNPL95SAbK49aMzZafviyoAI7Vxn68jfSuuEkN440 ci0O7pZO ep99xGBcnJr3uxjiOeguRWJi8hqvJceWhs9rIlaYmM9G75hLDQ9e1jWAlVhHcR2u0Tl1x1dJBf6DRru2Eeahd55nGtmuuj2Rq2wX3f9nEXfdrFQRrY2mD1uCxDvRr1HWVuZd/cbcewBqbKpa/gfvPsgCm7vSrL4Sf1Z+eMAyQH6eqTq21FUJsvo6WtfFx1zrN8swhXWcSVvxd22pbznGCj+6+J0hoMVbm8wd+49O8o+viwU+1nLUAehUbHbug+gqZkLOfTxarX5Xs3CAGQ7WlkMdF5dXTzSE680FiJUwfuOeTZFDDlMKVuPn2zP4+bieboq/Xi1FfLZa88uniwoXAJIsNunAugnx37mtxSjgK7tzslHZ10BUcmtjmqFmpnIgkAKA5zF1CNOMCi0B31B6tf9xE1lHxy0NmHBcz2yxsX24mEDyg0ZRHc8yg7FsS2beolFyCj9A+AATy24JIWIriULXP79RZvkHqqUowBrlLTUG4UscsotcdA9zQ5Vs7PPSfPP/z0ZDSMYZpE5krMxrHEc2oXpZtI8x2RAttl1zHriap+2xqxItryXW1PWpqdugc3Vkfwva3P1A81E8= 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 097680aaca1e..bd07289fc68e 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -1394,8 +1394,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 582523e73546..1f1f8bfeae36 100644 --- a/include/linux/mm_types.h +++ b/include/linux/mm_types.h @@ -437,7 +437,8 @@ struct anon_vma_name { 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 05490cb2d5c6..f76d5ecaf345 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -2918,6 +2918,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. @@ -2927,10 +2928,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(). @@ -3039,6 +3042,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); } /* @@ -3053,6 +3060,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 Tue Feb 28 04:50:22 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: 13154414 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 7DD72C64ED6 for ; Tue, 28 Feb 2023 04:52:10 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1B85F6B007D; Mon, 27 Feb 2023 23:52:10 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 1198B6B007E; Mon, 27 Feb 2023 23:52:10 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id EFC8B6B0081; Mon, 27 Feb 2023 23:52:09 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id DCA7A6B007D for ; Mon, 27 Feb 2023 23:52:09 -0500 (EST) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id A48424102E for ; Tue, 28 Feb 2023 04:52:09 +0000 (UTC) X-FDA: 80515478778.24.68F93EA Received: from NAM11-DM6-obe.outbound.protection.outlook.com (mail-dm6nam11on2061.outbound.protection.outlook.com [40.107.223.61]) by imf10.hostedemail.com (Postfix) with ESMTP id ACEBCC0004 for ; Tue, 28 Feb 2023 04:52:06 +0000 (UTC) Authentication-Results: imf10.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b=yAbA61ni; spf=pass (imf10.hostedemail.com: domain of Raghavendra.KodsaraThimmappa@amd.com designates 40.107.223.61 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=1677559926; 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=SG2lHw9tThuBVkRk5qf4n/6XlYiRv6aTMt+qRf5ht6w=; b=Cg8FA2RNoR7LwsCH/zPBy4aFNdmhXIWaB/38Fsgz3fEyQVF3jS/Mf/92WVbW/QilzpJNtI iqmR/6mEegpJzfwEUz6wbzrVkjQ2EPHijtZSBDq9x/IwUOurk7UlIwPATqb6nNyCN/ZyTd f8aSki4cjNS3Tgn2PgWde/o4dSuyz0I= ARC-Authentication-Results: i=2; imf10.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b=yAbA61ni; spf=pass (imf10.hostedemail.com: domain of Raghavendra.KodsaraThimmappa@amd.com designates 40.107.223.61 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=1677559926; a=rsa-sha256; cv=pass; b=NsLqqBGDBGQ6nAZg0L/vIxTMRXPAvyzhme+gMvc1XIi4zGvpHcyHBfBDSaF6RbiO6GywyQ 86Hgt+6IzvViwHWWtnsTjRCeZVKNaqk2wfa+ezKLTMlB976dX+ASp+FpckyDDBC7y9VZAH ZtBf3WLOqpykit6EHpdWIQe5Rv2tvuA= ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=JmqpFNshiSVeEv/u567UxBnNzKKEGwJgoSeqQ5Sd1rjWeTW+rQEBC1+kW451bEqumd9Rcp9XsXRwQDYLAimNrBWLHkCb5Kt5QcJH5s3OM+cWhCjlyFqYQXB7Ez/dXWiAx3G8jNLPxyFbNOEv/+7Fs3nA660meKH/AsyYRzVRoupPx0Eagmprqx+FjX19oeGdAjskozaG/P0Cn5Kh+ThsRNb5A5l55mM5xNAw42n1EeCRUxMXqm1E3xAe62Uj0Vq4uKb7bGXGbcOnhn3QaThXFd3cPVB/OhF0zZVQjJglCp0S76GmKesLTzjwyXRcnom7y0utq9KuoKBt9f12ydhGjQ== 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=SG2lHw9tThuBVkRk5qf4n/6XlYiRv6aTMt+qRf5ht6w=; b=Rm+L0/yhwwv/Z94Ke0bmmJ/1YPrrAFAlGcvtFux3pPFb38IvgiqPwMGIN6bHIeOR1VdMjOJURAtoMdoLe27+7Nq6D1np3hxWtX+OZ+//efcvO1hobtskCLdv0FdGxPZXqiJP4X8NKAjptERz4zupYKnZiEx8/bgE5L4lyTI7x0Ep+gNNS1cDpbMuAxUGNfUPSYcnmWr77agH+Zwq3oaPzWUv4HI0QH0TohNlrNNkuS9+lPLwULvFR3ij3gLTGYpM4FWpQ4NI9011EiYXDxCETvjSCshvSUjSyw6HiuU0uXCsoIZCp3IkvHYtJvyHB1mQD+Z6cRVuL+dDuDU+lq2Znw== 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=SG2lHw9tThuBVkRk5qf4n/6XlYiRv6aTMt+qRf5ht6w=; b=yAbA61niMue5WbxwrdtMSrdqQVXpLkz3+D/Qmlo8f8noaskmcykMHrU2eM2pzPCWWpa+pUzrhKNbg00iWNS4Q71o0O0IrN1pMNQ3gUss1tLAPpUZsZ/Av8z4gC38m2NP7mw4SErXagek8CcuXIE80kkEmr19Dp0N4/yxNgDjen0= Received: from MW2PR2101CA0034.namprd21.prod.outlook.com (2603:10b6:302:1::47) by MN0PR12MB5908.namprd12.prod.outlook.com (2603:10b6:208:37c::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6134.28; Tue, 28 Feb 2023 04:52:03 +0000 Received: from CO1NAM11FT024.eop-nam11.prod.protection.outlook.com (2603:10b6:302:1:cafe::c8) by MW2PR2101CA0034.outlook.office365.com (2603:10b6:302:1::47) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6086.5 via Frontend Transport; Tue, 28 Feb 2023 04:52:03 +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 CO1NAM11FT024.mail.protection.outlook.com (10.13.174.162) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6156.17 via Frontend Transport; Tue, 28 Feb 2023 04:52:02 +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; Mon, 27 Feb 2023 22:51:59 -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 V3 4/4] sched/numa: Use hash_32 to mix up PIDs accessing VMA Date: Tue, 28 Feb 2023 10:20:22 +0530 Message-ID: <1fe47cde783101152d1fc66fd6411f42184f6de1.1677557481.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: CO1NAM11FT024:EE_|MN0PR12MB5908:EE_ X-MS-Office365-Filtering-Correlation-Id: d29185d0-146f-420a-646d-08db194788c5 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: mmA8oTI/u3aOUyTCrnchsh+nfqJeJHOsYtSuhty3EM0xBVRec3urp5Tpj0xPBaPazyX4gD1DoDCR3hPUqpLXBIcmxi7kJE9qiP9CtplL7XmzjbExQY7QahQK5PGjIw4yfWIvn9BGPY+tQu70qdhD+tZi2qaVz7sKi6fDaN3R9Z1tUdFmCpi7TopiSa4/bLpxb9sglE012Qqr+kvQJONN9hXeknWtHURpECP6UN7YOkzXDGGMsQmiJn1RFqMA32ozOSOMd8Ta4y8wyp5Ovd8p1PQOR+gCZ8GiQFmyrgg8wUGBopmc8LalfCaX3xsqS4qbMODi6cViAc9nFabm12we8E+OO2sIEhbIWc7wtoH6P3sscrknIzyfe5GiJCO+PkpHpKyc6JiCJyuu/E+CHcIo/ZP0Ulhhjlh2e9HhqNwVrFLwNtpryUkOE+F6pBO8SpxiOi6gf/pcNldDVhJ2DAEK2nV02ctDBAUC1wa0szzQ5qHdEM/Z1iTkVnRFRKkRmGbEdb1G6s+ZkasZyvDulmuGfxa+PzRPafnFmq8yAjOf+ulYNFpsHaCRuVzo5K7762OvoHssexl2qPtIDhZavjoNq5+ng3l3QL3GRnLc4IxOz7tWZVVOP78qSzTAqitrBPFjIffbgrcX0jE1oz0NyUdaZA8Gz3TLLLbtif9bE4qUQkAYy3vvYo/tWEUmULBw6Vg5PkbMxWmqwQV5+UNNpHVAnShjP/Q3EDiX4s6SB+eaW6kMX5/AK2ELvm/YI+O8EB0V 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)(39860400002)(346002)(136003)(451199018)(46966006)(40470700004)(36840700001)(40480700001)(2616005)(356005)(316002)(36756003)(54906003)(478600001)(110136005)(40460700003)(7696005)(6666004)(41300700001)(70586007)(70206006)(4326008)(16526019)(26005)(82740400003)(186003)(336012)(8676002)(36860700001)(2906002)(426003)(8936002)(47076005)(83380400001)(81166007)(5660300002)(82310400005)(2101003)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Feb 2023 04:52:02.9661 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: d29185d0-146f-420a-646d-08db194788c5 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: CO1NAM11FT024.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN0PR12MB5908 X-Rspamd-Queue-Id: ACEBCC0004 X-Stat-Signature: uedt7drkzbgd451puxo3ghgwywzxddo7 X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1677559926-759492 X-HE-Meta: U2FsdGVkX1/mp4tmUZSdZmPfh7g9WYw4wkMRQLoRJYABw/l3wdxKO9uGoUhOMwZUiqsyUZXlAR4xuFn5BMcqLXgqIGZKfg1N4kP45xvU0bYzr4+6yWc7CBGAzZ175YEFb2cap51BqcIRNxeQBdryEIzA34QgqHnTFnKZQtnICr0r4O7RlLfKsn+7U6UvF2FagE2Fb9WIrVe9QptgSqWyDZZ/yMEGekWt2qOCeo0E6+c2rKDirmTgCWvtzv2SxR8bR9S6MGWXhjnqvNiKQG3D5nStLz6rcE73P537sbAf4kg871wjRNrIrsHiXWp2kaXroBKihbpd80HxozQulqkrI68+fq2fn2tlmts4JE8QJTyzi51on1teOgfeIpFsuF3NA3YozcuwYqwphZ4fS5nOh0V99sXcnCwn5MvGsp8HldQSvPZKbqbsqvf1qWaahokBhMu7lvdqaKwmXEx6K3sr11ORHGSEoOxce1yjt5O9dY6YWnR/BYlMt8nNDGt4RKyx+r1GSSiMMeQNyYWveKcA1dL6WFER8qCc1M09rKs56MM6IPAspJH6XCQcZKCtGZNleFz50E2MEZB1r77mZZM8bSXFsmd16GEpxe28B6mfzCYuUFadmA9aa39zFsPoEwXZYPK0bCpyP+NhBuhe+9kXj9ukO0C5WmKA9hbFD4M4NI2mJAH6sEcI1k1WQ+G6jOK8emVz3PtzmU+mZ1ezWv5PuETrKZ7aWIGzMXQ9eWTbu/3v4NCs2VCrRLq30CPe94uOaGOLw8gJR/kZdPIhnvCjdiRMcOF9RD2m91PYh3tJSQ447RRGEiw5eO8r+YiaaoVD5rTVz49d/QsL7DlXlVHIClTl2PxyQa+SGjk5rSu8l0iGL1cemyM/vjuf9TQUAy4l140UIcK1dRA+h/RnDINoLNRw636dmrXXDHNPqduRtgbg6voPOunZNuDq5Lk7b7bQ/Frgmg2RGd6lmWtLkkw M4oYWYuP tYI/Grb3lSRj4OYPb8AaPhs9MhV/r+QsQE6LMDMKLlpYAEGfF8tKm28R+mD9gUXZAWgbFGIjBIV7demcmCSwKOX0EgAfk3zhU6Jp5L/Nm9My7qsoWdSeQ8lGHN2+itOaM9pkorxRKTm+m0RmxJ0RFjIzcnsmwREFL9X2VlyrP2X+HG6H5vayDVlcp0deP9hF8ZufOmsBVHMZUsR7jtNucF2yCc9fIhMiF1XUkTwxIyZMbZanGtYQUqDeGqH0svHuCLijh7igCMrUKb9mu3UHksHqYKGlMW8oNN49NcAVB3e+jB5M9SB4JfBhoMOunbLFGdrSIF+IbnUmIQNd3Ed4/EgSa73zM5LslNrWnGlutDK/XP/UTG0XWXYi43ZfOPWHlRpIM45ObTyrT+c/2sCypj7FDc0eI8dOLEvH9fwzc9EFgpnbERW4ZTAout27YmpZjsor7ToDe3UNiDAZws78m4xz779GLZ4S41sz7sFoyryoCoaMbnNoKfaalh4+Vd7/1nQpX19gYqAlSCROqfoP9LczQRILNMlLKbXgFaOdL6F+NowowPRyvgQa2dgxkRdAizRdQpoLITRjxZgFCMSk9Gy/u758w1kz7ClP0e79MaFsunEgmY722APe3Mw== 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 by a huge margin. Kernbench anbd dbench showed around 5% improvement and system time in mmtest autonuma showed 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 bd07289fc68e..8493697d1dce 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -1393,7 +1393,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 f76d5ecaf345..46fd9b372e4c 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -2929,7 +2929,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)