From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:33378) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UfWmy-0003xQ-EL for qemu-devel@nongnu.org; Thu, 23 May 2013 10:46:46 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UfWmt-00034t-7K for qemu-devel@nongnu.org; Thu, 23 May 2013 10:46:44 -0400 Received: from mail-wg0-x22e.google.com ([2a00:1450:400c:c00::22e]:39167) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UfWa8-0006dm-1D for qemu-devel@nongnu.org; Thu, 23 May 2013 10:33:28 -0400 Received: by mail-wg0-f46.google.com with SMTP id l18so2076352wgh.1 for ; Thu, 23 May 2013 07:33:27 -0700 (PDT) Date: Thu, 23 May 2013 16:33:24 +0200 From: Stefan Hajnoczi Message-ID: <20130523143324.GT9093@stefanha-thinkpad.redhat.com> References: <1369280289-20928-1-git-send-email-famz@redhat.com> <1369280289-20928-10-git-send-email-famz@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1369280289-20928-10-git-send-email-famz@redhat.com> Subject: Re: [Qemu-devel] [PATCH v5 09/11] curl: add cache quota. List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Fam Zheng Cc: kwolf@redhat.com, jcody@redhat.com, qemu-devel@nongnu.org, stefanha@redhat.com On Thu, May 23, 2013 at 11:38:07AM +0800, Fam Zheng wrote: > Introduce a cache quota: BDRVCURLState.cache_quota. > When adding new CURLDataCache to BDRVCURLState, if number of existing > CURLDataCache is larger than CURL_CACHE_QUOTA, try to release some first > to limit the in memory cache size. > > A least used entry is selected for releasing. > > Signed-off-by: Fam Zheng > --- > block/curl.c | 27 +++++++++++++++++++++++++++ > 1 file changed, 27 insertions(+) > > diff --git a/block/curl.c b/block/curl.c > index 3ea2552..5adbc84 100644 > --- a/block/curl.c > +++ b/block/curl.c > @@ -40,6 +40,7 @@ > > #define SECTOR_SIZE 512 > #define READ_AHEAD_SIZE (256 * 1024) > +#define CURL_CACHE_QUOTA 10 > > struct BDRVCURLState; > > @@ -90,6 +91,8 @@ typedef struct BDRVCURLState { > QEMUTimer *timer; > /* List of data cache ordered by access, freed from tail */ > QLIST_HEAD(, CURLDataCache) cache; > + /* Threshold to release unused cache when cache list is longer than it */ > + int cache_quota; > /* Whether http server accept range in header */ > bool accept_range; > } BDRVCURLState; > @@ -526,6 +529,8 @@ static int curl_open(BlockDriverState *bs, QDict *options, int flags) > curl_multi_socket_action(s->multi, CURL_SOCKET_TIMEOUT, 0, &running); > > qemu_opts_del(opts); > + s->cache_quota = CURL_CACHE_QUOTA; > + > return 0; > > out: > @@ -595,6 +600,27 @@ static void curl_readv_bh_cb(void *p) > cache->data_len = aio_bytes + s->readahead_size; > cache->write_pos = 0; > cache->data = g_malloc(cache->data_len); > + /* Try to release some cache */ > + while (0 && s->cache_quota <= 0) { while (0) :(