From patchwork Mon Aug 31 22:27:23 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Song Liu X-Patchwork-Id: 11747095 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id D84AC109B for ; Mon, 31 Aug 2020 22:27:43 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C0F93207EA for ; Mon, 31 Aug 2020 22:27:43 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=fb.com header.i=@fb.com header.b="omHUtP/q" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728169AbgHaW1k (ORCPT ); Mon, 31 Aug 2020 18:27:40 -0400 Received: from mx0a-00082601.pphosted.com ([67.231.145.42]:57582 "EHLO mx0a-00082601.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728113AbgHaW1k (ORCPT ); Mon, 31 Aug 2020 18:27:40 -0400 Received: from pps.filterd (m0109334.ppops.net [127.0.0.1]) by mx0a-00082601.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 07VMN4qs028662 for ; Mon, 31 Aug 2020 15:27:39 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fb.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding : content-type; s=facebook; bh=6fQHUfYNWpoeGACRSWyXDFz6VwpJvMfrpeVXIWv5oG0=; b=omHUtP/q1efZ09lYrxiF2aUFfoO6ca9p1y4GIDJ2dDdV2qxUmiAQHmO+YWjYvWsaZel7 0RHrtIUvk1IlrlNJyZ++5+gBPfbRL8T/d/Eyu7ZtH+zeEcXHexWIqgVj0GK3jdMoGKwZ wvW+HPCL2w4qWcyESDOHIqWK86zdiFzL7TU= Received: from maileast.thefacebook.com ([163.114.130.16]) by mx0a-00082601.pphosted.com with ESMTP id 3386ukfb55-4 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Mon, 31 Aug 2020 15:27:39 -0700 Received: from intmgw004.08.frc2.facebook.com (2620:10d:c0a8:1b::d) by mail.thefacebook.com (2620:10d:c0a8:82::d) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1979.3; Mon, 31 Aug 2020 15:27:37 -0700 Received: by devbig006.ftw2.facebook.com (Postfix, from userid 4523) id 6046762E51BC; Mon, 31 Aug 2020 15:27:36 -0700 (PDT) From: Song Liu To: , , CC: , , , , , Song Liu , Christoph Hellwig Subject: [PATCH v3 1/3] block: introduce part_[begin|end]_io_acct Date: Mon, 31 Aug 2020 15:27:23 -0700 Message-ID: <20200831222725.3860186-2-songliubraving@fb.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200831222725.3860186-1-songliubraving@fb.com> References: <20200831222725.3860186-1-songliubraving@fb.com> MIME-Version: 1.0 X-FB-Internal: Safe X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.235,18.0.687 definitions=2020-08-31_10:2020-08-31,2020-08-31 signatures=0 X-Proofpoint-Spam-Details: rule=fb_default_notspam policy=fb_default score=0 lowpriorityscore=0 adultscore=0 mlxscore=0 mlxlogscore=854 suspectscore=0 clxscore=1015 impostorscore=0 malwarescore=0 bulkscore=0 spamscore=0 phishscore=0 priorityscore=1501 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2006250000 definitions=main-2008310132 X-FB-Internal: deliver Sender: linux-block-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org These functions can be used to enable iostat for partitions on devices like md, bcache. Reviewed-by: Christoph Hellwig Signed-off-by: Song Liu --- block/blk-core.c | 39 +++++++++++++++++++++++++++++++++------ include/linux/blkdev.h | 5 +++++ 2 files changed, 38 insertions(+), 6 deletions(-) diff --git a/block/blk-core.c b/block/blk-core.c index d9d632639bd18..abddf8d029b8d 100644 --- a/block/blk-core.c +++ b/block/blk-core.c @@ -1460,10 +1460,9 @@ void blk_account_io_start(struct request *rq) part_stat_unlock(); } -unsigned long disk_start_io_acct(struct gendisk *disk, unsigned int sectors, - unsigned int op) +static unsigned long __part_start_io_acct(struct hd_struct *part, + unsigned int sectors, unsigned int op) { - struct hd_struct *part = &disk->part0; const int sgrp = op_stat_group(op); unsigned long now = READ_ONCE(jiffies); @@ -1476,12 +1475,26 @@ unsigned long disk_start_io_acct(struct gendisk *disk, unsigned int sectors, return now; } + +unsigned long part_start_io_acct(struct gendisk *disk, struct hd_struct **part, + struct bio *bio) +{ + *part = disk_map_sector_rcu(disk, bio->bi_iter.bi_sector); + + return __part_start_io_acct(*part, bio_sectors(bio), bio_op(bio)); +} +EXPORT_SYMBOL_GPL(part_start_io_acct); + +unsigned long disk_start_io_acct(struct gendisk *disk, unsigned int sectors, + unsigned int op) +{ + return __part_start_io_acct(&disk->part0, sectors, op); +} EXPORT_SYMBOL(disk_start_io_acct); -void disk_end_io_acct(struct gendisk *disk, unsigned int op, - unsigned long start_time) +static void __part_end_io_acct(struct hd_struct *part, unsigned int op, + unsigned long start_time) { - struct hd_struct *part = &disk->part0; const int sgrp = op_stat_group(op); unsigned long now = READ_ONCE(jiffies); unsigned long duration = now - start_time; @@ -1492,6 +1505,20 @@ void disk_end_io_acct(struct gendisk *disk, unsigned int op, part_stat_local_dec(part, in_flight[op_is_write(op)]); part_stat_unlock(); } + +void part_end_io_acct(struct hd_struct *part, struct bio *bio, + unsigned long start_time) +{ + __part_end_io_acct(part, bio_op(bio), start_time); + hd_struct_put(part); +} +EXPORT_SYMBOL_GPL(part_end_io_acct); + +void disk_end_io_acct(struct gendisk *disk, unsigned int op, + unsigned long start_time) +{ + __part_end_io_acct(&disk->part0, op, start_time); +} EXPORT_SYMBOL(disk_end_io_acct); /* diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h index bb5636cc17b91..b3f5815a573aa 100644 --- a/include/linux/blkdev.h +++ b/include/linux/blkdev.h @@ -1930,6 +1930,11 @@ unsigned long disk_start_io_acct(struct gendisk *disk, unsigned int sectors, void disk_end_io_acct(struct gendisk *disk, unsigned int op, unsigned long start_time); +unsigned long part_start_io_acct(struct gendisk *disk, struct hd_struct **part, + struct bio *bio); +void part_end_io_acct(struct hd_struct *part, struct bio *bio, + unsigned long start_time); + /** * bio_start_io_acct - start I/O accounting for bio based drivers * @bio: bio to start account for From patchwork Mon Aug 31 22:27:24 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Song Liu X-Patchwork-Id: 11747097 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C21BC14E5 for ; Mon, 31 Aug 2020 22:27:49 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A71E4214D8 for ; Mon, 31 Aug 2020 22:27:49 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=fb.com header.i=@fb.com header.b="Mq4XhLOX" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728190AbgHaW1r (ORCPT ); Mon, 31 Aug 2020 18:27:47 -0400 Received: from mx0a-00082601.pphosted.com ([67.231.145.42]:33436 "EHLO mx0a-00082601.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728145AbgHaW1p (ORCPT ); Mon, 31 Aug 2020 18:27:45 -0400 Received: from pps.filterd (m0148461.ppops.net [127.0.0.1]) by mx0a-00082601.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 07VMNMuA016071 for ; Mon, 31 Aug 2020 15:27:44 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fb.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding : content-type; s=facebook; bh=3/qO9hKgMLtNVpJ/qjz2/Lrd1LgKB861yWJf8rT5enU=; b=Mq4XhLOXIXwHN2yfUNPIOriU7f+BaNxi8JJ01m6wrvoAL5WLPIDhda9Qx8HVEyUpUfhQ OR2FVQwGyWCvgrmB9lf8R8t2R9Bk7QqlBBZDwEgiC0Ync3blR8tIQfzB3kHug2BG+IWQ wBdzAc1opx6jyuxY+bMd8aWCkPtmvJbbx5M= Received: from maileast.thefacebook.com ([163.114.130.16]) by mx0a-00082601.pphosted.com with ESMTP id 33879nf93y-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Mon, 31 Aug 2020 15:27:44 -0700 Received: from intmgw004.08.frc2.facebook.com (2620:10d:c0a8:1b::d) by mail.thefacebook.com (2620:10d:c0a8:83::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1979.3; Mon, 31 Aug 2020 15:27:42 -0700 Received: by devbig006.ftw2.facebook.com (Postfix, from userid 4523) id 6FF8662E51BC; Mon, 31 Aug 2020 15:27:39 -0700 (PDT) From: Song Liu To: , , CC: , , , , , Song Liu , Christoph Hellwig Subject: [PATCH v3 2/3] md: use part_[begin|end]_io_acct instead of disk_[begin|end]_io_acct Date: Mon, 31 Aug 2020 15:27:24 -0700 Message-ID: <20200831222725.3860186-3-songliubraving@fb.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200831222725.3860186-1-songliubraving@fb.com> References: <20200831222725.3860186-1-songliubraving@fb.com> MIME-Version: 1.0 X-FB-Internal: Safe X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.235,18.0.687 definitions=2020-08-31_10:2020-08-31,2020-08-31 signatures=0 X-Proofpoint-Spam-Details: rule=fb_default_notspam policy=fb_default score=0 impostorscore=0 mlxlogscore=851 spamscore=0 lowpriorityscore=0 bulkscore=0 priorityscore=1501 adultscore=0 malwarescore=0 phishscore=0 mlxscore=0 clxscore=1015 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2006250000 definitions=main-2008310132 X-FB-Internal: deliver Sender: linux-block-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org This enables proper statistics in /proc/diskstats for md partitions. Reviewed-by: Christoph Hellwig Signed-off-by: Song Liu --- drivers/md/md.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/md/md.c b/drivers/md/md.c index 6072782070230..8d310d90001c8 100644 --- a/drivers/md/md.c +++ b/drivers/md/md.c @@ -464,6 +464,7 @@ struct md_io { bio_end_io_t *orig_bi_end_io; void *orig_bi_private; unsigned long start_time; + struct hd_struct *part; }; static void md_end_io(struct bio *bio) @@ -471,7 +472,7 @@ static void md_end_io(struct bio *bio) struct md_io *md_io = bio->bi_private; struct mddev *mddev = md_io->mddev; - disk_end_io_acct(mddev->gendisk, bio_op(bio), md_io->start_time); + part_end_io_acct(md_io->part, bio, md_io->start_time); bio->bi_end_io = md_io->orig_bi_end_io; bio->bi_private = md_io->orig_bi_private; @@ -517,9 +518,8 @@ static blk_qc_t md_submit_bio(struct bio *bio) bio->bi_end_io = md_end_io; bio->bi_private = md_io; - md_io->start_time = disk_start_io_acct(mddev->gendisk, - bio_sectors(bio), - bio_op(bio)); + md_io->start_time = part_start_io_acct(mddev->gendisk, + &md_io->part, bio); } /* bio could be mergeable after passing to underlayer */ From patchwork Mon Aug 31 22:27:25 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Song Liu X-Patchwork-Id: 11747099 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 6D319109B for ; Mon, 31 Aug 2020 22:28:13 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 54FB72083E for ; Mon, 31 Aug 2020 22:28:13 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=fb.com header.i=@fb.com header.b="OyWteilh" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728258AbgHaW2M (ORCPT ); Mon, 31 Aug 2020 18:28:12 -0400 Received: from mx0b-00082601.pphosted.com ([67.231.153.30]:61902 "EHLO mx0a-00082601.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728103AbgHaW2M (ORCPT ); Mon, 31 Aug 2020 18:28:12 -0400 Received: from pps.filterd (m0001303.ppops.net [127.0.0.1]) by m0001303.ppops.net (8.16.0.42/8.16.0.42) with SMTP id 07VMS7pD006482 for ; Mon, 31 Aug 2020 15:28:11 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fb.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding : content-type; s=facebook; bh=orOKGnMltIL2BkGpdDMfb191zkSKOEQGAJQMiCk1jzo=; b=OyWteilhr2XBhunMHCsFDP8UZGe/7Avuz2HsEYiGlpXIhP2K1QBSUcEL61adf3fKxcwf Yh/BiqhZ5+6cr3N/SL+A+zDrvzflzHHEI3s4z446nTirQMdx9GRyHa6h24y15Tc9+vnn ciTblBxsUIAVYOOcdpEedMlfwfUv8o/Y7Iw= Received: from mail.thefacebook.com ([163.114.132.120]) by m0001303.ppops.net with ESMTP id 337jpnagum-3 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Mon, 31 Aug 2020 15:28:11 -0700 Received: from intmgw002.03.ash8.facebook.com (2620:10d:c085:208::11) by mail.thefacebook.com (2620:10d:c085:11d::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1979.3; Mon, 31 Aug 2020 15:27:45 -0700 Received: by devbig006.ftw2.facebook.com (Postfix, from userid 4523) id DB76762E51BC; Mon, 31 Aug 2020 15:27:42 -0700 (PDT) From: Song Liu To: , , CC: , , , , , Song Liu , Christoph Hellwig Subject: [PATCH v3 3/3] bcache: use part_[begin|end]_io_acct instead of disk_[begin|end]_io_acct Date: Mon, 31 Aug 2020 15:27:25 -0700 Message-ID: <20200831222725.3860186-4-songliubraving@fb.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200831222725.3860186-1-songliubraving@fb.com> References: <20200831222725.3860186-1-songliubraving@fb.com> MIME-Version: 1.0 X-FB-Internal: Safe X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.235,18.0.687 definitions=2020-08-31_10:2020-08-31,2020-08-31 signatures=0 X-Proofpoint-Spam-Details: rule=fb_default_notspam policy=fb_default score=0 bulkscore=0 adultscore=0 mlxlogscore=843 impostorscore=0 spamscore=0 phishscore=0 suspectscore=0 mlxscore=0 malwarescore=0 lowpriorityscore=0 clxscore=1015 priorityscore=1501 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2006250000 definitions=main-2008310133 X-FB-Internal: deliver Sender: linux-block-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org This enables proper statistics in /proc/diskstats for bcache partitions. Reviewed-by: Coly Li Reviewed-by: Christoph Hellwig Signed-off-by: Song Liu --- drivers/md/bcache/request.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/drivers/md/bcache/request.c b/drivers/md/bcache/request.c index c7cadaafa9475..7f54ae2236441 100644 --- a/drivers/md/bcache/request.c +++ b/drivers/md/bcache/request.c @@ -475,6 +475,7 @@ struct search { unsigned int read_dirty_data:1; unsigned int cache_missed:1; + struct hd_struct *part; unsigned long start_time; struct btree_op op; @@ -669,7 +670,7 @@ static void bio_complete(struct search *s) { if (s->orig_bio) { /* Count on bcache device */ - disk_end_io_acct(s->d->disk, bio_op(s->orig_bio), s->start_time); + part_end_io_acct(s->part, s->orig_bio, s->start_time); trace_bcache_request_end(s->d, s->orig_bio); s->orig_bio->bi_status = s->iop.status; @@ -731,7 +732,7 @@ static inline struct search *search_alloc(struct bio *bio, s->write = op_is_write(bio_op(bio)); s->read_dirty_data = 0; /* Count on the bcache device */ - s->start_time = disk_start_io_acct(d->disk, bio_sectors(bio), bio_op(bio)); + s->start_time = part_start_io_acct(d->disk, &s->part, bio); s->iop.c = d->c; s->iop.bio = NULL; s->iop.inode = d->id; @@ -1072,6 +1073,7 @@ struct detached_dev_io_private { unsigned long start_time; bio_end_io_t *bi_end_io; void *bi_private; + struct hd_struct *part; }; static void detached_dev_end_io(struct bio *bio) @@ -1083,7 +1085,7 @@ static void detached_dev_end_io(struct bio *bio) bio->bi_private = ddip->bi_private; /* Count on the bcache device */ - disk_end_io_acct(ddip->d->disk, bio_op(bio), ddip->start_time); + part_end_io_acct(ddip->part, bio, ddip->start_time); if (bio->bi_status) { struct cached_dev *dc = container_of(ddip->d, @@ -1109,7 +1111,7 @@ static void detached_dev_do_request(struct bcache_device *d, struct bio *bio) ddip = kzalloc(sizeof(struct detached_dev_io_private), GFP_NOIO); ddip->d = d; /* Count on the bcache device */ - ddip->start_time = disk_start_io_acct(d->disk, bio_sectors(bio), bio_op(bio)); + ddip->start_time = part_start_io_acct(d->disk, &ddip->part, bio); ddip->bi_end_io = bio->bi_end_io; ddip->bi_private = bio->bi_private; bio->bi_end_io = detached_dev_end_io;