From mboxrd@z Thu Jan 1 00:00:00 1970 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 35971C004D4 for ; Thu, 19 Jan 2023 09:39:57 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A196C6B0072; Thu, 19 Jan 2023 04:39:56 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 9C9906B0073; Thu, 19 Jan 2023 04:39:56 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 891066B0074; Thu, 19 Jan 2023 04:39:56 -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 762E36B0072 for ; Thu, 19 Jan 2023 04:39:56 -0500 (EST) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 3C6F81201D9 for ; Thu, 19 Jan 2023 09:39:56 +0000 (UTC) X-FDA: 80371051992.03.FF3C681 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf16.hostedemail.com (Postfix) with ESMTP id 9C5E0180015 for ; Thu, 19 Jan 2023 09:39:54 +0000 (UTC) Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=ZYHsHP0M; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf16.hostedemail.com: domain of rppt@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=rppt@kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1674121194; 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: in-reply-to:in-reply-to:references:references:dkim-signature; bh=mslv0fxr9nEkPGIfKsWVw4Xlb5pR4B+c4PowZ0zLql8=; b=QPpcpD/+p73Q1WdXwpFatsEz4x3I+M4ej6KgdnOxfQu0ATWkPJBgMxvck/li/Ox+D35kdT PwlLnIpgApTV757oRGAO8bOn1W6HvlXctDvlu2S/K8tCvdG0rJRTrbLy9bsxSfOkxDaE33 KPimRi2bqu6zUfX8d01OTJAtSImDuq0= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=ZYHsHP0M; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf16.hostedemail.com: domain of rppt@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=rppt@kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1674121194; a=rsa-sha256; cv=none; b=4D4B07OPi6G4wMQuo6gnPFE7RR4gMaHR2ox9GbWAqxU+bjpZyzNCRP69zxeZPLIaThSXEd vH8QasJWOhbp8dxUXT2KV+o5vWk7uJmHo8XSrtJPlv7tmEhr804cU2r5mZnJnz021QO5GG +c3I2OZKWM2Lz8mP7RZOVtHUPh8d2MY= Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 8E1BC61382; Thu, 19 Jan 2023 09:39:53 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A0AE5C433EF; Thu, 19 Jan 2023 09:39:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1674121193; bh=oC4rK1vElis6p5UZEhMNSBbWkHGAXkm0JBiBL1EnbyM=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=ZYHsHP0Mmss5O6jrrdgh9VRP8MrCsP4GP6MitJFyW3HxUxoxwifctz8cD/uLuqokI 4ZfSATGVdLbN6QJ4z4tGVHPFqavkPJvqZi6a8M1EuoX4qUs43djPluB+n0UXv8MDNa 4ZDxkNTYWKED8vb1JLuDXOuLz87reKSzKPBrQe1iXDKDtRIyiN8ogm4nGMy06cr9/Y teXR1sKxx2QhLAuGwmyMo89vNXBeNpcKUXVbn2Wwo6ueZuATmNEajDnt0pInCC3oR3 yWlZCKewxkMonojOO5ht0RGTWqLW7joTDrNLW39TOi8zzERCrydbEaSLlO6A/ZvmMr s9dUJtvVqJfcg== Date: Thu, 19 Jan 2023 11:39:36 +0200 From: Mike Rapoport To: Raghavendra K T Cc: = , linux-mm@kvack.org, --cc=Ingo Molnar , Peter Zijlstra , Juri Lelli , Vincent Guittot , Dietmar Eggemann , Steven Rostedt , Ben Segall , Mel Gorman , Daniel Bristot de Oliveira , Valentin Schneider , Andrew Morton , Matthew Wilcox , Vlastimil Babka , "Liam R . Howlett" , Peter Xu , David Hildenbrand , xu xin , Yu Zhao , Colin Cross , Arnd Bergmann , Hugh Dickins , Bharata B Rao , Disha Talreja Subject: Re: [RFC PATCH V1 1/1] sched/numa: Enhance vma scanning logic Message-ID: References: <67bf778d592c39d02444825c416c2ed11d2ef4b2.1673610485.git.raghavendra.kt@amd.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <67bf778d592c39d02444825c416c2ed11d2ef4b2.1673610485.git.raghavendra.kt@amd.com> X-Rspam-User: X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: 9C5E0180015 X-Stat-Signature: iour9zdtcgcodri57qq379qeztn6jr8i X-HE-Tag: 1674121194-659726 X-HE-Meta: U2FsdGVkX18F7aSOQa5fa6ZYYZ2iWxuXKzXjCCaip7iwl+bk2lUN1MW6fktA5826uCPSMuqNHbDkGD/FVf4bSmV4W5bwnu2+gQS1Q+KhKk48MHf5Y/oKL4pGGrE/equS8XRdGwRkA3vqYT1l+W3BPmvJAxNluL/pslDVp+zgrrBBA5hNJOCRSvSW+9HbGENStsP3A4NopuSJgD9zWGvyrVYN1zfrxE/2HVBulAVflojEnk0U+/nhcpwrnNU8/mv+XiGvcXqaF6SUa7aDIyV4uWhCie77q99iQ5P98F123Ivw1paih7O0SY7awrCa1CEzVePs/fChZET1KptTX8qkWlUBNT1562aH95xyEKN6rk19NW6i9ElLQKw/F7mnU2rrSVaILTVdphqirMCR2utgUILHe9VuBy5q82PBa2l/E2MDSsPgTryijuDEG6otSx7njndmmbMEHrP+3xF3T+egMcTh+DYMCS083V6oFKav4S69Dd11VlgUrzIOf0en4SY4DUQaW3JdXBtpqPgwhCaRsZLB9IKptb6+mG90KNQdugnJCIjOaE+7ApC4DQid5hhfjKUWmj95F4O12nyhO411X8cM9SPsaUDe/CK72d1Qk9oz5afnWaMYP3g95R1eO7Qb4RYb6iB24MpmwvkahdVgxPapGwR8rWdk3rhq+Pw0986QDhLeJHZhRLiYex6ZYD8wH2CY75hTdh0SWi+so1YO/eweKFWHEplYkj7ZX3Apvz3taTRoAbNGvJM4pKF2gmhulvqr0uK9qgsXlOaAOlulYJHIAcarX+Pc5P3VFnl5O1G/mvdbH9UVH6ecZTlKYgiF2NwJyLGDaHyazAxn3pwSQPL7FMfj7jIaw4uLcrvejsNAkdcjkXH6fJk/pTihDRlpGqlSJIMDzoydagTPuRiD1aGvoI5xKr++1GwT12cR+a7EOykHOMKHUPLLBuykcmNRrNQuQnIZ1dSOEX/P7ZJ L5f7xeHx LNeey6AeLX9wNkXMgAqdVrCwr9UWmdPMrwKKl88mDzUiZt0X7pU668B+Gup96RT51GTYmpjs98E1fuj7+x/kwVz988r9pbYAGYjxDpu7CUOvPocc= 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: Hi, On Mon, Jan 16, 2023 at 07:05:34AM +0530, Raghavendra K T wrote: > During the Numa scanning make sure only relevant vmas of the > tasks are scanned. Please add more detailed description about what are the issues with the current scanning this patch aims to solve. > Logic: > 1) For the first two time allow unconditional scanning of vmas > 2) Store recent 4 unique tasks (last 8bits of PIDs) accessed the vma. > False negetives in case of collison should be fine here. ^ negatives > 3) If more than 4 pids exist assume task indeed accessed vma to > to avoid false negetives > > Co-developed-by: Bharata B Rao > (initial patch to store pid information) > > Suggested-by: Mel Gorman > Signed-off-by: Bharata B Rao > Signed-off-by: Raghavendra K T > --- > include/linux/mm_types.h | 2 ++ > kernel/sched/fair.c | 32 ++++++++++++++++++++++++++++++++ > mm/memory.c | 21 +++++++++++++++++++++ > 3 files changed, 55 insertions(+) > > diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h > index 500e536796ca..07feae37b8e6 100644 > --- a/include/linux/mm_types.h > +++ b/include/linux/mm_types.h > @@ -506,6 +506,8 @@ struct vm_area_struct { > struct mempolicy *vm_policy; /* NUMA policy for the VMA */ > #endif > struct vm_userfaultfd_ctx vm_userfaultfd_ctx; > + unsigned int accessing_pids; > + int next_pid_slot; > } __randomize_layout; > > struct kioctx_table; > diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c > index e4a0b8bd941c..944d2e3b0b3c 100644 > --- a/kernel/sched/fair.c > +++ b/kernel/sched/fair.c > @@ -2916,6 +2916,35 @@ 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) > +{ > + int i; > + bool more_pids_exist; > + unsigned long pid, max_pids; > + unsigned long current_pid = current->pid & LAST__PID_MASK; > + > + max_pids = sizeof(unsigned int) * BITS_PER_BYTE / LAST__PID_SHIFT; > + > + /* By default we assume >= max_pids exist */ > + more_pids_exist = true; > + > + if (READ_ONCE(current->mm->numa_scan_seq) < 2) > + return true; > + > + for (i = 0; i < max_pids; i++) { > + pid = (vma->accessing_pids >> i * LAST__PID_SHIFT) & > + LAST__PID_MASK; > + if (pid == current_pid) > + return true; > + if (pid == 0) { > + more_pids_exist = false; > + break; > + } > + } > + > + return more_pids_exist; > +} > + > /* > * The expensive part of numa migration is done from task_work context. > * Triggered from task_tick_numa(). > @@ -3015,6 +3044,9 @@ static void task_numa_work(struct callback_head *work) > if (!vma_is_accessible(vma)) > continue; > > + 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..fafd78d87a51 100644 > --- a/mm/memory.c > +++ b/mm/memory.c > @@ -4717,7 +4717,28 @@ static vm_fault_t do_numa_page(struct vm_fault *vmf) > pte_t pte, old_pte; > bool was_writable = pte_savedwrite(vmf->orig_pte); > int flags = 0; > + int pid_slot = vma->next_pid_slot; > > + int i; > + unsigned long pid, max_pids; > + unsigned long current_pid = current->pid & LAST__PID_MASK; > + > + max_pids = sizeof(unsigned int) * BITS_PER_BYTE / LAST__PID_SHIFT; > + > + /* Avoid duplicate PID updation */ > + for (i = 0; i < max_pids; i++) { > + pid = (vma->accessing_pids >> i * LAST__PID_SHIFT) & > + LAST__PID_MASK; > + if (pid == current_pid) > + goto skip_update; > + } > + > + vma->next_pid_slot = (++pid_slot) % max_pids; > + vma->accessing_pids &= ~(LAST__PID_MASK << (pid_slot * LAST__PID_SHIFT)); > + vma->accessing_pids |= ((current_pid) << > + (pid_slot * LAST__PID_SHIFT)); > + > +skip_update: > /* > * The "pte" at this point cannot be used safely without > * validation through pte_unmap_same(). It's of NUMA type but > -- > 2.34.1 > > -- Sincerely yours, Mike.