* [Qemu-devel] [PATCH 1/1] migration: fix ram decompression race deadlock
@ 2016-05-13 7:27 Denis V. Lunev
2016-05-19 12:03 ` Denis V. Lunev
2016-05-23 7:19 ` Amit Shah
0 siblings, 2 replies; 6+ messages in thread
From: Denis V. Lunev @ 2016-05-13 7:27 UTC (permalink / raw)
To: qemu-devel; +Cc: den, Maxim Nestratov, Juan Quintela, Amit Shah
From: Maxim Nestratov <mnestratov@virtuozzo.com>
There is a race in between do_data_decompress and start_decompression.
do_data_decompress()
while (!quit_decomp_thread) {
qemu_mutex_lock(¶m->mutex);
while (!param->start && !quit_decomp_thread) {
qemu_cond_wait(¶m->cond, ¶m->mutex);
...
param->start = false;
}
qemu_mutex_unlock(¶m->mutex);
[ preempted here, start_decompression() is executed ]
}
start_decompression()
{
qemu_mutex_lock(¶m->mutex);
param->start = true;
qemu_cond_signal(¶m->cond);
qemu_mutex_unlock(¶m->mutex);
}
In this case do_data_decompress will never enter inner loop again and
will eat 100% CPU. The patch fixes this problem by correcting while loop
where we wait for condition only and other actions are moved out of it.
Signed-off-by: Maxim Nestratov <mnestratov@virtuozzo.com>
Signed-off-by: Denis V. Lunev <den@openvz.org>
CC: Juan Quintela <quintela@redhat.com>
CC: Amit Shah <amit.shah@redhat.com>
---
migration/ram.c | 22 +++++++++++-----------
1 file changed, 11 insertions(+), 11 deletions(-)
diff --git a/migration/ram.c b/migration/ram.c
index 3f05738..579bfc0 100644
--- a/migration/ram.c
+++ b/migration/ram.c
@@ -2193,18 +2193,18 @@ static void *do_data_decompress(void *opaque)
qemu_mutex_lock(¶m->mutex);
while (!param->start && !quit_decomp_thread) {
qemu_cond_wait(¶m->cond, ¶m->mutex);
- pagesize = TARGET_PAGE_SIZE;
- if (!quit_decomp_thread) {
- /* uncompress() will return failed in some case, especially
- * when the page is dirted when doing the compression, it's
- * not a problem because the dirty page will be retransferred
- * and uncompress() won't break the data in other pages.
- */
- uncompress((Bytef *)param->des, &pagesize,
- (const Bytef *)param->compbuf, param->len);
- }
- param->start = false;
}
+ pagesize = TARGET_PAGE_SIZE;
+ if (!quit_decomp_thread) {
+ /* uncompress() will return failed in some case, especially
+ * when the page is dirted when doing the compression, it's
+ * not a problem because the dirty page will be retransferred
+ * and uncompress() won't break the data in other pages.
+ */
+ uncompress((Bytef *)param->des, &pagesize,
+ (const Bytef *)param->compbuf, param->len);
+ }
+ param->start = false;
qemu_mutex_unlock(¶m->mutex);
}
--
2.1.4
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [Qemu-devel] [PATCH 1/1] migration: fix ram decompression race deadlock
2016-05-13 7:27 [Qemu-devel] [PATCH 1/1] migration: fix ram decompression race deadlock Denis V. Lunev
@ 2016-05-19 12:03 ` Denis V. Lunev
2016-05-23 7:19 ` Amit Shah
1 sibling, 0 replies; 6+ messages in thread
From: Denis V. Lunev @ 2016-05-19 12:03 UTC (permalink / raw)
To: qemu-devel; +Cc: Maxim Nestratov, Juan Quintela, Amit Shah
On 05/13/2016 10:27 AM, Denis V. Lunev wrote:
> From: Maxim Nestratov <mnestratov@virtuozzo.com>
>
> There is a race in between do_data_decompress and start_decompression.
>
> do_data_decompress()
> while (!quit_decomp_thread) {
> qemu_mutex_lock(¶m->mutex);
> while (!param->start && !quit_decomp_thread) {
> qemu_cond_wait(¶m->cond, ¶m->mutex);
> ...
> param->start = false;
> }
> qemu_mutex_unlock(¶m->mutex);
> [ preempted here, start_decompression() is executed ]
> }
>
> start_decompression()
> {
> qemu_mutex_lock(¶m->mutex);
> param->start = true;
> qemu_cond_signal(¶m->cond);
> qemu_mutex_unlock(¶m->mutex);
> }
>
> In this case do_data_decompress will never enter inner loop again and
> will eat 100% CPU. The patch fixes this problem by correcting while loop
> where we wait for condition only and other actions are moved out of it.
>
> Signed-off-by: Maxim Nestratov <mnestratov@virtuozzo.com>
> Signed-off-by: Denis V. Lunev <den@openvz.org>
> CC: Juan Quintela <quintela@redhat.com>
> CC: Amit Shah <amit.shah@redhat.com>
> ---
> migration/ram.c | 22 +++++++++++-----------
> 1 file changed, 11 insertions(+), 11 deletions(-)
>
> diff --git a/migration/ram.c b/migration/ram.c
> index 3f05738..579bfc0 100644
> --- a/migration/ram.c
> +++ b/migration/ram.c
> @@ -2193,18 +2193,18 @@ static void *do_data_decompress(void *opaque)
> qemu_mutex_lock(¶m->mutex);
> while (!param->start && !quit_decomp_thread) {
> qemu_cond_wait(¶m->cond, ¶m->mutex);
> - pagesize = TARGET_PAGE_SIZE;
> - if (!quit_decomp_thread) {
> - /* uncompress() will return failed in some case, especially
> - * when the page is dirted when doing the compression, it's
> - * not a problem because the dirty page will be retransferred
> - * and uncompress() won't break the data in other pages.
> - */
> - uncompress((Bytef *)param->des, &pagesize,
> - (const Bytef *)param->compbuf, param->len);
> - }
> - param->start = false;
> }
> + pagesize = TARGET_PAGE_SIZE;
> + if (!quit_decomp_thread) {
> + /* uncompress() will return failed in some case, especially
> + * when the page is dirted when doing the compression, it's
> + * not a problem because the dirty page will be retransferred
> + * and uncompress() won't break the data in other pages.
> + */
> + uncompress((Bytef *)param->des, &pagesize,
> + (const Bytef *)param->compbuf, param->len);
> + }
> + param->start = false;
> qemu_mutex_unlock(¶m->mutex);
> }
>
ping
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [Qemu-devel] [PATCH 1/1] migration: fix ram decompression race deadlock
2016-05-13 7:27 [Qemu-devel] [PATCH 1/1] migration: fix ram decompression race deadlock Denis V. Lunev
2016-05-19 12:03 ` Denis V. Lunev
@ 2016-05-23 7:19 ` Amit Shah
2016-05-24 2:07 ` Li, Liang Z
1 sibling, 1 reply; 6+ messages in thread
From: Amit Shah @ 2016-05-23 7:19 UTC (permalink / raw)
To: Denis V. Lunev
Cc: qemu-devel, Maxim Nestratov, Juan Quintela, Liang Li,
Dr. David Alan Gilbert
Adding Liang Li to CC for his comments as the author of the feature.
On (Fri) 13 May 2016 [10:27:01], Denis V. Lunev wrote:
> From: Maxim Nestratov <mnestratov@virtuozzo.com>
>
> There is a race in between do_data_decompress and start_decompression.
>
> do_data_decompress()
> while (!quit_decomp_thread) {
> qemu_mutex_lock(¶m->mutex);
> while (!param->start && !quit_decomp_thread) {
> qemu_cond_wait(¶m->cond, ¶m->mutex);
> ...
> param->start = false;
> }
> qemu_mutex_unlock(¶m->mutex);
> [ preempted here, start_decompression() is executed ]
> }
>
> start_decompression()
> {
> qemu_mutex_lock(¶m->mutex);
> param->start = true;
> qemu_cond_signal(¶m->cond);
> qemu_mutex_unlock(¶m->mutex);
> }
>
> In this case do_data_decompress will never enter inner loop again and
> will eat 100% CPU. The patch fixes this problem by correcting while loop
> where we wait for condition only and other actions are moved out of it.
>
> Signed-off-by: Maxim Nestratov <mnestratov@virtuozzo.com>
> Signed-off-by: Denis V. Lunev <den@openvz.org>
> CC: Juan Quintela <quintela@redhat.com>
> CC: Amit Shah <amit.shah@redhat.com>
> ---
> migration/ram.c | 22 +++++++++++-----------
> 1 file changed, 11 insertions(+), 11 deletions(-)
>
> diff --git a/migration/ram.c b/migration/ram.c
> index 3f05738..579bfc0 100644
> --- a/migration/ram.c
> +++ b/migration/ram.c
> @@ -2193,18 +2193,18 @@ static void *do_data_decompress(void *opaque)
> qemu_mutex_lock(¶m->mutex);
> while (!param->start && !quit_decomp_thread) {
> qemu_cond_wait(¶m->cond, ¶m->mutex);
> - pagesize = TARGET_PAGE_SIZE;
> - if (!quit_decomp_thread) {
> - /* uncompress() will return failed in some case, especially
> - * when the page is dirted when doing the compression, it's
> - * not a problem because the dirty page will be retransferred
> - * and uncompress() won't break the data in other pages.
> - */
> - uncompress((Bytef *)param->des, &pagesize,
> - (const Bytef *)param->compbuf, param->len);
> - }
> - param->start = false;
> }
> + pagesize = TARGET_PAGE_SIZE;
> + if (!quit_decomp_thread) {
> + /* uncompress() will return failed in some case, especially
> + * when the page is dirted when doing the compression, it's
> + * not a problem because the dirty page will be retransferred
> + * and uncompress() won't break the data in other pages.
> + */
> + uncompress((Bytef *)param->des, &pagesize,
> + (const Bytef *)param->compbuf, param->len);
> + }
> + param->start = false;
> qemu_mutex_unlock(¶m->mutex);
> }
>
> --
> 2.1.4
>
Amit
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [Qemu-devel] [PATCH 1/1] migration: fix ram decompression race deadlock
2016-05-23 7:19 ` Amit Shah
@ 2016-05-24 2:07 ` Li, Liang Z
2016-05-24 5:35 ` Denis V. Lunev
0 siblings, 1 reply; 6+ messages in thread
From: Li, Liang Z @ 2016-05-24 2:07 UTC (permalink / raw)
To: Amit Shah, Denis V. Lunev
Cc: qemu-devel@nongnu.org, Maxim Nestratov, Juan Quintela,
Dr. David Alan Gilbert
> Adding Liang Li to CC for his comments as the author of the feature.
>
> On (Fri) 13 May 2016 [10:27:01], Denis V. Lunev wrote:
> > From: Maxim Nestratov <mnestratov@virtuozzo.com>
> >
> > There is a race in between do_data_decompress and start_decompression.
> >
> > do_data_decompress()
> > while (!quit_decomp_thread) {
> > qemu_mutex_lock(¶m->mutex);
> > while (!param->start && !quit_decomp_thread) {
> > qemu_cond_wait(¶m->cond, ¶m->mutex);
> > ...
> > param->start = false;
> > }
> > qemu_mutex_unlock(¶m->mutex);
> > [ preempted here, start_decompression() is executed ]
> > }
> >
> > start_decompression()
> > {
> > qemu_mutex_lock(¶m->mutex);
> > param->start = true;
> > qemu_cond_signal(¶m->cond);
> > qemu_mutex_unlock(¶m->mutex);
> > }
> >
> > In this case do_data_decompress will never enter inner loop again and
> > will eat 100% CPU. The patch fixes this problem by correcting while
> > loop where we wait for condition only and other actions are moved out of
> it.
> >
> > Signed-off-by: Maxim Nestratov <mnestratov@virtuozzo.com>
> > Signed-off-by: Denis V. Lunev <den@openvz.org>
> > CC: Juan Quintela <quintela@redhat.com>
> > CC: Amit Shah <amit.shah@redhat.com>
> > ---
> > migration/ram.c | 22 +++++++++++-----------
> > 1 file changed, 11 insertions(+), 11 deletions(-)
> >
> > diff --git a/migration/ram.c b/migration/ram.c index 3f05738..579bfc0
> > 100644
> > --- a/migration/ram.c
> > +++ b/migration/ram.c
> > @@ -2193,18 +2193,18 @@ static void *do_data_decompress(void
> *opaque)
> > qemu_mutex_lock(¶m->mutex);
> > while (!param->start && !quit_decomp_thread) {
> > qemu_cond_wait(¶m->cond, ¶m->mutex);
> > - pagesize = TARGET_PAGE_SIZE;
> > - if (!quit_decomp_thread) {
> > - /* uncompress() will return failed in some case, especially
> > - * when the page is dirted when doing the compression, it's
> > - * not a problem because the dirty page will be retransferred
> > - * and uncompress() won't break the data in other pages.
> > - */
> > - uncompress((Bytef *)param->des, &pagesize,
> > - (const Bytef *)param->compbuf, param->len);
> > - }
> > - param->start = false;
> > }
> > + pagesize = TARGET_PAGE_SIZE;
> > + if (!quit_decomp_thread) {
> > + /* uncompress() will return failed in some case, especially
> > + * when the page is dirted when doing the compression, it's
> > + * not a problem because the dirty page will be retransferred
> > + * and uncompress() won't break the data in other pages.
> > + */
> > + uncompress((Bytef *)param->des, &pagesize,
> > + (const Bytef *)param->compbuf, param->len);
> > + }
> > + param->start = false;
> > qemu_mutex_unlock(¶m->mutex);
> > }
Thanks for your patch! And it can help to fix this issue.
Actually, the is not the only issue in the current multi-thread (de)compression code.
So I submitted a path set to fix all of them before your patch. And sorry for my mistake.
Refer to the link:
https://lists.gnu.org/archive/html/qemu-devel/2016-05/msg00631.html
for more information.
Thanks
Liang
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [Qemu-devel] [PATCH 1/1] migration: fix ram decompression race deadlock
2016-05-24 2:07 ` Li, Liang Z
@ 2016-05-24 5:35 ` Denis V. Lunev
2016-06-10 6:43 ` Amit Shah
0 siblings, 1 reply; 6+ messages in thread
From: Denis V. Lunev @ 2016-05-24 5:35 UTC (permalink / raw)
To: Li, Liang Z, Amit Shah
Cc: qemu-devel@nongnu.org, Maxim Nestratov, Juan Quintela,
Dr. David Alan Gilbert
On 05/24/2016 05:07 AM, Li, Liang Z wrote:
>> Adding Liang Li to CC for his comments as the author of the feature.
>>
>> On (Fri) 13 May 2016 [10:27:01], Denis V. Lunev wrote:
>>> From: Maxim Nestratov <mnestratov@virtuozzo.com>
>>>
>>> There is a race in between do_data_decompress and start_decompression.
>>>
>>> do_data_decompress()
>>> while (!quit_decomp_thread) {
>>> qemu_mutex_lock(¶m->mutex);
>>> while (!param->start && !quit_decomp_thread) {
>>> qemu_cond_wait(¶m->cond, ¶m->mutex);
>>> ...
>>> param->start = false;
>>> }
>>> qemu_mutex_unlock(¶m->mutex);
>>> [ preempted here, start_decompression() is executed ]
>>> }
>>>
>>> start_decompression()
>>> {
>>> qemu_mutex_lock(¶m->mutex);
>>> param->start = true;
>>> qemu_cond_signal(¶m->cond);
>>> qemu_mutex_unlock(¶m->mutex);
>>> }
>>>
>>> In this case do_data_decompress will never enter inner loop again and
>>> will eat 100% CPU. The patch fixes this problem by correcting while
>>> loop where we wait for condition only and other actions are moved out of
>> it.
>>> Signed-off-by: Maxim Nestratov <mnestratov@virtuozzo.com>
>>> Signed-off-by: Denis V. Lunev <den@openvz.org>
>>> CC: Juan Quintela <quintela@redhat.com>
>>> CC: Amit Shah <amit.shah@redhat.com>
>>> ---
>>> migration/ram.c | 22 +++++++++++-----------
>>> 1 file changed, 11 insertions(+), 11 deletions(-)
>>>
>>> diff --git a/migration/ram.c b/migration/ram.c index 3f05738..579bfc0
>>> 100644
>>> --- a/migration/ram.c
>>> +++ b/migration/ram.c
>>> @@ -2193,18 +2193,18 @@ static void *do_data_decompress(void
>> *opaque)
>>> qemu_mutex_lock(¶m->mutex);
>>> while (!param->start && !quit_decomp_thread) {
>>> qemu_cond_wait(¶m->cond, ¶m->mutex);
>>> - pagesize = TARGET_PAGE_SIZE;
>>> - if (!quit_decomp_thread) {
>>> - /* uncompress() will return failed in some case, especially
>>> - * when the page is dirted when doing the compression, it's
>>> - * not a problem because the dirty page will be retransferred
>>> - * and uncompress() won't break the data in other pages.
>>> - */
>>> - uncompress((Bytef *)param->des, &pagesize,
>>> - (const Bytef *)param->compbuf, param->len);
>>> - }
>>> - param->start = false;
>>> }
>>> + pagesize = TARGET_PAGE_SIZE;
>>> + if (!quit_decomp_thread) {
>>> + /* uncompress() will return failed in some case, especially
>>> + * when the page is dirted when doing the compression, it's
>>> + * not a problem because the dirty page will be retransferred
>>> + * and uncompress() won't break the data in other pages.
>>> + */
>>> + uncompress((Bytef *)param->des, &pagesize,
>>> + (const Bytef *)param->compbuf, param->len);
>>> + }
>>> + param->start = false;
>>> qemu_mutex_unlock(¶m->mutex);
>>> }
> Thanks for your patch! And it can help to fix this issue.
> Actually, the is not the only issue in the current multi-thread (de)compression code.
> So I submitted a path set to fix all of them before your patch. And sorry for my mistake.
>
> Refer to the link:
> https://lists.gnu.org/archive/html/qemu-devel/2016-05/msg00631.html
> for more information.
>
> Thanks
> Liang
yep. thanks a lot. Your patch would be better ;)
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [Qemu-devel] [PATCH 1/1] migration: fix ram decompression race deadlock
2016-05-24 5:35 ` Denis V. Lunev
@ 2016-06-10 6:43 ` Amit Shah
0 siblings, 0 replies; 6+ messages in thread
From: Amit Shah @ 2016-06-10 6:43 UTC (permalink / raw)
To: Denis V. Lunev
Cc: Li, Liang Z, qemu-devel@nongnu.org, Maxim Nestratov,
Juan Quintela, Dr. David Alan Gilbert
On (Tue) 24 May 2016 [08:35:32], Denis V. Lunev wrote:
> On 05/24/2016 05:07 AM, Li, Liang Z wrote:
> > Thanks for your patch! And it can help to fix this issue.
> > Actually, the is not the only issue in the current multi-thread (de)compression code.
> > So I submitted a path set to fix all of them before your patch. And sorry for my mistake.
> >
> > Refer to the link:
> > https://lists.gnu.org/archive/html/qemu-devel/2016-05/msg00631.html
> > for more information.
> >
> > Thanks
> > Liang
> yep. thanks a lot. Your patch would be better ;)
OK, I'll drop this patch.
Amit
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2016-06-10 6:43 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-05-13 7:27 [Qemu-devel] [PATCH 1/1] migration: fix ram decompression race deadlock Denis V. Lunev
2016-05-19 12:03 ` Denis V. Lunev
2016-05-23 7:19 ` Amit Shah
2016-05-24 2:07 ` Li, Liang Z
2016-05-24 5:35 ` Denis V. Lunev
2016-06-10 6:43 ` Amit Shah
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).