From: Prasad Joshi Subject: Re: [PATCH v3] kvm tools: Add QCOW level2 caching support Date: Thu, 2 Jun 2011 21:57:11 +0100 Message-ID: References: <1307044916-18109-1-git-send-email-prasadjoshi124@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: QUOTED-PRINTABLE Cc: mingo@elte.hu, kvm@vger.kernel.org, asias.hejun@gmail.com, gorcunov@gmail.com, levinsasha928@gmail.com, chaitanyakulkarni15@gmail.com, ashwini.kulkarni@gmail.com, anupshendkar@gmail.com To: Pekka Enberg Return-path: Received: from mail-gy0-f174.google.com ([209.85.160.174]:56524 "EHLO mail-gy0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753308Ab1FBU5M convert rfc822-to-8bit (ORCPT ); Thu, 2 Jun 2011 16:57:12 -0400 Received: by gyd10 with SMTP id 10so512905gyd.19 for ; Thu, 02 Jun 2011 13:57:11 -0700 (PDT) In-Reply-To: Sender: kvm-owner@vger.kernel.org List-ID: On Thu, Jun 2, 2011 at 9:37 PM, Pekka Enberg wrote= : > On Thu, Jun 2, 2011 at 11:01 PM, Prasad Joshi wrote: >> QCOW uses two tables level1 (L1) table and level2 (L2) table. The L1= table >> points to offset of L2 table. When a QCOW image is probed, the L1 ta= ble is >> cached in the memory to avoid reading it from disk on every access. = This >> caching improves the performance. >> >> The similar performance improvement can be observed when L2 tables a= re cached. >> It is impossible to cache all of the L2 tables because of the memory >> constraint. The patch adds L2 table caching capability for up to 128= L2 tables, >> it uses combination of RB tree and List to manage the L2 cached tabl= es. The >> link list implementation helps in building simple LRU structure and = RB tree >> helps to search cached table efficiently >> >> The performance numbers are below, the machine was started with foll= owing >> command line arguments >> >> $ ./kvm run -d /home/prasad/VMDisks/Ubuntu10.10_64_cilk_qemu.qcow \ >>> --params "root=3D/dev/vda1" -m 1024 >> >> Without QCOW caching >> =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D >> $ bonnie++ -d tmp/ -c 10 -s 2048 >> Writing a byte at a time...done >> Writing intelligently...done >> Rewriting...done >> Reading a byte at a time...done >> Reading intelligently...done >> start 'em...done...done...done...done...done... >> Create files in sequential order...done. >> Stat files in sequential order...done. >> Delete files in sequential order...done. >> Create files in random order...done. >> Stat files in random order...done. >> Delete files in random order...done. >> Version =A01.96 =A0 =A0 =A0 ------Sequential Output------ --Sequenti= al Input- --Random- >> Concurrency =A010 =A0 =A0 -Per Chr- --Block-- -Rewrite- -Per Chr- --= Block-- --Seeks-- >> Machine =A0 =A0 =A0 =A0Size K/sec %CP K/sec %CP K/sec %CP K/sec %CP = K/sec %CP =A0/sec %CP >> prasad-virtual-m 2G =A01043 =A099 555406 =A074 227605 =A055 =A05360 = =A099 489080 =A068 +++++ +++ >> Latency =A0 =A0 =A0 =A0 =A0 =A0 24646us =A0 48544us =A0 57893us =A0 = =A06686us =A0 =A03595us =A0 21026us >> Version =A01.96 =A0 =A0 =A0 ------Sequential Create------ --------Ra= ndom Create-------- >> prasad-virtual-mach -Create-- --Read--- -Delete-- -Create-- --Read--= - -Delete-- >> =A0 =A0 =A0 =A0 =A0 =A0 =A0files =A0/sec %CP =A0/sec %CP =A0/sec %CP= =A0/sec %CP =A0/sec %CP =A0/sec %CP >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 16 +++++ +++ +++++ +++ +++++ +++ +++= ++ +++ +++++ +++ +++++ +++ >> Latency =A0 =A0 =A0 =A0 =A0 =A0 =A0 343us =A0 =A01175us =A0 =A0 327u= s =A0 =A0 555us =A0 =A0 =A048us =A0 =A0 =A082us >> 1.96,1.96,prasad-virtual-machine,10,1307043085,2G,,1043,99,555406,74= ,227605,55, >> 5360,99,489080,68,+++++,+++,16,,,,,+++++,+++,+++++,+++,+++++,+++,+++= ++,+++, >> +++++,+++,+++++,+++,24646us,48544us,57893us,6686us,3595us,21026us,34= 3us,1175us, >> 327us,555us,48us,82us >> >> With QCOW caching >> =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D >> $ bonnie++ -d tmp/ -c 10 -s 2048 >> Writing a byte at a time...done >> Writing intelligently...done >> Rewriting...done >> Reading a byte at a time...done >> Reading intelligently...done >> start 'em...done...done...done...done...done... >> Create files in sequential order...done. >> Stat files in sequential order...done. >> Delete files in sequential order...done. >> Create files in random order...done. >> Stat files in random order...done. >> Delete files in random order...done. >> Version =A01.96 =A0 =A0 =A0 ------Sequential Output------ --Sequenti= al Input- --Random- >> Concurrency =A010 =A0 =A0 -Per Chr- --Block-- -Rewrite- -Per Chr- --= Block-- --Seeks-- >> Machine =A0 =A0 =A0 =A0Size K/sec %CP K/sec %CP K/sec %CP K/sec %CP = K/sec %CP =A0/sec %CP >> prasad-virtual-m 2G =A01033 =A099 467899 =A064 182387 =A041 =A05422 = 100 338294 =A048 +++++ +++ >> Latency =A0 =A0 =A0 =A0 =A0 =A0 21549us =A0 60585us =A0 65723us =A0 = =A06331us =A0 30014us =A0 19994us >> Version =A01.96 =A0 =A0 =A0 ------Sequential Create------ --------Ra= ndom Create-------- >> prasad-virtual-mach -Create-- --Read--- -Delete-- -Create-- --Read--= - -Delete-- >> =A0 =A0 =A0 =A0 =A0 =A0 =A0files =A0/sec %CP =A0/sec %CP =A0/sec %CP= =A0/sec %CP =A0/sec %CP =A0/sec %CP >> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 16 +++++ +++ +++++ +++ +++++ +++ +++= ++ +++ +++++ +++ +++++ +++ >> Latency =A0 =A0 =A0 =A0 =A0 =A0 =A0 478us =A0 =A01142us =A0 =A0 344u= s =A0 =A0 402us =A0 =A0 =A072us =A0 =A0 =A098us >> 1.96,1.96,prasad-virtual-machine,10,1307042839,2G,,1033,99,467899,64= ,182387,41, >> 5422,100,338294,48,+++++,+++,16,,,,,+++++,+++,+++++,+++,+++++,+++,++= +++,+++, >> +++++,+++,+++++,+++,21549us,60585us,65723us,6331us,30014us,19994us,4= 78us,1142us, >> 344us,402us,72us,98us >> >> Summary of performance numbers >> =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D >> There is not much difference with sequential character operations ar= e >> performed, the code with caching performed better by small margin. T= he caching >> code performance raised by 18% to 24% with sequential block output a= nd by 44% >> for sequentail block input. Which is understandable as the Level2 ta= ble will >> always be cached after a write operation. Random seek operation work= ed slower >> with caching code. > > I see performance _degradation_ in the raw data: I think I copied the wrong results in the commit log. > > Before: > >> Concurrency =A010 =A0 =A0 -Per Chr- --Block-- -Rewrite- -Per Chr- --= Block-- --Seeks-- >> Machine =A0 =A0 =A0 =A0Size K/sec %CP K/sec %CP K/sec %CP K/sec %CP = K/sec %CP =A0/sec %CP >> prasad-virtual-m 2G =A01043 =A099 555406 =A074 227605 =A055 =A05360 = =A099 489080 =A068 +++++ +++ > > After: > >> prasad-virtual-m 2G =A01033 =A099 467899 =A064 182387 =A041 =A05422 = 100 338294 =A048 +++++ +++ > > So that's drop from 555406 to 467899 K/sec for sequential block write= s > and drop from 489080 K/sec to 338294 K/sec for sequential block reads= =2E > > Random seek latency shows _improvement_: > >> Latency =A0 =A0 =A0 =A0 =A0 =A0 24646us =A0 48544us =A0 57893us =A0 = =A06686us =A0 =A03595us =A0 21026us > >> Latency =A0 =A0 =A0 =A0 =A0 =A0 21549us =A0 60585us =A0 65723us =A0 = =A06331us =A0 30014us =A0 19994us > > Am I reading the Bonnie report wrong or did you mix up the 'about:sta= rtpagebefore' > and 'after' data? > > Assuming the data is just mixed up, I'm not completely happy that > we're making random seeks almost 5% slower. Any ideas why that's > happening? Yes they are mixed. I am assuming, probably delay while caching. > >> +static int search_table(struct qcow *q, u64 **table, u64 offset) >> +{ >> + =A0 =A0 =A0 struct qcow_l2_cache *c; >> + >> + =A0 =A0 =A0 *table =3D NULL; >> + >> + =A0 =A0 =A0 c =3D search(&q->root, offset); >> + =A0 =A0 =A0 if (!c) >> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 return -1; >> + >> + =A0 =A0 =A0 /* Update the LRU state */ >> + =A0 =A0 =A0 list_del_init(&c->list); >> + =A0 =A0 =A0 list_add_tail(&c->list, &q->lru_list); > > Why not use list_move() here? The "update the LRU state" comment is > pretty useless. It would be more important to explain the reader how > the list is ordered (i.e. least recently used are at the head of the > list). Okay > >> @@ -17,6 +19,16 @@ >> =A0#define QCOW2_OFLAG_COMPRESSED (1LL << 62) >> =A0#define QCOW2_OFLAG_MASK =A0 =A0 =A0 (QCOW2_OFLAG_COPIED|QCOW2_OF= LAG_COMPRESSED) >> >> +#define MAX_CACHE_NODES =A0 =A0 =A0 =A0 128 > > Did you test the results with MAX_CACHE_NODES set to 1? Did you get > similar results than with no caching at all? Never tested with MAX_CACHE_NODES with 1. I need to do that. > I also wonder if we could > get away with even smaller cache than 128. > What would be the right number? If number of cache nodes are pretty much less for example 32 or something. We can use arrays for caching rather than Link List and RB Tree. >> =A0struct qcow_table { >> =A0 =A0 =A0 =A0u32 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 table_siz= e; >> =A0 =A0 =A0 =A0u64 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 *l1_table= ; >> @@ -26,6 +38,11 @@ struct qcow { >> =A0 =A0 =A0 =A0void =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0*header; >> =A0 =A0 =A0 =A0struct qcow_table =A0 =A0 =A0 table; >> =A0 =A0 =A0 =A0int =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 fd; >> + >> + =A0 =A0 =A0 /* Level2 caching data structures */ >> + =A0 =A0 =A0 struct rb_root =A0 =A0 =A0 =A0 =A0root; >> + =A0 =A0 =A0 struct list_head =A0 =A0 =A0 =A0lru_list; >> + =A0 =A0 =A0 int =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 no_cached; > > I've said this many times: please don't invent strange new names. > Really, "no_cached" reads out like it's a boolean! Use 'nr_cached' > instead. okay. > > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0Pekka >