qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH] Fix I/O throttling pathologic oscillating behavior
@ 2013-03-20  9:12 Benoît Canet
  2013-03-20  9:12 ` [Qemu-devel] [PATCH] block: fix bdrv_exceed_iops_limits wait computation Benoît Canet
  0 siblings, 1 reply; 14+ messages in thread
From: Benoît Canet @ 2013-03-20  9:12 UTC (permalink / raw)
  To: qemu-devel; +Cc: kwolf, wuzhy, Benoît Canet, stefanha

Limiting a virtio device backed by a QED file at 150 iops with
"-drive  file=test.qed,if=virtio,cache=none,iops=150" and running in the guest
the load.c program lead to an iops oscillating behavior which amplify itself
as the time goes on.

At first an extract of "iostats -x -d 2" would look like this:
Device:         rrqm/s   wrqm/s     r/s     w/s    rkB/s    wkB/s avgrq-sz
vdb               0,00     4,11    0,10  149,09     0,39   614,02     8,24
vdb               0,00     0,00    0,00  163,27     0,00   653,06     8,00
vdb               0,00     0,00    0,00  164,65     0,00   658,59     8,00
vdb               0,00     0,00    0,00   84,85     0,00   339,39     8,00
vdb               0,00     0,00    0,00  170,71     0,00   682,83     8,00
vdb               0,00     0,00    0,00  185,71     0,00   742,86     8,00
vdb               0,00     0,00    0,00  174,75     0,00   698,99     8,00
vdb               0,00     0,00    0,00   87,88     0,00   351,52     8,00

w/s seems ok

After a few moment it would look like this:

Device:         rrqm/s   wrqm/s     r/s     w/s    rkB/s    wkB/s avgrq-sz
vdb               0,00     0,00    0,00  249,00     0,00   996,00     8,00
vdb               0,00     0,00    0,00    0,00     0,00     0,00     0,00
vdb               0,00     0,00    0,00  260,00     0,00  1040,00     8,00
vdb               0,00     0,00    0,00    0,00     0,00     0,00     0,00
vdb               0,00     0,00    0,00  250,00     0,00  1000,00     8,00
vdb               0,00     0,00    0,00  249,49     0,00   997,98     8,00
vdb               0,00     0,00    0,00    0,00     0,00     0,00     0,00

Here w/s start to oscillate on a few second cycle.

Waiting around ten hours leads to this.
Device:         rrqm/s   wrqm/s     r/s     w/s    rkB/s    wkB/s avgrq-sz
db               0,00     0,00    0,00    0,00     0,00     0,00     0,00
vdb               0,00     0,00    0,00  267,68     0,00  1070,71     8,00
vdb               0,00     0,00    0,00 1184,38     0,00  4737,50     8,00
vdb               0,00     0,00    0,00    0,00     0,00     0,00     0,00
vdb               0,00     0,00    0,00    0,00     0,00     0,00     0,00
vdb               0,00     0,00    0,00    0,00     0,00     0,00     0,00
vdb               0,00     0,00    0,00    0,00     0,00     0,00     0,00
vdb               0,00     0,00    0,00    0,00     0,00     0,00     0,00
vdb               0,00     0,00    0,00    0,00     0,00     0,00     0,00
vdb               0,00     0,00    0,00    0,00     0,00     0,00     0,00
vdb               0,00     0,00    0,00    0,00     0,00     0,00     0,00
vdb               0,00     0,00    0,00 1415,15     0,00  5660,61     8,00
vdb               0,00     0,00    0,00    0,00     0,00     0,00     0,00
vdb               0,00     0,00    0,00    0,00     0,00     0,00     0,00
vdb               0,00     0,00    0,00    0,00     0,00     0,00     0,00
vdb               0,00     0,00    0,00    0,00     0,00     0,00     0,00
vdb               0,00     0,00    0,00    0,00     0,00     0,00     0,00
vdb               0,00     0,00    0,00    0,00     0,00     0,00     0,00
vdb               0,00     0,00    0,00    0,00     0,00     0,00     0,00
vdb               0,00     0,00    0,00    0,00     0,00     0,00     0,00
vdb               0,00     0,00    0,00  939,18     0,00  3756,70     8,00
vdb               0,00     0,00    0,00  523,71     0,00  2094,85     8,00

It seems to get worse with the amplitude and duration of the cycle growing.

As the cause of the amplification of the oscillation seems to be the growing of
the cycle duration I wrote the "block: fix bdrv_exceed_iops_limits wait
computation" patch which solve this problem.

load.c - beware of hardcoded "/dev/vdb"
-------------------------------------------------------------------------------
#define _GNU_SOURCE
#include <pthread.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdlib.h>

#define BLOCKSIZE 4096
#define THREAD_COUNT 50
#define IOS 100000

pthread_mutex_t mutex;
pthread_cond_t  condition;

void *io_thread_body(void *opaque)
{
    int j, fd;
    int i = (int) *(int *) opaque;
    void *buffer;

    posix_memalign(&buffer, BLOCKSIZE, BLOCKSIZE);

    fd = open("/dev/vdb", O_RDWR|O_DIRECT);
    if (fd < 0) {
        printf("Fail to open /dev/vdb in O_DIRECT\n");
        goto exit;
    }


    printf("Waiting for signal\n");
    pthread_mutex_lock(&mutex);
    pthread_cond_wait(&condition, &mutex);
    pthread_mutex_unlock(&mutex);

    printf("Starting ios\n");

    while (1) {
        off_t offset = (i * IOS * BLOCKSIZE) + j * BLOCKSIZE;
        pwrite(fd, buffer, BLOCKSIZE, offset);
        j++;
    }

exit:
    free(opaque);
    pthread_exit(NULL);
}

int main(int argc, char **argv)
{
    int i;
    pthread_t threads[THREAD_COUNT];
    pthread_attr_t attr;

    pthread_mutex_init(&mutex, NULL);
    pthread_cond_init(&condition, NULL);

    pthread_attr_init(&attr);
    pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);

    printf("Creating threads\n");
    for (i = 0; i < THREAD_COUNT; i++) {
        int *j = malloc(sizeof(j));
        *j = i;
        pthread_create(&threads[i], &attr, io_thread_body, j);
    }

    sleep(1);

    printf("Waking up threads\n");
    pthread_cond_broadcast(&condition);

    printf("Waiting threads to finish\n");
    for (i = 0; i < THREAD_COUNT; i++) {
       pthread_join(threads[i], NULL);
    }

    pthread_attr_destroy(&attr);
    pthread_mutex_destroy(&mutex);
    pthread_cond_destroy(&condition);

    return 0;
}
-------------------------------------------------------------------------------

Benoît Canet (1):
  block: fix bdrv_exceed_iops_limits wait computation

 block.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

--
1.7.10.4

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

end of thread, other threads:[~2013-03-21 15:15 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-03-20  9:12 [Qemu-devel] [PATCH] Fix I/O throttling pathologic oscillating behavior Benoît Canet
2013-03-20  9:12 ` [Qemu-devel] [PATCH] block: fix bdrv_exceed_iops_limits wait computation Benoît Canet
2013-03-20 10:55   ` Zhi Yong Wu
2013-03-20 13:29   ` Stefan Hajnoczi
2013-03-20 14:28     ` Stefan Hajnoczi
2013-03-20 14:56       ` Benoît Canet
2013-03-20 15:12         ` Stefan Hajnoczi
2013-03-21  1:18           ` Zhi Yong Wu
2013-03-21  9:17             ` Stefan Hajnoczi
2013-03-21 13:04               ` Zhi Yong Wu
2013-03-21 15:14                 ` Stefan Hajnoczi
2013-03-20 15:27       ` Benoît Canet
2013-03-21 10:34         ` Stefan Hajnoczi
2013-03-21 14:28           ` Benoît Canet

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).