From 8f79f871150407662db672676ea386d1204e01d7 Mon Sep 17 00:00:00 2001 From: Fabian Keil Date: Wed, 16 Aug 2017 11:10:00 +0200 Subject: [PATCH 211/325] cam iosched: Fix trim statistics (XXX: may not be correct for nvme) When cam_iosched_bio_complete() gets called, all pending BIO_DELETEs are done. Previously only one of them was accounted for, as a result the "pending" counter got higher and higher and the "out" count was off. PR: https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=221952 PR submission date: 2017-08-31 Obtained from: ElectroBSD --- sys/cam/cam_iosched.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/sys/cam/cam_iosched.c b/sys/cam/cam_iosched.c index 0b4d89468804..94a4497eebe9 100644 --- a/sys/cam/cam_iosched.c +++ b/sys/cam/cam_iosched.c @@ -1501,8 +1501,15 @@ cam_iosched_bio_complete(struct cam_iosched_softc *isc, struct bio *bp, } else if (bp->bio_cmd == BIO_DELETE) { if ((bp->bio_flags & BIO_ERROR) != 0) isc->trim_stats.errs++; - isc->trim_stats.out++; - isc->trim_stats.pending--; + /* + * A single request sent to the disk may trim multiple + * areas that belong to different BIO_DELETE requests. + * We only sent one trim request to the disk at the time, + * when it completes all pending BIO_DELETEs are done and + * have to be counted as such. + */ + isc->trim_stats.out += isc->trim_stats.pending; + isc->trim_stats.pending = 0; } else if (bp->bio_cmd != BIO_FLUSH) { if (iosched_debug) printf("Completing command with bio_cmd == %#x\n", bp->bio_cmd); -- 2.32.0