From: Juan Quintela <quintela@redhat.com>
To: Fabiano Rosas <farosas@suse.de>
Cc: qemu-devel@nongnu.org, Peter Xu <peterx@redhat.com>,
Leonardo Bras <leobras@redhat.com>,
Elena Ufimtseva <elena.ufimtseva@oracle.com>
Subject: Re: [RFC PATCH v2 6/6] migration/multifd: Bring back the 'ready' semaphore
Date: Thu, 19 Oct 2023 12:43:26 +0200 [thread overview]
Message-ID: <877cni7v01.fsf@secure.mitica> (raw)
In-Reply-To: <20231012140651.13122-7-farosas@suse.de> (Fabiano Rosas's message of "Thu, 12 Oct 2023 11:06:51 -0300")
Fabiano Rosas <farosas@suse.de> wrote:
> Bring back the 'ready' semaphore, but this time make it per-channel,
> so that we can do true lockstep switching of MultiFDPages without
> taking the channel lock.
>
> Drop the channel lock as it now becomes useless. The rules for
> accessing the MultiFDSendParams are:
>
> - between sem and sem_done/ready if we're the channel
>
> qemu_sem_post(&p->ready);
> qemu_sem_wait(&p->sem);
> <owns p>
> qemu_sem_post(&p->sem_done);
>
> - between ready and sem if we're not the channel
>
> qemu_sem_wait(&p->ready);
> <owns p>
> qemu_sem_post(&p->sem);
>
> Signed-off-by: Fabiano Rosas <farosas@suse.de>
> ---
> One issue I can see with this is that we might now have to wait at
> multifd_send_pages() if a channel takes too long to send it's packet
> and come back to p->ready. We would need to find a way of ignoring a
> slow channel and skipping ahead to the next one in line.
See my 1st patch in the series. That is exactly what the channels_ready
sem does. In your network is faster than your multifd channels can
write, main thread never waits on channels_ready, because it is always
positive.
In case that there are no channels ready, we wait in the sem instead of
being busy waiting.
And searching for the channel that is ready is really fast:
static int multifd_send_pages(QEMUFile *f)
{
[...]
qemu_sem_wait(&multifd_send_state->channels_ready);
// taking a sem that is positive is basically 1 instruction
next_channel %= migrate_multifd_channels();
// we do crude load balancing here.
for (i = next_channel;; i = (i + 1) % migrate_multifd_channels()) {
qemu_mutex_lock(&p->mutex); // 1 lock instruction
if (p->quit) { // 1 check
....
}
if (!p->pending_job) { // 1 check
p->pending_job++;
next_channel = (i + 1) % migrate_multifd_channels();
break;
}
qemu_mutex_unlock(&p->mutex); // 1 unlock (another instruction)
}
....
So checking a channel is:
- taking a mutex that is almost always free.
- 2 checks
- unlock the mutex
So I can't really see the need to optimize this.
Notice that your scheme only has real advantanges if:
- all channels are busy
- the channel that becomes ready is just the previous one to
next_channel or so
And in that case, I think that the solution is to have more channels or
faster networking.
Later, Juan.
prev parent reply other threads:[~2023-10-19 10:44 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-10-12 14:06 [RFC PATCH v2 0/6] migration/multifd: Locking changes Fabiano Rosas
2023-10-12 14:06 ` [RFC PATCH v2 1/6] migration/multifd: Remove channels_ready semaphore Fabiano Rosas
2023-10-19 9:06 ` Juan Quintela
2023-10-19 14:35 ` Peter Xu
2023-10-19 15:00 ` Juan Quintela
2023-10-19 15:46 ` Peter Xu
2023-10-19 18:28 ` Juan Quintela
2023-10-19 18:50 ` Peter Xu
2023-10-20 7:56 ` Juan Quintela
2023-10-19 14:55 ` Fabiano Rosas
2023-10-19 15:18 ` Juan Quintela
2023-10-19 15:56 ` Fabiano Rosas
2023-10-19 18:41 ` Juan Quintela
2023-10-19 19:04 ` Peter Xu
2023-10-20 7:53 ` Juan Quintela
2023-10-20 12:48 ` Fabiano Rosas
2023-10-22 20:17 ` Peter Xu
2023-10-12 14:06 ` [RFC PATCH v2 2/6] migration/multifd: Stop checking p->quit in multifd_send_thread Fabiano Rosas
2023-10-19 9:08 ` Juan Quintela
2023-10-19 14:58 ` Fabiano Rosas
2023-10-19 15:19 ` Peter Xu
2023-10-19 15:19 ` Juan Quintela
2023-10-12 14:06 ` [RFC PATCH v2 3/6] migration/multifd: Decouple control flow from the SYNC packet Fabiano Rosas
2023-10-19 10:28 ` Juan Quintela
2023-10-19 15:31 ` Peter Xu
2023-10-12 14:06 ` [RFC PATCH v2 4/6] migration/multifd: Extract sem_done waiting into a function Fabiano Rosas
2023-10-12 14:06 ` [RFC PATCH v2 5/6] migration/multifd: Stop setting 'quit' outside of channels Fabiano Rosas
2023-10-19 10:35 ` Juan Quintela
2023-10-12 14:06 ` [RFC PATCH v2 6/6] migration/multifd: Bring back the 'ready' semaphore Fabiano Rosas
2023-10-19 10:43 ` Juan Quintela [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=877cni7v01.fsf@secure.mitica \
--to=quintela@redhat.com \
--cc=elena.ufimtseva@oracle.com \
--cc=farosas@suse.de \
--cc=leobras@redhat.com \
--cc=peterx@redhat.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).