From patchwork Wed Oct 31 11:35:02 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Nefedov X-Patchwork-Id: 10662515 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 2DB9A17DF for ; Wed, 31 Oct 2018 11:40:20 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 22F1D2AB09 for ; Wed, 31 Oct 2018 11:40:20 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 15B042AB63; Wed, 31 Oct 2018 11:40:20 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 8FA302AB46 for ; Wed, 31 Oct 2018 11:40:19 +0000 (UTC) Received: from localhost ([::1]:58756 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gHorC-0000OZ-RT for patchwork-qemu-devel@patchwork.kernel.org; Wed, 31 Oct 2018 07:40:18 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:34833) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gHomX-0003io-1Y for qemu-devel@nongnu.org; Wed, 31 Oct 2018 07:35:33 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gHomR-0001y8-0T for qemu-devel@nongnu.org; Wed, 31 Oct 2018 07:35:27 -0400 Received: from mail-eopbgr50114.outbound.protection.outlook.com ([40.107.5.114]:29664 helo=EUR03-VE1-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gHomQ-0001co-OB; Wed, 31 Oct 2018 07:35:22 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=virtuozzo.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Q17EkUpT94s3oeAgLbTa4+Mlnbp4+nx5VatptCxPFEw=; b=YfKDLN2pT0VrJ7cIJslswHAfk8KR9tBQnvsaCA8kINf/A5l4J7k5MG5wjRKScbowjToZyOHLF6EhdNgDWUS74t7C8oAi6rlvZbpBaBdZh2njq/NYmkihjJDty6kT8t+6dR7NJI3WXrGvExdcksaReUwtFU6SFjgsJO3KPiGPKUU= Received: from VI1PR08MB3358.eurprd08.prod.outlook.com (52.134.31.145) by VI1PR08MB0413.eurprd08.prod.outlook.com (10.162.12.20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1273.25; Wed, 31 Oct 2018 11:35:02 +0000 Received: from VI1PR08MB3358.eurprd08.prod.outlook.com ([fe80::614e:e2cd:51e1:a19c]) by VI1PR08MB3358.eurprd08.prod.outlook.com ([fe80::614e:e2cd:51e1:a19c%4]) with mapi id 15.20.1273.027; Wed, 31 Oct 2018 11:35:02 +0000 From: Anton Nefedov To: "qemu-devel@nongnu.org" Thread-Topic: [PATCH v5 8/9] file-posix: account discard operations Thread-Index: AQHUcQ3CtViFMrtHOEGD4I70d9FlKg== Date: Wed, 31 Oct 2018 11:35:02 +0000 Message-ID: <20181031113418.29796-9-anton.nefedov@virtuozzo.com> References: <20181031113418.29796-1-anton.nefedov@virtuozzo.com> In-Reply-To: <20181031113418.29796-1-anton.nefedov@virtuozzo.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: AM6PR05CA0028.eurprd05.prod.outlook.com (2603:10a6:20b:2e::41) To VI1PR08MB3358.eurprd08.prod.outlook.com (2603:10a6:803:3f::17) authentication-results: spf=none (sender IP is ) smtp.mailfrom=anton.nefedov@virtuozzo.com; x-ms-exchange-messagesentrepresentingtype: 1 x-originating-ip: [185.231.240.5] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1; VI1PR08MB0413; 20:+y1mH2Q1d2MbFoJGEH7pCG2o2+F5zy1EEDvghbLtTZ1i1dIH5Iv8uskrwDKIIQbim7QJTdnJq7dquysW/wht1WGZv/a3aWZ5+BmyR8rhtApCmYzAIQFHGRel+ozVqhQADXp1zF8reU0TXG1DZDO2Q/tcJTpoJX4Qxrrg9FYqSFU= x-ms-office365-filtering-correlation-id: 3504cdb3-0345-4916-79f5-08d63f24e53b x-microsoft-antispam: BCL:0; PCL:0; RULEID:(7020095)(4652040)(8989299)(5600074)(711020)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(2017052603328)(7153060)(7193020); SRVR:VI1PR08MB0413; x-ms-traffictypediagnostic: VI1PR08MB0413: x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:; x-ms-exchange-senderadcheck: 1 x-exchange-antispam-report-cfa-test: BCL:0; PCL:0; RULEID:(6040522)(2401047)(5005006)(8121501046)(93006095)(93001095)(3231382)(944501410)(52105095)(3002001)(10201501046)(148016)(149066)(150057)(6041310)(20161123560045)(20161123564045)(20161123562045)(20161123558120)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(201708071742011)(7699051)(76991095); SRVR:VI1PR08MB0413; BCL:0; PCL:0; RULEID:; SRVR:VI1PR08MB0413; x-forefront-prvs: 084285FC5C x-forefront-antispam-report: SFV:NSPM; SFS:(10019020)(136003)(376002)(346002)(39850400004)(366004)(396003)(189003)(199004)(6486002)(68736007)(76176011)(66066001)(5640700003)(2900100001)(6512007)(6436002)(2616005)(476003)(2501003)(53936002)(44832011)(11346002)(5250100002)(486006)(52116002)(97736004)(5660300001)(478600001)(14454004)(6916009)(6506007)(386003)(107886003)(71200400001)(71190400001)(25786009)(4326008)(1076002)(2906002)(186003)(86362001)(7416002)(316002)(15650500001)(446003)(3846002)(26005)(14444005)(102836004)(2351001)(305945005)(7736002)(105586002)(106356001)(99286004)(36756003)(6116002)(54906003)(8676002)(256004)(8936002)(81156014)(81166006); DIR:OUT; SFP:1102; SCL:1; SRVR:VI1PR08MB0413; H:VI1PR08MB3358.eurprd08.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; MX:1; A:1; received-spf: None (protection.outlook.com: virtuozzo.com does not designate permitted sender hosts) x-microsoft-antispam-message-info: 3q4dJXmGeqIVPxKomeIW3nzxCLBeBWXihEcrDliia8CE5WdUaPN0tiGgpy8dtmjbGWWaXuknyFdJdgarwKGnTD5EpQlmBEW/o2ShdGnf2XBRF9flOX8pGcQZxxeygnK/GG7JGY1VH3+vpvebF5JfE0Nm4jaA+W3NT3zHRya42UV/OqWevQceIn1cf2Vmyg/61HoPM540QEBtg3pxJQuqNQjaSYl19NP0O7rCkrmaZSn8f2nK1tY1jx7TuTQIe8c9F+6gym5FRp6/Z2xIQ4g+F8fD6J1tRSvGlyfzDO8bsMrX/Wv0he077UUAUr46knVHGQ12X2LPw1/eYE20FQ2ZTFaJvQRc9R4+Tjd+TZmdYOg= spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM MIME-Version: 1.0 X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-Network-Message-Id: 3504cdb3-0345-4916-79f5-08d63f24e53b X-MS-Exchange-CrossTenant-originalarrivaltime: 31 Oct 2018 11:35:02.6293 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 0bc7f26d-0264-416e-a6fc-8352af79c58f X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR08MB0413 X-detected-operating-system: by eggs.gnu.org: Windows 7 or 8 [fuzzy] X-Received-From: 40.107.5.114 Subject: [Qemu-devel] [PATCH v5 8/9] file-posix: account discard operations X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: "kwolf@redhat.com" , Vladimir Sementsov-Ogievskiy , "famz@redhat.com" , Denis Lunev , "qemu-block@nongnu.org" , "armbru@redhat.com" , "mreitz@redhat.com" , "berto@igalia.com" , Anton Nefedov , "pbonzini@redhat.com" , "jsnow@redhat.com" Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP This will help to identify how many of the user-issued discard operations (accounted on a device level) have actually suceeded down on the host file (even though the numbers will not be exactly the same if non-raw format driver is used (e.g. qcow2 sending metadata discards)). Note that these numbers will not include discards triggered by write-zeroes + MAY_UNMAP calls. Signed-off-by: Anton Nefedov Reviewed-by: Vladimir Sementsov-Ogievskiy --- block/file-posix.c | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/block/file-posix.c b/block/file-posix.c index 2da3a76355..1a7126046c 100644 --- a/block/file-posix.c +++ b/block/file-posix.c @@ -163,6 +163,11 @@ typedef struct BDRVRawState { bool has_fallocate; bool needs_alignment; bool check_cache_dropped; + struct { + int64_t discard_nb_ok; + int64_t discard_nb_failed; + int64_t discard_bytes_ok; + } stats; PRManager *pr_mgr; } BDRVRawState; @@ -2582,12 +2587,25 @@ static void coroutine_fn raw_co_invalidate_cache(BlockDriverState *bs, #endif /* !__linux__ */ } +static void raw_account_discard(BDRVRawState *s, uint64_t nbytes, int ret) +{ + if (ret) { + s->stats.discard_nb_failed++; + } else { + s->stats.discard_nb_ok++; + s->stats.discard_bytes_ok += nbytes; + } +} + static coroutine_fn int raw_co_pdiscard(BlockDriverState *bs, int64_t offset, int bytes) { BDRVRawState *s = bs->opaque; + int ret; - return paio_submit_co(bs, s->fd, offset, NULL, bytes, QEMU_AIO_DISCARD); + ret = paio_submit_co(bs, s->fd, offset, NULL, bytes, QEMU_AIO_DISCARD); + raw_account_discard(s, bytes, ret); + return ret; } static int coroutine_fn raw_co_pwrite_zeroes( @@ -3084,10 +3102,14 @@ hdev_co_pdiscard(BlockDriverState *bs, int64_t offset, int bytes) ret = fd_open(bs); if (ret < 0) { + raw_account_discard(s, bytes, ret); return ret; } - return paio_submit_co(bs, s->fd, offset, NULL, bytes, - QEMU_AIO_DISCARD | QEMU_AIO_BLKDEV); + + ret = paio_submit_co(bs, s->fd, offset, NULL, bytes, + QEMU_AIO_DISCARD | QEMU_AIO_BLKDEV); + raw_account_discard(s, bytes, ret); + return ret; } static coroutine_fn int hdev_co_pwrite_zeroes(BlockDriverState *bs,