From patchwork Tue Nov 15 06:37:12 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Butsykin X-Patchwork-Id: 9429487 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 DB5E16047D for ; Tue, 15 Nov 2016 11:18:35 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CAEA42875F for ; Tue, 15 Nov 2016 11:18:35 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BF3942898B; Tue, 15 Nov 2016 11:18:35 +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 24DAD2875F for ; Tue, 15 Nov 2016 11:18:35 +0000 (UTC) Received: from localhost ([::1]:45589 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1c6bl4-0000SI-EA for patchwork-qemu-devel@patchwork.kernel.org; Tue, 15 Nov 2016 06:18:34 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46489) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1c6bfm-0004pr-4Q for qemu-devel@nongnu.org; Tue, 15 Nov 2016 06:13:07 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1c6bfh-0001og-GR for qemu-devel@nongnu.org; Tue, 15 Nov 2016 06:13:06 -0500 Received: from mail-db5eur01on0106.outbound.protection.outlook.com ([104.47.2.106]:18784 helo=EUR01-DB5-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 1c6bfh-0001mh-68; Tue, 15 Nov 2016 06:13:01 -0500 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=mdYqh0TYfN1KuIimgj3q+vML0+KKmuYH3opvqh1wk6k=; b=JwuFMo2BzqA3zYEh3G4BlcO+e0quCTZB6AfX0PnhGxxQXJSzOPb7lnf9C9vIvK+VoImj8xlaUnu5L3pWpUpt1z8ZGsoyHqznBV27imDRbpvspYWadf3tdRJbod7Gwik4gHWtDuhVUba8hW0NVDt3VLDZZIHThVKpOwusxcrRzy4= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=pbutsykin@virtuozzo.com; Received: from pavelb-Z68P-DS3.sw.ru (195.214.232.10) by VI1PR0802MB2558.eurprd08.prod.outlook.com (10.172.255.136) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.721.10; Tue, 15 Nov 2016 06:38:29 +0000 From: Pavel Butsykin To: , Date: Tue, 15 Nov 2016 09:37:12 +0300 Message-ID: <20161115063715.12561-16-pbutsykin@virtuozzo.com> X-Mailer: git-send-email 2.10.1 In-Reply-To: <20161115063715.12561-1-pbutsykin@virtuozzo.com> References: <20161115063715.12561-1-pbutsykin@virtuozzo.com> MIME-Version: 1.0 X-Originating-IP: [195.214.232.10] X-ClientProxiedBy: AM5PR0101CA0010.eurprd01.prod.exchangelabs.com (10.169.240.20) To VI1PR0802MB2558.eurprd08.prod.outlook.com (10.172.255.136) X-Microsoft-Exchange-Diagnostics: 1; VI1PR0802MB2558; 2:utv/j8UHPLS5+e/AulJICiioXwifXcM3X/Hu8/Ft70LGqV+82L8fgBuVtjJsvQCRi9QIcCBRAvzp+c6B1r7yRy84pJA7t35Wm8eLa5Zdcqp6h1NHcGJt2wcg+2Pv96FNwFAZGyAlPhWqxULwJ/d5glEQaJsR9DCbtJJrFql0Rkw=; 3:LfP9SDc7lRpm4y19oBkgZzHvcpR/kluJ29U67IxOzPOUQYTl28A6WYmyDGgRiUXbeQAPB5pXQ70xeIQWumYx/jj+R/j9HSO6AwMvZmtH9JJ8xPbf+tIfm+DCcHx7IOPVse+B8PWeSnhU5CZV5nPP4ScTTEtkN5IdSX73/ZsFr8g=; 25:H5b9HJdK0k4Wz2ieoGoxqLOgQO7O7Y/BVGmueBkw3zlpuwE00jMybSlr6CsbeB90AoSCzCC3imMTkz4rwQM/eGDMxFHsZjqnuMF5bB9o5K573GIVbcAMj+8MHCHSyj/egtrHbS1OGjFcok5vN6JGRGNiW/oqIII/41EngS0i3qvGw0GMNKwa88MJ7yHtC/K8C9z0SDE6i7y1NXBwVSUkFGXz0gUFVNiM0jhjnh7yDZNh6KUDB86axXYZTQF4KR+YW8SiEU+eiiwsmyGibUTJuYhn7CekmE63ESTukioY/9QW/fmreYVpYMlKsMEhXZAKVhEXjGyDnl29xvfk/Y4zv/Apa0TQYNFUc92dBOEbN2Cir3B9cgPPzQkTG6ZOPAM/s9qgLc4NB0eRXc6e3goWOy54M11SbscdC4JSfAD1M/LpAq1X3rFOYW7doEouHtsI X-MS-Office365-Filtering-Correlation-Id: b4239d2c-dd2b-4a45-be1d-08d40d22039a X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(22001); SRVR:VI1PR0802MB2558; X-Microsoft-Exchange-Diagnostics: 1; VI1PR0802MB2558; 31:DHlce/7pVbeheM7maO+C9F1/EKs9NhkK+Jgk9jz8HF+eD+yNhpsCfaNROIJD3H1FNwueZPIJAHVWqsa+gjTSq/8JRU0fFPF8SYeVt0q8L27iXYRti2++OrUlcSMmkSbMOWNykisyZ4mtLbVimCJl1rKujF7S3VNTYNZY1S2iPWHnwh1m7N2+Un3pEANJpU4PauYK+S4TlOl9gdwEmnxXjwGEinpEXvW4w2TmH13V36KYY4siKK53FEUYz/xUeOU9isElsVBpNSIbOyN0wpyViA==; 20:spcIzHzpGEGgZoPhpS69RlrtPp5eLhkyfXhaY7W/XieytVyHZmVthVJhRbJBEPxxhm2ogB3jcGjmTVOZOU7fiCx4DzaFR5qCHHbU815JoH+XDTcIQjGeuy7b07OrwXHog7y88jty44WX1e5nPVaPoj61B6TM549bF0K768Z5fTg=; 4:WXWdZlkqAtDn0HNMBnVbKej5i/6Uz6WH5eRGJHnhbm84cliskEjBkciyJMj0G2OBn8/RmN0dzZsRm1sXRfPNF7MyzA/Dai0xUXB+zj4PfwdyXX7JDSxxU1xTOYtsQVyrh34FoIN1Blbb+B3OBs3rxQ9ey8E5OO5Rwqvw+Y5YKiE9F+wyotXbYhFGATLTBB/RaDQt5iIBKBwgEtiAL+9UDM9ArrnHeQYN6jsmjqisxCYEVL0W3SKyoBCxjxE9HWAzOc2uTuROjL6ATqRdH94mxM0PlVS8pUJhwAKJzFF6O5vLOS3y+t6YmcE3ZUHmm7412eXVaHGM30/y9315SXxWOt5jHc59K0iRPoAjbN89o+pwYgbwM36tAVK3bkNcG8GHKLuEeWj5b7rGljz/+hxk494rLfXI4bR54lggQwsQ16J0J2VLj1nLdfPzM9FLrysY X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6060326)(601004)(2401047)(8121501046)(5005006)(10201501046)(3002001)(6061324)(6043046); SRVR:VI1PR0802MB2558; BCL:0; PCL:0; RULEID:; SRVR:VI1PR0802MB2558; X-Forefront-PRVS: 012792EC17 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10019020)(4630300001)(6009001)(7916002)(199003)(189002)(47776003)(105586002)(101416001)(1076002)(68736007)(106356001)(6666003)(76176999)(305945005)(4326007)(97736004)(66066001)(53416004)(189998001)(42186005)(69596002)(2906002)(7736002)(5001770100001)(7846002)(86362001)(48376002)(50226002)(2950100002)(50466002)(50986999)(5003940100001)(33646002)(77096005)(81156014)(8676002)(92566002)(81166006)(3846002)(36756003)(6116002)(5660300001); DIR:OUT; SFP:1102; SCL:1; SRVR:VI1PR0802MB2558; 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; VI1PR0802MB2558; 23:/pEn46XuYDtLiHIXv8MGoLPaWJOKEJ3EdV8VvFd?= =?us-ascii?Q?LxCP0KVDamZUFj/kCX+AoHRjmMMd7a9e/mBdSoGRqv23krbW7hlpuzGedOqn?= =?us-ascii?Q?M9j8SvmUFqMaHqWLNP5f0ykd0RgFD8LhhIs6yBVM/ehLQn/ms8VdOpgRCqg7?= =?us-ascii?Q?al00N2Y1KBbk5/DDXaSV5VISuuxhJDKEBXL4RmAoC8/I4pEExmotui+Q+4Af?= =?us-ascii?Q?yGHf2uPCjf00rMJelC9UU3x4pNHqheiuAghcreTHBG3hHTQAle5vHdYRQkoF?= =?us-ascii?Q?Ix8JMfKrpioCQV67OeojFoyhS8COsHct+EFPGUOdHlzkRDF/8a0K0Lnr4tA+?= =?us-ascii?Q?XdTVuSMlXGEUWF6TmN9AHW3MgusI+X+lDVNuhiukguP6s5spkTDa8D7ae39E?= =?us-ascii?Q?w85yb/EnREPZ6V+//iCg/ZPqfg3X8iM252zO+SQlQGJ7Ph6zstnN5UMZsjH0?= =?us-ascii?Q?+Rmu8ZQMt/c6motG57toy586q+Yy7X27lQbGFOAjeYmXy+9kzjaAbxQX+AtG?= =?us-ascii?Q?nyMCitwqI/XVbf9kajvpRHWyg90DSEhuOLbzHehflwNU+V+ZVLXStxngR4AZ?= =?us-ascii?Q?QVCSaeKjXUMk3UQ/hne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9NkrDvsO74P2M2DFA8v9C2usG3p4noA9g3nzN5MgQaGTizMLZoKicKoZ0Q8n4/eiUpkEPdS80CKhZqO2Y6kVfJBLUZ6ttM5tmEjkDL5DpI772Oc7ijBQRFjgpFHa+g=; 24:t00x+/9XGhQD6YhdTpxoH1ZJLRMlKuddzp9wJYIjvErz+wYXhcEataA/lPBsG/Hp0d+K+agVtnvr12IiLMsdO9XvRRN9qolU2B8Yy6Q4HrU= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; VI1PR0802MB2558; 7:6lVmQj29buKNAnKWaChZZ0niI/R9ePYU8cY3u5J1PhCbtbj5cGN6rRxKyosDL7JErJu1DOlU83WekXxPSTMZMoYxYWjqqrWTK3TiOWiPOizT4Pm+duqK0sjqaO5TSdG+tlnbErepNC/0ve2Z00LdXpoJuAXHrXjAHRalagY2/yW4AnLHAwt640r0qm0XBt07gTzxFZbr9BAOGvyl+b52dnYFyto/eLoYQ2D0IjuxA/HyQliPF41NV51bALaaPS7FfqPN+Ld7V+acH1xnWfSoeNxmjZ/3hGSc2SeyGxD87yAayhoEAYVu0NvvGEkU70GZ2SQHxL0Kioa403ZnrFvlY5zHewJGD/iCNtuOOEsvhpc=; 20:KfC2iWYXkC8tFQJeDqr6iHvKGl9PAC2m2gQ+7+TlVvZteELvmXhl3ChsXYRudWZAZKZAs3gUvPH21OC6oaTH48jK+GOIv+lnOgrkEtrUSkqZor5rlblSSM3u3k8JKge78jtAMD1lQ98eCJDos6qAnd5lcca67J7l5sS64FNaAx0= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Nov 2016 06:38:29.9778 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR0802MB2558 X-detected-operating-system: by eggs.gnu.org: Windows 7 or 8 [fuzzy] X-Received-From: 104.47.2.106 Subject: [Qemu-devel] [PATCH v1 15/18] block/pcache: drop used pcache nodes 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 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 | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/block/pcache.c b/block/pcache.c index 40fa3f3..df4834a 100644 --- a/block/pcache.c +++ b/block/pcache.c @@ -83,6 +83,7 @@ typedef struct PCacheNode { NODE_STATUS_REMOVE = 3, NODE_STATUS_DELETED = 4, /* only for debugging */ } status; + uint64_t rdcnt; int ref; } PCacheNode; @@ -142,10 +143,14 @@ static uint64_t ranges_overlap_size(uint64_t offset1, uint64_t size1, static void read_cache_data(PCacheAIOCBRead *acb, PCacheNode *node, uint64_t offset, uint64_t bytes) { + BDRVPCacheState *s = acb->bs->opaque; uint64_t qiov_offs = 0, node_offs = 0; uint64_t size; uint64_t copy; + assert(node->status == NODE_STATUS_COMPLETED || + node->status == NODE_STATUS_REMOVE); + if (offset < node->common.offset) { qiov_offs = node->common.offset - offset; } else { @@ -156,6 +161,12 @@ static void read_cache_data(PCacheAIOCBRead *acb, PCacheNode *node, copy = qemu_iovec_from_buf(acb->qiov, qiov_offs, node->data + node_offs, size); + node->rdcnt += size; + if (node->rdcnt >= node->common.bytes && + node->status == NODE_STATUS_COMPLETED) + { + rbcache_remove(s->cache, &node->common); + } assert(copy == size); } @@ -314,6 +325,7 @@ static RBCacheNode *pcache_node_alloc(uint64_t offset, uint64_t bytes, node->data = g_malloc(bytes); node->status = NODE_STATUS_NEW; + node->rdcnt = 0; node->ref = 1; QTAILQ_INIT(&node->wait_list);