From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=95.215.58.40 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796033702; b=zHzs6H2MCthBPITt8bXjj3CA5kM5f9BK0U6bl+F9BNV6jvGvYBmtG/uSJ3c5mtVqhK51 mtDOq5ZnPW0GHTyuLDr5QaU3A6Gpu90qwKjNkDUxn3055pnXzeCMZ0PNmNz/T543rFH70 TtNNMnbHUiImT9Q5ZjwnBJUOptdYqVg0B3LV2yqo/flcCciCyRwMOzWrpMX1d86cRBcX9 chyaMZjqZaLVYuKXzLi4nq+GM2D638b9Xfuk/daGTywCdqKoi+LeesM6b2MuOPeHF6wXM i91h+qyk+MGgSlNscM/fmK3Hz5Ay7uDupw8O4kwZB2rynxjTMqj5dX3Of5SlvZIA1hQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796033702; h=DMARC-Filter:X-Envelope-To:DKIM-Signature:X-Envelope-To:Received: X-Mizu-Trace-ID:X-Migadu-Flow:Message-ID:Date:MIME-Version:User-Agent: Cc:Subject:To:References:From:In-Reply-To:Content-Type: Content-Transfer-Encoding; bh=m1hPDoVfOgk6A0kTR1UDbxiEdNexoAUfiznW0Lk4J/A=; b=qDhoDmchxQTxoiuxHFXUqCJKsW5S3K/6ZTi+91PkKcqi2RBjaQobqQwEmyuoX9i9QYfT ziwd/Snbl4572eFL5qrQVUwwsGeMzvll2gJRlfoxqxWP/5W4CvOGIsH+vl9l1EFT9HmbM f4JAwQ6xy3uoVvnJguFK89298dVfgwkFJ6OCwomWr55tvUr0PkbRsK1pEREHL0Cgp5/8w Yxi2/nfvi1AiRDbmRpmHz8j/aQOplmp4Kc/fdM6QZrmkV5Srs/3S6C+4gPGNhZ1FbLl8S mUnHvLlrJ2rr8L5W9qmPx/oUUHswLNdkiMx4ociYmdi3dd+KOm+I4ggxsKMxWoIwcIA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=RHTM1eMd; arc=none smtp.remote-ip=95.215.58.40 Received: from mta1.migadu.com (out-40.mta1.migadu.com [95.215.58.40]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9828E606A333 for ; Mon, 30 Nov 2026 10:15:01 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 9828E606A333 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key, unprotected) header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=RHTM1eMd X-Envelope-To: cgroups@vger.kernel.org DKIM-Signature: a=rsa-sha256; bh=mdPk67+4B7Ko390QW98fYNYmOBbWIm1qyfD2nZ8wODc=; c=simple/simple; d=linux.dev; h=from:to:subject:date:message-id:mime-version:content-type; s=key1; t=1796033699; v=1; x=1796638499; b=RHTM1eMd7DAesugZD+c/LQunM8xQ8zjwSNPAKrMJgFlWmjmngAvRItawI0JQBeGzLT0fKcyL enlAkP0tPaohx8KKq/TCa8do594xrEuoC5sld3+V8jAjvG3msZrHBIEpGudlki9aMNjMdoMvY0R i2CfDLDl4Fq9CrgJArGuhZzY= X-Envelope-To: cgroups@vger.kernel.org Received: by smtp.migadu.com with ESMTPS id a032312720cf9849; Mon, 30 Nov 2026 10:14:59 +0000 X-Mizu-Trace-ID: a032312720cf9849 X-Migadu-Flow: FLOW_OUT Message-ID: <88713b2f-180a-4ed0-9626-53f1ae4af9f5@linux.dev> Date: Mon, 30 Nov 2026 18:14:53 +0800 X-Mailing-List: cgroups@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Cc: cui.tao@linux.dev, josef@toxicopanda.com, axboe@kernel.dk, ast@kernel.org, alexei.starovoitov@gmail.com, cgroups@vger.kernel.org, linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, bpf@vger.kernel.org, andrii@kernel.org, eddyz87@gmail.com, daniel@iogearbox.net, linux-kselftest@vger.kernel.org, cuitao@kylinos.cn, ameryhung@gmail.com Subject: Re: [RFC PATCH v14 1/4] blk-iocost: add BPF struct_ops cost model support To: Tejun Heo References: <20261118131029.797007-1-cui.tao@linux.dev> <20261118131029.797007-2-cui.tao@linux.dev> From: Tao Cui In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Hello, Tejun, 在 2026/11/30 03:10, Tejun Heo 写道: > Hello, Tao. > > On Wed, Nov 18, 2026 at 09:10:26PM +0800, Tao Cui wrote: >> + const struct iocost_model_ops *attached; >> + struct bpf_link *attached_link; >> + /* either NULL (linear) or ->attached */ >> + const struct iocost_model_ops __rcu *bpf_model; > > Can you put these inside #ifdef CONFIG_BLK_CGROUP_IOCOST_BPF and go through > helpers with stubs where they're used outside the struct_ops code, e.g. in > ioc_cost_model_write()? > Makes sense. I'll put the three fields under the ifdef and use helpers for accesses outside the struct_ops code, with ioc_bpf_attached() returning NULL and ioc_bpf_model_set() being a no-op when BPF support is disabled. >> @@ -2657,6 +2723,41 @@ static u64 calc_vtime_cost(struct bio *bio, struct ioc_gq *iocg, bool is_merge) > ... >> + cost = model->calc_cost(bio, is_merge ? IOCOST_CALC_MERGE : 0); >> + return min(cost, VTIME_PER_SEC); > > Maybe calc_vtime_cost() and calc_vtime_cost_builtin() can take IOCOST_CALC_ > flags from the callers instead of the is_merge bool? > Agreed. I'll have both helpers take IOCOST_CALC_* flags directly, with callers passing either 0 or IOCOST_CALC_MERGE. This keeps the builtin behavior unchanged and aligns the helper interface with the BPF callback. > Also, what's the justification for capping the cost at VTIME_PER_SEC? > The intent was to protect the downstream accounting arithmetic from unexpectedly large costs returned by a BPF model. For example, abs_cost_to_cost() multiplies the absolute cost by WEIGHT_ONE, which can overflow with an arbitrary u64 return value. However, VTIME_PER_SEC was chosen as a conservative per-bio bound rather than one derived from the accounting arithmetic. I'll revisit the bound and check what limit is actually needed. >> @@ -3535,11 +3680,12 @@ static u64 ioc_cost_model_prfill(struct seq_file *sf, > ... >> - seq_printf(sf, "%s ctrl=%s model=linear " >> + seq_printf(sf, "%s ctrl=%s model=%s " >> "rbps=%llu rseqiops=%llu rrandiops=%llu " >> "wbps=%llu wseqiops=%llu wrandiops=%llu " >> "flushiops=%llu\n", > > ctrl and the coefficients describe the linear model and don't mean anything > while a BPF model is selected. Can you add a name[] member to > iocost_model_ops and print that instead when the model is bpf? Something > like: > > 252:1 model=bpf name= > Yes. I'll add a name member to iocost_model_ops, validate it during initialization, and print only 252:1 model=bpf name= when a BPF model is selected. The existing output format will remain unchanged for the linear model. >> +static void ioc_bpf_unreg(void *kdata, struct bpf_link *link) >> +{ > ... >> + /* del_gendisk() is in progress or done. ioc_rqos_exit() detaches. */ >> + bdev = blkdev_get_no_open(new_decode_dev(ops->dev), false); >> + if (!bdev) >> + return; > > Looking the device up by dev_t again here is what makes iocost hold its own > reference on the map and handle the window after the bdev is unhashed. I > wonder whether it'd be simpler to make .unreg the only detach path: > > - .reg keeps the device reference it already has and stores the pointer in > a private member of iocost_model_ops, like hid_bpf_ops->hdev. .unreg > reaches the queue through it and drops the reference. > > - ioc_rqos_exit() runs under rq_qos_mutex and can't detach the link > directly, but it can queue a work item which calls link->ops->detach() > so that the usual .unreg runs. It'd need to hold the link for that, > maybe with bpf_link_inc_not_zero(). > > The link holds the map until .unreg has run, so iocost wouldn't need its > own reference on it. The device reference would be there only for .unreg > calls which run after rq_qos_exit(), from the work item or from a link > close racing the removal. Can you add a comment explaining that? > I implemented the workqueue-based approach locally, and it passed the same validation as the current implementation. This avoids the dev_t lookup in .unreg() and allows the link to hold the map reference until .unreg() runs, removing the need for iocost to hold an additional map reference. I'll adopt this approach in the next revision and add a comment explaining why the bdev reference is retained until .unreg(), including the case where it runs after ioc_rqos_exit(). Thanks, Tao > Thanks. > > -- > tejun