From patchwork Thu Aug 25 13:44:20 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Butsykin X-Patchwork-Id: 9299423 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 77CC060757 for ; Thu, 25 Aug 2016 14:07:41 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 68A3929323 for ; Thu, 25 Aug 2016 14:07:41 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5D11629345; Thu, 25 Aug 2016 14:07:41 +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 979B829323 for ; Thu, 25 Aug 2016 14:07:40 +0000 (UTC) Received: from localhost ([::1]:56490 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bcvJj-0006ri-CX for patchwork-qemu-devel@patchwork.kernel.org; Thu, 25 Aug 2016 10:07:39 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47316) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bcuyr-0004bk-8f for qemu-devel@nongnu.org; Thu, 25 Aug 2016 09:46:06 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bcuyn-0002KZ-9a for qemu-devel@nongnu.org; Thu, 25 Aug 2016 09:46:05 -0400 Received: from mail-db5eur01on0101.outbound.protection.outlook.com ([104.47.2.101]:9856 helo=EUR01-DB5-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bcuyc-0002He-Fd; Thu, 25 Aug 2016 09:45:50 -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=bBDbo/YsKR++cfFedUsbHY6fIsTnbEiEVIIEZkSfN0g=; b=P++LjqcHhqtp7Bic87u5EI06BisetSIfMPsv/2bHQISMyCYL343EEGGaipALPpJ3TQRa+UO9px1e/fY544ya7WC3D4tSfOYteh8/wb4dzqAX4wca7kia/thJnUx4lf+Bws0kdaQeyYvTH5a1cSUYCpxe/N2RIpCnxsbJkcKK4zY= 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:48 +0000 From: Pavel Butsykin To: , Date: Thu, 25 Aug 2016 16:44:20 +0300 Message-ID: <20160825134421.20231-22-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: b4457eeb-ef61-4f84-c8c8-08d3ccee1f2f X-Microsoft-Exchange-Diagnostics: 1; DB6PR0802MB2549; 2:UHGxq1K7oAFN3xzHX/So/3uKtMryGKacyTAltiycxqE3DKVagzOEaQXR0W5EoPIyXDPHbJ6RUfu4RXw45DWbSvTNsRHFGfYfla/t4xyKzVXL+zwJrHKs047jsi2G4NbVaZeSiwRXbi9fAWjSLH7fvocl1vsz2L3xqDHKX7OvNGvkjiv91tZjDhe6pT5brYu7; 3:stnd7wzfoAueQmAuFf7/Llq2+6p7lUwNnwnVj248GQJPK4qfKrFUZObRWEAs40BEuXHLYNyl/hoiDN0b4OwragIAbxA9qjl4rlekfRuLN3f/xA9SJfRlpY2ay2rD29wb; 25:EFAb9bEdB3z1H72USfXxisikjpiS2FitErjcjsbgciL92GXkQQnuDsSBJvRKRgFdJJnnTqDuuaNnqTqsLZImQzBtJO6/kwpLuyfkfGjOpcfAlP7Bcw+cnLxMbL+iJ3LlAT03URe5HGRqqqvWw3X9msm48iWRryaXUlCd54DUEmt4PrCfjYnm9plGDydNtIZgJnBEPbN45rPti7jXLs0VSx4R+7SdqGaSptmG4nAD2L24KWMD7bkATU2xoPRMiGZbX3dgB+xS0pKZUo5kfSMiugVlWQiP+VSfVfdn/1ePfJfg9nzpS39iwin6h7RuS31z1s9pOSc67JYCtQeQb5IYhdMIUAi22gxj6w4RvhRSip6a/qZNKvfDWuzF2c+g86GZY8vOAH0sizQ+aeIKzu5Bt8V4j+t+ir4hHsbeI6S1Euw= X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:DB6PR0802MB2549; X-Microsoft-Exchange-Diagnostics: 1; DB6PR0802MB2549; 31:eVVJdffMoLuxldXPypZoARiy59oPJWIjGjaVRaU0w2vPmb+8bZaWS+fCeP9IkfPh+C2w2IsnqKjDUiNqCwYExRiCmW9BwO1P2clvGv0FSiLTGMwqQN5/FN/OITDMTjAO8mZ2iwWDQ+St38KP2i6QXASYRw2rMQAYXmF34h8AjcMakj7O/GlttTcnOS/UTQO9IQG/81dy92sgTlfG2huiu0zaps+Xy/hGNCmhEOIE3SA=; 4:c6HByqwm3ViFnwAU9WI+gK3G733VsgjEErkdD5L0hm1R/nAJ0cSnkyLXSh94O+8igheQXt7UBRUm8AqjAtg/gCWaT8M8/Ol8AyY2dPSQ7fGa2IUaH6G//LNdRcLe9H66WcPoVDgITkml2QG87ZTyTuBjFzrWGj38/vvucFk6Yn/mlnnmvToSKRrounhy+qequsBC0dlhkj+4bholwH4CL6YvtJCEoa5DKof5tshmO3eXatOLN7O3HC8Gu3c74IZW5Lf1nmLmksALB1+SIuAJjqexWaqNXruU58ZdlA/ekpWtr83KdF98EkqqEDVs3hjM53IF5I6noedFIgarnnxL7pW9dWJMHlJaM9IuSZZgNJ7/gREiknZ6peQqKSbrTg9ogxTrdXwAN384kEeu35TC8okQtYu4rEHoL+WNtLR5uQA= 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: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yLvXimBLbj+5ET7eI85ML55JbmkDV45YJZyFs5822EAoZSdRpfaTBz5lppEu0JMlf5GjxzZJ40C2OZxhRUrhTJiXW/DxTV5OiD3OpFg5Mk1OPXxhb78DQ4pcG5rW9UgX8xAL7/PaiMwxP2v4K56r45xqFMByboBmuvTP3o8v+SrKxJqA5ILkcqWpzSsBAv3spZJciy5J693g5X3RAMZs+/XFE7d0dDKwdK23T0i5z7Qc SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; DB6PR0802MB2549; 20:4v/q/bv8zONCvBtoqYvpm3IHDQC748+R8GQe/SVPKPFZbdnYCxaa5iNfd/YhX9MmG7CDdt8ydxA3UUiclKzfBhyGBFf/O6PYxQXmHToJGCqYvEQh/8RnZPpwW04NDIjOCUBEwYdz3tgVe/E4CfqWXqy6w2mJgLo5XkyiO4I1LZc= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Aug 2016 13:45:48.0054 (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 21/22] block/pcache: add write through 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 Write-through is another way to keep the cache up-to-date. Even if this case will be rare, a node write buf is easier than a node drop. Signed-off-by: Pavel Butsykin --- block/pcache.c | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/block/pcache.c b/block/pcache.c index c5fe689..2b2edf5 100644 --- a/block/pcache.c +++ b/block/pcache.c @@ -200,6 +200,8 @@ static QemuOptsList runtime_opts = { #define PCACHE_DEFAULT_POOL_STAT_SIZE (1 << MB_BITS) #define PCACHE_DEFAULT_MAX_AIO_SIZE (32 << KB_BITS) +#define PCACHE_WRITE_THROUGH_NODE TRUE + enum { NODE_SUCCESS_STATUS = 0, NODE_WAIT_STATUS = 1, @@ -538,7 +540,12 @@ static uint64_t ranges_overlap_size(uint64_t node1, uint32_t size1, return MIN(node1 + size1, node2 + size2) - MAX(node1, node2); } -static inline void pcache_node_read_buf(PrefCacheAIOCB *acb, PCNode* node) +enum { + NODE_READ_BUF = 1, + NODE_WRITE_BUF = 2 +}; + +static void pcache_node_rw_buf(PrefCacheAIOCB *acb, PCNode* node, uint32_t type) { uint64_t qiov_offs = 0, node_offs = 0; uint32_t size; @@ -554,8 +561,9 @@ static inline void pcache_node_read_buf(PrefCacheAIOCB *acb, PCNode* node) << BDRV_SECTOR_BITS; qemu_co_mutex_lock(&node->lock); /* XXX: use rw lock */ - copy = \ - qemu_iovec_from_buf(acb->qiov, qiov_offs, node->data + node_offs, size); + 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); assert(copy == size); } @@ -586,7 +594,7 @@ static void pcache_node_read(PrefCacheAIOCB *acb, PCNode* node) } qemu_co_mutex_unlock(&node->lock); - pcache_node_read_buf(acb, node); + pcache_node_rw_buf(acb, node, NODE_READ_BUF); pcache_node_unref(acb->s, node); } @@ -712,7 +720,7 @@ static void pcache_complete_acb_wait_queue(BDRVPCacheState *s, PCNode *node, g_slice_free1(sizeof(*link), link); if (ret == 0) { - pcache_node_read_buf(wait_acb, node); + pcache_node_rw_buf(wait_acb, node, NODE_READ_BUF); } else { /* write only fail, because next request can rewrite error */ wait_acb->ret = ret; } @@ -761,7 +769,7 @@ static void pcache_merge_requests(PrefCacheAIOCB *acb) if (acb->ret == 0) { pcache_node_submit(req); if (!(acb->aio_type & PCACHE_AIO_READAHEAD)) { - pcache_node_read_buf(acb, node); + pcache_node_rw_buf(acb, node, NODE_READ_BUF); } } else { pcache_node_drop(acb->s, node); @@ -774,7 +782,7 @@ static void pcache_merge_requests(PrefCacheAIOCB *acb) qemu_co_mutex_unlock(&acb->requests.lock); } -static void pcache_try_node_drop(PrefCacheAIOCB *acb) +static void pcache_update_node_state(PrefCacheAIOCB *acb) { BDRVPCacheState *s = acb->s; RbNodeKey key; @@ -793,7 +801,11 @@ static void pcache_try_node_drop(PrefCacheAIOCB *acb) } if (node->status != NODE_WAIT_STATUS) { NODE_ASSERT(node->status == NODE_SUCCESS_STATUS, node); +#if PCACHE_WRITE_THROUGH_NODE + pcache_node_rw_buf(acb, node, NODE_WRITE_BUF); +#else pcache_node_drop(s, node); +#endif } key.num = node->cm.sector_num + node->cm.nb_sectors; @@ -820,7 +832,7 @@ static void pcache_aio_cb(void *opaque, int ret) return; } } else { /* PCACHE_AIO_WRITE */ - pcache_try_node_drop(acb); /* XXX: use write through */ + pcache_update_node_state(acb); } complete_aio_request(acb);