From patchwork Mon Aug 29 17:10:09 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Butsykin X-Patchwork-Id: 9304519 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 AF69B6077C for ; Mon, 29 Aug 2016 21:47:26 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A08FF26E5D for ; Mon, 29 Aug 2016 21:47:26 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 93CB2289C6; Mon, 29 Aug 2016 21:47:26 +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 CE5B826E5D for ; Mon, 29 Aug 2016 21:47:25 +0000 (UTC) Received: from localhost ([::1]:45894 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1beUOq-00074D-3s for patchwork-qemu-devel@patchwork.kernel.org; Mon, 29 Aug 2016 17:47:24 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45238) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1beUL9-00042t-2y for qemu-devel@nongnu.org; Mon, 29 Aug 2016 17:43:38 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1beUL6-00027u-Fy for qemu-devel@nongnu.org; Mon, 29 Aug 2016 17:43:34 -0400 Received: from mail-db5eur01on0114.outbound.protection.outlook.com ([104.47.2.114]:63264 helo=EUR01-DB5-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1beUL0-00023R-Fa; Mon, 29 Aug 2016 17:43:26 -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=ZiksOnh4p8RYVgOg9h2sYWfJG/PtfkDuBi+SMVlXtzc=; b=ZunhRfk9W4CN3v0xw5S1YzZu6pvL+o3cB4hLZHqosE6MNbRD2VJULuYymZX57AuE22JkRkkP7n8X34NA0B5j03cUdzqMm9Vux32eARqjT18YWPEOu3gmO2yc5gigNiWEQAmuimGFgIXnzfs0Tik9eTqpi7fC1oI16Ndif2XZFm0= 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:23 +0000 From: Pavel Butsykin To: , Date: Mon, 29 Aug 2016 20:10:09 +0300 Message-ID: <20160829171021.4902-11-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: 20cf8252-ac7f-428b-f44a-08d3d02f80fe X-Microsoft-Exchange-Diagnostics: 1; AM5PR0802MB2547; 2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BjnAsg=; 4:aQaRELBu1O6/KbV7U9In22KU41TToQIC8Br4eDYQCo1Qeqrjg8Y7+iRwbrj/1vnZ/6emKj9Q9jHC3W0Ixg68lConySF/WVeVGNLbrA/ocIJ1Gr6Pad933sR3WhKR5yqmTmwmAwvHoDX4k7K380tgcEkI9sH2uZmoCa1uLMFBHBHHqIUQ1kKYvqp8yhNjhMKmaluNRsyWsMWz7MpA233IsId4GxXpJhLg2qsTE1z0PJx4BiBO5VhSwUdSTCuwO2WZU0Hg6e9Wrayt3zotHbFs0m3MDivxkl5UxSTmbjKqXmMjX3B7gIf2CAeltt5KIzTCUsKLVdaZOg8TJnPbMLJxcawHu1bLvq8SDXITzrt3fWGxlXPfKuE8TCDyJcu3tsgGwPboVLwbEZ46j+Ksw5NPEu5kdI0aPFb8Tf052z6qeds= 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-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:4tAuNqlmjujmXGpIrnJ8Qa6eGOZJKuBYqnZ/uAY?= =?us-ascii?Q?iUHy1Q8Vn4YskNGQbnzU9LfqTyaYEl0TufwfpZdmWIEf9VYjxsfVKjB81jn6?= =?us-ascii?Q?9HwWrfeMZE9hIqPPQM+EeLEkKfnzac8raMQKcfK2++hOQ+bgFn6NVREvZa+D?= =?us-ascii?Q?SW2Rr7y5LoLKEvVsod+DNSwyff/PssStubuIcju7cqBoNqHB/Bzpc5QbmCEb?= =?us-ascii?Q?9KlrpGhxj/jQ7z24NeDlIqG8EDLI6LcnOtQ3KqbzWJc2VeDzFEUKhQ1XgF9b?= =?us-ascii?Q?/T1S5nJP7RSuKbHhoQJVukW4hsJ1mC/bJ0fkZFWCcS3wpA35r0nd3ui3zvdV?= =?us-ascii?Q?d1zzYL7FmYnHGDfR2MPFnmAgyhRS6AeDjWo5roj0ujuLfbT/h+Cu+CGC7HJy?= =?us-ascii?Q?xQZZvUT+aa8EOg+lzsThvz2Rm99Eg8AgrdFVJyW1DLCgLflFRRshH34Miib2?= =?us-ascii?Q?H931pilKbVlNYk6VgjEODS7UTFgCkOoS2zcQ6PKcml9k9KxMEVy30S5UGcFt?= =?us-ascii?Q?vow+40obsqcB0WDqK24z2oJhb5ZYwGW76ORgXpn/C+UmRinU1XTgJIJNL+I5?= =?us-ascii?Q?f1pqmtTmUd+xWFzjrjXmx4HgyaUls2z3IjxhypnC/peag03XzI8c7zObExD3?= =?us-ascii?Q?bODTLmMh3LW2agC3sjC8lLA1Ce5r0uoSkWE2JU9bQzJmWsYrWPWI2qvgdYnV?= =?us-ascii?Q?hUAh+ZGDOqZeKMNY55i63+wuVyNDyaZLZkVfL3l0+JgZdW6QTEKWl4X/DqzQ?= =?us-ascii?Q?JypDoqzwLcAW/3Z0lsuIh5W/CWMH/lCwlnP4Ey3SeMZ6rqHP5PCFAiIL4hfw?=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/kfEBzR+2ARFw6IxsTdduY=; 7:Qn1x1gnsw3EyPmLY4lnldWHUwf68GOVZnlwTOIqytlsxElDICld4rv1WSYqCw/1Afp7vRF0z3Uv5IwxYGgBy69mBQd9Ggll9Os24f/TdNmz8SFlHmRoYvWxTg4H3y9m98GpKn5ilM/ZyXz33nZ9HDqIqgV4+X40K6p4xV+JLZoqcRearfpyAYyKbp0tb7T4hE7kExUcpGcc24R6JZa/71Wo2XAW9Sg31BmP/6nXv1ZQ0/SwU7LYRE5q1pcS9plU8 SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; AM5PR0802MB2547; 20:j03Npz6vGDNqOnfoAt1wnb0ktOGPWuEiPcPKC1Az42Sselz8qEaU7iFl9vMabd1ODFMrCzXTvERolURVBrAUbtdIHY76DR2Wbqdvow/wcb9nQNsWdUVGkJMN81lWOwnozlyWAeGAmbc92mtnQQfNKtuA9LjqHj/B63Ibzyu6F5Q= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 Aug 2016 17:11:23.0169 (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.114 Subject: [Qemu-devel] [PATCH RFC v2 10/22] block/pcache: add check node leak 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 If the pcache has a bug with node reference, then s->death_node_list can help to know about it. Signed-off-by: Pavel Butsykin --- block/pcache.c | 45 +++++++++++++++++++++++++++++++++++++++------ 1 file changed, 39 insertions(+), 6 deletions(-) diff --git a/block/pcache.c b/block/pcache.c index 6114289..a8a57e3 100644 --- a/block/pcache.c +++ b/block/pcache.c @@ -87,6 +87,8 @@ typedef struct BDRVPCacheState { #ifdef PCACHE_DEBUG uint64_t shrink_cnt_node; + QTAILQ_HEAD(death_node_head, BlockNode) death_node_list; + CoMutex death_node_lock; #endif } BDRVPCacheState; @@ -152,7 +154,7 @@ enum { #define PCNODE(_n) ((PCNode *)(_n)) -static inline void pcache_node_unref(PCNode *node) +static inline void pcache_node_unref(BDRVPCacheState *s, PCNode *node) { assert(node->status == NODE_SUCCESS_STATUS || node->status == NODE_REMOVE_STATUS); @@ -161,6 +163,12 @@ static inline void pcache_node_unref(PCNode *node) assert(node->status == NODE_REMOVE_STATUS); node->status = NODE_GHOST_STATUS; + +#ifdef PCACHE_DEBUG + qemu_co_mutex_lock(&s->death_node_lock); + QTAILQ_REMOVE(&s->death_node_list, &node->cm, entry); + qemu_co_mutex_unlock(&s->death_node_lock); +#endif g_free(node->data); g_slice_free1(sizeof(*node), node); } @@ -263,11 +271,17 @@ static void pcache_node_drop(BDRVPCacheState *s, PCNode *node) QTAILQ_REMOVE(&s->pcache.lru.list, &node->cm, entry); qemu_co_mutex_unlock(&s->pcache.lru.lock); +#ifdef PCACHE_DEBUG + qemu_co_mutex_lock(&s->death_node_lock); + QTAILQ_INSERT_HEAD(&s->death_node_list, &node->cm, entry); + qemu_co_mutex_unlock(&s->death_node_lock); +#endif + qemu_co_mutex_lock(&s->pcache.tree.lock); rb_erase(&node->cm.rb_node, &s->pcache.tree.root); qemu_co_mutex_unlock(&s->pcache.tree.lock); - pcache_node_unref(node); + pcache_node_unref(s, node); } static void pcache_try_shrink(BDRVPCacheState *s) @@ -367,7 +381,7 @@ static void pcache_pickup_parts_of_cache(PrefCacheAIOCB *acb, PCNode *node, up_size = lc_key.size; if (!pcache_node_find_and_create(acb, &lc_key, &new_node)) { - pcache_node_unref(node); + pcache_node_unref(acb->s, node); node = new_node; continue; } @@ -377,7 +391,7 @@ static void pcache_pickup_parts_of_cache(PrefCacheAIOCB *acb, PCNode *node, /* XXX: node read */ up_size = MIN(node->cm.sector_num + node->cm.nb_sectors - num, size); - pcache_node_unref(node); + pcache_node_unref(acb->s, node); size -= up_size; num += up_size; @@ -416,7 +430,7 @@ static int32_t pcache_prefetch(PrefCacheAIOCB *acb) acb->nb_sectors) { /* XXX: node read */ - pcache_node_unref(node); + pcache_node_unref(acb->s, node); return PREFETCH_FULL_UP; } pcache_pickup_parts_of_cache(acb, node, key.num, key.size); @@ -459,7 +473,7 @@ static void pcache_merge_requests(PrefCacheAIOCB *acb) /* XXX: pcache read */ - pcache_node_unref(req->node); + pcache_node_unref(acb->s, req->node); g_slice_free1(sizeof(*req), req); } @@ -544,6 +558,11 @@ static void pcache_state_init(QemuOpts *opts, BDRVPCacheState *s) s->pcache.curr_size = 0; s->cfg_cache_size = cache_size >> BDRV_SECTOR_BITS; + +#ifdef PCACHE_DEBUG + QTAILQ_INIT(&s->death_node_list); + qemu_co_mutex_init(&s->death_node_lock); +#endif } static int pcache_file_open(BlockDriverState *bs, QDict *options, int flags, @@ -597,6 +616,20 @@ static void pcache_close(BlockDriverState *bs) cnt++; } DPRINTF("used %d nodes\n", cnt); + +#ifdef PCACHE_DEBUG + if (!QTAILQ_EMPTY(&s->death_node_list)) { + cnt = 0; + DPRINTF("warning: death node list contains of node\n"); + QTAILQ_FOREACH_SAFE(node, &s->death_node_list, entry, next) { + QTAILQ_REMOVE(&s->death_node_list, node, entry); + g_free(PCNODE(node)->data); + g_slice_free1(sizeof(*node), node); + cnt++; + } + DPRINTF("death nodes: %d", cnt); + } +#endif } static void pcache_parse_filename(const char *filename, QDict *options,