From patchwork Fri Dec 13 09:54:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gabriele Monaco X-Patchwork-Id: 13906788 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 2551DE7717D for ; Fri, 13 Dec 2024 09:55:29 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B6D9D6B0088; Fri, 13 Dec 2024 04:55:28 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id B1DB16B0089; Fri, 13 Dec 2024 04:55:28 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9E54D6B008A; Fri, 13 Dec 2024 04:55:28 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 7EE366B0088 for ; Fri, 13 Dec 2024 04:55:28 -0500 (EST) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 2B282AECAA for ; Fri, 13 Dec 2024 09:55:28 +0000 (UTC) X-FDA: 82889477580.12.E86A2D7 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf20.hostedemail.com (Postfix) with ESMTP id B2F511C000A for ; Fri, 13 Dec 2024 09:54:59 +0000 (UTC) Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=CYZwMRSR; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf20.hostedemail.com: domain of gmonaco@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=gmonaco@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1734083714; a=rsa-sha256; cv=none; b=pG/XJRQ2R/fGUMvfbT1EtpdxJzJyOUeDTT8CfCgkrJWUVQGS8V6/sVTQqreSIwMAMGpYRp PJEDBdmFGYaj9lhKRiYFOsJ80uzP9bh1PkNWDlOalOpuCIlgXp+m/XjdCeeSWnc6vayXp5 BQBd/tu0dH36IEEoXUWh7GeDj5GmkzM= ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=CYZwMRSR; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf20.hostedemail.com: domain of gmonaco@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=gmonaco@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1734083714; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=Zoc1rmo1ZxPdELSIwUBxgusiNNtCrVkbWCsaBTVZCO8=; b=fZvRHisx6fr6tCyQq0rVS7qZKjPKuiShe1q1iiIvKxIOcFDzX1+Th9fszLSICzsciXcuvh Bs4cKC2aO3vEGFvI8p9UwBU8tm+jOvx1YYNVevpF1WJzzlh7OncA1Yn+sUE/ihRrGFWAaR F/Rgc4709Vlc/zNZZdMFB1VgUTspi78= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1734083725; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Zoc1rmo1ZxPdELSIwUBxgusiNNtCrVkbWCsaBTVZCO8=; b=CYZwMRSRwsqztNd1aIK/aTnQ/SiLVOUDQx5Vc7jlxWH7apg/AXzep+mhZvXa/ReUK/JpWC ADC71xd7TT6MfaVjNXqwQU9InOm4I+Or+gWVoEHYzxgkwt1qSw1W6A7NR9+UILAclkETwm mMMKTu5Rv5f9W1sprdOR8T6eFk+KThc= Received: from mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-515-uVqnbA6wPtKoeuvb26eCFw-1; Fri, 13 Dec 2024 04:55:22 -0500 X-MC-Unique: uVqnbA6wPtKoeuvb26eCFw-1 X-Mimecast-MFC-AGG-ID: uVqnbA6wPtKoeuvb26eCFw Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id C8A721955BFE; Fri, 13 Dec 2024 09:55:20 +0000 (UTC) Received: from gmonaco-thinkpadt14gen3.rmtit.com (unknown [10.39.192.43]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 6B19E1953951; Fri, 13 Dec 2024 09:55:16 +0000 (UTC) From: Gabriele Monaco To: Mathieu Desnoyers , Ingo Molnar , Peter Zijlstra , Andrew Morton , linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: Juri Lelli , Vincent Guittot , Mel Gorman , Shuah Khan , linux-kselftest@vger.kernel.org, Gabriele Monaco Subject: [PATCH v2 2/4] sched: Remove mm_cid_next_scan as obsolete Date: Fri, 13 Dec 2024 10:54:05 +0100 Message-ID: <20241213095407.271357-3-gmonaco@redhat.com> In-Reply-To: <20241213095407.271357-1-gmonaco@redhat.com> References: <20241213095407.271357-1-gmonaco@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 X-Rspam-User: X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: B2F511C000A X-Stat-Signature: 6bgqwwhw7em5cdacrg33r9yx6u9c8mam X-HE-Tag: 1734083699-307731 X-HE-Meta: U2FsdGVkX1+fIqJGPIvHwi/duh9WekG8OXBLdvf5au1igDHwcJzldAdxJdzfWL4/GxE6lt9e1jjsjG01lKqw5/SZ9RQRDnp/NnGKoEbs4ixShi1Ewzgb6J8DbfZQhK0w1qhrQ9sZDHWLU7QN983gbCXY5+SQcvIEQqE23ziF4WEhTs/y+EPEMkTANP/ANS9J2E9l4gT+rgXaKdk2BMr6ljf9hqcL9eWbvyBWGCu6uympysaN9q3xMd5yTm9QCIr47wgnca1OAkzkPjiidpF8iZc9OUmEleQ3CioeJTkTGGMX4swP9KJ276Ei71JDwdKd3TKCbh4I9wvZcCr6AAJwY6gO+FqtYi504IYioPFuYrR/nwnC0z6U7xvTXGFv5Hy4f/IqsF1oM9bYebp2oUOP0S1TBRD4SEeYPn9UpZ/ggbz8KFDqMduUUmm5otq5MFOUl1FShl7mQi6Z/pAjuc2mDK+iqeTs8wm++BDatuhHjB/gMx8s8hefnFBsW7XiuD/usADmzfxlbC1xhzPSv8zXr9zhVGC5QOxzQykWiegN394F0DhMCEOm5bQethoIVkEY0wR04rcPN0qQYj4YzMtAzIOmumDkyVwLncxPGQc9HDPyoWEf+1dpDmmrKtrXinvTlSHxpne82cyDA+cyKOLTDXG4b5tIbkUd/6KpLyCMvxl0mAS6oDl6UZx58cC51r5PJq84vMFI7IZW/nSQIegiE/KwCqrfmWQXr/46f+VTeLTIwxnzb/y0bDG4K3Ij3sJaS1cD2N5ZqwaHOW5FhCdRa6WbsBRznfVS3hK73Y2jsrsA5nbP8YsrKI7AkM4dcR24t0nAiAkrBVmOCxFfpaEa5mTApvhYnwMnjJ2uvh7k86WJv6bU+PG21CFxCEL44w/eDVicleawRAfE4x+5EzsDW4jXfHncQ2OQ8vN8YtjOJ5NQ6J87oNh8RRteETNpFpZvkklcZql1EjghL+uRYXP KcQT5YMx yT89NBtCoIR8KCo+bgX89ydVX56bTE2pvn5VhkNjI8eNV2r4zJzW07d6Cg+Mgwi65gtfpVl08kCZzmVnairqvb82CoxsnOJQcvQ67ADn9y//dDRGUTDPo8jqtQM5eLeK6yJT3gC09PReafAuLEqybbY3bczmxUTbbdUffZE7kW3W0ascoX5FtcymPQWu/c0x2dEneKfKixO3eX3I3TnlR7vuAPBp1LYazcoO+UlMjeWnX2o6T4Aj0Q9EGIdr2Ko2Tkzfa6pgG+1AjlNhVvx1Oj/l+R7aykf9hqTLxOyfUmLT27XOr+lHPZcLsjyGvWUo2Um66U8CMd41WjLSiEjxlEM8GK4mKAHUFSg9f25JNERBreSVmT6Y7Oh7xMb2EPu9CjzK9vNuwHUTGrJvQnc8xE6IQcg== 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: List-Subscribe: List-Unsubscribe: The checks for the scan time in task_mm_cid_work are now superfluous since the task runs in a delayed_work and the minimum periodicity is already implied. This patch removes those checks and the field from the mm_struct. Additionally, we include a simple check to quickly terminate the function if we have no work to be done (i.e. no mm_cid is allocated). This is helpful for tasks that sleep for a long time, but also for terminated task. We are no longer following the process' state, hence the function continues to run after a process terminates but before its mm is freed. Signed-off-by: Gabriele Monaco --- include/linux/mm_types.h | 7 ------- kernel/sched/core.c | 19 +++---------------- 2 files changed, 3 insertions(+), 23 deletions(-) diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h index 92acb827fee4..8a76a1c09234 100644 --- a/include/linux/mm_types.h +++ b/include/linux/mm_types.h @@ -829,12 +829,6 @@ struct mm_struct { * runqueue locks. */ struct mm_cid __percpu *pcpu_cid; - /* - * @mm_cid_next_scan: Next mm_cid scan (in jiffies). - * - * When the next mm_cid scan is due (in jiffies). - */ - unsigned long mm_cid_next_scan; /** * @nr_cpus_allowed: Number of CPUs allowed for mm. * @@ -1228,7 +1222,6 @@ static inline int mm_alloc_cid_noprof(struct mm_struct *mm, struct task_struct * return -ENOMEM; mm_init_cid(mm, p); INIT_DELAYED_WORK(&mm->mm_cid_work, task_mm_cid_work); - mm->mm_cid_next_scan = jiffies + msecs_to_jiffies(MM_CID_SCAN_DELAY); schedule_delayed_work(&mm->mm_cid_work, msecs_to_jiffies(MM_CID_SCAN_DELAY)); return 0; diff --git a/kernel/sched/core.c b/kernel/sched/core.c index e3b27b73301c..30d78fe14eff 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -10520,28 +10520,15 @@ static void sched_mm_cid_remote_clear_weight(struct mm_struct *mm, int cpu, void task_mm_cid_work(struct work_struct *work) { - unsigned long now = jiffies, old_scan, next_scan; struct cpumask *cidmask; struct delayed_work *delayed_work = container_of(work, struct delayed_work, work); struct mm_struct *mm = container_of(delayed_work, struct mm_struct, mm_cid_work); int weight, cpu; - old_scan = READ_ONCE(mm->mm_cid_next_scan); - next_scan = now + msecs_to_jiffies(MM_CID_SCAN_DELAY); - if (!old_scan) { - unsigned long res; - - res = cmpxchg(&mm->mm_cid_next_scan, old_scan, next_scan); - if (res != old_scan) - old_scan = res; - else - old_scan = next_scan; - } - if (time_before(now, old_scan)) - goto out; - if (!try_cmpxchg(&mm->mm_cid_next_scan, &old_scan, next_scan)) - goto out; cidmask = mm_cidmask(mm); + /* Nothing to clear for now */ + if (cpumask_empty(cidmask)) + goto out; /* Clear cids that were not recently used. */ for_each_possible_cpu(cpu) sched_mm_cid_remote_clear_old(mm, cpu);