728x90

5. Asynchronous I/O


Write
의 동기화 특질

동기화(디스크까지 보장)

비동기화(버퍼까지 보장)

동기식

(쓰기연산 완료 후 결과 return)

쓰기 연산은 자료를 디스크에 강제로 쓰기 전까지 결과를 반환하지 않는다. (파일을 열 때 O_SYNC를 명세한 경우)

TM기 연산은 자료가 커널 버퍼에 저장될 때까지 결과를 반환하지 않는다.(일반적인 동작)

비동기식

(요청 큐에 들어가자마자 결과 return)

쓰기 연산은 요청이 큐에 들어가자마자 결과를 바로 반호나한다. 일단 쓰기 연산이 최종적으로 수행되면, 자료는 디스크네 확실히 저장됨

쓰기 연산은 요청이 큐에 들어가자마자 결과를 바로 반환, 일단 쓰기 연산이 최종적으로 수행되면, 자료는 최소한 커널 버퍼에 확실히 저장됨

Read의 동기화 특질

동기화

동기식

읽기 연산은 최신 자료가 지정된 버퍼에 저장될 때까지 결과를 반환하지 않는다(일반적인 동작방식)

비동기식

읽기 연산은 요청이 큐에 들어가면 바로 결과를 반환(읽기 연산이 최종적으로 수행될 때 최신 자료를 반환)


aio interface (linux
에서는 O_DIRECT flag로 연 파일에서만 aio를 지원)

#include <aio.h>

/* asynchronous I/O control block */

struct aiocb {

int aio_filedes; /* file descriptor *

int aio_lio_opcode; /* operation to perform */

int aio_reqprio; /* request priority offset *

volatile void *aio_buf; /* pointer to buffer */

size_t aio_nbytes; /* length of operation */

struct sigevent aio_sigevent; /* signal number and value */

/* internal, private members follow... */

};

int aio_read (struct aiocb *aiocbp);

int aio_write (struct aiocb *aiocbp);

int aio_error (const struct aiocb *aiocbp);

int aio_return (struct aiocb *aiocbp);

int aio_cancel (int fd, struct aiocb *aiocbp);

int aio_fsync (int op, struct aiocb *aiocbp);

int aio_suspend (const struct aiocb * const cblist[],

int n,

const struct timespec *timeout);


thread
기반 (aio interface와 비슷하지만 thread관리에 더 큰 overhead가 발생)
 

1. worker thread pool 생성

2. work queue I/O operation을 넣는 인터페이스 집합을 구현

3. 각 인터페이스가 유일한 I/O id return하도록 구현(operation 구분), 개별 작업자 스레드(worker thread) queue 앞부분에서 request submit(제출) 후 완료될 때까지 대기

4. 완료되면 연산결과(반환값, 오류코드, 읽은 자료 등)를 결과 큐에 추가

5. 결과 큐에서 상태정보를 조회하는 인터페이스 집합을 구현.

 

728x90

+ Recent posts