Message ID | 20180810062647.23211-2-lbloch@janustech.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | Take the image size into account when allocating the L2 cache | expand |
On Fri 10 Aug 2018 08:26:39 AM CEST, Leonid Bloch wrote: > Signed-off-by: Leonid Bloch <lbloch@janustech.com> > --- > docs/qcow2-cache.txt | 16 +++++++++++----- > qemu-options.hx | 9 ++++++--- > 2 files changed, 17 insertions(+), 8 deletions(-) > > diff --git a/docs/qcow2-cache.txt b/docs/qcow2-cache.txt > index 8a09a5cc5f..0f157d859a 100644 > --- a/docs/qcow2-cache.txt > +++ b/docs/qcow2-cache.txt > @@ -97,12 +97,15 @@ 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 > +With the default cluster size, to cover each 8 GB of the virtual image > +size, 1MB of L2 cache is needed: > > - 1048576 / 131072 = 8 GB of virtual disk covered by that cache > - 262144 / 32768 = 8 GB > + 65536 / 8 = 8192 = 8 GB / 1 MB Where does this 65536 / 8 come from? The line that you changed follows directly from the formula immediately before that paragraph: l2_cache_size = disk_size_GB * 131072 that is l2_cache_size / 131072 = disk_size_GB 1048576 / 131072 = 8 GB Berto
On 8/10/18 2:50 PM, Alberto Garcia wrote: > On Fri 10 Aug 2018 08:26:39 AM CEST, Leonid Bloch wrote: >> Signed-off-by: Leonid Bloch <lbloch@janustech.com> >> --- >> docs/qcow2-cache.txt | 16 +++++++++++----- >> qemu-options.hx | 9 ++++++--- >> 2 files changed, 17 insertions(+), 8 deletions(-) >> >> diff --git a/docs/qcow2-cache.txt b/docs/qcow2-cache.txt >> index 8a09a5cc5f..0f157d859a 100644 >> --- a/docs/qcow2-cache.txt >> +++ b/docs/qcow2-cache.txt >> @@ -97,12 +97,15 @@ 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 >> +With the default cluster size, to cover each 8 GB of the virtual image >> +size, 1MB of L2 cache is needed: >> >> - 1048576 / 131072 = 8 GB of virtual disk covered by that cache >> - 262144 / 32768 = 8 GB >> + 65536 / 8 = 8192 = 8 GB / 1 MB > > Where does this 65536 / 8 come from? The line that you changed follows > directly from the formula immediately before that paragraph: > > l2_cache_size = disk_size_GB * 131072 > > that is > > l2_cache_size / 131072 = disk_size_GB > 1048576 / 131072 = 8 GB > > Berto > How about the following (all the relevant section reproduced below, for a continuous readability): """""""""" Choosing the right cache sizes ------------------------------ In order to choose the cache sizes we need to know how they relate to the amount of the allocated space. The amount of virtual disk that can be mapped by the L2 and refcount caches (in bytes) is: disk_size = l2_cache_size * cluster_size / 8 disk_size = refcount_cache_size * cluster_size * 8 / refcount_bits With the default values for cluster_size (64KB) and refcount_bits (16), this becomes: disk_size = l2_cache_size * 8192 disk_size = refcount_cache_size * 32768 So in order to cover n GB of disk space with the default values we need: l2_cache_size = disk_size_GB * 131072 refcount_cache_size = disk_size_GB * 32768 For example, 1MB of L2 cache is needed to cover each 8 GB of the virtual image size (given that the default cluster size is used): 8 * 131072 = 1 MB A default refcount cache is 4 times the cluster size, which defaults to 256 KB (262144 bytes). This is sufficient for 8 GB of image size: 262144 / 32768 = 8 GB """"""""""
diff --git a/docs/qcow2-cache.txt b/docs/qcow2-cache.txt index 8a09a5cc5f..0f157d859a 100644 --- a/docs/qcow2-cache.txt +++ b/docs/qcow2-cache.txt @@ -97,12 +97,15 @@ 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 +With the default cluster size, to cover each 8 GB of the virtual image +size, 1MB of L2 cache is needed: - 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 +256 KB (262144 bytes). This is sufficient for 8 GB of image size: + + 262144 / 32768 = 8 GB How to configure the cache sizes @@ -130,6 +133,9 @@ There are a few things that need to be taken into account: memory as possible to the L2 cache before increasing the refcount cache size. + - At most two of "l2-cache-size", "refcount-cache-size", and "cache-size" + can be set simultaneously. + Unlike L2 tables, refcount blocks are not used during normal I/O but only during allocations and internal snapshots. In most cases they are accessed sequentially (even during random guest I/O) so increasing the diff --git a/qemu-options.hx b/qemu-options.hx index b1bf0f485f..f6804758d3 100644 --- a/qemu-options.hx +++ b/qemu-options.hx @@ -752,15 +752,18 @@ image file) @item cache-size The maximum total size of the L2 table and refcount block caches in bytes -(default: 1048576 bytes or 8 clusters, whichever is larger) +(default: the sum of l2-cache-size and refcount-cache-size) @item l2-cache-size The maximum size of the L2 table cache in bytes -(default: 4/5 of the total cache size) +(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) @item refcount-cache-size The maximum size of the refcount block cache in bytes -(default: 1/5 of the total cache size) +(default: 4 times the cluster size; or if cache-size is specified, the part of +it which is not used for the L2 cache) @item cache-clean-interval Clean unused entries in the L2 and refcount caches. The interval is in seconds.
Signed-off-by: Leonid Bloch <lbloch@janustech.com> --- docs/qcow2-cache.txt | 16 +++++++++++----- qemu-options.hx | 9 ++++++--- 2 files changed, 17 insertions(+), 8 deletions(-)