All of lore.kernel.org
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH] blockjob: kick jobs on set-speed
@ 2017-12-11 23:46 John Snow
  2017-12-12  0:08 ` Jeff Cody
  0 siblings, 1 reply; 5+ messages in thread
From: John Snow @ 2017-12-11 23:46 UTC (permalink / raw)
  To: qemu-block; +Cc: kwolf, jcody, qemu-devel, mreitz, John Snow

If users set an unreasonably low speed (like one byte per second), the
calculated delay may exceed many hours. While we like to punish users
for asking for stupid things, we do also like to allow users to correct
their wicked ways.

When a user provides a new speed, kick the job to allow it to recalculate
its delay.

Signed-off-by: John Snow <jsnow@redhat.com>
---
 blockjob.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/blockjob.c b/blockjob.c
index 715c2c2680..43f01ad190 100644
--- a/blockjob.c
+++ b/blockjob.c
@@ -483,6 +483,7 @@ static void block_job_completed_txn_success(BlockJob *job)
 void block_job_set_speed(BlockJob *job, int64_t speed, Error **errp)
 {
     Error *local_err = NULL;
+    int64_t old_speed = job->speed;
 
     if (!job->driver->set_speed) {
         error_setg(errp, QERR_UNSUPPORTED);
@@ -495,6 +496,10 @@ void block_job_set_speed(BlockJob *job, int64_t speed, Error **errp)
     }
 
     job->speed = speed;
+    /* Kick the job to recompute its delay */
+    if ((speed > old_speed) && timer_pending(&job->sleep_timer)) {
+        block_job_enter(job);
+    }
 }
 
 void block_job_complete(BlockJob *job, Error **errp)
-- 
2.14.3

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [Qemu-devel] [PATCH] blockjob: kick jobs on set-speed
  2017-12-11 23:46 [Qemu-devel] [PATCH] blockjob: kick jobs on set-speed John Snow
@ 2017-12-12  0:08 ` Jeff Cody
  2017-12-12 18:22   ` John Snow
  0 siblings, 1 reply; 5+ messages in thread
From: Jeff Cody @ 2017-12-12  0:08 UTC (permalink / raw)
  To: John Snow; +Cc: qemu-block, kwolf, qemu-devel, mreitz

On Mon, Dec 11, 2017 at 06:46:09PM -0500, John Snow wrote:
> If users set an unreasonably low speed (like one byte per second), the
> calculated delay may exceed many hours. While we like to punish users
> for asking for stupid things, we do also like to allow users to correct
> their wicked ways.
> 
> When a user provides a new speed, kick the job to allow it to recalculate
> its delay.
> 
> Signed-off-by: John Snow <jsnow@redhat.com>
> ---
>  blockjob.c | 5 +++++
>  1 file changed, 5 insertions(+)
> 
> diff --git a/blockjob.c b/blockjob.c
> index 715c2c2680..43f01ad190 100644
> --- a/blockjob.c
> +++ b/blockjob.c
> @@ -483,6 +483,7 @@ static void block_job_completed_txn_success(BlockJob *job)
>  void block_job_set_speed(BlockJob *job, int64_t speed, Error **errp)
>  {
>      Error *local_err = NULL;
> +    int64_t old_speed = job->speed;
>  
>      if (!job->driver->set_speed) {
>          error_setg(errp, QERR_UNSUPPORTED);
> @@ -495,6 +496,10 @@ void block_job_set_speed(BlockJob *job, int64_t speed, Error **errp)
>      }
>  
>      job->speed = speed;
> +    /* Kick the job to recompute its delay */
> +    if ((speed > old_speed) && timer_pending(&job->sleep_timer)) {

job->sleep_timer is protected by block_job_mutex (via
block_job_lock/unlock); is it safe for us to check it here outside the
mutex?

But in any case, I think we could get rid of the timer_pending check, and
just always kick the job if we have a speed increase.  block_job_enter()
should do the right thing (mutex protected check on job->busy and
job->sleep_timer).

> +        block_job_enter(job);
> +    }
>  }
>  
>  void block_job_complete(BlockJob *job, Error **errp)
> -- 
> 2.14.3
> 

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Qemu-devel] [PATCH] blockjob: kick jobs on set-speed
  2017-12-12  0:08 ` Jeff Cody
@ 2017-12-12 18:22   ` John Snow
  2017-12-13 10:48     ` [Qemu-devel] [Qemu-block] " Stefan Hajnoczi
  0 siblings, 1 reply; 5+ messages in thread
From: John Snow @ 2017-12-12 18:22 UTC (permalink / raw)
  To: Jeff Cody; +Cc: kwolf, qemu-devel, qemu-block, mreitz



