2018年4月12日 星期四

C use O_DIRECT vs O_SYNC => blktrace

1. O_DIRECT
fd = open("/dev/escache0", O_RDWR | O_DIRECT);

blktrace -d /dev/escache0 -o - | blkparse -i -
252,0    4        1     0.000000000 30655  Q  WS 0 + 1 [openescache]

2. O_SYNC
252,0    6        1   129.714324326 30666  Q  WS 0 + 8 [openescache]
252,0    6        2   129.725375608 30666  Q FWS [openescache]
F means 'flush'

openescache.c
#define _GNU_SOURCE
#include <string.h>
#include <stdlib.h>
#include <fcntl.h>
#include <stdio.h>

#define BLOCKSIZE 512
int main() {
    int fd, i;
    void *buffer;
    char image[BLOCKSIZE];

    for(i=0; i<BLOCKSIZE; i++)
        image[i] = 0xa2;

    posix_memalign(&buffer, BLOCKSIZE, BLOCKSIZE);
    memcpy(buffer, image, sizeof(image));

    fd = open("/dev/escache0", O_RDWR | O_SYNC);
    if (fd == -1) {
        printf("open failed");
        return -1;
    }
    write(fd, buffer, BLOCKSIZE);
    close(fd);
    free(buffer);
    return 0;
}

沒有留言:

張貼留言

kgdb

--0313-- ken 不好意思 请教一下 之前你有交过我 在没有coredump的情况下 可以用gdb直接载入ko.debug, 然后dis -l register_bcache, 我记得使用方式是不是这样, 不过我现在dis -l出现错误^^" [root@...