From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=95.215.58.79 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796310234; b=jcOPu0FDKN93Wk01Cir8cvJ2hfxia2eGmi43GHTNmj0UZhBEoHwZX9jqWZ9X2YC9cAtw Et29pO92SuXL8g4xZ5fc/0tJ0t4+iTsH4xZ7yUT6vgcQMwHtPmwuYUyLFOTTBGUIW2auB Ep2jVBiPqDHb86En2tVwXAJsjtnqOOhrgwZsJLV3S87kNUmgwKMEzMwURPFxE2lERRbe9 yE5aAyEZGSYvMKbmQKZpcmcde7RNnznWjHpqc3ytIXrc7YRIcWxlJei48DwY4pog1Q30S P0zD/Mk5GgrIp7oEVYIqxv0DSwYgI5iPUhR4q8t/EzA2MAm2OeEDpYqhqrv60KI0tJQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796310234; h=DMARC-Filter:X-Envelope-To:DKIM-Signature:X-Envelope-To:Received: X-Mizu-Trace-ID:X-Migadu-Flow:From:To:Cc:Subject:Date:Message-ID: X-Mailer:MIME-Version:Content-Transfer-Encoding; bh=Zk2Sp7BGrxxzWlS3dkvQnaBWlW36q6T0kfRseV4Y5wc=; b=L6lF/G3Es9I73d6V7+eSx3Th/ccwgSPlf4/1JAzs/AR/iPaepOki0orP3NiTaIxlBcGj +VJayrasNvuCcr3VaLO9r+WDwsIW7H9HZWxu8fZFUHRjyoTZUeyYHA+dIbpEP4KADpvFm v8KsVlSRx2gE42WyzPBw0LmmInTUrsyHY5Bfy8BQNmsmyoAfRnC77L1y6Sf+5a771frVW b6oTw/J2c8IVzqnFKIzHCixGfnSaM40NXR36iNGmkswyxBob1+jl+pqquAa3jnbZTtLm9 pnwkSnO8fM7mFw0PXTfvPolDv5qVGsUsX6vAbOCJTp0mPuEEkRColhtSxrYXcTjGfkQ== 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=RxxFyu32; arc=none smtp.remote-ip=95.215.58.79 Received: from mta1.migadu.com (out-79.mta1.migadu.com [95.215.58.79]) (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 0887F606A32F for ; Thu, 3 Dec 2026 15:03:53 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 0887F606A32F 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=RxxFyu32 X-Envelope-To: linux-block@vger.kernel.org DKIM-Signature: a=rsa-sha256; bh=ryo0wRf1Yo4K9VFON99j/cgTJxb/s7myVFAjFTxty3M=; c=simple/simple; d=linux.dev; h=from:to:subject:date:message-id:mime-version:content-type; s=key1; t=1796310232; v=1; x=1796915032; b=RxxFyu32rODwgeLubkr8nFW7TZEi9FcooH5qyb5NU673AdJ55QbhCeYzItHn5fAz+HmSirQM j91SIuwjkdFoBZfUx+N8Acov7DBlrhtnVA6bHZHUv1w7yCx9A//q2QaGkxt0R8A3P6/+hTN6unZ QtWf5790BNgBNMQAJfKF3Zog= X-Envelope-To: linux-block@vger.kernel.org Received: by smtp.migadu.com with ESMTPS id 0d6b2b13f40601e3; Thu, 03 Dec 2026 15:03:52 +0000 X-Mizu-Trace-ID: 0d6b2b13f40601e3 X-Migadu-Flow: FLOW_OUT From: Tao Cui To: tj@kernel.org, josef@toxicopanda.com, axboe@kernel.dk, ast@kernel.org, alexei.starovoitov@gmail.com Cc: 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, cui.tao@linux.dev, cuitao@kylinos.cn, ameryhung@gmail.com Subject: [PATCH v15 0/4] blk-iocost: BPF struct_ops cost model Date: Thu, 3 Dec 2026 23:03:34 +0800 Message-ID: <20261203150338.2625598-1-cui.tao@linux.dev> X-Mailer: git-send-email 2.53.0 X-Mailing-List: linux-block@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Tao Cui This series lets a BPF program take over the cost model of one device. The BPF model provides calc_cost() for charged IOs plus two transfer coefficients for the completion-time sizing, io.cost.model selects between the attached model and the builtin one, and enabling and disabling the controller stays with io.cost.qos. The builtin model is a linear formula derived from a handful of device parameters, and the right formula is device specific. A BPF model can be adapted to the device and updated without rebuilding the kernel. The series is based on next-20261201. Changes since v14: - p1: put the three BPF fields under CONFIG_BLK_CGROUP_IOCOST_BPF with stub helpers, and pass IOCOST_CALC_* flags into calc_vtime_cost() instead of a bool (review from tj) - p1: iocost_model_ops gains a name[] member; io.cost.model prints "model=bpf name=" and the docs cover the new key (review from tj) - p1: rework the attach/detach lifecycle: .reg() keeps the bdev reference and stores the ops pointer in a private member, .unreg() reaches the queue through it and drops the reference, and ioc_rqos_exit() queues a work item running the usual .unreg(); a NULL-link attach is rejected with -EOPNOTSUPP (review from tj) - p1: switching the cost model resets the per-iocg vtime state accumulated under the old pricing: debts, delays and waiters are dropped and vtime snaps to the activation target. An RCU grace period before the reset ensures every bio priced by the outgoing model is accounted for; the accounting also resets on attach and on device removal, and the model write resets before freezing the queue so it cannot stall behind the waiters it releases (review from tj) - p1: clamp a bio's completion-time payoff to vtime so that stale costs from bios still in flight across a switch cannot push done_vtime past vtime - p2: drop the field documentation block that v14 added to the iocost_ioc_tick tracepoint and return it to its v13 form (report from bpf-ci) - p3: mount cgroup2 in a private mount namespace, return negative error codes from open_nullb_dev(), and preserve the working directory across the setns() unwind (reports from sashiko and bpf-ci) - p3: add the upper-bound validate case, snapshot the stream counters per phase so the assertions cover that phase alone, and probe the tracepoint via kallsyms instead of tracefs - p4: the coefficient readback under a BPF model shows only "model=bpf" plus the model name, and the io.cost.model key table lists name= The p1 lifecycle rework and the model-switch reset change the reference semantics Alexei's ack covered (the bdev handoff, the workfn eject, the new iocost_model_ops members and the NULL-link rejection); a re-review would be appreciated. Tested on next-20261201 (two qemu x86_64 VMs, rotational device): the builtin model collapses two sequential 4K readers to ~2 MB/s, switching to the attached BPF model completes the io.cost.model write in 0.02s and recovers immediately, and switching back collapses again; an overnight tidal run of 37 load cycles over 9.6h completed 13M+ transactions with all 37 model switches in 0.01-0.03s and nothing in dmesg. The selftests pass (3 tests, 0 skipped). The final tree also rebuilds cleanly from the four patches applied to a fresh next-20261201 tree, kernel and selftests alike. Link: https://lore.kernel.org/r/20261118131029.797007-1-cui.tao@linux.dev # v14 Tao Cui (4): blk-iocost: add BPF struct_ops cost model support blk-iocost: add iocost_ioc_tick tracepoint for per-period device summary selftests/bpf: add iocost cost model test docs: cgroup-v2: document the iocost BPF cost model attachment Documentation/admin-guide/cgroup-v2.rst | 56 +- MAINTAINERS | 1 + block/Kconfig | 4 + block/blk-iocost.c | 705 ++++++++++++++- include/trace/events/iocost.h | 43 + tools/testing/selftests/bpf/config | 2 + .../selftests/bpf/prog_tests/iocost_model.c | 1021 +++++++++++++++ .../selftests/bpf/progs/iocost_model.c | 189 +++ tools/testing/selftests/bpf/progs/iocost_ms.c | 206 +++ 9 files changed, 2192 insertions(+), 35 deletions(-) create mode 100644 tools/testing/selftests/bpf/prog_tests/iocost_model.c create mode 100644 tools/testing/selftests/bpf/progs/iocost_model.c create mode 100644 tools/testing/selftests/bpf/progs/iocost_ms.c -- 2.53.0