From patchwork Thu Aug 25 13:44:14 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Butsykin X-Patchwork-Id: 9299391 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 4549760459 for ; Thu, 25 Aug 2016 13:46:49 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3584A29332 for ; Thu, 25 Aug 2016 13:46:49 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2925E29336; Thu, 25 Aug 2016 13:46:49 +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 4F38A29332 for ; Thu, 25 Aug 2016 13:46:48 +0000 (UTC) Received: from localhost ([::1]:56357 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bcuzX-0004gv-GW for patchwork-qemu-devel@patchwork.kernel.org; Thu, 25 Aug 2016 09:46:47 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47218) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bcuyg-0004QG-02 for qemu-devel@nongnu.org; Thu, 25 Aug 2016 09:45:57 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bcuye-0002IS-G6 for qemu-devel@nongnu.org; Thu, 25 Aug 2016 09:45:53 -0400 Received: from mail-db5eur01on0106.outbound.protection.outlook.com ([104.47.2.106]:49715 helo=EUR01-DB5-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bcuyW-0002F8-Hh; Thu, 25 Aug 2016 09:45:44 -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=tt+TngU6gwB2WgRAr6oBg5rYoJN5vL4YpHqia40xZTY=; b=WcGwLFdazl+AilTxt/F2TjuYGPrieYj/IVWQWCBWt7ynFcTkhntbFD6ABO6jtYg3luVWfmSi5w1Pvo+iyBUi0U9yC1HSSdERWLsybC8yVz/AC5vqpZmdJ63YOcPVjPHoeorcch/s/Cb3YU5Kz3t7ZtYGu8ZnHcWvduypSw5ImUY= 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:41 +0000 From: Pavel Butsykin To: , Date: Thu, 25 Aug 2016 16:44:14 +0300 Message-ID: <20160825134421.20231-16-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: 615fc9b9-4fb1-490d-ae77-08d3ccee1b81 X-Microsoft-Exchange-Diagnostics: 1; DB6PR0802MB2549; 2:hNe6I5D9E4bkx5PWJbHsb2abbu/sCR/DIQlMw6oBXot6XfqBfamifZ8xdfLmmrGIJUikZRl9sOP8c8XtlehFw/psMUXzfchzkOD6ymTkfDYLFyWRkzg46D+IRAsBx1U459AtPoSitr0L1ZrQQorsfMnSlrepdBkQ6gKHO50CDie4fsEIPHIoVECST5z/aTFJ; 3:sJn5FzeLS5zEjd5NqmczOdULq6AfcFNgRSqf+LqRUpCDX2RV6VYvqCF5i8xLNyTAYYARQCN6vcAJelFT8kqDDovkeOsmuwrsqKdwCN1PqgX/cIb04GvC1ZpTCPwx3lMv X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:DB6PR0802MB2549; X-Microsoft-Exchange-Diagnostics: 1; DB6PR0802MB2549; 25:rCxSMP171oylEQQEu8A5GK5Va7isxV+cdZ8WOn/g9eKsIvOMdqSpOnO9V/q1E2F7pTy2wzr4r0wg3BDuDKFhJqwV0ZDBPX+R5dwUFwSpJxS91ixeorI13tK1Rfyrm9H4iX9CWeOZkmjPLwWMQmavc/12J8T89OmLkZIO73QoXcY2TC1KeTKfs2iGObrJGp/oejnq22v+C5jvAHvFxGt/zT6ydvtZIeC/xLc3/namJBOK6Cu29+6TMNWF4ZmwBL2FZ/lB3EVXLXpE1QoSSC/Fc2j12qDQrRhD7ntBPudAnmFKwEMAJ9I8CE4SWkOvW4FECx0cMczv8GbAtsF9PtRhDxvmwb/I/47bflUsFdyyOCbed328mGsp97Nmt6hV3nzQopkBqXZx2pWnNgYWOWsV+emQNZjwDB8dj0+ceELQz7Ix68NOA18RAptcSVOMN8FkynW/NqrSMYAh/XsTsGuNWjlvi9zRtz2NjMDriXW736/g/GmeOoatOrbgcsCQRVunhVqTP7KR+D0CNwXAQj8DRjo+jI8r1xfSn87pZ+L+Kx+yqNGH8GnwdPJWgczFIkzU2I0qB/fxwnSzIsZsEbW7/yR2igNS3ObvVFEeOhyJst8ZnnUs1hH4CmFiG/XBrhMVzHLr70uRqsLWw2lW+qmnBJHu8wkxVXztzwtljTKVwIX+m5NJBCiv0BJa/7X5mN+rBxx5O3f8PcrpRkGzlNsYOA==; 31:dZ+IynEvLgfTYqZ8sxcS+4yubwsFUF2i0DaT76Mznn/afGvMc2UBYqVxljOlaXd/KtUTrYg+ZlspLHrkMnxwaNQoKJWvM6eOyTkol+xDJyoUTT+zKtBjaRURxNe8aaeE7G7zc3rx6AlpfJ8cWs56BWcxQ+TusiqjUkPC1+vog9CiNyKf+UQDA3gtuBThKseUMP8V54qGJTh6iv/jucykwt0adpFUOt5pgAPTZHgMXfo= 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-Microsoft-Exchange-Diagnostics: 1; DB6PR0802MB2549; 4:8C+mYj3LkZ+aFMxP6VfF4tdmGgBcTBaZnBz52L2Nn/M5VTgcfU7E2EnIgI9JtC4LexhMPuPpoJuHywIAOEyv7iZkQrNeApLIO7lMT+V35lTWoXpv0XRSIxZibULsPB36Q4//XC89bK+0ejCS/uZL/EwzaiFq5js1PXFN1ktsTvWixfjln5WQzmhqN+qQIU0w+F6SpnY/9yB534wJeb5thNWhlUUtVM4iyI6R4XFpMxXq+3hTwFjIRsXMp/UDbdKIZBypHAqK0uL9celF7BI+AIEYRIjzQQEdLWEMu08t7mAcgA8k93ORz8jM/hIuoYo8Xemy0GRX1QFdUUMr1H0wOaoi4MXcDBOoKAhHCX+wSC92Z2FsIKp8hMB3CqT9XD1Z4+GWvEWhs88TWvIZD5AcLhaRR9vJuRtwioXuXEbWeME= 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:2fa/0EA7tQ9F+lubUoguKqo8HgDiww4wH4IEQGY?= =?us-ascii?Q?n7QkFGWQwbZ3jkLQwSLRK3+IJ2GsT0DeoFex01wvn/EmJf9vsCIz2QdrqhNe?= =?us-ascii?Q?ea4IOeJZwtAJOflD6tx2Y3qYQTYq7Y1tcM0CEoxfLsphlCsJtfHsjJs1b+hE?= =?us-ascii?Q?aVHAd4HFr2AC5NVAiQuEP/f0XNDxEWr18hjrGcP0jUyMhEekwGRhLxbYj7gf?= =?us-ascii?Q?nIzmsxJon+U/x7+80XYFskENL+ttZaGARQPNQ9tAsHyi7vMZv2FGIVOi3rgZ?= =?us-ascii?Q?9LnyG1UVs4EgPZKSPc88h3HnudxUNekn0vFylfK3rQwMiN1frl+n+C+vZ7iy?= =?us-ascii?Q?VynfaF6jk2oLwn5D+IbqgpYDDrcs1JECAo2JHgs8AsP2M4MJm791Z3AeDDSy?= =?us-ascii?Q?83vYwmdT2eX3IIaIgaVzBoPUhl7SJUPJpxvDwgxodeJWHf5j+9WBfIFmSKf1?= =?us-ascii?Q?KB24sN8zFUjNC1rTitNe1F2HzJBMjKL9YG8ps+y6VPWz4ajNTGDLylABGY+g?= =?us-ascii?Q?vNLkRfvdzQHoAaLcrNm5NYMZ18DU4/k8iifnwYcfr7lSf2PCicLL459jrpKC?= =?us-ascii?Q?7S8sV9O2kXAL3HCKW7g6UG4vBMoo96EFnOSKnC1cU+nmJ+ikpDMHu2fLMwZq?= =?us-ascii?Q?onmOm1WcAAcOZN3s8z62x8WeI/8ArbAqrX7Izs/R1wOb7HnTUA4kERvCO1SG?= =?us-ascii?Q?Zc7qRQI7awjbRxMzjhBG1S6hKbdt4ROl1BNic+N3SiXXFEEZMNRa9h13bAbs?= =?us-ascii?Q?GXqhmDMaqaA3MneWzYPAIfSa3b1yL87UE1hvQPAajCjkmsPJBCm0Skz0YNHU?= =?us-ascii?Q?v6/2dwjikRVIA25n6r43lwH1t7sVn4m3+cr26UdNKk1IaZwyny2ubis6v87/?= =?us-ascii?Q?BIIdp5YLnd5o9Spwx+13wtNyF/un/inFEPmxMz4QqCs7v1Mu8a3jyXjY0Zmr?= =?us-ascii?Q?eqN2fH1xX2oQaoQmUj+M8SO81ZgQzH9wAJ2/QARQg9IQoyucUshozo9PduMj?= =?us-ascii?Q?bAhxQpBula+MNFpanrdkOatVU2xZEIefyofMDeb80aYtHZNzcSfXUBiZt5C6?= =?us-ascii?Q?69syqFXHZ0Fmvv6CEuRkd6Kum7+pfeO/XGsWKdeVrppmqX7a+xqtfEPxSP0J?= =?us-ascii?Q?si5AI8m2jGdV1zEZN18xsob5SQWq/FYZD80xmzwHABdTzK1R0/P6P9yMaLWW?= =?us-ascii?Q?MSy9xzPe8PCxhuIU=3D?= X-Microsoft-Exchange-Diagnostics: 1; DB6PR0802MB2549; 6:ENPGzpIlAlgO/S732To4pz+W3xVAQoLxQj2xysfLGLfCRuQGkeZtNWZr2ttLvIyNnWwKmXgSeb1FRnvk8Xh1We77xG/8xXy/y6Oqv/2A06nhZoWEfW13LBfDrjyzzBzBArSVNvoEB39ryC9QZEH144RtyUNPkPZj7ANlOBHgLzwcIhYytA2atqAG16Df0U7oyGcB83DzeUjubO+TjgfDimag5nCLCAZrjybTvL/8VeGAGPK+136fclHlG+nFU1ijqzP5Cv1X4BTAYYUU/oNLd0frFJKGGiCMzJqnQMpIM2MlrL82WyBj5j8nLMridThV; 5:KlTKL4986k5+5IZuzTFqfXa7ZnbXLRkQJq7FUD3Nv9Q2MfgLmIxdtsOve5AVmEQ8lx4lyUdYuo0b21SP+GjBF1Ih94GgkcRibXiqMPdfSKHsnUtPX168Es3BWxlmtEninUShqiMaL7n19RMLzRp1uw==; 24:7FDEZ2RoZmg4szw7T/KXPqO9WWTfuvvz/BQWWvuyRAUl1IGVZVSQ+4bLqUj9t2JTeITcXk1ajmS26mNplbQu3qsLToGCNKLGgqA+hST2Pn0=; 7:nKMhAGXYoYSQXVAo5nAOS3ld5pBKBZ+rs1gFImiBNBHKS73uHj3m8T/eiLnbXrrHDqLzvRO08UYmjiY6D62BytT7rzaRDzkqywaAg1OKuqem2h/YhnjXUM4U8sywtuNvgVVPyGkUrwCJY+Htjg3q32KTntufKVa28nQfXmSmQC92cjTLzSCTseLxXZ3vvHJe1yUEZdpuF56qjzjBUpaXPVsj/shJwpK96I65bejhos3YjA1IwYbGwOa4GUwpZGgr SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; DB6PR0802MB2549; 20:9qq79BEB2h+MFSkhe4gVfrHFjHQqb4IesO4y5YqDJJYgVp3c3C2cQSoRZTAL/4tzs8U6EX7KQFZE057hhUtBfsWiNoAq3ZChy9VN4lUFMzdZVP5dElgifB1SNKtS3D0+9j2mITGraJnD1EKHdYzIqLWS9vBf/DRIeWX3m1Ou/lk= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Aug 2016 13:45:41.8152 (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.106 Subject: [Qemu-devel] [PATCH RFC 15/22] block/pcache: simple readahead one chunk forward 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 The performance improvement occurs mainly because of this element. An advantage is achieved due to the fact that from readahead requests can become queued faster than request from Guest OS. Add pcache-readahead-size open parameter. Signed-off-by: Pavel Butsykin --- block/pcache.c | 118 ++++++++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 100 insertions(+), 18 deletions(-) diff --git a/block/pcache.c b/block/pcache.c index cb5f884..90b3f85 100644 --- a/block/pcache.c +++ b/block/pcache.c @@ -92,7 +92,10 @@ typedef struct BDRVPCacheState { ReqStor pcache; - uint32_t cfg_cache_size; + struct { + uint32_t cache_size; + uint32_t readahead_size; + } cfg; #ifdef PCACHE_DEBUG uint64_t shrink_cnt_node; @@ -134,6 +137,7 @@ static const AIOCBInfo pcache_aiocb_info = { }; #define PCACHE_OPT_CACHE_SIZE "pcache-full-size" +#define PCACHE_OPT_READAHEAD_SIZE "pcache-readahead-size" static QemuOptsList runtime_opts = { .name = "pcache", @@ -149,6 +153,11 @@ static QemuOptsList runtime_opts = { .type = QEMU_OPT_SIZE, .help = "Total cache size", }, + { + .name = PCACHE_OPT_READAHEAD_SIZE, + .type = QEMU_OPT_SIZE, + .help = "Prefetch cache readahead size", + }, { /* end of list */ } }, }; @@ -156,6 +165,7 @@ static QemuOptsList runtime_opts = { #define KB_BITS 10 #define MB_BITS 20 #define PCACHE_DEFAULT_CACHE_SIZE (4 << MB_BITS) +#define PCACHE_DEFAULT_READAHEAD_SIZE (128 << KB_BITS) enum { NODE_SUCCESS_STATUS = 0, @@ -164,13 +174,16 @@ enum { NODE_GHOST_STATUS = 3 /* only for debugging */ }; +enum { + PCACHE_AIO_READ = 1, + PCACHE_AIO_WRITE = 2, + PCACHE_AIO_READAHEAD = 4 +}; + #define PCNODE(_n) ((PCNode *)(_n)) static inline void pcache_node_unref(BDRVPCacheState *s, PCNode *node) { - assert(node->status == NODE_SUCCESS_STATUS || - node->status == NODE_REMOVE_STATUS); - if (atomic_fetch_dec(&node->ref) == 0) { assert(node->status == NODE_REMOVE_STATUS); @@ -333,7 +346,7 @@ static inline PCNode *pcache_get_most_unused_node(BDRVPCacheState *s) static void pcache_try_shrink(BDRVPCacheState *s) { - while (s->pcache.curr_size > s->cfg_cache_size) { + while (s->pcache.curr_size > s->cfg.cache_size) { PCNode *rmv_node; /* it can happen if all nodes are waiting */ if (QTAILQ_EMPTY(&s->pcache.lru.list)) { @@ -626,7 +639,9 @@ static void pcache_merge_requests(PrefCacheAIOCB *acb) pcache_node_submit(req); - pcache_node_read_buf(acb, node); + if (!(acb->aio_type & PCACHE_AIO_READAHEAD)) { + pcache_node_read_buf(acb, node); + } pcache_complete_acb_wait_queue(acb->s, node); @@ -668,12 +683,16 @@ static void pcache_aio_cb(void *opaque, int ret) { PrefCacheAIOCB *acb = opaque; - if (acb->aio_type & QEMU_AIO_READ) { + if (acb->aio_type & PCACHE_AIO_READ) { if (atomic_dec_fetch(&acb->requests.cnt) > 0) { return; } pcache_merge_requests(acb); - } else { /* QEMU_AIO_WRITE */ + if (acb->aio_type & PCACHE_AIO_READAHEAD) { + qemu_aio_unref(acb); + return; + } + } else { /* PCACHE_AIO_WRITE */ pcache_try_node_drop(acb); /* XXX: use write through */ } @@ -702,6 +721,69 @@ static PrefCacheAIOCB *pcache_aio_get(BlockDriverState *bs, int64_t sector_num, return acb; } +static void pcache_send_acb_request_list(BlockDriverState *bs, + PrefCacheAIOCB *acb) +{ + PrefCachePartReq *req; + + assert(acb->requests.cnt != 0); + qemu_co_mutex_lock(&acb->requests.lock); + QTAILQ_FOREACH(req, &acb->requests.list, entry) { + bdrv_aio_readv(bs->file, req->sector_num, &req->qiov, + req->nb_sectors, pcache_aio_cb, acb); + } + qemu_co_mutex_unlock(&acb->requests.lock); +} + +static bool check_allocated_blocks(BlockDriverState *bs, int64_t sector_num, + int32_t nb_sectors) +{ + int ret, num; + + do { + ret = bdrv_is_allocated(bs, sector_num, nb_sectors, &num); + if (ret <= 0) { + return false; + } + sector_num += num; + nb_sectors -= num; + + } while (nb_sectors); + + return true; +} + +static void pcache_readahead_request(BlockDriverState *bs, PrefCacheAIOCB *acb) +{ + BDRVPCacheState *s = acb->s; + PrefCacheAIOCB *acb_readahead; + RbNodeKey key; + uint64_t total_sectors = bdrv_nb_sectors(bs); + PCNode *node = NULL; + + prefetch_init_key(acb, &key); + + key.num = key.num + key.size; + if (total_sectors <= key.num + s->cfg.readahead_size) { + return; /* readahead too small or beyond end of disk */ + } + key.size = s->cfg.readahead_size; + + if (!check_allocated_blocks(bs->file->bs, key.num, key.size)) { + return; + } + + acb_readahead = pcache_aio_get(bs, key.num, NULL, key.size, acb->common.cb, + acb->common.opaque, PCACHE_AIO_READ | + PCACHE_AIO_READAHEAD); + if (!pcache_node_find_and_create(acb_readahead, &key, &node)) { + pcache_node_unref(s, node); + qemu_aio_unref(acb_readahead); + return; + } + pcache_send_acb_request_list(bs, acb_readahead); +} + static BlockAIOCB *pcache_aio_readv(BlockDriverState *bs, int64_t sector_num, QEMUIOVector *qiov, @@ -710,22 +792,18 @@ static BlockAIOCB *pcache_aio_readv(BlockDriverState *bs, void *opaque) { PrefCacheAIOCB *acb = pcache_aio_get(bs, sector_num, qiov, nb_sectors, cb, - opaque, QEMU_AIO_READ); + opaque, PCACHE_AIO_READ); int32_t status = pcache_prefetch(acb); if (status == PREFETCH_FULL_UP) { assert(acb->requests.cnt == 0); complete_aio_request(acb); } else { - PrefCachePartReq *req; assert(acb->requests.cnt != 0); - qemu_co_mutex_lock(&acb->requests.lock); - QTAILQ_FOREACH(req, &acb->requests.list, entry) { - bdrv_aio_readv(bs->file, req->sector_num, &req->qiov, - req->nb_sectors, pcache_aio_cb, acb); - } - qemu_co_mutex_unlock(&acb->requests.lock); + pcache_send_acb_request_list(bs, acb); } + pcache_readahead_request(bs, acb); + return &acb->common; } @@ -737,7 +815,7 @@ static BlockAIOCB *pcache_aio_writev(BlockDriverState *bs, void *opaque) { PrefCacheAIOCB *acb = pcache_aio_get(bs, sector_num, qiov, nb_sectors, cb, - opaque, QEMU_AIO_WRITE); + opaque, PCACHE_AIO_WRITE); bdrv_aio_writev(bs->file, sector_num, qiov, nb_sectors, pcache_aio_cb, acb); @@ -748,8 +826,11 @@ static void pcache_state_init(QemuOpts *opts, BDRVPCacheState *s) { uint64_t cache_size = qemu_opt_get_size(opts, PCACHE_OPT_CACHE_SIZE, PCACHE_DEFAULT_CACHE_SIZE); + uint64_t readahead_size = qemu_opt_get_size(opts, PCACHE_OPT_READAHEAD_SIZE, + PCACHE_DEFAULT_READAHEAD_SIZE); DPRINTF("pcache configure:\n"); DPRINTF("pcache-full-size = %jd\n", cache_size); + DPRINTF("readahead_size = %jd\n", readahead_size); s->pcache.tree.root = RB_ROOT; qemu_co_mutex_init(&s->pcache.tree.lock); @@ -757,7 +838,8 @@ static void pcache_state_init(QemuOpts *opts, BDRVPCacheState *s) qemu_co_mutex_init(&s->pcache.lru.lock); s->pcache.curr_size = 0; - s->cfg_cache_size = cache_size >> BDRV_SECTOR_BITS; + s->cfg.cache_size = cache_size >> BDRV_SECTOR_BITS; + s->cfg.readahead_size = readahead_size >> BDRV_SECTOR_BITS; #ifdef PCACHE_DEBUG QTAILQ_INIT(&s->death_node_list);