On 12/11/2017 07:08 PM, Jeff Cody wrote:
> On Mon, Dec 11, 2017 at 06:46:09PM -0500, John Snow wrote:
>> If users set an unreasonably low speed (like one byte per second), the
>> calculated delay may exceed many hours. While we like to punish users
>> for asking for stupid things, we do also like to allow users to correct
>> their wicked ways.
>>
>> When a user provides a new speed, kick the job to allow it to recalculate
>> its delay.
>>
>> Signed-off-by: John Snow <jsnow@redhat.com>
>> ---
>>  blockjob.c | 5 +++++
>>  1 file changed, 5 insertions(+)
>>
>> diff --git a/blockjob.c b/blockjob.c
>> index 715c2c2680..43f01ad190 100644
>> --- a/blockjob.c
>> +++ b/blockjob.c
>> @@ -483,6 +483,7 @@ static void block_job_completed_txn_success(BlockJob *job)
>>  void block_job_set_speed(BlockJob *job, int64_t speed, Error **errp)
>>  {
>>      Error *local_err = NULL;
>> +    int64_t old_speed = job->speed;
>>  
>>      if (!job->driver->set_speed) {
>>          error_setg(errp, QERR_UNSUPPORTED);
>> @@ -495,6 +496,10 @@ void block_job_set_speed(BlockJob *job, int64_t speed, Error **errp)
>>      }
>>  
>>      job->speed = speed;
>> +    /* Kick the job to recompute its delay */
>> +    if ((speed > old_speed) && timer_pending(&job->sleep_timer)) {
> 
> job->sleep_timer is protected by block_job_mutex (via
> block_job_lock/unlock); is it safe for us to check it here outside the
> mutex?
> 

My hunch is that in this specific case that it is; but only because of
assumptions about holding the aio_context and the QEMU global mutex here.

> But in any case, I think we could get rid of the timer_pending check, and
> just always kick the job if we have a speed increase.  block_job_enter()
> should do the right thing (mutex protected check on job->busy and
> job->sleep_timer).
> 

I could lock it for inarguable correctness; I just didn't want to kick a
job that didn't actually require any kicking to limit any potential
problems from that interaction.

(I'm fond of the extra conditional because I feel like it makes the
intent of the kick explicit.)

I can remove it.

>> +        block_job_enter(job);
>> +    }
>>  }
>>  
>>  void block_job_complete(BlockJob *job, Error **errp)
>> -- 
>> 2.14.3
>>
> 

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Qemu-devel] [Qemu-block] [PATCH] blockjob: kick jobs on set-speed
  2017-12-12 18:22   ` John Snow
@ 2017-12-13 10:48     ` Stefan Hajnoczi
  2017-12-13 17:37       ` John Snow
  0 siblings, 1 reply; 5+ messages in thread
From: Stefan Hajnoczi @ 2017-12-13 10:48 UTC (permalink / raw)
  To: John Snow; +Cc: Jeff Cody, kwolf, qemu-devel, qemu-block, mreitz

[-- Attachment #1: Type: text/plain, Size: 2417 bytes --]

On Tue, Dec 12, 2017 at 01:22:28PM -0500, John Snow wrote:
> 
> 
> On 12/11/2017 07:08 PM, Jeff Cody wrote:
> > On Mon, Dec 11, 2017 at 06:46:09PM -0500, John Snow wrote:
> >> If users set an unreasonably low speed (like one byte per second), the
> >> calculated delay may exceed many hours. While we like to punish users
> >> for asking for stupid things, we do also like to allow users to correct
> >> their wicked ways.
> >>
> >> When a user provides a new speed, kick the job to allow it to recalculate
> >> its delay.
> >>
> >> Signed-off-by: John Snow <jsnow@redhat.com>
> >> ---
> >>  blockjob.c | 5 +++++
> >>  1 file changed, 5 insertions(+)
> >>
> >> diff --git a/blockjob.c b/blockjob.c
> >> index 715c2c2680..43f01ad190 100644
> >> --- a/blockjob.c
> >> +++ b/blockjob.c
> >> @@ -483,6 +483,7 @@ static void block_job_completed_txn_success(BlockJob *job)
> >>  void block_job_set_speed(BlockJob *job, int64_t speed, Error **errp)
> >>  {
> >>      Error *local_err = NULL;
> >> +    int64_t old_speed = job->speed;
> >>  
> >>      if (!job->driver->set_speed) {
> >>          error_setg(errp, QERR_UNSUPPORTED);
> >> @@ -495,6 +496,10 @@ void block_job_set_speed(BlockJob *job, int64_t speed, Error **errp)
> >>      }
> >>  
> >>      job->speed = speed;
> >> +    /* Kick the job to recompute its delay */
> >> +    if ((speed > old_speed) && timer_pending(&job->sleep_timer)) {
> > 
> > job->sleep_timer is protected by block_job_mutex (via
> > block_job_lock/unlock); is it safe for us to check it here outside the
> > mutex?
> > 
> 
> My hunch is that in this specific case that it is; but only because of
> assumptions about holding the aio_context and the QEMU global mutex here.
> 
> > But in any case, I think we could get rid of the timer_pending check, and
> > just always kick the job if we have a speed increase.  block_job_enter()
> > should do the right thing (mutex protected check on job->busy and
> > job->sleep_timer).
> > 
> 
> I could lock it for inarguable correctness; I just didn't want to kick a
> job that didn't actually require any kicking to limit any potential
> problems from that interaction.
> 
> (I'm fond of the extra conditional because I feel like it makes the
> intent of the kick explicit.)
> 
> I can remove it.

Removing the conditional would introduce a bug.  block_job_enter() will
unpause the job.

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 455 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Qemu-devel] [Qemu-block] [PATCH] blockjob: kick jobs on set-speed
  2017-12-13 10:48     ` [Qemu-devel] [Qemu-block] " Stefan Hajnoczi
