From patchwork Thu Jan 18 19:20:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Axboe X-Patchwork-Id: 13523115 Received: from mail-io1-f42.google.com (mail-io1-f42.google.com [209.85.166.42]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AC6FB2E3F8 for ; Thu, 18 Jan 2024 19:23:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.166.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705605833; cv=none; b=tFQpZbeDYbrMyElmC9SxszQvnVzIOmDRr5oFzW4Sx5BrxMfmWHsPJfSOH9Y4oVgCsW6LOCMk4V5A0aEOYBYcGS0V+BPBGPIeSWFZ8Kj1o1SocZHR2rDO/tLiOJ1cr9FEJvXzXwFOgwUa2uJ8NV7GXNULHUMzrgF7H8dbLSdMFVQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705605833; c=relaxed/simple; bh=+mtYadm3M+ilgJiBZY+vUq8IU5xjNYe+J28FqoPsnj8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=M9HBruxgI0A5IhSqApTTBuDcZQpMb3wFTk56oQoANInPahqDb+78b7pmdzKAoSi8erQ7O/v73AO5x1c8LNNDpHiEk4DBdomO4Bu+bZFpL2NBsxqGOuQNjNeX4BhxbvGc9uPpzQYSysBSP4nccsfBPqxYzlRCqNu5G+upecsnf7E= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=kernel.dk; spf=pass smtp.mailfrom=kernel.dk; dkim=pass (2048-bit key) header.d=kernel-dk.20230601.gappssmtp.com header.i=@kernel-dk.20230601.gappssmtp.com header.b=CPQ1aONl; arc=none smtp.client-ip=209.85.166.42 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=kernel.dk Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=kernel.dk Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel-dk.20230601.gappssmtp.com header.i=@kernel-dk.20230601.gappssmtp.com header.b="CPQ1aONl" Received: by mail-io1-f42.google.com with SMTP id ca18e2360f4ac-7bee01886baso50332239f.1 for ; Thu, 18 Jan 2024 11:23:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel-dk.20230601.gappssmtp.com; s=20230601; t=1705605829; x=1706210629; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Fl7xBNgNabyen0blKRPhiVPUOU+ukJNqSOFOnGFVt7U=; b=CPQ1aONlkJl5kMNKdcnDcpnZdqDs5Vh7Vh8vpwPM02R+faACbfNSIjUq6el8RpdRNh uuq6wDT6mH3ed4KxVNuO5Sp8gn3p8Zi6k6oWyRtBwph2yUgZsbwhpjKvW0cyiUZLea84 V3HxS4XoweIUu3oQQuK/Q19N7o7iMMjAXdL1U3RN47z3F3cERl9b/rF+AeIOYHDhjzWC XWYSAMTCZ8INdY18H3pMjuaFvzuwho1Z8CQofbLwrg9A9szjGuj4k+WboA2nVsB+I1q5 4xJ69MwzaT/6vl8DjrLQjTeBPDuUcKqQBTMb+CS6vru/Uvl23QciuiEXBP1Yrv9JuMI8 KM9Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1705605829; x=1706210629; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Fl7xBNgNabyen0blKRPhiVPUOU+ukJNqSOFOnGFVt7U=; b=XQJsIdW0zeKd3LSvtdaSHPsWEhz4dgD7Fjy19BHobEkQWILK7YbJU+3HDArTyA+4vo iRGLlzlW8cFFVrnYST+iE94cR9Kvs4qyiDj8yWxHnwUQNZCcuB/AgxZ8xinFdI6apY8L nLe051Imz5iMjuudzxvIFckqoBUl2GSKH1VR++aVTCam5H4P+yi6RV9UMqtC3JAzlNWk adFqgLxUXEAzsykIHuHmy72eGFCO1bz2jEUf8urSaqIE8yV9YvUOBFs4DJEaTvR/jr+p Yg9gIT6/XYRhs4PMgYH5GDoRqEyfH8Rqcyg0hkUbpqAuv6C0DBw7rzRmlXBeY0w0JFxa Ts5g== X-Gm-Message-State: AOJu0YxjB72loldMklx11S8AszdnNAcoBez0gNrb58g8kNzOkz1HRlix QDww2vw7X7wn6/LZ0kriolZ/eQcSfadw/AIw1Oy+Yo9xAnS/sqC1O70xtWEWxIf6/wjY+CqyS/S yhsc= X-Google-Smtp-Source: AGHT+IEH7pCx5Oo1v/Im3VilHn0TAfTpltlALsNiDAiqbGs1IJrB+cCCM0eC/rPdapRquUhgT16V2Q== X-Received: by 2002:a6b:5a0d:0:b0:7bf:35d5:bd21 with SMTP id o13-20020a6b5a0d000000b007bf35d5bd21mr356065iob.1.1705605829454; Thu, 18 Jan 2024 11:23:49 -0800 (PST) Received: from localhost.localdomain ([96.43.243.2]) by smtp.gmail.com with ESMTPSA id gc18-20020a056638671200b0046e5c69376asm1155588jab.40.2024.01.18.11.23.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 Jan 2024 11:23:48 -0800 (PST) From: Jens Axboe To: linux-block@vger.kernel.org Cc: Jens Axboe Subject: [PATCH 1/6] block: move cgroup time handling code into blkdev.h Date: Thu, 18 Jan 2024 12:20:52 -0700 Message-ID: <20240118192343.953539-2-axboe@kernel.dk> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240118192343.953539-1-axboe@kernel.dk> References: <20240118192343.953539-1-axboe@kernel.dk> Precedence: bulk X-Mailing-List: linux-block@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 In preparation for moving time keeping into blkdev.h, move the cgroup related code for timestamps in here too. This will help avoid a circular dependency. Leave struct bio_issue in blk_types.h as it's a proper time definition. Signed-off-by: Jens Axboe --- include/linux/blk_types.h | 42 -------------------------------------- include/linux/blkdev.h | 43 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 42 deletions(-) diff --git a/include/linux/blk_types.h b/include/linux/blk_types.h index f288c94374b3..1c07848dea7e 100644 --- a/include/linux/blk_types.h +++ b/include/linux/blk_types.h @@ -206,52 +206,10 @@ static inline bool blk_path_error(blk_status_t error) return true; } -/* - * From most significant bit: - * 1 bit: reserved for other usage, see below - * 12 bits: original size of bio - * 51 bits: issue time of bio - */ -#define BIO_ISSUE_RES_BITS 1 -#define BIO_ISSUE_SIZE_BITS 12 -#define BIO_ISSUE_RES_SHIFT (64 - BIO_ISSUE_RES_BITS) -#define BIO_ISSUE_SIZE_SHIFT (BIO_ISSUE_RES_SHIFT - BIO_ISSUE_SIZE_BITS) -#define BIO_ISSUE_TIME_MASK ((1ULL << BIO_ISSUE_SIZE_SHIFT) - 1) -#define BIO_ISSUE_SIZE_MASK \ - (((1ULL << BIO_ISSUE_SIZE_BITS) - 1) << BIO_ISSUE_SIZE_SHIFT) -#define BIO_ISSUE_RES_MASK (~((1ULL << BIO_ISSUE_RES_SHIFT) - 1)) - -/* Reserved bit for blk-throtl */ -#define BIO_ISSUE_THROTL_SKIP_LATENCY (1ULL << 63) - struct bio_issue { u64 value; }; -static inline u64 __bio_issue_time(u64 time) -{ - return time & BIO_ISSUE_TIME_MASK; -} - -static inline u64 bio_issue_time(struct bio_issue *issue) -{ - return __bio_issue_time(issue->value); -} - -static inline sector_t bio_issue_size(struct bio_issue *issue) -{ - return ((issue->value & BIO_ISSUE_SIZE_MASK) >> BIO_ISSUE_SIZE_SHIFT); -} - -static inline void bio_issue_init(struct bio_issue *issue, - sector_t size) -{ - size &= (1ULL << BIO_ISSUE_SIZE_BITS) - 1; - issue->value = ((issue->value & BIO_ISSUE_RES_MASK) | - (ktime_get_ns() & BIO_ISSUE_TIME_MASK) | - ((u64)size << BIO_ISSUE_SIZE_SHIFT)); -} - typedef __u32 __bitwise blk_opf_t; typedef unsigned int blk_qc_t; diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h index 99e4f5e72213..da0f7e1caa5a 100644 --- a/include/linux/blkdev.h +++ b/include/linux/blkdev.h @@ -974,6 +974,49 @@ static inline void blk_flush_plug(struct blk_plug *plug, bool async) int blkdev_issue_flush(struct block_device *bdev); long nr_blockdev_pages(void); + +/* + * From most significant bit: + * 1 bit: reserved for other usage, see below + * 12 bits: original size of bio + * 51 bits: issue time of bio + */ +#define BIO_ISSUE_RES_BITS 1 +#define BIO_ISSUE_SIZE_BITS 12 +#define BIO_ISSUE_RES_SHIFT (64 - BIO_ISSUE_RES_BITS) +#define BIO_ISSUE_SIZE_SHIFT (BIO_ISSUE_RES_SHIFT - BIO_ISSUE_SIZE_BITS) +#define BIO_ISSUE_TIME_MASK ((1ULL << BIO_ISSUE_SIZE_SHIFT) - 1) +#define BIO_ISSUE_SIZE_MASK \ + (((1ULL << BIO_ISSUE_SIZE_BITS) - 1) << BIO_ISSUE_SIZE_SHIFT) +#define BIO_ISSUE_RES_MASK (~((1ULL << BIO_ISSUE_RES_SHIFT) - 1)) + +/* Reserved bit for blk-throtl */ +#define BIO_ISSUE_THROTL_SKIP_LATENCY (1ULL << 63) + +static inline u64 __bio_issue_time(u64 time) +{ + return time & BIO_ISSUE_TIME_MASK; +} + +static inline u64 bio_issue_time(struct bio_issue *issue) +{ + return __bio_issue_time(issue->value); +} + +static inline sector_t bio_issue_size(struct bio_issue *issue) +{ + return ((issue->value & BIO_ISSUE_SIZE_MASK) >> BIO_ISSUE_SIZE_SHIFT); +} + +static inline void bio_issue_init(struct bio_issue *issue, + sector_t size) +{ + size &= (1ULL << BIO_ISSUE_SIZE_BITS) - 1; + issue->value = ((issue->value & BIO_ISSUE_RES_MASK) | + (ktime_get_ns() & BIO_ISSUE_TIME_MASK) | + ((u64)size << BIO_ISSUE_SIZE_SHIFT)); +} + #else /* CONFIG_BLOCK */ struct blk_plug { }; From patchwork Thu Jan 18 19:20:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Axboe X-Patchwork-Id: 13523116 Received: from mail-io1-f45.google.com (mail-io1-f45.google.com [209.85.166.45]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 92E6F2C6BD for ; Thu, 18 Jan 2024 19:23:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.166.45 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705605834; cv=none; b=kgOlIrLtxSHYVk+OM+EcxN13ANNi6/mgSo2I5TdEnGlAj0W23sJjEUE8YuuYB1bYvmMK3B3PmBRVpNx703K/jsP2Vm//8SHPJ0qmMNuiI604UYCG3m9fN9lGofdguCSM7BPSmLyIU1iuO7PtipmuvFPz3YyRrlRgsHvg71BwvdI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705605834; c=relaxed/simple; bh=izIKyOww1azzDBjl4cXQlt24OidbE1Kga6yc3tS2ZgM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=BNpzsNSmh+L3LEPZJCQOJ3jIeSXlSi0/thNUrhQgQybGlbOSfRW9O7vLsGhpBpzX+ebBzzv9ciHNcDQyP1J9ThcP8Dtqc2RZughUIuKpht76JvHY7CL3B6UCYMwhs1gThnXkUmce39KjXDlXrTtUGlHxVTf7H04cSllHP/3s1QU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=kernel.dk; spf=pass smtp.mailfrom=kernel.dk; dkim=pass (2048-bit key) header.d=kernel-dk.20230601.gappssmtp.com header.i=@kernel-dk.20230601.gappssmtp.com header.b=ga+d97OD; arc=none smtp.client-ip=209.85.166.45 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=kernel.dk Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=kernel.dk Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel-dk.20230601.gappssmtp.com header.i=@kernel-dk.20230601.gappssmtp.com header.b="ga+d97OD" Received: by mail-io1-f45.google.com with SMTP id ca18e2360f4ac-7bee9f626caso76939f.0 for ; Thu, 18 Jan 2024 11:23:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel-dk.20230601.gappssmtp.com; s=20230601; t=1705605831; x=1706210631; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Uvg2KK7irZ4BlTFmSlyH/nNhecbvByBtDeVpstIzykM=; b=ga+d97ODOhVfehRrCa8zFVPBvBheXMXVKVnk6cIH4QlnTxbXjVYmy4p1JWseiaSbJF 6MhfpgPXfKyajY8eN90NnMH6Y7N7/UckIhFiarCXK+klMdQPYCaPLmFtNTySdA1db046 0oqrqXIBpT3+4bpkFODX0fB1y0AIQFWXaUbrDHcrzh2Z4z7RLPRYu06KepSlCapsNa/v mbQj2NEzWd7PyN5ZZSili+CKK8L3bZlOEk4DS5X/DRW+nYZPXzdSe2iAe5e3XukF34pd 0FDYkAnzSrZP91lG8XmEjXZGJbYVMw1w1n3zv0v4HRH0D/hZUQZd4vOjxoG7qft4qBvt wVBA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1705605831; x=1706210631; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Uvg2KK7irZ4BlTFmSlyH/nNhecbvByBtDeVpstIzykM=; b=eJ4Qhd0MTeFWIHXUMujc9FjmoMUK7czqB7U7XtrGd87/t5hnD16lVH8atduqQLH4Rs +0eGQJaGKgGW7purya1esbV2SOgWQSFYykZAndrXVlmV0Vt2b8l9yU4l5Yr6vkMymF10 39axhziSev10lsEFxs7+luQB0mYzcKrNZ1ipS4vSS/Wm4mVPOzkdk81sHHfp81y9mG/4 wYJmbyeeV7zZLfkw2ce12HOJPYDDTeiA1ENAO9/gHBulAxLy8c472K7XY2jROpyxrviC W1PkDCl4o8Eu3/zQUNwgZkQelRe2OjgXtEqI8DaDl9+XcMbbP/kIy5MSsCB8002LxTiz 9fUg== X-Gm-Message-State: AOJu0YwJlo2jlpvEyCxJ9IdlOeNwyZsbTsRvkc+Pm+zh4qfeIhMXMIZn duKIstk6NDFCGBceKvyVZK6skPeTFGw8yq8j7xs3mjkW1teli4fG5cJ68RT4JUBdUV/yeI7k1Jy oItI= X-Google-Smtp-Source: AGHT+IHTib5pX3W451HLNZECGft43sIZ4A3OnC+N3ngL8U9bh2nbk9i8O7EFczsMEuouXf/9h1b2IQ== X-Received: by 2002:a05:6602:1233:b0:7bc:207d:5178 with SMTP id z19-20020a056602123300b007bc207d5178mr2700790iot.2.1705605831275; Thu, 18 Jan 2024 11:23:51 -0800 (PST) Received: from localhost.localdomain ([96.43.243.2]) by smtp.gmail.com with ESMTPSA id gc18-20020a056638671200b0046e5c69376asm1155588jab.40.2024.01.18.11.23.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 Jan 2024 11:23:49 -0800 (PST) From: Jens Axboe To: linux-block@vger.kernel.org Cc: Jens Axboe , Johannes Thumshirn Subject: [PATCH 2/6] block: add blk_time_get_ns() helper Date: Thu, 18 Jan 2024 12:20:53 -0700 Message-ID: <20240118192343.953539-3-axboe@kernel.dk> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240118192343.953539-1-axboe@kernel.dk> References: <20240118192343.953539-1-axboe@kernel.dk> Precedence: bulk X-Mailing-List: linux-block@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Convert any user of ktime_get_ns() to use blk_time_get_ns(), so we have a unified API for querying the current time in nanoseconds. No functional changes intended, this patch just wraps ktime_get_ns() with a block helper. Reviewed-by: Johannes Thumshirn Signed-off-by: Jens Axboe --- block/bfq-cgroup.c | 14 +++++++------- block/bfq-iosched.c | 22 +++++++++++----------- block/blk-cgroup.c | 2 +- block/blk-flush.c | 2 +- block/blk-iocost.c | 6 +++--- block/blk-iolatency.c | 6 +++--- block/blk-mq.c | 16 ++++++++-------- block/blk-throttle.c | 6 +++--- block/blk-wbt.c | 5 ++--- include/linux/blkdev.h | 8 +++++++- 10 files changed, 46 insertions(+), 41 deletions(-) diff --git a/block/bfq-cgroup.c b/block/bfq-cgroup.c index 2c90e5de0acd..d442ee358fc2 100644 --- a/block/bfq-cgroup.c +++ b/block/bfq-cgroup.c @@ -127,7 +127,7 @@ static void bfqg_stats_update_group_wait_time(struct bfqg_stats *stats) if (!bfqg_stats_waiting(stats)) return; - now = ktime_get_ns(); + now = blk_time_get_ns(); if (now > stats->start_group_wait_time) bfq_stat_add(&stats->group_wait_time, now - stats->start_group_wait_time); @@ -144,7 +144,7 @@ static void bfqg_stats_set_start_group_wait_time(struct bfq_group *bfqg, return; if (bfqg == curr_bfqg) return; - stats->start_group_wait_time = ktime_get_ns(); + stats->start_group_wait_time = blk_time_get_ns(); bfqg_stats_mark_waiting(stats); } @@ -156,7 +156,7 @@ static void bfqg_stats_end_empty_time(struct bfqg_stats *stats) if (!bfqg_stats_empty(stats)) return; - now = ktime_get_ns(); + now = blk_time_get_ns(); if (now > stats->start_empty_time) bfq_stat_add(&stats->empty_time, now - stats->start_empty_time); @@ -183,7 +183,7 @@ void bfqg_stats_set_start_empty_time(struct bfq_group *bfqg) if (bfqg_stats_empty(stats)) return; - stats->start_empty_time = ktime_get_ns(); + stats->start_empty_time = blk_time_get_ns(); bfqg_stats_mark_empty(stats); } @@ -192,7 +192,7 @@ void bfqg_stats_update_idle_time(struct bfq_group *bfqg) struct bfqg_stats *stats = &bfqg->stats; if (bfqg_stats_idling(stats)) { - u64 now = ktime_get_ns(); + u64 now = blk_time_get_ns(); if (now > stats->start_idle_time) bfq_stat_add(&stats->idle_time, @@ -205,7 +205,7 @@ void bfqg_stats_set_start_idle_time(struct bfq_group *bfqg) { struct bfqg_stats *stats = &bfqg->stats; - stats->start_idle_time = ktime_get_ns(); + stats->start_idle_time = blk_time_get_ns(); bfqg_stats_mark_idling(stats); } @@ -242,7 +242,7 @@ void bfqg_stats_update_completion(struct bfq_group *bfqg, u64 start_time_ns, u64 io_start_time_ns, blk_opf_t opf) { struct bfqg_stats *stats = &bfqg->stats; - u64 now = ktime_get_ns(); + u64 now = blk_time_get_ns(); if (now > io_start_time_ns) blkg_rwstat_add(&stats->service_time, opf, diff --git a/block/bfq-iosched.c b/block/bfq-iosched.c index 3cce6de464a7..1922574e1c0d 100644 --- a/block/bfq-iosched.c +++ b/block/bfq-iosched.c @@ -1005,7 +1005,7 @@ static struct request *bfq_check_fifo(struct bfq_queue *bfqq, rq = rq_entry_fifo(bfqq->fifo.next); - if (rq == last || ktime_get_ns() < rq->fifo_time) + if (rq == last || blk_time_get_ns() < rq->fifo_time) return NULL; bfq_log_bfqq(bfqq->bfqd, bfqq, "check_fifo: returned %p", rq); @@ -1829,7 +1829,7 @@ static void bfq_bfqq_handle_idle_busy_switch(struct bfq_data *bfqd, * bfq_bfqq_update_budg_for_activation for * details on the usage of the next variable. */ - arrived_in_time = ktime_get_ns() <= + arrived_in_time = blk_time_get_ns() <= bfqq->ttime.last_end_request + bfqd->bfq_slice_idle * 3; unsigned int act_idx = bfq_actuator_index(bfqd, rq->bio); @@ -2208,7 +2208,7 @@ static void bfq_add_request(struct request *rq) struct request *next_rq, *prev; unsigned int old_wr_coeff = bfqq->wr_coeff; bool interactive = false; - u64 now_ns = ktime_get_ns(); + u64 now_ns = blk_time_get_ns(); bfq_log_bfqq(bfqd, bfqq, "add_request %d", rq_is_sync(rq)); bfqq->queued[rq_is_sync(rq)]++; @@ -2262,7 +2262,7 @@ static void bfq_add_request(struct request *rq) bfqd->rqs_injected && bfqd->tot_rq_in_driver > 0)) && time_is_before_eq_jiffies(bfqq->decrease_time_jif + msecs_to_jiffies(10))) { - bfqd->last_empty_occupied_ns = ktime_get_ns(); + bfqd->last_empty_occupied_ns = blk_time_get_ns(); /* * Start the state machine for measuring the * total service time of rq: setting @@ -3433,7 +3433,7 @@ static void bfq_reset_rate_computation(struct bfq_data *bfqd, struct request *rq) { if (rq != NULL) { /* new rq dispatch now, reset accordingly */ - bfqd->last_dispatch = bfqd->first_dispatch = ktime_get_ns(); + bfqd->last_dispatch = bfqd->first_dispatch = blk_time_get_ns(); bfqd->peak_rate_samples = 1; bfqd->sequential_samples = 0; bfqd->tot_sectors_dispatched = bfqd->last_rq_max_size = @@ -3590,7 +3590,7 @@ static void bfq_update_rate_reset(struct bfq_data *bfqd, struct request *rq) */ static void bfq_update_peak_rate(struct bfq_data *bfqd, struct request *rq) { - u64 now_ns = ktime_get_ns(); + u64 now_ns = blk_time_get_ns(); if (bfqd->peak_rate_samples == 0) { /* first dispatch */ bfq_log(bfqd, "update_peak_rate: goto reset, samples %d", @@ -5591,7 +5591,7 @@ static void bfq_init_bfqq(struct bfq_data *bfqd, struct bfq_queue *bfqq, struct bfq_io_cq *bic, pid_t pid, int is_sync, unsigned int act_idx) { - u64 now_ns = ktime_get_ns(); + u64 now_ns = blk_time_get_ns(); bfqq->actuator_idx = act_idx; RB_CLEAR_NODE(&bfqq->entity.rb_node); @@ -5903,7 +5903,7 @@ static void bfq_update_io_thinktime(struct bfq_data *bfqd, */ if (bfqq->dispatched || bfq_bfqq_busy(bfqq)) return; - elapsed = ktime_get_ns() - bfqq->ttime.last_end_request; + elapsed = blk_time_get_ns() - bfqq->ttime.last_end_request; elapsed = min_t(u64, elapsed, 2ULL * bfqd->bfq_slice_idle); ttime->ttime_samples = (7*ttime->ttime_samples + 256) / 8; @@ -6194,7 +6194,7 @@ static bool __bfq_insert_request(struct bfq_data *bfqd, struct request *rq) bfq_add_request(rq); idle_timer_disabled = waiting && !bfq_bfqq_wait_request(bfqq); - rq->fifo_time = ktime_get_ns() + bfqd->bfq_fifo_expire[rq_is_sync(rq)]; + rq->fifo_time = blk_time_get_ns() + bfqd->bfq_fifo_expire[rq_is_sync(rq)]; list_add_tail(&rq->queuelist, &bfqq->fifo); bfq_rq_enqueued(bfqd, bfqq, rq); @@ -6370,7 +6370,7 @@ static void bfq_completed_request(struct bfq_queue *bfqq, struct bfq_data *bfqd) bfq_weights_tree_remove(bfqq); } - now_ns = ktime_get_ns(); + now_ns = blk_time_get_ns(); bfqq->ttime.last_end_request = now_ns; @@ -6585,7 +6585,7 @@ static void bfq_completed_request(struct bfq_queue *bfqq, struct bfq_data *bfqd) static void bfq_update_inject_limit(struct bfq_data *bfqd, struct bfq_queue *bfqq) { - u64 tot_time_ns = ktime_get_ns() - bfqd->last_empty_occupied_ns; + u64 tot_time_ns = blk_time_get_ns() - bfqd->last_empty_occupied_ns; unsigned int old_limit = bfqq->inject_limit; if (bfqq->last_serv_time_ns > 0 && bfqd->rqs_injected) { diff --git a/block/blk-cgroup.c b/block/blk-cgroup.c index ff93c385ba5a..bdbb557feb5a 100644 --- a/block/blk-cgroup.c +++ b/block/blk-cgroup.c @@ -1846,7 +1846,7 @@ static void blkcg_maybe_throttle_blkg(struct blkcg_gq *blkg, bool use_memdelay) { unsigned long pflags; bool clamp; - u64 now = ktime_to_ns(ktime_get()); + u64 now = blk_time_get_ns(); u64 exp; u64 delay_nsec = 0; int tok; diff --git a/block/blk-flush.c b/block/blk-flush.c index 3f4d41952ef2..b0f314f4bc14 100644 --- a/block/blk-flush.c +++ b/block/blk-flush.c @@ -143,7 +143,7 @@ static void blk_account_io_flush(struct request *rq) part_stat_lock(); part_stat_inc(part, ios[STAT_FLUSH]); part_stat_add(part, nsecs[STAT_FLUSH], - ktime_get_ns() - rq->start_time_ns); + blk_time_get_ns() - rq->start_time_ns); part_stat_unlock(); } diff --git a/block/blk-iocost.c b/block/blk-iocost.c index c8beec6d7df0..e54b17261d96 100644 --- a/block/blk-iocost.c +++ b/block/blk-iocost.c @@ -829,7 +829,7 @@ static int ioc_autop_idx(struct ioc *ioc, struct gendisk *disk) /* step up/down based on the vrate */ vrate_pct = div64_u64(ioc->vtime_base_rate * 100, VTIME_PER_USEC); - now_ns = ktime_get_ns(); + now_ns = blk_time_get_ns(); if (p->too_fast_vrate_pct && p->too_fast_vrate_pct <= vrate_pct) { if (!ioc->autop_too_fast_at) @@ -1044,7 +1044,7 @@ static void ioc_now(struct ioc *ioc, struct ioc_now *now) unsigned seq; u64 vrate; - now->now_ns = ktime_get(); + now->now_ns = blk_time_get_ns(); now->now = ktime_to_us(now->now_ns); vrate = atomic64_read(&ioc->vtime_rate); @@ -2810,7 +2810,7 @@ static void ioc_rqos_done(struct rq_qos *rqos, struct request *rq) return; } - on_q_ns = ktime_get_ns() - rq->alloc_time_ns; + on_q_ns = blk_time_get_ns() - rq->alloc_time_ns; rq_wait_ns = rq->start_time_ns - rq->alloc_time_ns; size_nsec = div64_u64(calc_size_vtime_cost(rq, ioc), VTIME_PER_NSEC); diff --git a/block/blk-iolatency.c b/block/blk-iolatency.c index c1a6aba1d59e..ebb522788d97 100644 --- a/block/blk-iolatency.c +++ b/block/blk-iolatency.c @@ -609,7 +609,7 @@ static void blkcg_iolatency_done_bio(struct rq_qos *rqos, struct bio *bio) if (!iolat->blkiolat->enabled) return; - now = ktime_to_ns(ktime_get()); + now = blk_time_get_ns(); while (blkg && blkg->parent) { iolat = blkg_to_lat(blkg); if (!iolat) { @@ -661,7 +661,7 @@ static void blkiolatency_timer_fn(struct timer_list *t) struct blk_iolatency *blkiolat = from_timer(blkiolat, t, timer); struct blkcg_gq *blkg; struct cgroup_subsys_state *pos_css; - u64 now = ktime_to_ns(ktime_get()); + u64 now = blk_time_get_ns(); rcu_read_lock(); blkg_for_each_descendant_pre(blkg, pos_css, @@ -985,7 +985,7 @@ static void iolatency_pd_init(struct blkg_policy_data *pd) struct blkcg_gq *blkg = lat_to_blkg(iolat); struct rq_qos *rqos = iolat_rq_qos(blkg->q); struct blk_iolatency *blkiolat = BLKIOLATENCY(rqos); - u64 now = ktime_to_ns(ktime_get()); + u64 now = blk_time_get_ns(); int cpu; if (blk_queue_nonrot(blkg->q)) diff --git a/block/blk-mq.c b/block/blk-mq.c index aa87fcfda1ec..aff9e9492f59 100644 --- a/block/blk-mq.c +++ b/block/blk-mq.c @@ -323,7 +323,7 @@ void blk_rq_init(struct request_queue *q, struct request *rq) RB_CLEAR_NODE(&rq->rb_node); rq->tag = BLK_MQ_NO_TAG; rq->internal_tag = BLK_MQ_NO_TAG; - rq->start_time_ns = ktime_get_ns(); + rq->start_time_ns = blk_time_get_ns(); rq->part = NULL; blk_crypto_rq_set_defaults(rq); } @@ -333,7 +333,7 @@ EXPORT_SYMBOL(blk_rq_init); static inline void blk_mq_rq_time_init(struct request *rq, u64 alloc_time_ns) { if (blk_mq_need_time_stamp(rq)) - rq->start_time_ns = ktime_get_ns(); + rq->start_time_ns = blk_time_get_ns(); else rq->start_time_ns = 0; @@ -444,7 +444,7 @@ static struct request *__blk_mq_alloc_requests(struct blk_mq_alloc_data *data) /* alloc_time includes depth and tag waits */ if (blk_queue_rq_alloc_time(q)) - alloc_time_ns = ktime_get_ns(); + alloc_time_ns = blk_time_get_ns(); if (data->cmd_flags & REQ_NOWAIT) data->flags |= BLK_MQ_REQ_NOWAIT; @@ -629,7 +629,7 @@ struct request *blk_mq_alloc_request_hctx(struct request_queue *q, /* alloc_time includes depth and tag waits */ if (blk_queue_rq_alloc_time(q)) - alloc_time_ns = ktime_get_ns(); + alloc_time_ns = blk_time_get_ns(); /* * If the tag allocator sleeps we could get an allocation for a @@ -1042,7 +1042,7 @@ static inline void __blk_mq_end_request_acct(struct request *rq, u64 now) inline void __blk_mq_end_request(struct request *rq, blk_status_t error) { if (blk_mq_need_time_stamp(rq)) - __blk_mq_end_request_acct(rq, ktime_get_ns()); + __blk_mq_end_request_acct(rq, blk_time_get_ns()); blk_mq_finish_request(rq); @@ -1085,7 +1085,7 @@ void blk_mq_end_request_batch(struct io_comp_batch *iob) u64 now = 0; if (iob->need_ts) - now = ktime_get_ns(); + now = blk_time_get_ns(); while ((rq = rq_list_pop(&iob->req_list)) != NULL) { prefetch(rq->bio); @@ -1255,7 +1255,7 @@ void blk_mq_start_request(struct request *rq) if (test_bit(QUEUE_FLAG_STATS, &q->queue_flags) && !blk_rq_is_passthrough(rq)) { - rq->io_start_time_ns = ktime_get_ns(); + rq->io_start_time_ns = blk_time_get_ns(); rq->stats_sectors = blk_rq_sectors(rq); rq->rq_flags |= RQF_STATS; rq_qos_issue(q, rq); @@ -3107,7 +3107,7 @@ blk_status_t blk_insert_cloned_request(struct request *rq) blk_mq_run_dispatch_ops(q, ret = blk_mq_request_issue_directly(rq, true)); if (ret) - blk_account_io_done(rq, ktime_get_ns()); + blk_account_io_done(rq, blk_time_get_ns()); return ret; } EXPORT_SYMBOL_GPL(blk_insert_cloned_request); diff --git a/block/blk-throttle.c b/block/blk-throttle.c index 16f5766620a4..da9dc1f793c3 100644 --- a/block/blk-throttle.c +++ b/block/blk-throttle.c @@ -1815,7 +1815,7 @@ static bool throtl_tg_is_idle(struct throtl_grp *tg) time = min_t(unsigned long, MAX_IDLE_TIME, 4 * tg->idletime_threshold); ret = tg->latency_target == DFL_LATENCY_TARGET || tg->idletime_threshold == DFL_IDLE_THRESHOLD || - (ktime_get_ns() >> 10) - tg->last_finish_time > time || + (blk_time_get_ns() >> 10) - tg->last_finish_time > time || tg->avg_idletime > tg->idletime_threshold || (tg->latency_target && tg->bio_cnt && tg->bad_bio_cnt * 5 < tg->bio_cnt); @@ -2060,7 +2060,7 @@ static void blk_throtl_update_idletime(struct throtl_grp *tg) if (last_finish_time == 0) return; - now = ktime_get_ns() >> 10; + now = blk_time_get_ns() >> 10; if (now <= last_finish_time || last_finish_time == tg->checked_last_finish_time) return; @@ -2327,7 +2327,7 @@ void blk_throtl_bio_endio(struct bio *bio) if (!tg->td->limit_valid[LIMIT_LOW]) return; - finish_time_ns = ktime_get_ns(); + finish_time_ns = blk_time_get_ns(); tg->last_finish_time = finish_time_ns >> 10; start_time = bio_issue_time(&bio->bi_issue) >> 10; diff --git a/block/blk-wbt.c b/block/blk-wbt.c index 5ba3cd574eac..4c1c04345040 100644 --- a/block/blk-wbt.c +++ b/block/blk-wbt.c @@ -274,13 +274,12 @@ static inline bool stat_sample_valid(struct blk_rq_stat *stat) static u64 rwb_sync_issue_lat(struct rq_wb *rwb) { - u64 now, issue = READ_ONCE(rwb->sync_issue); + u64 issue = READ_ONCE(rwb->sync_issue); if (!issue || !rwb->sync_cookie) return 0; - now = ktime_to_ns(ktime_get()); - return now - issue; + return blk_time_get_ns() - issue; } static inline unsigned int wbt_inflight(struct rq_wb *rwb) diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h index da0f7e1caa5a..4495de020d9a 100644 --- a/include/linux/blkdev.h +++ b/include/linux/blkdev.h @@ -24,6 +24,7 @@ #include #include #include +#include struct module; struct request_queue; @@ -975,6 +976,11 @@ static inline void blk_flush_plug(struct blk_plug *plug, bool async) int blkdev_issue_flush(struct block_device *bdev); long nr_blockdev_pages(void); +static inline u64 blk_time_get_ns(void) +{ + return ktime_get_ns(); +} + /* * From most significant bit: * 1 bit: reserved for other usage, see below @@ -1013,7 +1019,7 @@ static inline void bio_issue_init(struct bio_issue *issue, { size &= (1ULL << BIO_ISSUE_SIZE_BITS) - 1; issue->value = ((issue->value & BIO_ISSUE_RES_MASK) | - (ktime_get_ns() & BIO_ISSUE_TIME_MASK) | + (blk_time_get_ns() & BIO_ISSUE_TIME_MASK) | ((u64)size << BIO_ISSUE_SIZE_SHIFT)); } From patchwork Thu Jan 18 19:20:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Axboe X-Patchwork-Id: 13523117 Received: from mail-io1-f48.google.com (mail-io1-f48.google.com [209.85.166.48]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 76B232E3F8 for ; Thu, 18 Jan 2024 19:23:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.166.48 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705605836; cv=none; b=k6dswxdjLx06qEf3r2bOT/wCY0orV+k6PgPevegvJL1e419wCBp2WvLf+RgLVwfG6GhByUbUwlEuLtMwUTB84fIdHubTBevi/zRzlH2QP2o/L28Mx6DucAQ23ncvAGLV+oC0mzPs1BGwdimfcXPoJx/vsydMVs3YcGKetliZU7o= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705605836; c=relaxed/simple; bh=KrkEwpyLUCm9K4yMuhSJJ1LIar/4ExZN2t7cEh8dOaI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=nqflI3r0tmK8sFpkKcM83BwHrIKkxHkagNlZAXzDI4NFUs9GBBcKqXhXhOOYsywTBjmPo1xB5dgzsVXxeeWHwrc3coth6CJs8Qrn+QQu15qtPZozSDFdjTZz+1ZosaBktz7JbVHCnmj1JntpkS/T9b//Ldfstz1fNBpCRJxlQtc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=kernel.dk; spf=pass smtp.mailfrom=kernel.dk; dkim=pass (2048-bit key) header.d=kernel-dk.20230601.gappssmtp.com header.i=@kernel-dk.20230601.gappssmtp.com header.b=EzfO7iJ1; arc=none smtp.client-ip=209.85.166.48 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=kernel.dk Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=kernel.dk Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel-dk.20230601.gappssmtp.com header.i=@kernel-dk.20230601.gappssmtp.com header.b="EzfO7iJ1" Received: by mail-io1-f48.google.com with SMTP id ca18e2360f4ac-7bbdd28a52aso84041539f.1 for ; Thu, 18 Jan 2024 11:23:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel-dk.20230601.gappssmtp.com; s=20230601; t=1705605833; x=1706210633; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=NrTfITcy5xm7tHNgS6AMID6p74u6gKo/HsHWXAFrnLE=; b=EzfO7iJ1jz1JsVABPv2W4vCUBvL/TVuK7AUsnoX+2nDCbdCsWmz8TfLx6hInYQbMdk bshouqdYM9AxlDhij7hRQIRx0E5RWQfhKwDxmshp23/A/DGc+Lk/SZMTO66uUXb+GoUU YrogHtTNJYQBrz6pJrn0okIQmsfvTAgalKASKDNGI5aL15ulipkTq/6qKYaCXQhy9u6q RMdosKfZitGsQDAyCcRAcrIS5cykaP1v91JfYPE95ztUG88AJ9P3NRplOgcPcHF0f+ew dHdhUN/BQlnXCdaj4mRatBD0sQA52mkMsUH6jWpljfVMTj3hdR4p4QbduT7RfpSZF5ti rzlQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1705605833; x=1706210633; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=NrTfITcy5xm7tHNgS6AMID6p74u6gKo/HsHWXAFrnLE=; b=nG6H7Oyj3Z+JPxQuFEJKSzOr6nqXOYufAhaf2dqPppPzyRCodWxK1Wga6kt31E3vll d2pah6PcXMEJX9sc8PXM6dIDxW95brFLWimVhW/YotDsrxG821e33LwryW4lAePKoLjf F2jwtYFv0cWNpj77TX7oJNpdNdUch4WzvW4N3/5sv8yDr8kI+SI45WxRUtAEPcyNZoMo qmWNUsj4wDgzz4m9c4jw0rlbuHgo/b8r4uuHp3tXHOxL0yKxXOm5KCFD6NoClufbV24h 2cY1yj+458qdK8MCxSMGPmm4qWcbRSbL9v5Q4UkJNmxkKuI+oNkVY6JpNiHTevCpKr/n Rkiw== X-Gm-Message-State: AOJu0Yx94LYKCz5BoaHIHs1hkK7LCIfQucKs0c+8v28ASpHtfC4OXRvY uroCpu0froP/s7RQQDmpgehlVu8yM5XBfjvLLli3p5HH8kN1uaX6CsRUhIPsIh8UVFvQptQauVG umFo= X-Google-Smtp-Source: AGHT+IEj7AdGjD3oJmEkC4C7/AzOt4kWeP1z4BO5i9CLAZ/qEk3IZjUQ0FAnadthY5x2gVas15hmYQ== X-Received: by 2002:a05:6602:1233:b0:7bc:207d:5178 with SMTP id z19-20020a056602123300b007bc207d5178mr2700865iot.2.1705605832939; Thu, 18 Jan 2024 11:23:52 -0800 (PST) Received: from localhost.localdomain ([96.43.243.2]) by smtp.gmail.com with ESMTPSA id gc18-20020a056638671200b0046e5c69376asm1155588jab.40.2024.01.18.11.23.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 Jan 2024 11:23:51 -0800 (PST) From: Jens Axboe To: linux-block@vger.kernel.org Cc: Jens Axboe , Johannes Thumshirn Subject: [PATCH 3/6] block: cache current nsec time in struct blk_plug Date: Thu, 18 Jan 2024 12:20:54 -0700 Message-ID: <20240118192343.953539-4-axboe@kernel.dk> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240118192343.953539-1-axboe@kernel.dk> References: <20240118192343.953539-1-axboe@kernel.dk> Precedence: bulk X-Mailing-List: linux-block@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Querying the current time is the most costly thing we do in the block layer per IO, and depending on kernel config settings, we may do it many times per IO. None of the callers actually need nsec granularity. Take advantage of that by caching the current time in the plug, with the assumption here being that any time checking will be temporally close enough that the slight loss of precision doesn't matter. If the block plug gets flushed, eg on preempt or schedule out, then we invalidate the cached clock. On a basic peak IOPS test case with iostats enabled, this changes the performance from: IOPS=108.41M, BW=52.93GiB/s, IOS/call=31/31 IOPS=108.43M, BW=52.94GiB/s, IOS/call=32/32 IOPS=108.29M, BW=52.88GiB/s, IOS/call=31/32 IOPS=108.35M, BW=52.91GiB/s, IOS/call=32/32 IOPS=108.42M, BW=52.94GiB/s, IOS/call=31/31 IOPS=108.40M, BW=52.93GiB/s, IOS/call=32/32 IOPS=108.31M, BW=52.89GiB/s, IOS/call=32/31 to IOPS=118.79M, BW=58.00GiB/s, IOS/call=31/32 IOPS=118.62M, BW=57.92GiB/s, IOS/call=31/31 IOPS=118.80M, BW=58.01GiB/s, IOS/call=32/31 IOPS=118.78M, BW=58.00GiB/s, IOS/call=32/32 IOPS=118.69M, BW=57.95GiB/s, IOS/call=32/31 IOPS=118.62M, BW=57.92GiB/s, IOS/call=32/31 IOPS=118.63M, BW=57.92GiB/s, IOS/call=31/32 which is more than a 9% improvement in performance. Looking at perf diff, we can see a huge reduction in time overhead: 10.55% -9.88% [kernel.vmlinux] [k] read_tsc 1.31% -1.22% [kernel.vmlinux] [k] ktime_get Note that since this relies on blk_plug for the caching, it's only applicable to the issue side. But this is where most of the time calls happen anyway. On the completion side, cached time stamping is done with struct io_comp patch, as long as the driver supports it. It's also worth noting that the above testing doesn't enable any of the higher cost CPU items on the block layer side, like wbt, cgroups, iocost, etc, which all would add additional time querying and hence overhead. IOW, results would likely look even better in comparison with those enabled, as distros would do. Reviewed-by: Johannes Thumshirn Signed-off-by: Jens Axboe --- block/blk-core.c | 1 + include/linux/blkdev.h | 15 ++++++++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/block/blk-core.c b/block/blk-core.c index 11342af420d0..cc4db4d92c75 100644 --- a/block/blk-core.c +++ b/block/blk-core.c @@ -1073,6 +1073,7 @@ void blk_start_plug_nr_ios(struct blk_plug *plug, unsigned short nr_ios) if (tsk->plug) return; + plug->cur_ktime = 0; plug->mq_list = NULL; plug->cached_rq = NULL; plug->nr_ios = min_t(unsigned short, nr_ios, BLK_MAX_REQUEST_COUNT); diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h index 4495de020d9a..26226afaeb91 100644 --- a/include/linux/blkdev.h +++ b/include/linux/blkdev.h @@ -943,6 +943,7 @@ struct blk_plug { /* if ios_left is > 1, we can batch tag/rq allocations */ struct request *cached_rq; + u64 cur_ktime; unsigned short nr_ios; unsigned short rq_count; @@ -978,7 +979,19 @@ long nr_blockdev_pages(void); static inline u64 blk_time_get_ns(void) { - return ktime_get_ns(); + struct blk_plug *plug = current->plug; + + if (!plug) + return ktime_get_ns(); + + /* + * 0 could very well be a valid time, but rather than flag "this is + * a valid timestamp" separately, just accept that we'll do an extra + * ktime_get_ns() if we just happen to get 0 as the current time. + */ + if (!plug->cur_ktime) + plug->cur_ktime = ktime_get_ns(); + return plug->cur_ktime; } /* From patchwork Thu Jan 18 19:20:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Axboe X-Patchwork-Id: 13523118 Received: from mail-io1-f50.google.com (mail-io1-f50.google.com [209.85.166.50]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 073A72E41A for ; Thu, 18 Jan 2024 19:23:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.166.50 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705605838; cv=none; b=htTx51smYRG0WoyixOwGhcjcmNkO6KmCypkslY4jsTUs4W255abzk50VPc77Z2XEhOPs2Jx5t/6+nCOC4zpFGTh//0rwxVG6zyRg0BFG6ZrbGGkMbMr4R6n+R/Gl0um9fhhbY1CyJ4CZ50aTsVxT77+DhTXzLWyAydrbPV2lXT0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705605838; c=relaxed/simple; bh=KY5qKDHUEdtAiLOzRKB7ikeqsfi0OBJRwdVu0qawenM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Z0cdxVBxNSL77B9QTfi6orGmsTd7brevDeysNzN4dBLm73lZkEiYQj5cvaE0pxgsxsweq06nPuAxCQDfW93yjIMVxFUrlpEcbpPoW3ZgljsNXrC3eLSUoopkYOpM0CTUXB08KRVjgf8dyENw8NJ6q5dec19rYwMHIxLMA6ijxkU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=kernel.dk; spf=pass smtp.mailfrom=kernel.dk; dkim=pass (2048-bit key) header.d=kernel-dk.20230601.gappssmtp.com header.i=@kernel-dk.20230601.gappssmtp.com header.b=GeV2daDf; arc=none smtp.client-ip=209.85.166.50 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=kernel.dk Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=kernel.dk Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel-dk.20230601.gappssmtp.com header.i=@kernel-dk.20230601.gappssmtp.com header.b="GeV2daDf" Received: by mail-io1-f50.google.com with SMTP id ca18e2360f4ac-7bf3283c18dso99839f.0 for ; Thu, 18 Jan 2024 11:23:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel-dk.20230601.gappssmtp.com; s=20230601; t=1705605835; x=1706210635; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=nG9bYwLCypK88nVwwMvHo/MQtnbDeCQ4odqIEB4uqt8=; b=GeV2daDfrIthDUAVh8jqG5h7djRbQM7FiBxD7lldiz0Di9M5GkkyasFELO0HhRUkZ+ 42RgMl8dsfBGvyt+pvHhcKboPBNB8a6aHdop3RzfzECfVmIPp54NaO5jRvK5nl1sznyJ d040dEJB+Wo3Kvh75SJcZmAZBUFl1WG5goDaTUT75FAg4KxDfjWIoElgvjLWRpnAVBJj PJiDfEQ4xSgAWDo/hzMzK23Bsr2fCyHRtt7ROWr2j3mqAioez9+fnm/bjpCijemas2sF Dh8TL/HOFGZn/RsBq4XkmBCIhlUebl+4njsQWvSUTgwMClEZ6Accd8HbaYKQ0VbNfNcC 0wwQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1705605835; x=1706210635; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=nG9bYwLCypK88nVwwMvHo/MQtnbDeCQ4odqIEB4uqt8=; b=ozTvEX/vpiGimVluLp4U2rtnL2JUnjYrMzU4/rERL4UKbHUif945VYC1Cwe3WXWPbC MKzhlWya+liT3Y9G3MHUDpceQPjlYwG1wxky4hgsNG5HeFE27RWGNS1crXxjTY0yWVSC PZiZPqzl52KmIQlV6Aee7CYmRbxBzTOsSQrr0HCFLExuP9oMPwLdUFKwtBnX1mzOR6NJ jn9zGzAn9u5DGAgUjYyU97K8699L+YPFzk/5U5cdLScTaljWzrFkbz/5/X8Qga+RXWhH oyeay0RG6jdxw7+LG4dGTL0WN5ZFvNMV43YwF1W5dwz7ZHrSc8Ryd7KszBDMOmy3/5Gq KNBA== X-Gm-Message-State: AOJu0Yw7LpFM8Ywegb6S+EjIgXHDHvv4uqOCCe5PrDw4y3UckqWp4m9c NG6Nyp8wmEEAJ52DLNceq6fQJAzvVeYQ2gp/g2UI31iJMRC7HiC/Q/JfxwC+sTeCB9LpY5ozhjm 1PW4= X-Google-Smtp-Source: AGHT+IGPbRNmeIwwoBg/o1yVOjJ1Tf0T7e9UDGPZFa3nmr4E9dl/ef2YvgRft6cnQUkFNwxbmgmNqA== X-Received: by 2002:a5e:8302:0:b0:7be:e376:fc44 with SMTP id x2-20020a5e8302000000b007bee376fc44mr357826iom.2.1705605834694; Thu, 18 Jan 2024 11:23:54 -0800 (PST) Received: from localhost.localdomain ([96.43.243.2]) by smtp.gmail.com with ESMTPSA id gc18-20020a056638671200b0046e5c69376asm1155588jab.40.2024.01.18.11.23.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 Jan 2024 11:23:53 -0800 (PST) From: Jens Axboe To: linux-block@vger.kernel.org Cc: Jens Axboe , Johannes Thumshirn Subject: [PATCH 4/6] block: update cached timestamp post schedule/preemption Date: Thu, 18 Jan 2024 12:20:55 -0700 Message-ID: <20240118192343.953539-5-axboe@kernel.dk> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240118192343.953539-1-axboe@kernel.dk> References: <20240118192343.953539-1-axboe@kernel.dk> Precedence: bulk X-Mailing-List: linux-block@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Mark the task as having a cached timestamp when set assign it, so we can efficiently check if it needs updating post being scheduled back in. This covers both the actual schedule out case, which would've flushed the plug, and the preemption case which doesn't touch the plugged requests (for many reasons, one of them being then we'd need to have preemption disabled around plug state manipulation). Reviewed-by: Johannes Thumshirn Signed-off-by: Jens Axboe --- block/blk-core.c | 2 ++ include/linux/blkdev.h | 20 +++++++++++++++++++- include/linux/sched.h | 2 +- kernel/sched/core.c | 4 +++- 4 files changed, 25 insertions(+), 3 deletions(-) diff --git a/block/blk-core.c b/block/blk-core.c index cc4db4d92c75..71c6614a97fe 100644 --- a/block/blk-core.c +++ b/block/blk-core.c @@ -1173,6 +1173,8 @@ void __blk_flush_plug(struct blk_plug *plug, bool from_schedule) */ if (unlikely(!rq_list_empty(plug->cached_rq))) blk_mq_free_plug_rqs(plug); + + current->flags &= ~PF_BLOCK_TS; } /** diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h index 26226afaeb91..518c77d1f0c3 100644 --- a/include/linux/blkdev.h +++ b/include/linux/blkdev.h @@ -977,6 +977,18 @@ static inline void blk_flush_plug(struct blk_plug *plug, bool async) int blkdev_issue_flush(struct block_device *bdev); long nr_blockdev_pages(void); +/* + * tsk == current here + */ +static inline void blk_plug_invalidate_ts(struct task_struct *tsk) +{ + struct blk_plug *plug = tsk->plug; + + if (plug) + plug->cur_ktime = 0; + current->flags &= ~PF_BLOCK_TS; +} + static inline u64 blk_time_get_ns(void) { struct blk_plug *plug = current->plug; @@ -989,8 +1001,10 @@ static inline u64 blk_time_get_ns(void) * a valid timestamp" separately, just accept that we'll do an extra * ktime_get_ns() if we just happen to get 0 as the current time. */ - if (!plug->cur_ktime) + if (!plug->cur_ktime) { plug->cur_ktime = ktime_get_ns(); + current->flags |= PF_BLOCK_TS; + } return plug->cur_ktime; } @@ -1057,6 +1071,10 @@ static inline void blk_flush_plug(struct blk_plug *plug, bool async) { } +static inline void blk_plug_invalidate_ts(struct task_struct *tsk) +{ +} + static inline int blkdev_issue_flush(struct block_device *bdev) { return 0; diff --git a/include/linux/sched.h b/include/linux/sched.h index 9a66147915b2..d8a073b06495 100644 --- a/include/linux/sched.h +++ b/include/linux/sched.h @@ -1642,7 +1642,7 @@ extern struct pid *cad_pid; #define PF_NO_SETAFFINITY 0x04000000 /* Userland is not allowed to meddle with cpus_mask */ #define PF_MCE_EARLY 0x08000000 /* Early kill for mce process policy */ #define PF_MEMALLOC_PIN 0x10000000 /* Allocation context constrained to zones which allow long term pinning. */ -#define PF__HOLE__20000000 0x20000000 +#define PF_BLOCK_TS 0x20000000 /* plug has ts that needs updating */ #define PF__HOLE__40000000 0x40000000 #define PF_SUSPEND_TASK 0x80000000 /* This thread called freeze_processes() and should not be frozen */ diff --git a/kernel/sched/core.c b/kernel/sched/core.c index 9116bcc90346..4675d59313ba 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -6787,7 +6787,9 @@ static inline void sched_submit_work(struct task_struct *tsk) static void sched_update_worker(struct task_struct *tsk) { - if (tsk->flags & (PF_WQ_WORKER | PF_IO_WORKER)) { + if (tsk->flags & (PF_WQ_WORKER | PF_IO_WORKER | PF_BLOCK_TS)) { + if (tsk->flags & PF_BLOCK_TS) + blk_plug_invalidate_ts(tsk); if (tsk->flags & PF_WQ_WORKER) wq_worker_running(tsk); else From patchwork Thu Jan 18 19:20:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Axboe X-Patchwork-Id: 13523119 Received: from mail-io1-f43.google.com (mail-io1-f43.google.com [209.85.166.43]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C76842E627 for ; Thu, 18 Jan 2024 19:23:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.166.43 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705605839; cv=none; b=KS6+A97KvBTNJkVGMbJfZRo/DlKchGPyYi3bdIVzoijEnMOStMac9BlwU0FKA0BhqrhmxtwwXGBgdiZ+9zD4yarOtFoXt/o4CJYgYUhhgE2wW9PMJARxjkEsEPqmsZtQGRdcR7x81hupKeW2UClKMbWRX4UaHQlMJ1OzvIGKQSo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705605839; c=relaxed/simple; bh=2+jD+dAJoAmbHwxBuTYGGTBTalKI4J0VNuRxTZdHS8g=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=cnqLyItaCsQZ1RQ5dzGT/rhOuDRs6ug1hALha6DPXRQ3E4z9ZfXIK6kWrwR32wE3oLQ0L+kZYLcl6/K1PlDI0gGq3yzICZESsiMo3Ewtgo18ZI0ge2BibQPr1HHDdW8LHphIycjXWrlSjnleHJrdweR0ikaNAau+3S/YqKCfDi4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=kernel.dk; spf=pass smtp.mailfrom=kernel.dk; dkim=pass (2048-bit key) header.d=kernel-dk.20230601.gappssmtp.com header.i=@kernel-dk.20230601.gappssmtp.com header.b=znUPn2pt; arc=none smtp.client-ip=209.85.166.43 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=kernel.dk Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=kernel.dk Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel-dk.20230601.gappssmtp.com header.i=@kernel-dk.20230601.gappssmtp.com header.b="znUPn2pt" Received: by mail-io1-f43.google.com with SMTP id ca18e2360f4ac-7bee01886baso50334339f.1 for ; Thu, 18 Jan 2024 11:23:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel-dk.20230601.gappssmtp.com; s=20230601; t=1705605836; x=1706210636; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=4Nj3hM/YCE8GL2EPHEiO+vgsWtZQHNFa8Pn/Qr89Xv4=; b=znUPn2ptXByBw1llgLnJH6lqGkjzvTtwGisvrbTpEZVAFB8GJc63NSveh7p50UKBCg tPGmGUVX0OvI2c1s1khM3iEJbIVLY/LPWGlhObQ+sMeLx0JDnmTZc0ws4YA7q9oyJtSK RYI+lx1waI36glizHvF8uVoQZ4JlplpwNa32qdowX/81322Wz58K9F3fB08SQMnH7t3i dZjp11mjGzfbjHQuoFikGXLf5sz/xBT9B3mEXagtmjOuf+MJbMkSLDiEORL6I8fWAaEG bryWYfrxWHFQHB4Vjdugd6jD64lmp3zLxMdMT0phOcTW9+v6ViuXVIA/p1XAvk5AXFLm eZ+A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1705605836; x=1706210636; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=4Nj3hM/YCE8GL2EPHEiO+vgsWtZQHNFa8Pn/Qr89Xv4=; b=sKJyKrlHERBIw6LEFlZkpTLxqmf3GvLG909XZVnLZCyKZrPLVyVDt+UC0T8jgRGL9g zDLbWvl7Vi2E4DLWNyP1H6mndbWbE9kmo63TOGptDCtcz5+hDd7Ciitux5I2cUJ6kJHo jg00deLAs9ZQ8Dv3bpIKK/8qyogkGSJSgXqoMk3s72FfUbWWD5HlOcDA9lnEm/2B+G1X hRUNC9rLMOvM/nsHWtqMNZ7x7+i6bXy4IAbUYixebU/WimihCVcOj6XePIv5AiGPr5Fq 425r9XXQs/cBgcXicBW/E5zuoHSID+yNXYOYs3YQnYimf6ZXgvs7f9iFNU+VoU7ykZ3J vI8Q== X-Gm-Message-State: AOJu0YyKt3A0zj5V3oCWCzGrR0QTwfPxP03Oh3wA0R0e3V/c0qIUm1is uojwZS0LZWMJoE1rkAmPwFgaxe2vrvGBGJdIklfRbw91sQmDFEHEhYqWsDXnHvJcIVHUtsGNvSP nao8= X-Google-Smtp-Source: AGHT+IF1anoSzGVCxZcjPLBRNSHXUgU8I9ZMamuJQPllV3EA5BAUnIZAf+W145BYkoaZWcXxvDU5Gw== X-Received: by 2002:a6b:5a0d:0:b0:7bf:35d5:bd21 with SMTP id o13-20020a6b5a0d000000b007bf35d5bd21mr356474iob.1.1705605836686; Thu, 18 Jan 2024 11:23:56 -0800 (PST) Received: from localhost.localdomain ([96.43.243.2]) by smtp.gmail.com with ESMTPSA id gc18-20020a056638671200b0046e5c69376asm1155588jab.40.2024.01.18.11.23.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 Jan 2024 11:23:54 -0800 (PST) From: Jens Axboe To: linux-block@vger.kernel.org Cc: Jens Axboe Subject: [PATCH 5/6] block: shrink plug->{nr_ios, rq_count} to unsigned char Date: Thu, 18 Jan 2024 12:20:56 -0700 Message-ID: <20240118192343.953539-6-axboe@kernel.dk> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240118192343.953539-1-axboe@kernel.dk> References: <20240118192343.953539-1-axboe@kernel.dk> Precedence: bulk X-Mailing-List: linux-block@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 We never use more than 64 max in here, we can change them from unsigned short to just a byte. Add a BUILD_BUG_ON() check, in case the max plug count changes in the future. Signed-off-by: Jens Axboe --- block/blk-core.c | 4 ++-- block/blk-mq.c | 2 ++ include/linux/blkdev.h | 8 ++++---- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/block/blk-core.c b/block/blk-core.c index 71c6614a97fe..dd593008511c 100644 --- a/block/blk-core.c +++ b/block/blk-core.c @@ -1063,7 +1063,7 @@ int kblockd_mod_delayed_work_on(int cpu, struct delayed_work *dwork, } EXPORT_SYMBOL(kblockd_mod_delayed_work_on); -void blk_start_plug_nr_ios(struct blk_plug *plug, unsigned short nr_ios) +void blk_start_plug_nr_ios(struct blk_plug *plug, unsigned char nr_ios) { struct task_struct *tsk = current; @@ -1076,7 +1076,7 @@ void blk_start_plug_nr_ios(struct blk_plug *plug, unsigned short nr_ios) plug->cur_ktime = 0; plug->mq_list = NULL; plug->cached_rq = NULL; - plug->nr_ios = min_t(unsigned short, nr_ios, BLK_MAX_REQUEST_COUNT); + plug->nr_ios = min_t(unsigned char, nr_ios, BLK_MAX_REQUEST_COUNT); plug->rq_count = 0; plug->multiple_queues = false; plug->has_elevator = false; diff --git a/block/blk-mq.c b/block/blk-mq.c index aff9e9492f59..a9b4a66e1e13 100644 --- a/block/blk-mq.c +++ b/block/blk-mq.c @@ -1283,6 +1283,8 @@ EXPORT_SYMBOL(blk_mq_start_request); */ static inline unsigned short blk_plug_max_rq_count(struct blk_plug *plug) { + BUILD_BUG_ON(2 * BLK_MAX_REQUEST_COUNT > U8_MAX); + if (plug->multiple_queues) return BLK_MAX_REQUEST_COUNT * 2; return BLK_MAX_REQUEST_COUNT; diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h index 518c77d1f0c3..80da19cb3b39 100644 --- a/include/linux/blkdev.h +++ b/include/linux/blkdev.h @@ -944,9 +944,9 @@ struct blk_plug { /* if ios_left is > 1, we can batch tag/rq allocations */ struct request *cached_rq; u64 cur_ktime; - unsigned short nr_ios; + unsigned char nr_ios; - unsigned short rq_count; + unsigned char rq_count; bool multiple_queues; bool has_elevator; @@ -964,7 +964,7 @@ struct blk_plug_cb { extern struct blk_plug_cb *blk_check_plugged(blk_plug_cb_fn unplug, void *data, int size); extern void blk_start_plug(struct blk_plug *); -extern void blk_start_plug_nr_ios(struct blk_plug *, unsigned short); +extern void blk_start_plug_nr_ios(struct blk_plug *, unsigned char); extern void blk_finish_plug(struct blk_plug *); void __blk_flush_plug(struct blk_plug *plug, bool from_schedule); @@ -1055,7 +1055,7 @@ struct blk_plug { }; static inline void blk_start_plug_nr_ios(struct blk_plug *plug, - unsigned short nr_ios) + unsigned char nr_ios) { } From patchwork Thu Jan 18 19:20:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Axboe X-Patchwork-Id: 13523120 Received: from mail-io1-f42.google.com (mail-io1-f42.google.com [209.85.166.42]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BA1B22E632 for ; Thu, 18 Jan 2024 19:23:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.166.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705605841; cv=none; b=RUHCECk/lyKMQpT5/rCdxFBedI4yoMRfAiiPmktP2K25ZxnPXLSIu3HkNBIoLpEMNfla6Ln0IN4rD7DeY5ArsZgeBmVqyfJj8Jlwto19WRvIs/LAYMK/hh7qrY+1A0fvEbcC+ifQytwmNGty/ABOtBd4Z6iPY9cOZk9AxXFJ2l8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705605841; c=relaxed/simple; bh=izpqGQ98MQGbVGqs/qD+xOZIdrARJYufHDBYcyxdY0Q=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=utGsa8wnMyugziX0VdBm2HDwVaV/OMHvPA0eYtoXRc7UmzkJI2Z9UDqYH4FQfiBeFZegzwDcFNfXtU5gwV9q4bx1WHit3zBqzaRGx8YilRfS4OA5vNp1leEdzbdDh/FwB2PcHWHlNXkvj6LL+5WIaMZG6pPIEQRcp5iHQ8v/y1c= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=kernel.dk; spf=pass smtp.mailfrom=kernel.dk; dkim=pass (2048-bit key) header.d=kernel-dk.20230601.gappssmtp.com header.i=@kernel-dk.20230601.gappssmtp.com header.b=qp+4dD9N; arc=none smtp.client-ip=209.85.166.42 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=kernel.dk Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=kernel.dk Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel-dk.20230601.gappssmtp.com header.i=@kernel-dk.20230601.gappssmtp.com header.b="qp+4dD9N" Received: by mail-io1-f42.google.com with SMTP id ca18e2360f4ac-7bf3283c18dso100639f.0 for ; Thu, 18 Jan 2024 11:23:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel-dk.20230601.gappssmtp.com; s=20230601; t=1705605838; x=1706210638; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=MYN1mAKCjzZWpKS1gzf0M4TIG0GwrP7YPsWEeIuIwrk=; b=qp+4dD9NhlPU02ujcAl6KcKtN564VqvmipxKFMQx4tHpBjC3NqzsoBAnkwdET50y+T VLRqxz7vH1DSj6uNbX4SIJtXdtDUF66DMyjMWsjoOXeXtQz/A588In6hESkZSjTInMjY MpNviTZBExlF7S7XHIpXBa6PbJMAhU4EeEy+6BtFBePrybSbXYADidhshb9Du4k9di2m sIxozipRK7VWrzZRPvVdF9dvHAZ+EIivmYvf6pMD70hp6L/AyC40iOY3UmdXcJ4n4hRx sBITRcGrc0cmQHgvOfms801PrLkjqS4hEEC9ofpo8wEGN6iTZbR9W39yQQ6DUXNVmjIi /3rw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1705605838; x=1706210638; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=MYN1mAKCjzZWpKS1gzf0M4TIG0GwrP7YPsWEeIuIwrk=; b=Zf7XbY4ye1YB7HZWpT/fHk5KtH2eatFLeDVkaZKj/i7ybC08swhTsJIob/DvnNKunj FkhVXBClZCPIB2hv9vZWMS9zWo1unVBn6qLb1bpjwGKTba9A+5a8IaJ9BAyW8UcjgrTf SGlFPXILr0SLJFIvNKPoROqls6wMvE/TEQ6/bqyA06GSnTDO89Qp7G8S4fBtraO3AWF/ SrnZ/vHVNpBe4yRwWYW5+Yh/2MIs/mnHcjnLzll8YTEt+tjrnzbsAzHLLGapik5yO6lJ GhWa7hvUujBKFYD7PGYFLrivpU7eTPb86e85qq10c/Qe8HUv2cjZMpfn1zXpfgU1fzbx r0/A== X-Gm-Message-State: AOJu0Yyg1YUIsCRcK6PN+CfSaNB8OHd6Xd7k2BSW2o6aCUMhdYSc7Djq GBT1UUBNb1mjMzD8M8FQuOZxnojBwjDYSy8l1fDRj4PEmRBkFUYNC5ZWh7EpBjGpNT5PoY2o6uH jEPA= X-Google-Smtp-Source: AGHT+IFVswBvHO0hg7lwOFANGJ9CZxaQ0mFENKgGRLSn0weUo4B6LrrfY2C6/Y19sbVjtU7cAz+aVQ== X-Received: by 2002:a5e:8302:0:b0:7be:e376:fc44 with SMTP id x2-20020a5e8302000000b007bee376fc44mr357973iom.2.1705605838367; Thu, 18 Jan 2024 11:23:58 -0800 (PST) Received: from localhost.localdomain ([96.43.243.2]) by smtp.gmail.com with ESMTPSA id gc18-20020a056638671200b0046e5c69376asm1155588jab.40.2024.01.18.11.23.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 Jan 2024 11:23:56 -0800 (PST) From: Jens Axboe To: linux-block@vger.kernel.org Cc: Jens Axboe Subject: [PATCH 6/6] block: convert struct blk_plug callback list to hlists Date: Thu, 18 Jan 2024 12:20:57 -0700 Message-ID: <20240118192343.953539-7-axboe@kernel.dk> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240118192343.953539-1-axboe@kernel.dk> References: <20240118192343.953539-1-axboe@kernel.dk> Precedence: bulk X-Mailing-List: linux-block@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 We currently use a doubly linked list, which means the head takes up 16 bytes. As any iteration goes over the full list by first splicing it to an on-stack copy, we never need to remove members from the middle of the list. Convert it to an hlist instead, saving 8 bytes in the blk_plug structure. This also helps save 40 bytes of text in the core block code, tested on arm64. This does mean that flush callbacks will be run in reverse. While this should not pose a problem, we can always change the list splicing to just iteration-and-add instead, preservering ordering. These lists are generally just a single entry (or a few entries), either way this should be fine. Signed-off-by: Jens Axboe --- block/blk-core.c | 26 ++++++++++++++------------ drivers/md/raid1-10.c | 2 +- include/linux/blkdev.h | 4 ++-- 3 files changed, 17 insertions(+), 15 deletions(-) diff --git a/block/blk-core.c b/block/blk-core.c index dd593008511c..f28859b4a3ef 100644 --- a/block/blk-core.c +++ b/block/blk-core.c @@ -1080,7 +1080,7 @@ void blk_start_plug_nr_ios(struct blk_plug *plug, unsigned char nr_ios) plug->rq_count = 0; plug->multiple_queues = false; plug->has_elevator = false; - INIT_LIST_HEAD(&plug->cb_list); + INIT_HLIST_HEAD(&plug->cb_list); /* * Store ordering should not be needed here, since a potential @@ -1120,16 +1120,18 @@ EXPORT_SYMBOL(blk_start_plug); static void flush_plug_callbacks(struct blk_plug *plug, bool from_schedule) { - LIST_HEAD(callbacks); + HLIST_HEAD(callbacks); - while (!list_empty(&plug->cb_list)) { - list_splice_init(&plug->cb_list, &callbacks); + while (!hlist_empty(&plug->cb_list)) { + struct hlist_node *entry, *tmp; - while (!list_empty(&callbacks)) { - struct blk_plug_cb *cb = list_first_entry(&callbacks, - struct blk_plug_cb, - list); - list_del(&cb->list); + hlist_move_list(&plug->cb_list, &callbacks); + + hlist_for_each_safe(entry, tmp, &callbacks) { + struct blk_plug_cb *cb; + + cb = hlist_entry(entry, struct blk_plug_cb, list); + hlist_del(&cb->list); cb->callback(cb, from_schedule); } } @@ -1144,7 +1146,7 @@ struct blk_plug_cb *blk_check_plugged(blk_plug_cb_fn unplug, void *data, if (!plug) return NULL; - list_for_each_entry(cb, &plug->cb_list, list) + hlist_for_each_entry(cb, &plug->cb_list, list) if (cb->callback == unplug && cb->data == data) return cb; @@ -1154,7 +1156,7 @@ struct blk_plug_cb *blk_check_plugged(blk_plug_cb_fn unplug, void *data, if (cb) { cb->data = data; cb->callback = unplug; - list_add(&cb->list, &plug->cb_list); + hlist_add_head(&cb->list, &plug->cb_list); } return cb; } @@ -1162,7 +1164,7 @@ EXPORT_SYMBOL(blk_check_plugged); void __blk_flush_plug(struct blk_plug *plug, bool from_schedule) { - if (!list_empty(&plug->cb_list)) + if (!hlist_empty(&plug->cb_list)) flush_plug_callbacks(plug, from_schedule); blk_mq_flush_plug_list(plug, from_schedule); /* diff --git a/drivers/md/raid1-10.c b/drivers/md/raid1-10.c index 512746551f36..4a1b6f17067f 100644 --- a/drivers/md/raid1-10.c +++ b/drivers/md/raid1-10.c @@ -152,7 +152,7 @@ static inline bool raid1_add_bio_to_plug(struct mddev *mddev, struct bio *bio, plug = container_of(cb, struct raid1_plug_cb, cb); bio_list_add(&plug->pending, bio); if (++plug->count / MAX_PLUG_BIO >= copies) { - list_del(&cb->list); + hlist_del(&cb->list); cb->callback(cb, false); } diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h index 80da19cb3b39..65e8c5f2e43a 100644 --- a/include/linux/blkdev.h +++ b/include/linux/blkdev.h @@ -951,13 +951,13 @@ struct blk_plug { bool multiple_queues; bool has_elevator; - struct list_head cb_list; /* md requires an unplug callback */ + struct hlist_head cb_list; /* md requires an unplug callback */ }; struct blk_plug_cb; typedef void (*blk_plug_cb_fn)(struct blk_plug_cb *, bool); struct blk_plug_cb { - struct list_head list; + struct hlist_node list; blk_plug_cb_fn callback; void *data; };