From patchwork Thu Aug 25 13:44:21 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Butsykin X-Patchwork-Id: 9299415 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 62FAD60757 for ; Thu, 25 Aug 2016 14:01:10 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 541FC2930C for ; Thu, 25 Aug 2016 14:01:10 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 48B152933B; Thu, 25 Aug 2016 14:01:10 +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=-6.8 required=2.0 tests=BAD_ENC_HEADER,BAYES_00, DKIM_SIGNED, RCVD_IN_DNSWL_HI, T_DKIM_INVALID 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 504272930C for ; Thu, 25 Aug 2016 14:01:08 +0000 (UTC) Received: from localhost ([::1]:56452 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bcvDP-0001T5-Et for patchwork-qemu-devel@patchwork.kernel.org; Thu, 25 Aug 2016 10:01:07 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47250) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bcuyi-0004S5-LZ for qemu-devel@nongnu.org; Thu, 25 Aug 2016 09:45:57 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bcuyg-0002J2-J5 for qemu-devel@nongnu.org; Thu, 25 Aug 2016 09:45:55 -0400 Received: from mail-db5eur01on0101.outbound.protection.outlook.com ([104.47.2.101]:58930 helo=EUR01-DB5-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bcuye-0002I1-44; Thu, 25 Aug 2016 09:45:52 -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; bh=b2VlX9e1kMS8DDuyUGs8pXta6G5f25HAY/DmdN8NPVs=; b=QGZdxZTKTKIObmHJujCnvRPqIl8ECEKNt5N77g/AYwOJgZZPiaiKFlerz4IIPskzcvMAU12XSunaL4Y/raCKA6VyWop4jiv+JYqSABsNpN+yJLzRcT18efv2xp9p9qTEjhxobWlTpLQbmlf2pYKJEgElSvvQBBue44qOhSrUamQ= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=pbutsykin@virtuozzo.com; Received: from pavelb-Z68P-DS3.sw.ru (195.214.232.10) by DB6PR0802MB2549.eurprd08.prod.outlook.com (10.172.251.147) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA_P384) id 15.1.587.9; Thu, 25 Aug 2016 13:45:49 +0000 From: Pavel Butsykin To: , Date: Thu, 25 Aug 2016 16:44:21 +0300 Message-ID: <20160825134421.20231-23-pbutsykin@virtuozzo.com> X-Mailer: git-send-email 2.8.3 In-Reply-To: <20160825134421.20231-1-pbutsykin@virtuozzo.com> References: <20160825134421.20231-1-pbutsykin@virtuozzo.com> MIME-Version: 1.0 X-Originating-IP: [195.214.232.10] X-ClientProxiedBy: AMSPR02CA0013.eurprd02.prod.outlook.com (10.242.225.141) To DB6PR0802MB2549.eurprd08.prod.outlook.com (10.172.251.147) X-MS-Office365-Filtering-Correlation-Id: a2ae4760-9e80-4b58-9bcb-08d3ccee1fce X-Microsoft-Exchange-Diagnostics: 1; DB6PR0802MB2549; 2:ih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2FjJNSmqnkUQbXc=; 4:vRDzFvNDMLvda0fDbzcL0cmDYYodo4mRodp9dSjC2dvYscJQX4j/5OECsj+B6i6ewuip6zC3Aw4NqQhuwcbnU1l2Oc4jEFXLvL0+CvFJRFfVZEHQrUBwGjT6V65dypFYCvapPSDMvdDZITq6o/ZadLhM36J6XgbNSmbbYpBAHhgH4ZzMvPmqTPUlmCSlOdY2O4j6Y0Yx8mS5qUTtiOK0xHYl/APheTlI5Z3GEGJYqWFzNAHcYLSJGMzsvxQpaNukQj3pV4g8GFlft4D1XgNUr5PZCEL31rgcjmvSEa97HrWk2qSm2D3C/Y6HM4lvRSMw+5cWj4tjEp8nGJDLK2qJp9yb1kybBilL91ZvHK+6MgJVkO0UVw+0z0cB+aideUtV+z1PjjZWIkAU8VQGcM+OYbnjoTwOuy5jEspUbnxlqBg= X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6040176)(601004)(2401047)(8121501046)(5005006)(10201501046)(3002001)(6043046)(6042046); SRVR:DB6PR0802MB2549; BCL:0; PCL:0; RULEID:; SRVR:DB6PR0802MB2549; X-Forefront-PRVS: 0045236D47 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10019020)(4630300001)(6009001)(7916002)(189002)(199003)(86362001)(33646002)(1076002)(69596002)(5003940100001)(42186005)(68736007)(189998001)(92566002)(66066001)(106356001)(47776003)(6116002)(3846002)(586003)(36756003)(5001770100001)(97736004)(2906002)(4326007)(2950100001)(5660300001)(76176999)(48376002)(53416004)(105586002)(50466002)(81156014)(8676002)(50226002)(77096005)(81166006)(19580405001)(50986999)(229853001)(101416001)(7846002)(7736002)(305945005)(19580395003)(21314002)(217873001); DIR:OUT; SFP:1102; SCL:1; SRVR:DB6PR0802MB2549; H:pavelb-Z68P-DS3.sw.ru; FPR:; SPF:None; PTR:InfoNoRecords; MX:1; A:1; LANG:en; Received-SPF: None (protection.outlook.com: virtuozzo.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; DB6PR0802MB2549; 23:sxYjoEBdhBgQGZwqdAEEQCAyLr/TfEYO14ZrNOz?= =?us-ascii?Q?TBVIHIaMpxb+7d6yJZWmThD0vgI0CifIJ02B53MK0dP4CyPu69TsTB+ypQSd?= =?us-ascii?Q?lmt0y545CDCZlGhWx533X+aS0+H0LmlSVqV43h/NQExo9dQU/vgsgL8GgKzb?= =?us-ascii?Q?SxQi/0LVrMh7WJTp/qaxOsrDi4NIuhtZnsBJSGOf3tAVRj4ap/qCiR+5o/mp?= =?us-ascii?Q?wLBXzy6Mip9w6pJIkwInQqkZMtfX5xSdsbui7PP7t9oY8y1RToLDgYMaZGuN?= =?us-ascii?Q?JaqTRaSUOmzYmch6ivMBqfHjEqbuPGEyUIjT54HjXzp0yfVjMk401zACj4tp?= =?us-ascii?Q?Xqze2+x9cPgURwp/4ZSKGWGIY01EGeHdmKsfjbzsBVj3SWnMEsQdsm0ZhTlP?= =?us-ascii?Q?quS9d/CN8UdrKQiIWfsraZbLEkfKw7iljoixi2qkunVlXvWdoItvTRvSBJEY?= =?us-ascii?Q?xtTd8jNPu4k80TFkv2iEICCeAgfsLrlFK66hx4s666uP8sKXbeiFQKhSUi3M?= =?us-ascii?Q?tQkXdx6T/x+KRQMONjCel8A68fBXi41hSB9Ymvt/J5yZz2tseciChxf7ZCFj?= =?us-ascii?Q?CEBIFIIkW4p0qe0zxdUCsDaPFqu18/mrgQGv4OYanVRFraqqldV+aXILsZ4X?= =?us-ascii?Q?IF4Y2e7kjK9YPW98cF9L/g1Vf3IkWbXoyW/81j2FB5nozCU5QSCKTO7/m7LJ?= =?us-ascii?Q?iTvcU7yRKBIGaW/wfREL+AxGU1xS/xybcP7eJLIaHm9iQTnhx/OOEWDddFYT?= =?us-ascii?Q?GYg23sPka7PWBoYEsGVLjuKJU7h+lktw0KRExfAJHdCTj70lpstf8WFYjy0X?= =?us-ascii?Q?fIY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4=; 7:DPlol951L499JVj/9w8HvsCQN1s8EdXR0ss2fbWZ1KEhKO78rP1RKAI/Eo0+Uoj7vktx7YBuxaT/qh8UWsvHgENRDJMocmfnt96w45QU0DCXoML/rugmkYXEVtNqUD2c//RsT8c5qVUqpXd4khfzO5Xjr26DNaggEqhtto7nr39XyoJ6UPJjNhGCXTrHEBHbB15BG4b5zkClikhzvOaSdOEDhLLUueWmkoLx/bW2eULlLE1Lh7kEmT3+yA/rbZYc SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; DB6PR0802MB2549; 20:U0GaeDuQO4giPcJYi22X1ShIIDUmGoFvXa7tkzLGrnjO7dLtFESE70bur33+h7f2KqPBA2oT87ae2dG+T7mTxwMDN9eGe9w+LHDzxICBTYr6t54u16Une/FjD4vtkbmIkojnBbglCDUcXh/bgI2DbnD3H+ynThFfJ8rVB9BI2Qk= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Aug 2016 13:45:49.0292 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB6PR0802MB2549 X-detected-operating-system: by eggs.gnu.org: Windows 7 or 8 [fuzzy] X-Received-From: 104.47.2.101 Subject: [Qemu-devel] [PATCH RFC 22/22] block/pcache: drop used pcache node 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, den@openvz.org, jsnow@redhat.com, stefanha@redhat.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP The pcache is directed to certain situations to sequential reads. This concept allows to drop parts of the cache that were already used, which will reduce the size of cache and the number of displaced nodes. Signed-off-by: Pavel Butsykin --- block/pcache.c | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/block/pcache.c b/block/pcache.c index 2b2edf5..3fad4ca 100644 --- a/block/pcache.c +++ b/block/pcache.c @@ -88,6 +88,7 @@ typedef struct PCNode { uint32_t status; uint32_t ref; uint8_t *data; + uint32_t rdcnt; CoMutex lock; } PCNode; @@ -342,6 +343,7 @@ static inline void *pcache_node_alloc(RbNodeKey* key) node->cm.nb_sectors = key->size; node->ref = 0; node->status = NODE_WAIT_STATUS; + node->rdcnt = 0; qemu_co_mutex_init(&node->lock); node->data = g_malloc(node->cm.nb_sectors << BDRV_SECTOR_BITS); node->wait.cnt = 0; @@ -560,11 +562,23 @@ static void pcache_node_rw_buf(PrefCacheAIOCB *acb, PCNode* node, uint32_t type) node->cm.sector_num, node->cm.nb_sectors) << BDRV_SECTOR_BITS; - qemu_co_mutex_lock(&node->lock); /* XXX: use rw lock */ - copy = type & NODE_READ_BUF ? - qemu_iovec_from_buf(acb->qiov, qiov_offs, node->data + node_offs, size) - : qemu_iovec_to_buf(acb->qiov, qiov_offs, node->data + node_offs, size); - qemu_co_mutex_unlock(&node->lock); + if (type & NODE_READ_BUF) { + qemu_co_mutex_lock(&node->lock); /* XXX: use rw lock */ + copy = qemu_iovec_from_buf(acb->qiov, qiov_offs, + node->data + node_offs, size); + qemu_co_mutex_unlock(&node->lock); + + /* pcache node is no longer needed, when it was all read */ + atomic_add(&node->rdcnt, size >> BDRV_SECTOR_BITS); + if (node->rdcnt >= node->cm.nb_sectors) { + pcache_node_drop(acb->s, node); + } + } else { + qemu_co_mutex_lock(&node->lock); /* XXX: use rw lock */ + copy = qemu_iovec_to_buf(acb->qiov, qiov_offs, + node->data + node_offs, size); + qemu_co_mutex_unlock(&node->lock); + } assert(copy == size); }