From patchwork Mon Aug 29 17:10: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: 9304513 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 E42816077C for ; Mon, 29 Aug 2016 21:44:43 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D93A428998 for ; Mon, 29 Aug 2016 21:44:43 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CDC1E289C6; Mon, 29 Aug 2016 21:44:43 +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 33B0428998 for ; Mon, 29 Aug 2016 21:44:43 +0000 (UTC) Received: from localhost ([::1]:45877 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1beUME-0004gm-0O for patchwork-qemu-devel@patchwork.kernel.org; Mon, 29 Aug 2016 17:44:42 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45485) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1beULk-0004ad-QQ for qemu-devel@nongnu.org; Mon, 29 Aug 2016 17:44:13 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1beULj-0002I8-Tz for qemu-devel@nongnu.org; Mon, 29 Aug 2016 17:44:12 -0400 Received: from mail-db5eur01on0135.outbound.protection.outlook.com ([104.47.2.135]:47849 helo=EUR01-DB5-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1beULe-0002Gj-AL; Mon, 29 Aug 2016 17:44:06 -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=f1n6vqTI/RSwWXOp6F8AIOdCp2XOBRLlO+Crljf8RaCDm+MRgMM60Lx5sRzzztUkYutz7liQ7RFv1LArbCBK5HtwiiI+BUHkrNFXYFXqCjAIF7LUhSJH7UAkpIOjE5k7dDp4+EtiWodgdAU0uNKQD3GO06HlH66aveY83PFF0Wc= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=pbutsykin@virtuozzo.com; Received: from pavelb-Z68P-DS3.sw.ru (195.214.232.10) by AM5PR0802MB2547.eurprd08.prod.outlook.com (10.175.45.23) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA_P384) id 15.1.587.13; Mon, 29 Aug 2016 17:11:32 +0000 From: Pavel Butsykin To: , Date: Mon, 29 Aug 2016 20:10:21 +0300 Message-ID: <20160829171021.4902-23-pbutsykin@virtuozzo.com> X-Mailer: git-send-email 2.8.3 In-Reply-To: <20160829171021.4902-1-pbutsykin@virtuozzo.com> References: <20160829171021.4902-1-pbutsykin@virtuozzo.com> MIME-Version: 1.0 X-Originating-IP: [195.214.232.10] X-ClientProxiedBy: AM5PR0901CA0011.eurprd09.prod.outlook.com (10.164.186.149) To AM5PR0802MB2547.eurprd08.prod.outlook.com (10.175.45.23) X-MS-Office365-Filtering-Correlation-Id: 59b92e70-e242-44df-6b32-08d3d02f86e2 X-Microsoft-Exchange-Diagnostics: 1; AM5PR0802MB2547; 2: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fTyraE7RuPuc/01GvxVTeoiNNUX3yZ/WmQ9jXPcX7+kQ8m8MSyEETleuDogdkaWLarsA==; 31:jFEC50/6p2mfCyLA0N9iiyujdNks2seHcqizs+JQ2V/dmsqgb0Q+jYhJdv10zZAtFnRnYTNg936wdRmEMw14fCE+IGNYOX5HjUvLc3hkDDlvgz4WKn4kj7zMxMSh/xYkMSfg2cp8z/JiQFs9V3lYAAd+RWji81lmFHqnWoLWTlteqD46ClS6WBi3/3DydM8B0AOd7aFRP2YCR/GpAW3UEXFLICgXeKhNi6Bx32rpjvo= 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)(6042046)(6043046); SRVR:AM5PR0802MB2547; BCL:0; PCL:0; RULEID:; SRVR:AM5PR0802MB2547; X-Microsoft-Exchange-Diagnostics: 1; AM5PR0802MB2547; 4:csdcO4dl4h3AFhgAR7SWk6F5MhH+JGIaLfPxCz64z9oqQVMnwbUHrOE4meNnH508MUVixjt9OvABxvn9LBdTM1dzBkuZWNzcsHe6Sw+RSFRvxj/VVXom0HPvLIy5Env/BpkACBxbvuzHxtjrD4rindsMNLihi2FE6EpTDKqIH1LuqEYOOaQtRHnOUdAi1RID4Wl024pjapUo8eCxoWNjBhhSuAIthm0xHmcdEF5w0SF1kfrNCjVNEcwA6WUbwGMKssC6aDjpk+nrT3w1eklqs+3Bv2aKVCfX5oRLCDnNWcdMUoBjiNvlUSe6aFEO958/+WEYqnOwSqjDHfQ4swNa7tFch+ynR0ObXFTzp5XW2CBbjx2wKJgXZ+KBGtXe6CIpjVUIMQ/YfqTmiT8Hr0a4wZ7MbUcECcLu1TH4GN+z/ks= X-Forefront-PRVS: 0049B3F387 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10019020)(4630300001)(6009001)(7916002)(199003)(189002)(3846002)(305945005)(77096005)(86362001)(1076002)(53416004)(92566002)(68736007)(42186005)(97736004)(5001770100001)(47776003)(105586002)(2906002)(6116002)(189998001)(50986999)(4326007)(48376002)(586003)(2950100001)(5003940100001)(50466002)(66066001)(19580405001)(19580395003)(76176999)(69596002)(5660300001)(229853001)(101416001)(36756003)(7736002)(8676002)(106356001)(50226002)(7846002)(81156014)(33646002)(81166006)(21314002)(217873001); DIR:OUT; SFP:1102; SCL:1; SRVR:AM5PR0802MB2547; H:pavelb-Z68P-DS3.sw.ru; FPR:; SPF:None; PTR:InfoNoRecords; A:1; MX: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; AM5PR0802MB2547; 23:8CocN7i2vvr3pRwt9W9WxPehDTtL64p+RWK13Ep?= =?us-ascii?Q?SmPk9vUjzFh0dMWc+wMYVyTQkYL5t5scdMAghTgPhhBCWUSvdXsp86xuTY1H?= =?us-ascii?Q?RpdHNUrRNEnaLS5Z8Ce3Y5lH6ZCYgc0yn+e3LHBoDFDQBfty4kp3o4cuKgOv?= =?us-ascii?Q?tBVk/dL9SH20F1+kXgm5JDCBH9ckPjvnWTWhH31JGYQseXdu3Tz41UX5siec?= =?us-ascii?Q?6hAnompGjT9Z4zF/+yteXxH0YKPaqFWQcctOw0Rob8zrXHoZJSLiWk1ZZPat?= =?us-ascii?Q?C1ah7dwToMygebc4Ogmw18zfSot/nVbt4OjJ9DhniPDTsBQRJLoQthsX5w7D?= =?us-ascii?Q?jMD/2oYdXnI07OXLSbqZ+m2Ii61KqrIxnlyZlNvNKIuQDJsVcNTb8WBCi7yB?= =?us-ascii?Q?uW2hsuFko+23kmgbJ8JI/bJppDzqDjS3rIdhVIsuG8k//WOsl1C6n/f0blbr?= =?us-ascii?Q?nR1g32w8tQ6vSMRO0PyFcYeOZSTXICk7eGvaIFpQ8UiYx2rO/i11HsRZaUt1?= =?us-ascii?Q?N82qzFpHfUL7mE9iI+BbJ/qppx3xgXksg0R86Yl/rCLZm9xWfoqdBbOFxDoa?= =?us-ascii?Q?XookflfyhB4J0+wIldghGNUfM+CHXCKDdqEJm1jEPk8uFrEXgiTrqj+fNvTE?= =?us-ascii?Q?Qpt/mTFvWkSigSqHgrUt5ZfMxKJA7JrXhka/xlZA9oXOjiGKTWQ5K15+wooS?= =?us-ascii?Q?ncozSRSbWJyMul6rtgu9F4LlZYTEB9sWb7xo8EgS/7ROHXVwfMWf4iVtec3z?= =?us-ascii?Q?s6OqFrerHQ0oeeVocWC5NNpl2tX2gMwVD9e50r1UPaPv+Ag3e3u7XIqkPKo5?= =?us-ascii?Q?/lRwr/vzntMUmta6PxI7VjkAMaBYuIrAveuVIvTSZQFM7GQ/JKNgALis/Nlr?= =?us-ascii?Q?2rmqtZo3ynTWgcUcADvyLkdMikq3PjB5QmBanDNKz3SNaZzv5oEpux0Wqb9l?= =?us-ascii?Q?mEZ6rDQE0H74SyW43bW229FPu5GY9ccU6U1Klx/TfY9hDBRJ5gxZukCavk4G?= =?us-ascii?Q?EUFsir53S0Kj6f9CosDBBKENAvGkUXElY6VA1dGM/+2jkCMx9srI+UrkDJ6m?= =?us-ascii?Q?Pkc3wilYMOer0LguSs5StFNdGXLjnxeN/0/lZ+6B12wTfTbzPwi7f5bg4Hg/?= =?us-ascii?Q?OQxaYixnUdIIMq8+mNWvajZIL51cdz9/WRBX3xMFUKaXBreZvPEh0KEu1qza?= =?us-ascii?Q?a2srNlcqMfR9DIuY=3D?= X-Microsoft-Exchange-Diagnostics: 1; AM5PR0802MB2547; 6:quOpqoKF5yAi0aM9sSFoHXhyiNW32dT/KnG4iz4L6BwGJeCoTlx3/S+rz9jal1xwLTAYlngTEf10spmS42ycfCY8PjEcGvlfUT4byS71jJybdCcdVC23r5KWszTVvfcfUZ4faMMurAC+X6UmNCGimM7FJT1NwwVhxfZyIxkkL58VgUX0tqicu9w5whe5ej9KSkczYyApARWDHnkXMUQqadAct+1bSOUDgsjiQe4aFCbnhT7fdMrAJApz2b2d6/2I0QxFRrRMPariT0CpXox65hntwtwDKt4lO2HN3Y+P5qKQGfGJ6VW/2By9QIB7FU8L; 5:GlZWx7JLIqWYNIX50P6EHFfpBAtx+qNQgdelhOXlJZOwCunbp5ktoOkVPUIU7//JXOxLcgEXNvmln6/MfUjnpazM54VFFYaE4zeIx3CBXogin6QEs7mwgLBnVcJF0RiHNBE+AjXfch5BoP8zTOqUzw==; 24:bus+wJLcNhcoLdIsE43G7MDy0YnF44xbuNpjBNwbA+961dOFNyxnnJdCKAh5eVRwvmYkZAFOgwBEup/kBueLThAYiHZrGAl9ZGpUM4xH7/g=; 7:MXDB+RlckNd7uWg/X810Pz2uzCUWbaV4wiUpvRHlEkI4e9qauz0Bc8y9NYKGZtOJJdaQVKtlxBSLfK+kKGqGXrJi9ds7eFbtv/m3/Mn8YSJW5CDf3fR4vppbUBKbT496PvD7cLxIhdSFXoUzyC0v/kEjVNCQym0M7w+JDJVWzWeU+m5vG6mpPgBOey2InqsmoeVV/Mjhm/up3lwWR1yP2K/F4TRtda8z7APM3o71tP8BGoTTxjYi3CWF+Li6F+N9 SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; AM5PR0802MB2547; 20:sdg7jBO3bJyce2jFsNhrAXFNLzr4+0vxgTdvu4R+HKqThwP6+NHPRpYZPN4uSFYqq8pjeCSz84zrYJpH8hsjg3gFsxEi/iWJXEtGehb9qDnohrk7L6T6qGu8HudQ7QIHosmNdfFTfAyAlGXA70+ia/D0NAt6Yut3ORR0A7XQdgI= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 Aug 2016 17:11:32.8973 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM5PR0802MB2547 X-detected-operating-system: by eggs.gnu.org: Windows 7 or 8 [fuzzy] X-Received-From: 104.47.2.135 Subject: [Qemu-devel] [PATCH RFC v2 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, famz@redhat.com, mreitz@redhat.com, stefanha@redhat.com, den@openvz.org, 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 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); }