@ 2017-12-13 17:37       ` John Snow
  0 siblings, 0 replies; 5+ messages in thread
From: John Snow @ 2017-12-13 17:37 UTC (permalink / raw)
  To: Stefan Hajnoczi; +Cc: kwolf, Jeff Cody, qemu-devel, qemu-block, mreitz



On 12/13/2017 05:48 AM, Stefan Hajnoczi wrote:
> On Tue, Dec 12, 2017 at 01:22:28PM -0500, John Snow wrote:
>>
>>
>> On 12/11/2017 07:08 PM, Jeff Cody wrote:
>>> On Mon, Dec 11, 2017 at 06:46:09PM -0500, John Snow wrote:
>>>> If users set an unreasonably low speed (like one byte per second), the
>>>> calculated delay may exceed many hours. While we like to punish users
>>>> for asking for stupid things, we do also like to allow users to correct
>>>> their wicked ways.
>>>>
>>>> When a user provides a new speed, kick the job to allow it to recalculate
>>>> its delay.
>>>>
>>>> Signed-off-by: John Snow <jsnow@redhat.com>
>>>> ---
>>>>  blockjob.c | 5 +++++
>>>>  1 file changed, 5 insertions(+)
>>>>
>>>> diff --git a/blockjob.c b/blockjob.c
>>>> index 715c2c2680..43f01ad190 100644
>>>> --- a/blockjob.c
>>>> +++ b/blockjob.c
>>>> @@ -483,6 +483,7 @@ static void block_job_completed_txn_success(BlockJob *job)
>>>>  void block_job_set_speed(BlockJob *job, int64_t speed, Error **errp)
>>>>  {
>>>>      Error *local_err = NULL;
>>>> +    int64_t old_speed = job->speed;
>>>>  
>>>>      if (!job->driver->set_speed) {
>>>>          error_setg(errp, QERR_UNSUPPORTED);
>>>> @@ -495,6 +496,10 @@ void block_job_set_speed(BlockJob *job, int64_t speed, Error **errp)
>>>>      }
>>>>  
>>>>      job->speed = speed;
>>>> +    /* Kick the job to recompute its delay */
>>>> +    if ((speed > old_speed) && timer_pending(&job->sleep_timer)) {
>>>
>>> job->sleep_timer is protected by block_job_mutex (via
>>> block_job_lock/unlock); is it safe for us to check it here outside the
>>> mutex?
>>>
>>
>> My hunch is that in this specific case that it is; but only because of
>> assumptions about holding the aio_context and the QEMU global mutex here.
>>
>>> But in any case, I think we could get rid of the timer_pending check, and
>>> just always kick the job if we have a speed increase.  block_job_enter()
>>> should do the right thing (mutex protected check on job->busy and
>>> job->sleep_timer).
>>>
>>
>> I could lock it for inarguable correctness; I just didn't want to kick a
>> job that didn't actually require any kicking to limit any potential
>> problems from that interaction.
>>
>> (I'm fond of the extra conditional because I feel like it makes the
>> intent of the kick explicit.)
>>
>> I can remove it.
> 
> Removing the conditional would introduce a bug.  block_job_enter() will
> unpause the job.
> 

It will almost certainly pause again immediately, but maybe not before
work is performed.

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2017-12-13 17:37 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-12-11 23:46 [Qemu-devel] [PATCH] blockjob: kick jobs on set-speed John Snow
2017-12-12  0:08 ` Jeff Cody
2017-12-12 18:22   ` John Snow
2017-12-13 10:48     ` [Qemu-devel] [Qemu-block] " Stefan Hajnoczi
2017-12-13 17:37       ` John Snow

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.