From patchwork Thu Aug 25 13:44: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: 9299389 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 F327560459 for ; Thu, 25 Aug 2016 13:46:34 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E4E9B29332 for ; Thu, 25 Aug 2016 13:46:34 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D9A6C29336; Thu, 25 Aug 2016 13:46:34 +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 A1FDE29332 for ; Thu, 25 Aug 2016 13:46:33 +0000 (UTC) Received: from localhost ([::1]:56353 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bcuzI-0004Rj-Qq for patchwork-qemu-devel@patchwork.kernel.org; Thu, 25 Aug 2016 09:46:32 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47109) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bcuya-0004JL-Ma for qemu-devel@nongnu.org; Thu, 25 Aug 2016 09:45:51 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bcuyY-0002G8-Dx for qemu-devel@nongnu.org; Thu, 25 Aug 2016 09:45:47 -0400 Received: from mail-db5eur01on0101.outbound.protection.outlook.com ([104.47.2.101]:42816 helo=EUR01-DB5-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bcuyR-0002Bq-8K; Thu, 25 Aug 2016 09:45:39 -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=FvhPZrALLL75J4gme2/bRlJ9Wp57J7BNfe9vNQQeWueOJr8lJeVy8U+3pJtm8QusEJ1ET3YOcfxTofIJpjocn3OGTlQIkdnOyc8vN1YlKxVDD4V1M3R2NMH9rMFd3jD7+CgIWvwtVrq/bSh6PxJdU2LONcSi+MDvG1GpPoe6dyc= 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:36 +0000 From: Pavel Butsykin To: , Date: Thu, 25 Aug 2016 16:44:09 +0300 Message-ID: <20160825134421.20231-11-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: fbe36af2-74b1-4fec-1fd8-08d3ccee1830 X-Microsoft-Exchange-Diagnostics: 1;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ogPcXWyhCS9yJqyPXiuIWvSsN1590=; 4:4WpzQIlrzEhsz3HRcDn219roOFErJqS+6TGlHt1N6lADEUQ4s9Hx8D5L/e5Ucmlwn35qNidK4vicfEXXSqwnTr1/rpcL8b03bX8sJ1bYR4Ta9jXlLJkGlJiAjVGgxXazSpARpINDGut2HYxrBReFhLUrn+J2URV6CNls73UXD3PpPX9oySj2DPQWC01rnG0QBDOBw+Hk1tyz1TtuTxcxtA5cnZQCv+vWmnQ55k3+xKk0wVbkU8GABTaRCRJ5CUDkAEB27CTa5zbhUITSpEVfmFEyqOrAj0KO9IMXqnhWdoPLMAQi2SK5SczY7mmjTjOD6438BbmaNznqZvvd+Po0R9nLu8SYFojTDPOR/iAYCQ9UoutFROkEb3OKu6l3NODH8znhBcLAjDqMflWq7ZkP2Rv4JeQMNUvLX7Dr1DG3Axw= 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:bV3OrlVBynoWSa0xKrS/BrUa/HgbdlbKGdAZQ60?= =?us-ascii?Q?AXoqnAROYMnfDtcj+zqS7wIyOWVd+0ggwj9GSJ2WjT42SV1PGcPdwiXt9Zh7?= =?us-ascii?Q?XSswlPVBTZ5HdhYwWzAE9MnQMWt48dD4QeLWGb4ZrpkNm6yJ+lGaRuyy+lXq?= =?us-ascii?Q?O8PpiggLDY9BUbiAlkO70hS5PkBQTsIgyyXZqg9+aTGjcDtVT0GRhPaL4w11?= =?us-ascii?Q?u6iKp4Cho4sidqm7+qF8/GR9HuMGCmwMrjxfRNyicmBs4wy0Zity8blSCpgT?= =?us-ascii?Q?7SRSkTwFtscFGd9+N0G8G5WnxEMAsTKTLbCCuCCP/0aIz/5oKShUWP81Y2cQ?= =?us-ascii?Q?CUZHihzgt5BiAk9V08QCKGQvFsskqh3KWugu5rmNibi5v0I1GBdAslCcdgjr?= =?us-ascii?Q?Aja1GE3VWmWxKfkHiSPZ/fm+Xe/RezjQpXT3gBH2Al/n3rAd7YLcR/FSBVWi?= =?us-ascii?Q?CfXH1yGetART8TkEcdMMg6XVaq7sVccn6+LwwQoV3S7bysTTlk929yfhoQv6?= =?us-ascii?Q?cIDYtzQFD2LB2mtA4tRgPaYNK8wzAjVkOYfQtMA0v/rdLQspbFG/hr/oaL7B?= =?us-ascii?Q?b0X3RbVT45xU4/cvQfYKWOleS5xq4kLJjprtVB4AfJ1bkyleSEaxeTAT87nd?= =?us-ascii?Q?jcPvn9ojLEaYxfe8dTzGoYfkUOPZv9dIw4IwzxPGb6IacIF5n7UTpl0QM6XG?= =?us-ascii?Q?6J7d9yaxeGxxBMMA0ufOXl5H/olxZGhDI1FH06SgyNxtdVxk0Y3tCIXd7uk0?= =?us-ascii?Q?FZ66gSPQoievw7jxB5tG+WVcJx1op2YUe6r6Xk8qdgBgRN6PAztHB5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OaT/gW4SCyxp3aC8Wry90XAjBPYGF4=; 7:6NHusnkRym0P8+xmhUkh2Yq/W3dbHP/BZ6WbrBlDcACxUZnB84fd5q8DJXp+YO+Zct912KVSlzJcyJfn8kRCqAeCaumug10TD3FmKwbw4A2e6ypy5Y8Aa19cfHmMDbdaYdAyDUzwFP4X8TwTF4y2kTOZRhn9+WFC33xhVM2IhOuDLvdnN/JBbjPszkfJfbUEcFKpqzsfwskcpKOPpIxn9LA12u3idD4cVfiKoS6VJ/qZp4VXzVr5KPYm/T5PJwhV SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; DB6PR0802MB2549; 20:tcal6BwJ8D6sk31YmlkXjqABJHCxCDjOnNDo4KHU2n4xUhcXxsaxhD6Aq9M4idBgUcbhcmrRHoLNyIpSjFXj8XMgSlVZXYV+eoSQqbluHZ9tImy6bP4sqqVZMtTm363w9HcLxj3XVTsFAUaOOpLYm7x9r7W3N3NUCQYbDo7G5zo= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Aug 2016 13:45:36.2615 (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 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, 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 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,