From patchwork Sun Jul 29 21:27:43 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leonid Bloch X-Patchwork-Id: 10548315 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 3228A14BC for ; Sun, 29 Jul 2018 21:33:27 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 24658288BC for ; Sun, 29 Jul 2018 21:33:27 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 18C7629A8E; Sun, 29 Jul 2018 21:33:27 +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=-7.8 required=2.0 tests=BAD_ENC_HEADER,BAYES_00, DKIM_SIGNED,MAILING_LIST_MULTI,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 6A7DC288BC for ; Sun, 29 Jul 2018 21:33:26 +0000 (UTC) Received: from localhost ([::1]:49692 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fjtJd-000659-J0 for patchwork-qemu-devel@patchwork.kernel.org; Sun, 29 Jul 2018 17:33:25 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33883) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fjtF2-00020J-7k for qemu-devel@nongnu.org; Sun, 29 Jul 2018 17:28:41 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fjtF0-0000XD-D8 for qemu-devel@nongnu.org; Sun, 29 Jul 2018 17:28:40 -0400 Received: from mail-sn1nam02on0111.outbound.protection.outlook.com ([104.47.36.111]:45370 helo=NAM02-SN1-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fjtF0-0000W0-7K; Sun, 29 Jul 2018 17:28:38 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=janustech.onmicrosoft.com; s=selector1-janustech-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=WRgFzJsxSh7tzuci/flKSI6BKbDynhTPfKlIQm3TPnk=; b=N27hqlXQUjvAQlDV6bLOKkRWVudgVAnqSZVW/fvTkgdco91mh3GkEJQ+4CwM3dDnlnIxxKUfRPRBtPLWI8d0ZCMJ7H3qVgYaU2QlON92x8Cmu8tTX+iGIrTrDTwpAQTIi3nMwegMCiSUcKTSzKHBUnC1iB2CCYQpY/qMz+1uU8k= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=lbloch@janustech.com; Received: from Jupiter.local (141.226.29.227) by CY1PR07MB2617.namprd07.prod.outlook.com (2a01:111:e400:c637::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.995.19; Sun, 29 Jul 2018 21:28:30 +0000 From: Leonid Bloch To: qemu-devel@nongnu.org Date: Mon, 30 Jul 2018 00:27:43 +0300 Message-Id: <20180729212744.23709-6-lbloch@janustech.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180729212744.23709-1-lbloch@janustech.com> References: <20180729212744.23709-1-lbloch@janustech.com> MIME-Version: 1.0 X-Originating-IP: [141.226.29.227] X-ClientProxiedBy: HE1PR06CA0138.eurprd06.prod.outlook.com (2603:10a6:7:16::25) To CY1PR07MB2617.namprd07.prod.outlook.com (2a01:111:e400:c637::15) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 5fd2a9ee-7514-4bde-8616-08d5f59a3bf4 X-Microsoft-Antispam: BCL:0; PCL:0; RULEID:(7020095)(4652040)(7021125)(8989117)(5600074)(711020)(4534165)(7022125)(4603075)(4627221)(201702281549075)(8990107)(7048125)(7024125)(7027125)(7028125)(7023125)(2017052603328)(7153060)(7193020); SRVR:CY1PR07MB2617; X-Microsoft-Exchange-Diagnostics: 1; CY1PR07MB2617; 3:8fjqfGZ+P4H5G85gNRvJQDqgGHDXy9Jsqbk8p+9f5QZFYPKRFqvDCfhUo0Epaj46RLRasniUB1IRrr1RsryTsO833wuzo/H6PrI7+Hkr75+rMgTGDayOwakFO7rra41Two5N5iNsk79XBCGTX+cGJxdRfZ13mQ7H1ih/LygJ5/ngef33O1f3pmhuKDtWy8bytvwebbmUqKJq4HnbWpliGXj5w7x6Tg1hUu6uYvmnMD5WSpsXJZX6+DrrM8JS1hbS; 25:qah0qqvNVV+STCbeEpvxM54NIZoUe7XmmKjgJ3m0OAidHBcirgCMJin6Q9WIJxxseofs8tMle/oPj9vBkZzj7gUlH2Y7pCpYRrGKAKVOXqJbCKyYJsk3oR3HPXNdwWCyeajCF285KjaTwNW7Uk/WP4dms4DQgiFzsoaaPwPwo+CpWTo9VBqCtaW9LQqSNoohfdPI5ohfws0GYhU+metKKqqnEqzqBuQvVQC73YvJnuHb3z6KbDiPS4CvB110i3zceq4EBE58gmxxVrExRHNWUOwE1v3fbo6ixO5uaF+UOV97JVnpOwp19cLoLCHo3Y3xppKNJL+bT9eanbyHOFo/Gw==; 31:Nx/E/zD7yPuCuJlscyqeOXOCD/XZkP5o4ZPZzKWnu9mppuAVVnaVS0NEvefSHKmW2XgEBI1rE5ZO5PMyGW6QuRe7glC+JSrkE11el3NXBBH8yW8l2JSryiNtI0/SgxhIYRpQFA6kPsUO+3qk8dtE2M8k+29NFLhgV6uylg+R4mpd+9KxuZCheFzdphQILniNs5oBy8JTKqMqhYG8g63w6uw9GIxK08oqXHnISRVmrZc= X-MS-TrafficTypeDiagnostic: CY1PR07MB2617: X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-MS-Exchange-SenderADCheck: 1 X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6040522)(2401047)(5005006)(8121501046)(93006095)(93001095)(3231311)(944501410)(52105095)(3002001)(10201501046)(149027)(150027)(6041310)(2016111802025)(20161123560045)(20161123564045)(20161123562045)(20161123558120)(6072148)(6043046)(201708071742011)(7699016); SRVR:CY1PR07MB2617; BCL:0; PCL:0; RULEID:; SRVR:CY1PR07MB2617; X-Microsoft-Exchange-Diagnostics: 1; CY1PR07MB2617; 4:/oq0oRGWIpR96CK7ritQ1m/7eHZyQXXdbDod5rJtMySEG9yLwR3VTG2VlG/WG2kBNCjfCeSW+mji1Y2ZJbrjzsIrn5rqXorHpYhWNdGUjQAtAKdux3IWPTdY0F6aQ1doYLtjYuIjgZyGxBajEepV0YogVtqYGcv7rdBBJbX0RK22Nj4pS36vZkBmLpZSYel7JPC6lAJQ4rJrF0abpc/31Q/KDd/GuecWFGYJK0ga2wgu3gHDY6IwqzGXenAeViEXn8RWiET2UzZNMYEbUD34QQ== X-Forefront-PRVS: 0748FF9A04 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10019020)(136003)(39830400003)(366004)(346002)(376002)(396003)(199004)(189003)(3846002)(6116002)(4326008)(53936002)(51416003)(316002)(107886003)(52116002)(14444005)(26005)(486006)(81156014)(81166006)(8936002)(956004)(8676002)(16526019)(7736002)(186003)(6486002)(105586002)(476003)(305945005)(2616005)(6512007)(25786009)(478600001)(16586007)(66066001)(68736007)(47776003)(11346002)(54906003)(2906002)(2351001)(36756003)(106356001)(1076002)(76176011)(50466002)(5660300001)(6666003)(6506007)(446003)(386003)(2361001)(48376002)(97736004)(50226002)(6916009)(86362001); DIR:OUT; SFP:1102; SCL:1; SRVR:CY1PR07MB2617; H:Jupiter.local; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; A:1; MX:1; Received-SPF: None (protection.outlook.com: janustech.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; CY1PR07MB2617; 23:0/7yi+5U2lHnwNWLrVVEGInaNzU5JodHqNR62mZZQ?= 3pgl8wx4DLeqDm9ry0GMzvphtRmGnBr9bRWMR/YrbOFpmR4IWAnJcX4fIwTFc9dtB2jFjtOEE23TdlydEBaW7ILRIv2/F9fp+e7p9AANLQtQIBesRHqKyBzoGMA7iiqyIRnMMxZjZxWcW0INs+A48eYPaDi2OgUCpnwlJd96IJyOtfbpZqp0o/FBLtKmss3QB8pOfyP+tGN4hFlGscJUGsm4erDizn35s7L96/SImEb0J9TPIhHl7tLIDrsi0Isb7njM9JExdSOeakLDML2oNb2KuHyv7aQqChRq42yjlkhjQwDsRlLSwuEoGT9OeSqt/Efq5knrjDyGdvYAZObL80DOma7Hi+r7iNHdHAE1GcXHqTHxIEIQ3yVDCM0n37vcIWvBh5zUYFGpeA5dt/SdEeTllOqoML9i36w/ot2QfevHSLfAKn1EaxCHmPHinKxSeTLWBfPUWCKl+8357acKhq1RtrupkOWV07sa3Cgz4+kEu2htfB3D7Iyp3XuPru6bHwmQu7pf9J5QaQdzT8o/E7YrxIT/LZg1yOgE+ZceJVEKjp9q7A2Snqb79UrS3HQcDiT8zVbuMj23K8rrrAq6QWxQsaeOZtLafqHx1xAQ84YsPx8svSg0Mpe292kisfA9FeUJ4H8Kj9L/b5XGOl9RDRfxT1alz2cdFYz6j6Ay42WGEahZLHiLCZWElWK2MhYPLPr30fcIK6ugruq1nAt8X10tTnJDgB1zQRpP0B1093auk+yKRcGWFWT0HMXj2gzLnL9Pl7/XyXAHY8vO9OlVigc1hbUN5fzi2fPHW/5iTfe3/fOEAlYvlkRx3dgnMYQ3cYMJViLk5RTAvVv1MZ0Q8PeD9B49ovBSCAy1S4n0PjPrA1QWplWDXP3jGQxmLpxt/XYzrUbIDZiHUxWgqor6WapYtaOa0+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FOdZlkqwgRWJ1dOUa9oa0j1PgLhWoZRVHKvdjs4FfKtYta/T308Cmdg2RvCoJhUo+hk4ZMT6Urh3GBCCvS2LceP1kOObp/YPTxMwskYHbf95mQaIvY8rJh17txndxbNnI+asqgJg==; 5:0EYiAamaDoKJAbW0Rk5TDuR4bzmhyUzGdYJZJvafXmGISzIUtBOuTrL0jtxh9gfcELkQW6u74XboJlvLB6+IvzE/t17ZYEksDyfTsLYrRXW4QIUUhNKMjOxjBxYrs1GDhbQ9VZ7o/ZBwCLpRqHRqR+ofran2D3NXfFGvt9jNMZQ=; 7:qo1fqnnKFFleHTbBAcVkRGLGncy3QmG29Ksk4f/UiBUv9U1mEV4xowCy+0tkfh0dc8/mk1o4nENzZ1Us42Lrau+S6SYpQFadD2r+7haF6z5Z3VNp6QZuiMeRk2kfPGlaBJtjSbkAD494aackrNQDF7eh7kr6uvuNtmWlpHZJ5jmTTfKrszfeT3t4uzP4k0aYoBnP0e2OWQySOPiMlsbjWVVPob/bBmJ6S7D5qvDSYH0JAzZKTvOoDrwL0xI3bge8 SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: janustech.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 Jul 2018 21:28:30.2437 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 5fd2a9ee-7514-4bde-8616-08d5f59a3bf4 X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 34eb020e-3cf3-43a1-afeb-f5cf1310628e X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY1PR07MB2617 X-detected-operating-system: by eggs.gnu.org: Windows 7 or 8 [fuzzy] X-Received-From: 104.47.36.111 Subject: [Qemu-devel] [PATCH 5/6] qcow2: Make the default L2 cache sufficient to cover the entire image 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: Kevin Wolf , Leonid Bloch , qemu-block@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP Sufficient L2 cache can noticeably improve the performance when using large images with frequent I/O. The memory overhead is not significant, as the cache size is only 1 MB for each 8 GB of virtual image size (with the default cluster size of 64 KB). On systems with limited memory, one can limit the cache size by the l2-cache-size and cache-size options. Signed-off-by: Leonid Bloch --- block/qcow2.c | 10 ++++------ block/qcow2.h | 4 ---- docs/qcow2-cache.txt | 21 +++++++++++---------- qemu-options.hx | 6 +++--- 4 files changed, 18 insertions(+), 23 deletions(-) diff --git a/block/qcow2.c b/block/qcow2.c index 223d351e40..74f2cb10a4 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -793,6 +793,9 @@ static void read_cache_sizes(BlockDriverState *bs, QemuOpts *opts, *l2_cache_entry_size = qemu_opt_get_size( opts, QCOW2_OPT_L2_CACHE_ENTRY_SIZE, s->cluster_size); + uint64_t virtual_disk_size = bs->total_sectors * BDRV_SECTOR_SIZE; + uint64_t max_l2_cache = virtual_disk_size / (s->cluster_size / 8); + if (combined_cache_size_set) { if (l2_cache_size_set && refcount_cache_size_set) { error_setg(errp, QCOW2_OPT_CACHE_SIZE ", " QCOW2_OPT_L2_CACHE_SIZE @@ -814,9 +817,6 @@ static void read_cache_sizes(BlockDriverState *bs, QemuOpts *opts, } else if (refcount_cache_size_set) { *l2_cache_size = combined_cache_size - *refcount_cache_size; } else { - uint64_t virtual_disk_size = bs->total_sectors * BDRV_SECTOR_SIZE; - uint64_t max_l2_cache = virtual_disk_size / (s->cluster_size / 8); - /* Assign as much memory as possible to the L2 cache, and * use the remainder for the refcount cache */ if (combined_cache_size >= max_l2_cache + min_refcount_cache) { @@ -830,9 +830,7 @@ static void read_cache_sizes(BlockDriverState *bs, QemuOpts *opts, } } else { if (!l2_cache_size_set) { - *l2_cache_size = MAX(DEFAULT_L2_CACHE_BYTE_SIZE, - (uint64_t)DEFAULT_L2_CACHE_CLUSTERS - * s->cluster_size); + *l2_cache_size = max_l2_cache; } if (!refcount_cache_size_set) { *refcount_cache_size = min_refcount_cache; diff --git a/block/qcow2.h b/block/qcow2.h index 81b844e936..1b9005e13c 100644 --- a/block/qcow2.h +++ b/block/qcow2.h @@ -73,10 +73,6 @@ /* Must be at least 4 to cover all cases of refcount table growth */ #define MIN_REFCOUNT_CACHE_SIZE 4 /* clusters */ -/* Whichever is more */ -#define DEFAULT_L2_CACHE_CLUSTERS 8 /* clusters */ -#define DEFAULT_L2_CACHE_BYTE_SIZE 1048576 /* bytes */ - #define DEFAULT_CLUSTER_SIZE 65536 diff --git a/docs/qcow2-cache.txt b/docs/qcow2-cache.txt index fd9a6911cc..bcc03c8857 100644 --- a/docs/qcow2-cache.txt +++ b/docs/qcow2-cache.txt @@ -97,12 +97,14 @@ need: l2_cache_size = disk_size_GB * 131072 refcount_cache_size = disk_size_GB * 32768 -QEMU has a default L2 cache of 1MB (1048576 bytes) and a refcount -cache of 256KB (262144 bytes), so using the formulas we've just seen -we have +QEMU will use a default L2 cache sufficient to cover the entire virtual +size of an image, which with the default cluster size will result in 1MB +of cache for every 8GB of virtual image size: - 1048576 / 131072 = 8 GB of virtual disk covered by that cache - 262144 / 32768 = 8 GB + 65536 / 8 = 8192 = 8 GB / 1 MB + +A default refcount cache is 4 times the cluster size, which defaults to +256KB (262144 bytes). How to configure the cache sizes @@ -121,8 +123,8 @@ There are a few things that need to be taken into account: - Both caches must have a size that is a multiple of the cluster size (or the cache entry size: see "Using smaller cache sizes" below). - - The default L2 cache size is 8 clusters or 1MB (whichever is more), - and the minimum is 2 clusters (or 2 cache entries, see below). + - The default L2 cache size is enough to cover the entire virtual size of + an image, and the minimum is 2 clusters (or 2 cache entries, see below). - The default (and minimum) refcount cache size is 4 clusters. @@ -180,9 +182,8 @@ Some things to take into account: always uses the cluster size as the entry size. - If the L2 cache is big enough to hold all of the image's L2 tables - (as explained in the "Choosing the right cache sizes" section - earlier in this document) then none of this is necessary and you - can omit the "l2-cache-entry-size" parameter altogether. + (the default behavior) then none of this is necessary and you can + omit the "l2-cache-entry-size" parameter altogether. Reducing the memory usage diff --git a/qemu-options.hx b/qemu-options.hx index 18f3f87da5..c9e7764c13 100644 --- a/qemu-options.hx +++ b/qemu-options.hx @@ -756,9 +756,9 @@ The maximal total size of the L2 table and refcount block caches in bytes @item l2-cache-size The maximal size of the L2 table cache in bytes -(default: if cache-size is not defined - 1048576 bytes or 8 clusters, whichever -is larger; otherwise, as large as possible or needed within the cache-size, -while permitting the requested or the minimal refcount cache size) +(default: if cache-size is not defined - enough to cover the entire image; +otherwise, as large as possible or needed within the cache-size, while +permitting the requested or the minimal refcount cache size) @item refcount-cache-size The maximal size of the refcount block cache in bytes