qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH v2 5/9] block/write-threshold: don't use aio context lock


From: Max Reitz
Subject: Re: [PATCH v2 5/9] block/write-threshold: don't use aio context lock
Date: Wed, 5 May 2021 18:09:12 +0200
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.8.1

On 04.05.21 10:25, Vladimir Sementsov-Ogievskiy wrote:
Instead of relying on aio context lock, let's make use of atomic
operations.

The tricky place is bdrv_write_threshold_check_write(): we want
atomically unset bs->write_threshold_offset iff
   offset + bytes > bs->write_threshold_offset
We don't have such atomic operation, so let's go in a loop:

This could also be solved by untangling the overloaded meaning of write_threshold_offset – if we had an additional boolean write_threshold_check, then this wouldn’t be a problem, and we could do this:

if (end > bdrv_write_threshold_get(bs)) {
    if (qatomic_xchg(&bs->write_threshold_check, false) == true) {
        qapi_event_send(...);
    }
}

However, the problem then becomes thinking about the memory access semantics, because if some other thread sets the threshold offset and enables the threshold check, we need to ensure that we see the updated offset here...

So I suppose your loop is simpler then.

1. fetch wtr atomically
2. if condition satisfied, try cmpxchg (if not satisfied, we are done,
    don't send event)
3. if cmpxchg succeeded, we are done (send event), else go to [1]

Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
---
  block/write-threshold.c | 32 +++++++++++++++++---------------
  1 file changed, 17 insertions(+), 15 deletions(-)

Reviewed-by: Max Reitz <mreitz@redhat.com>




reply via email to

[Prev in Thread] Current Thread [Next in Thread]