From patchwork Mon Aug 29 17:10: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: 9304223 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 853A460756 for ; Mon, 29 Aug 2016 17:44:13 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 78892288E2 for ; Mon, 29 Aug 2016 17:44:13 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6CED2288E5; Mon, 29 Aug 2016 17:44:13 +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 317D7288E2 for ; Mon, 29 Aug 2016 17:44:10 +0000 (UTC) Received: from localhost ([::1]:45020 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1beQbR-0003E4-H5 for patchwork-qemu-devel@patchwork.kernel.org; Mon, 29 Aug 2016 13:44:09 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49819) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1beQaz-0003BA-J9 for qemu-devel@nongnu.org; Mon, 29 Aug 2016 13:43:42 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1beQay-0006NE-5a for qemu-devel@nongnu.org; Mon, 29 Aug 2016 13:43:41 -0400 Received: from mail-eopbgr00099.outbound.protection.outlook.com ([40.107.0.99]:57657 helo=EUR02-AM5-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1beQar-0006Kb-Sv; Mon, 29 Aug 2016 13:43:34 -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=Yy3JZMEaA/qZYFVj01a8CEnSvfjfzZBumIgeLsOrujvg4U2RINUW7YdZDHzOvsgWhcrNwWT6D9A3qwRdQ0COo20WZ5P+REKJXeyj+Uame8hEhF8H2HjUSLz7uCmVIM41c9E5Gc5N05nU2OIwTNBVvEU/tIwanUa40CaSbSwFMW8= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=pbutsykin@virtuozzo.com; Received: from pavelb-Z68P-DS3.sw.ru (195.214.232.10) by AM5PR0802MB2547.eurprd08.prod.outlook.com (10.175.45.23) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA_P384) id 15.1.587.13; Mon, 29 Aug 2016 17:11:27 +0000 From: Pavel Butsykin To: , Date: Mon, 29 Aug 2016 20:10:14 +0300 Message-ID: <20160829171021.4902-16-pbutsykin@virtuozzo.com> X-Mailer: git-send-email 2.8.3 In-Reply-To: <20160829171021.4902-1-pbutsykin@virtuozzo.com> References: <20160829171021.4902-1-pbutsykin@virtuozzo.com> MIME-Version: 1.0 X-Originating-IP: [195.214.232.10] X-ClientProxiedBy: AM5PR0901CA0011.eurprd09.prod.outlook.com (10.164.186.149) To AM5PR0802MB2547.eurprd08.prod.outlook.com (10.175.45.23) X-MS-Office365-Filtering-Correlation-Id: f4a9023d-78a6-4415-05e2-08d3d02f8370 X-Microsoft-Exchange-Diagnostics: 1; AM5PR0802MB2547; 2:pOtnq8LYQVf0TNJi24WU098uTc1R9JF5/LHTqXyQsj9dsY3D9PD9jZmuDspp2fQ3du/LxqO7GnR66BrTn+64PvsHpkozf87CIqSMOMASJ13SdnKlwO+1SoqqIUUg/eNpoTbb46GklZa9eiUjtyTfLhQLWmYtuEiNUjhm/ynLR/Hsbf1L3eQLdvw73/IO7XP/; 3:Nezue4/v9xq3DL3bSYleTbz9pvjaQ5VUa+mA5LmnaYQ0Nj3LIfhKQSrcJpJXz6Tcim3zoyKYqSMvLnmXjp1ap5n5f4anozeRKfLrgZXSYGG2QtGHndcliBYQOxRzzCnZ X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:AM5PR0802MB2547; X-Microsoft-Exchange-Diagnostics: 1; AM5PR0802MB2547; 25:m6ydDSoPM4ryhXfbMRcOSVooWF1tP5QGexKbeTkHqS9zny/KS/yE3Cd/Mk4uXkKABLz5lUhz5PzseX/Qnbqe7haTFvUVKOH3otwnWQSjF12xrEMf1c6kBPE2ABGFI42Vcm8rFDKqksBdWZRw+30yU+82XILl7bjgPUk9FsF6i02NQC41XgZ8vWPr7gf73LGtETf+3eymuzIfJ80rWR6lKWwVJxSQz99rVpKO8YR39g3k8Xx9bCS6xTesHGCdHLwbWYd06xepCYbpdlBRjoP78FcQnOV+hieA4iBTLjLQvep0VR+4NYWx5MeufTED9LcyaPoV/UQz2fWirfnjwAvIsiDj3G5tRdf5akNjgL5FNbXJGSAkRsHqJlpKKmW6t9PR3cwbq3k3nr3Mo/a6bdzVJ72mYg5lazG3hDr59p1sqxy+suVF0XoTYsbeE/4VuxIt3sjYNLlnB4y64LuhqnfcDB7eYrBIXrrlU+IdMmPtj0eYSJMl2ZD8KInWAx6srJBrM2r+DoTs0svPhaMyXgKzWT3SX3rlOLa9agKec0Pm0Bg5bfnnctxWSFYGbNJa4g1f9slpl0Twg/pbD1kiUMtCX2HYpbMggO0wz7isllbuxOvfLF4Q8o0NaP8wf5JC8r+ToCmVOUfNqaUKx3V7ZmnqXMSFWq9o/X+6hX15K3kYlFtaUawdhx4Ri/ANHA4qNdQLFBUhBlzXXzQ9Hlyiiny+3w==; 31:v1I50o8joJs57Cbat4zBqOU2Zf8b3fO8P7Ui3jlWQDrv1OFaYSLzADikmBDyP0DF5LuV7kiIf+6ntR/FNSzQsjt46CBbV6xVmBd9o2Q3n7ojaf75IPg4JqG5XjqUEqGWIEC5L2onURNSDxWiVf9BcJRuOHC59feGrXnwttTKiRzrDrCn25u5/GH7eYh7jV0TunUdq0sHTFy6quLXNF58Z07H85Ve6Ql4kzqQ9rKnD5E= 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)(6042046)(6043046); SRVR:AM5PR0802MB2547; BCL:0; PCL:0; RULEID:; SRVR:AM5PR0802MB2547; X-Microsoft-Exchange-Diagnostics: 1; AM5PR0802MB2547; 4:jnWQqUjFKtX9mnujh1KGR5e2vt9ohCq5tWCpeOot4IZ+u5Gc6G2g5bw4zqpoob7+/c2Djy7RCpE8PGaejX1pyn12ZrHlycq16s/3XTnPAauioWtacYqs/wUa79WFNboeJTKBWygn3EY7uQWiM4TNafFJBQRZD5R8tTrK2qbbggGKREYHr189MtLHkDZMK+dGdBk4iCVC6U3ttshApvLd7ARQ6Fd8tiDvQvZ5HI88vBVDC/KJqCYYicZKWMtETrVrLFMiX6QVD84DJ5NI2iwFvv9vU1TVWan9YXoko8fWypYSMTyFZ7rJ4ALQt7sR1X/mWKcag5QfbjJLMsq1Lsn0MojP6w0U3/+brtjXB2LSuxSdkRTkG/RCGOU1LXrwGhPyM5J6WKEY/N4RsUT6mX/oclHTB5rd0W/rOcx+qk+Vob4= X-Forefront-PRVS: 0049B3F387 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10019020)(4630300001)(6009001)(7916002)(199003)(189002)(3846002)(305945005)(77096005)(86362001)(1076002)(53416004)(92566002)(68736007)(42186005)(97736004)(5001770100001)(47776003)(105586002)(2906002)(6116002)(189998001)(50986999)(4326007)(48376002)(586003)(2950100001)(5003940100001)(50466002)(66066001)(19580405001)(19580395003)(76176999)(69596002)(5660300001)(229853001)(101416001)(36756003)(7736002)(8676002)(106356001)(50226002)(7846002)(81156014)(33646002)(81166006)(21314002)(217873001); DIR:OUT; SFP:1102; SCL:1; SRVR:AM5PR0802MB2547; H:pavelb-Z68P-DS3.sw.ru; FPR:; SPF:None; PTR:InfoNoRecords; A:1; MX: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; AM5PR0802MB2547; 23:+aMxMKvRCm5XDlLO0ta5YOa2pil/USNz27dWA2r?= =?us-ascii?Q?UkHZULCixRKnOXyLVN6xK9xLHEV8Ih+yQP68Tme2A5BYuYWXDgAgIDjkgJ34?= =?us-ascii?Q?gV74YC4SQlhQQktpS4cHOu2aH4QSB/v8OkWkaogg1HYkKrNq0JMmFD/azWYr?= =?us-ascii?Q?VYpzpSiHmuYcnIbrWQQ3n46u5Di901yFTdSLrxumiyu/TXH9NtkBIm7QpNWI?= =?us-ascii?Q?Aq/o4f36ktK3PGnEprTa0uu/NQW5PzIr5Yrktk2iyG9xygFNfIJqZYCLnIxU?= =?us-ascii?Q?5Ijjyq1NMEWpGmM8BjUTwIJp+8zInYDvjAsDRDC9cuFGYO7H80WKQAwSC2xX?= =?us-ascii?Q?ky962mqj6ZUCGYCDQugWi2MVp2s8cZC5FE6zGO+cijxZVAxLPrxCK0CvN88I?= =?us-ascii?Q?cB6J3GXJ5Df1I+XHKYb4ypkXncAb+bCDda0S7eDXsCf5eACI7Wk08O1GgtYi?= =?us-ascii?Q?SqIl2YANjHPbx/ecbk372gusy3AT/AhOnsh4kVch09tH99mB7i9UPBFxj+pl?= =?us-ascii?Q?Yv8l6XYtMjktFKVbyaec4pqW8wp6tbZ/2W+10/3jR3J1T+E5nZiOY9kNhPmB?= =?us-ascii?Q?jin88i+VQrFVQc6zTWEOb+0CQ+EjcJ4k4gE8S5mcFcSCEl6IXte+VeHerava?= =?us-ascii?Q?cRZi5TP6XJEX7IU6GtaaAdEi6vi+2sAWJ6lfD2U7T1pDpuf7Y3qhfUXSbZrH?= =?us-ascii?Q?Uo6vFeelABl2WtggElqCL5aGoSZVLuZDD0IYNzJRrvIoL6JxbEtkPR0YAx6Z?= =?us-ascii?Q?eatGDOw+Jd9IbP2bZ5LJkl1asTotn51Evzi185UPxTX/iFmQgtf3HuPrHGVZ?= =?us-ascii?Q?2cTFC7b6cT6VFP3qeOaXd+rNToFn7BJph+YliroIW4oVn9iRrmwIASlhqQxI?= =?us-ascii?Q?VISvWNG+9SSZeXlbqH86rkU5iurQQL1PZg7rMaR9DWq0CMrjgJpuXYH7DNX5?= =?us-ascii?Q?ZmnutFdX60LXdOALrGChOzD3nssDM3U8gUk2t9fZSzjMUyecvFONZsacQvli?= =?us-ascii?Q?UDsRX4VR3UtZdlNUGa7WVs+3ZBRG9vagRS009WXGQPDDX7evmTWyy13C4QE3?= =?us-ascii?Q?LHHAIOVNPupNqkQPKoszwrd9F5l+jnLxP8DfJGYgBP0yVsk+mKboqEurdt1d?= =?us-ascii?Q?Gid1lSfwFlCUCDs89zsrbrmAd8ve1QAPensda/j6TQdTGzfnIeT+hTjl0XiI?= =?us-ascii?Q?vRBpOF4z4X66rri8=3D?= X-Microsoft-Exchange-Diagnostics: 1; AM5PR0802MB2547; 6:g+BSJBcrZ+k11FumnkA/mJ2T1FJA1XG/Po79SmmZF6ykSvqZLHrXbmrETj5H52243s6GuldO7MG3ERXMKxIaylXm61dSk0KVm0pYDVx4aVI7ydbH7tcebjN0Mp3KxIqkRblKuN0fLi60fqESxD1ywF24jyYO7MyXLvvEVOu9O7N3C4q2kk6//xB4FtRD8GDTI1kefpt/srALTXbbiuHohVC0ZHJLcg8veX/BFFZoNy8/A9i+BLSDDd75hz3qSaQsKGpi2O7pc/ZpdzMISzdvVtZhxPSNIVndQs9TakvCMwnximm+pa8PQTrnbsYWL1oV; 5:DrSZ6zaMpBdV67ZxI2OcUSlrqmyHLbXR5ud7L+YK//em/qTEdS2gex4Xvd8lRJcPVkdgUAgqjJBeJnoTb6HVtdArKxSNIad4bZi9EhLtv/UsbQg37Vw/CCe3npukKSCUIGRjz1bWGOwFY8B0++fjEg==; 24:22eM+rUvkgJZZLNTeXEL5hAWeivJYqFl7GwNHCPDcgEe3Eab8/qAgUKc6ywrlpv2JIJlJVZkwjMQ43yUa+U2Tq9nye9MkmfrfFpsSjENPhQ=; 7:AM5tadO3BG2jjml/kDICL1+G1Ce/KQfiS8cROWKPf7fItbni3QzWVt20p4n0OHP0sbU0m1kC+cRsmWnpzlaZ3ilFfCj+g8hcXCzYVLCsuEMaLugl1sLR3ayN+k3HxAGmUlKfD3PhdClKT7RO4fhH+AK7DwPpL44WGGSwJ0cU6iIAKP/ZczoXy6FXqAnlkObiIV9uUxMH79C2HGdgD3653GVEJlVjsaHBqEfH2Zqvw0j/W+aXYSlUb0cbiBz13NwB SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; AM5PR0802MB2547; 20:d/A9nS7YO/neUf4RN7trXQkFGcKJk9qTczY6dhPrbDRsFBraW2qo7aCYRlfZLtNdEn3O5CB6JzR9H2vqrTXVmfAa/RpiY1wJQat0VmnHiVnatF7uMTuQMIJ7tYABDzKmh+HM0ICEcP2l26sqAqHNnYo1oNGyozWO/HEuC+n5N0o= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 Aug 2016 17:11:27.1154 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM5PR0802MB2547 X-detected-operating-system: by eggs.gnu.org: Windows 7 or 8 [fuzzy] X-Received-From: 40.107.0.99 Subject: [Qemu-devel] [PATCH RFC v2 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, famz@redhat.com, mreitz@redhat.com, stefanha@redhat.com, den@openvz.org, jsnow@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);