From patchwork Mon Feb 25 17:12:02 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Orit Wasserman X-Patchwork-Id: 222980 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 910802C008C for ; Tue, 26 Feb 2013 04:44:50 +1100 (EST) Received: from localhost ([::1]:52902 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UA1at-0003lu-4Q for incoming@patchwork.ozlabs.org; Mon, 25 Feb 2013 12:12:03 -0500 Received: from eggs.gnu.org ([208.118.235.92]:39846) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UA1a7-0001Z9-Iq for qemu-devel@nongnu.org; Mon, 25 Feb 2013 12:11:31 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UA1Zr-0002hQ-Kq for qemu-devel@nongnu.org; Mon, 25 Feb 2013 12:11:15 -0500 Received: from mx1.redhat.com ([209.132.183.28]:24983) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UA1Zr-0002gh-7q for qemu-devel@nongnu.org; Mon, 25 Feb 2013 12:10:59 -0500 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r1PHArR6000679 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Mon, 25 Feb 2013 12:10:54 -0500 Received: from dhcp-1-120.tlv.redhat.com (vpn-200-236.tlv.redhat.com [10.35.200.236]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id r1PHAlVr009053; Mon, 25 Feb 2013 12:10:52 -0500 From: Orit Wasserman To: qemu-devel@nongnu.org Date: Mon, 25 Feb 2013 19:12:02 +0200 Message-Id: <1361812324-10674-3-git-send-email-owasserm@redhat.com> In-Reply-To: <1361812324-10674-1-git-send-email-owasserm@redhat.com> References: <1361812324-10674-1-git-send-email-owasserm@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.24 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: Orit Wasserman , peter.maydell@linaro.org, pl@kamp.de, quintela@redhat.com Subject: [Qemu-devel] [PATCH v2 2/4] Fix cache_resize to keep old entry age X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Instead of using cache_insert do the update itself Signed-off-by: Orit Wasserman --- page_cache.c | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/page_cache.c b/page_cache.c index 748957b..e5717d5 100644 --- a/page_cache.c +++ b/page_cache.c @@ -192,18 +192,17 @@ int64_t cache_resize(PageCache *cache, int64_t new_num_pages) if (old_it->it_addr != -1) { /* check for collision, if there is, keep MRU page */ new_it = cache_get_by_addr(new_cache, old_it->it_addr); - if (new_it->it_data) { + if (new_it->it_data && new_it->it_age >= old_it->it_age) { /* keep the MRU page */ - if (new_it->it_age >= old_it->it_age) { - g_free(old_it->it_data); - } else { - g_free(new_it->it_data); - new_it->it_data = old_it->it_data; - new_it->it_age = old_it->it_age; - new_it->it_addr = old_it->it_addr; - } + g_free(old_it->it_data); } else { - cache_insert(new_cache, old_it->it_addr, old_it->it_data); + if (!new_it->it_data) { + new_cache->num_items++; + } + g_free(new_it->it_data); + new_it->it_data = old_it->it_data; + new_it->it_age = old_it->it_age; + new_it->it_addr = old_it->it_addr; } } }