diff mbox series

[6/6] qcow2: Resize the cache upon image resizing

Message ID 20180729212744.23709-7-lbloch@janustech.com
State New
Headers show
Series qcow2: Make the L2 cache cover the whole image by default | expand

Commit Message

Leonid Bloch July 29, 2018, 9:27 p.m. UTC
The caches are now recalculated upon image resizing. This is done
because the new default behavior of assigning a sufficient L2 cache to
cover the entire image implies that the cache will still be sufficient
after image resizing. To put a limit on the cache, the options
cache-size and l2-cache-size can be used.

Signed-off-by: Leonid Bloch <lbloch@janustech.com>
---
 block/qcow2.c | 6 ++++++
 1 file changed, 6 insertions(+)

Comments

Alberto Garcia Aug. 3, 2018, 12:42 p.m. UTC | #1
On Sun 29 Jul 2018 11:27:44 PM CEST, Leonid Bloch wrote:
> The caches are now recalculated upon image resizing. This is done
> because the new default behavior of assigning a sufficient L2 cache to
> cover the entire image implies that the cache will still be sufficient
> after image resizing. To put a limit on the cache, the options
> cache-size and l2-cache-size can be used.
>
> Signed-off-by: Leonid Bloch <lbloch@janustech.com>
> ---
>  block/qcow2.c | 6 ++++++
>  1 file changed, 6 insertions(+)
>
> diff --git a/block/qcow2.c b/block/qcow2.c
> index 74f2cb10a4..06fac1bb8c 100644
> --- a/block/qcow2.c
> +++ b/block/qcow2.c
> @@ -3656,6 +3656,12 @@ static int coroutine_fn qcow2_co_truncate(BlockDriverState *bs, int64_t offset,
>      }
>  
>      s->l1_vm_state_index = new_l1_size;
> +    /* Update cache sizes */
> +    QDict *options = qdict_clone_shallow(bs->options);
> +    ret = qcow2_update_options(bs, options, s->flags, errp);
> +    if (ret < 0) {
> +        goto fail;
> +    }

Perhaps this could be merged with the "Update total_sectors when
resizing" patch. When you put both changes together it is quite clear
why you need to update bs->total_sectors, and doing it is only necessary
if you want to do this afterwards.

Berto
Leonid Bloch Aug. 4, 2018, 11:53 a.m. UTC | #2
On 08/03/2018 03:42 PM, Alberto Garcia wrote:
> On Sun 29 Jul 2018 11:27:44 PM CEST, Leonid Bloch wrote:
>> The caches are now recalculated upon image resizing. This is done
>> because the new default behavior of assigning a sufficient L2 cache to
>> cover the entire image implies that the cache will still be sufficient
>> after image resizing. To put a limit on the cache, the options
>> cache-size and l2-cache-size can be used.
>>
>> Signed-off-by: Leonid Bloch <lbloch@janustech.com>
>> ---
>>   block/qcow2.c | 6 ++++++
>>   1 file changed, 6 insertions(+)
>>
>> diff --git a/block/qcow2.c b/block/qcow2.c
>> index 74f2cb10a4..06fac1bb8c 100644
>> --- a/block/qcow2.c
>> +++ b/block/qcow2.c
>> @@ -3656,6 +3656,12 @@ static int coroutine_fn qcow2_co_truncate(BlockDriverState *bs, int64_t offset,
>>       }
>>   
>>       s->l1_vm_state_index = new_l1_size;
>> +    /* Update cache sizes */
>> +    QDict *options = qdict_clone_shallow(bs->options);
>> +    ret = qcow2_update_options(bs, options, s->flags, errp);
>> +    if (ret < 0) {
>> +        goto fail;
>> +    }
> 
> Perhaps this could be merged with the "Update total_sectors when
> resizing" patch. When you put both changes together it is quite clear
> why you need to update bs->total_sectors, and doing it is only necessary
> if you want to do this afterwards.

Indeed. I agree.

Leonid.

> 
> Berto
>
diff mbox series

Patch

diff --git a/block/qcow2.c b/block/qcow2.c
index 74f2cb10a4..06fac1bb8c 100644
--- a/block/qcow2.c
+++ b/block/qcow2.c
@@ -3656,6 +3656,12 @@  static int coroutine_fn qcow2_co_truncate(BlockDriverState *bs, int64_t offset,
     }
 
     s->l1_vm_state_index = new_l1_size;
+    /* Update cache sizes */
+    QDict *options = qdict_clone_shallow(bs->options);
+    ret = qcow2_update_options(bs, options, s->flags, errp);
+    if (ret < 0) {
+        goto fail;
+    }
     ret = 0;
 fail:
     qemu_co_mutex_unlock(&s->lock);