From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from canpmsgout12.his.huawei.com (canpmsgout12.his.huawei.com [113.46.200.227]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9DD1C37B019 for ; Tue, 14 Jul 2026 02:22:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=113.46.200.227 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783995784; cv=none; b=li+e+YIbiHjZZpRWL3OujYMiLgCigWJTkapiBgwBtNu6Cv+UNevSzWS+7SBQV5mHt/h9TdNtEv4DbkhaJxL7fnanQ525o+l9soPiLhKD2dtZIi9s6Yejlc/EaG3JEkAHnh6CDqBvbH/+5gK76/qRFKgZOj1IdOCIBO8CEXCwsco= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783995784; c=relaxed/simple; bh=jVMi1QjJKGiGMexe8czQUWjPUe4ODKr0+CUIIKXYttc=; h=Message-ID:Date:MIME-Version:Subject:To:CC:References:From: In-Reply-To:Content-Type; b=K7/t1SKGW+sfVaIe6S+bxpEd+kXxD1Cs8+QrHYqi7Lnx71dM+exFF9GR+Mhj9Z9gXsthNFM9q3+ogBZey33YhKkoOnEMNoSazqh0BUZNfXz+ZuN48Pv5bZU8HtaXkNi68nh7PEi5VReyXGCfiBQcncGZbM5YYw70seGJyQk7Ln4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; dkim=pass (1024-bit key) header.d=huawei.com header.i=@huawei.com header.b=wQ9p3G32; arc=none smtp.client-ip=113.46.200.227 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=huawei.com header.i=@huawei.com header.b="wQ9p3G32" dkim-signature: v=1; a=rsa-sha256; d=huawei.com; s=dkim; c=relaxed/relaxed; q=dns/txt; h=From; bh=t++5fpwDK59j0lGC8eCYu29LSCmjROqzT83sJeysBDM=; b=wQ9p3G32iq9YrOsb0FOwTB/tnMsTRrA5dGtyE/IOPJDuQ2HKe4zSIut1AsWNRP8vc/QSs0y+2 kNZefWvazKnR75wIlKChrpVjkjolh1maa4twHtDwyUVb/9aUTZiZ8T+MHxNKDHahiLFeFm2zzRE MvBXCJh18RxDY08dUwKpUYU= Received: from mail.maildlp.com (unknown [172.19.163.163]) by canpmsgout12.his.huawei.com (SkyGuard) with ESMTPS id 4gzjWv0kKnznTtT; Tue, 14 Jul 2026 10:13:15 +0800 (CST) Received: from kwepemj100017.china.huawei.com (unknown [7.202.194.11]) by mail.maildlp.com (Postfix) with ESMTPS id 0B7674057A; Tue, 14 Jul 2026 10:22:51 +0800 (CST) Received: from [10.67.108.244] (10.67.108.244) by kwepemj100017.china.huawei.com (7.202.194.11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.36; Tue, 14 Jul 2026 10:22:50 +0800 Message-ID: Date: Tue, 14 Jul 2026 10:22:49 +0800 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v5 1/2] sched/cache: Reduce the overhead of task_cache_work by only scan the visisted cpus To: "Chen, Yu C" CC: , , , , , , , , , , , , "chen.yu@linux.dev" References: <20260709130053.2749834-1-luogengkun2@huawei.com> <20260709130053.2749834-2-luogengkun2@huawei.com> Content-Language: en-US From: Luo Gengkun In-Reply-To: Content-Type: text/plain; charset="UTF-8"; format=flowed Content-Transfer-Encoding: 8bit X-ClientProxiedBy: kwepems500002.china.huawei.com (7.221.188.17) To kwepemj100017.china.huawei.com (7.202.194.11) On 2026/7/9 23:01, Chen, Yu C wrote: > Hi Gengkun, > > thanks for the update, > > On 7/9/2026 9:00 PM, Luo Gengkun wrote: > >> +static unsigned long fraction_mm_sched(int cpu, >> +                       struct mm_struct *mm) >>   { >> +    struct sched_cache_time *pcpu_sched = >> +        per_cpu_ptr(mm->sc_stat.pcpu_sched, cpu); >> +    struct rq *rq = cpu_rq(cpu); >> + >>       guard(raw_spinlock_irqsave)(&rq->cpu_epoch_lock); >> +    /* Skip the rq that has not been hit for a long time */ >> +    if ((rq->cpu_epoch - pcpu_sched->epoch_timeout) > llc_epoch_affinity_timeout) { >> +        cpumask_clear_cpu(cpu, &mm->sc_stat.visited_cpus); >> +        return 0; >> +    } >> + > > I was wondering if there is a race condition in the scenario > above: If the rq has just updated its cpu_epoch field, and the > CPU subsequently remains idle, then rq->cpu_epoch stays unchanged. > That is to say, a race could occur as follows: if CPU1 becomes idle, > CPU2's task_cache_work() might compute > rq->cpu_epoch - pcpu_sched->epoch_timeout == 0 and consequently fail > to clear CPU1 from visit_cpus. > > CPU_1                                     CPU_2 > ------------------------------------      --------------------------------- > account_mm_sched(rq_X) >   set CPU1 in visited_cpus > > > (idle: fair task runs here, >  CPU1.cpu_epoch frozen afterwards, >  pcpu_sched->epoch_timeout = CPU1.epoch) >                                           fraction_mm_sched() >                                             CPU1->cpu_epoch - pcpu_sched->epoch_timeout = 0 >                                             -> bit CPU1 not cleared >                                             __update_mm_sched() ->update cpu_epoch, too late > I wonder if we should let __update_mm_sched() be invoked before > if ((rq->cpu_epoch - pcpu_sched->epoch_timeout) > llc_epoch_affinity_timeout)? Thanks, I will fix it. > > BTW, in your test data: > sched_cache_scan: comm=redis-server pid=24660 scan=384 > Is it because NUMA balancing is disabled on your platform that it has > to scan all the CPUs? It would be helpful to know what the result would > be with NUMA balancing enabled. The following tests were conducted based on the fixed version. It appears that the --mbind parameter in numactl causes NUMA balancing to fail, so the following test only includes the --cpunodebind parameter. When NUMA balancing is disabled: valkey-benchmark rps | baseline | schedcache | schedcache_visit | (no cache aware) | (without this series) | (with this series) ----------------------+---------------------+---------------------+-----------+-------------------+-------- | p99 latency(ms) | p99 latency(ms) | DIFF(%) | p99 latency(ms) | DIFF(%) 400000 | 0.436 | 0.554 | -25.68% | 0.441 | -1.14% The overhead of task_cache_work is as follows: valkey-benchmark rps | schedcache | schedcache_visit ----------------------+-------------------------------------------+--------------------------------------- 400000 | 0.81% [kernel] [k] task_cache_work | 0.02% [kernel] [k] task_cache_work When NUMA balancing is enabled: valkey-benchmark rps | baseline | schedcache | schedcache_visit | (no cache aware) | (without this series) | (with this series) ----------------------+---------------------+---------------------+-----------+-------------------+-------- | p99 latency(ms) | p99 latency(ms) | DIFF(%) | p99 latency(ms) | DIFF(%) 400000 | 0.437 | 0.454 | -3.89% | 0.442 | -1.14% The overhead of task_cache_work is as follows: valkey-benchmark rps | schedcache | schedcache_visit ----------------------+-------------------------------------------+--------------------------------------- 400000 | 0.13% [kernel] [k] task_cache_work | 0.03% [kernel] [k] task_cache_work The scan count for schedcache has been reduced to 96. Additionally, I also conducted a test without restricting CPU affinity (no numactl), and the results are as follows: When NUMA balancing is disabled: valkey-benchmark rps | baseline | schedcache | schedcache_visit | (no cache aware) | (without this series) | (with this series) ----------------------+---------------------+---------------------+-----------+-------------------+-------- | p99 latency(ms) | p99 latency(ms) | DIFF(%) | p99 latency(ms) | DIFF(%) 400000 | 0.741 | 0.82 | -10.66% | 0.705 | +4.86% When NUMA balancing is enabled: valkey-benchmark rps | baseline | schedcache | schedcache_visit | (no cache aware) | (without this series) | (with this series) ----------------------+---------------------+---------------------+-----------+-------------------+-------- | p99 latency(ms) | p99 latency(ms) | DIFF(%) | p99 latency(ms) | DIFF(%) 400000 | 0.75 | 0.744 | +0.80% | 0.736 | +1.87% > I found some reports from sashiko here that are worth taking a look at: > https://sashiko.dev/#/patchset/20260709130053.2749834-1-luogengkun2%40huawei.com > Thank you for the reminder. I will fix these issues in the next version. thanks, Gengkun > thanks, > Chenyu > >