From nobody Sat Sep 26 13:51:50 2026 Received: from mailgw.kylinos.cn (mailgw.kylinos.cn [124.126.103.232]) (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 07E2B35CBD7 for ; Tue, 1 Sep 2026 01:33:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=124.126.103.232 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788226413; cv=none; b=BCnW4poNDciuqk3O0rXLPZ3aq+hAzRWv0/sMca/J7Nj//yUXcXr2/OVEVIJUB0xQ7GqM2wpUR7Z2tkU5zb9DFN0OL/EaDQbMx8JfGeNPRZgEvq/FS9r/+A8Wl5JlXz++k9TdMaH95SMYLY85Z6LfbaZfB3OBpPFFli/rJYFTpYo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788226413; c=relaxed/simple; bh=MVe3fhosTbGp/4ts06944KfXYDttY1ikDT2o/bZl/MI=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=spPoNgrsEn/TBnI7o29mSlylrpagFlGoUkpf7nfl703zNhdkkeGL3icXefgMDO/Kk/v0X8w0ohxdAUy/RNBHScrSzQkH7RZxTVUnNntAq56vfA6ZZeKU6sDgvWhQMqne0W6Z6dI9+v8w+heRXxDxKaz/ouvrMdsgU/o+yK3IRGA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=kylinos.cn; spf=pass smtp.mailfrom=kylinos.cn; arc=none smtp.client-ip=124.126.103.232 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=kylinos.cn Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=kylinos.cn X-UUID: 1da4fcd0a5a511f19a56ed5b684f684d-20260901 X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.3.19,REQID:169f227e-99b4-4206-80db-e0307f73e229,IP:0,U RL:0,TC:0,Content:-25,EDM:25,RT:0,SF:0,FILE:0,BULK:0,RULE:Release_Ham,ACTI ON:release,TS:0 X-CID-META: VersionHash:7db8b62,CLOUDID:a55854cb5697e8fc70b46ab33d5bccf8,BulkI D:nil,BulkQuantity:0,SF:81|82|102|850|865|898,TC:nil,Content:0|15|50,EDM:5 ,IP:nil,URL:0,File:nil,RT:nil,Bulk:nil,QS:nil,BEC:nil,COL:0,OSI:0,OSA:0,AV :0,LES:1,SPR:NO,DKR:0,DKP:0,BRR:0,BRE:0,ARC:0 X-CID-BVR: 2,SSN|SDN X-CID-BAS: 2,SSN|SDN,0,_ X-CID-FACTOR: TF_CID_SPAM_SNR X-CID-RHF: D41D8CD98F00B204E9800998ECF8427E X-UUID: 1da4fcd0a5a511f19a56ed5b684f684d-20260901 X-User: fangqiurong@kylinos.cn Received: from localhost.localdomain [(10.44.16.150)] by mailgw.kylinos.cn (envelope-from ) (Generic MTA with TLSv1.3 TLS_AES_256_GCM_SHA384 256/256) with ESMTP id 1414786781; Tue, 01 Sep 2026 09:33:21 +0800 From: Qiurong Fang To: tj@kernel.org Cc: fangqiurong , void@manifault.com, arighi@kernel.org, changwoo@kernel.org, sched-ext@lists.linux.dev, linux-kernel@vger.kernel.org, zhanxusheng@xiaomi.com Subject: [PATCH v2] sched_ext: Skip per-CPU data allocation for built-in DSQs Date: Tue, 1 Sep 2026 09:32:58 +0800 Message-Id: <20260901013258.1822890-1-fangqiurong@kylinos.cn> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20260827082329.3368255-1-fangqiurong@kylinos.cn> References: <20260827082329.3368255-1-fangqiurong@kylinos.cn> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: fangqiurong Deferred reenqueue tracking is only supported for user DSQs: schedule_dsq_reenq() serves the local DSQ through sch->pcpu->deferred_reenq_local and rejects all other built-in DSQ ids. Every DSQ still allocates nr_cpu_ids * sizeof(struct scx_dsq_pcpu) bytes of per-CPU memory for it. Skip the allocation for built-in DSQ ids. While at it, rename ->pcpu to ->pcpu_user so that the per-CPU data reads as user-DSQ only. Signed-off-by: fangqiurong Reviewed-by: Zhan Xusheng --- v2: Rename ->pcpu to ->pcpu_user as suggested by Tejun. Describe the memory waste as quadratic as pointed out by Zhan Xusheng. Drop the Fixes: tag as this is a plain memory saving with no correctness impact. --- include/linux/sched/ext.h | 2 +- kernel/sched/ext/ext.c | 20 ++++++++++++++------ 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/include/linux/sched/ext.h b/include/linux/sched/ext.h index 582d7cd4a983..3c793d51c000 100644 --- a/include/linux/sched/ext.h +++ b/include/linux/sched/ext.h @@ -91,7 +91,7 @@ struct scx_dispatch_q { struct rhash_head hash_node; struct llist_node free_node; struct scx_sched *sched; - struct scx_dsq_pcpu __percpu *pcpu; + struct scx_dsq_pcpu __percpu *pcpu_user; struct rcu_head rcu; }; =20 diff --git a/kernel/sched/ext/ext.c b/kernel/sched/ext/ext.c index c539d15cda63..efb492876cd6 100644 --- a/kernel/sched/ext/ext.c +++ b/kernel/sched/ext/ext.c @@ -1127,7 +1127,8 @@ void schedule_dsq_reenq(struct scx_sched *sch, struct= scx_dispatch_q *dsq, } else if (!(dsq->id & SCX_DSQ_FLAG_BUILTIN)) { rq =3D this_rq(); =20 - struct scx_dsq_pcpu *dsq_pcpu =3D per_cpu_ptr(dsq->pcpu, cpu_of(rq)); + struct scx_dsq_pcpu *dsq_pcpu =3D + per_cpu_ptr(dsq->pcpu_user, cpu_of(rq)); struct scx_deferred_reenq_user *dru =3D &dsq_pcpu->deferred_reenq_user; =20 /* @@ -5048,12 +5049,16 @@ s32 scx_init_dsq(struct scx_dispatch_q *dsq, u64 ds= q_id, struct scx_sched *sch) dsq->id =3D dsq_id; dsq->sched =3D sch; =20 - dsq->pcpu =3D alloc_percpu(struct scx_dsq_pcpu); - if (!dsq->pcpu) + /* Deferred reenqueue tracking is only supported for user DSQs */ + if (dsq_id & SCX_DSQ_FLAG_BUILTIN) + return 0; + + dsq->pcpu_user =3D alloc_percpu(struct scx_dsq_pcpu); + if (!dsq->pcpu_user) return -ENOMEM; =20 for_each_possible_cpu(cpu) { - struct scx_dsq_pcpu *pcpu =3D per_cpu_ptr(dsq->pcpu, cpu); + struct scx_dsq_pcpu *pcpu =3D per_cpu_ptr(dsq->pcpu_user, cpu); =20 pcpu->dsq =3D dsq; INIT_LIST_HEAD(&pcpu->deferred_reenq_user.node); @@ -5066,8 +5071,11 @@ static void exit_dsq(struct scx_dispatch_q *dsq) { s32 cpu; =20 + if (!dsq->pcpu_user) + return; + for_each_possible_cpu(cpu) { - struct scx_dsq_pcpu *pcpu =3D per_cpu_ptr(dsq->pcpu, cpu); + struct scx_dsq_pcpu *pcpu =3D per_cpu_ptr(dsq->pcpu_user, cpu); struct scx_deferred_reenq_user *dru =3D &pcpu->deferred_reenq_user; struct rq *rq =3D cpu_rq(cpu); =20 @@ -5081,7 +5089,7 @@ static void exit_dsq(struct scx_dispatch_q *dsq) } } =20 - free_percpu(dsq->pcpu); + free_percpu(dsq->pcpu_user); } =20 static void free_dsq_rcufn(struct rcu_head *rcu) --=20 2.43.0