pipe, splice, sendfile, vmsplice, tee
ãã¡ã¤ã«ããèªãã ãã¼ã¿ããCPUã§å å·¥ããã«ã½ã±ããã«éãããã¨ããã
read(in_fd, buffer, 4096); write(out_fd, buffer, 4096);
ã¨ãããããããªãããããã¯å®éã«ã¯é常ã«ç¡é§ã§ãread æã«ããã¡ã¤ã«ã·ã¹ãã ãã£ãã·ã¥ããã¦ã¼ã¶ç©ºéã¸ã³ãã¼ãã¦ã¼ã¶ç©ºéããskbã¸ã³ãã¼ãã¦ããã
ã¾ã1Gb Etherãªãå ¨ç¶å¤§ãããªã¼ãã¼ãããã«ã¯ãªããªããã©(ããããªããã ããªãâ¦(ãªãã§ï¼))ãNVMe Flash ããã100Gb ã¤ã¼ãµã«éãã¨ãããã¨ãmemcpy ãä¸åå¢ããã ãã§ç¡è¦ã§ããªããªã¼ãã¼ãããã«ãªãã®ã§ãç¡é§ãããã
ãã㧠sendfile ã¨ããã·ã¹ãã ã³ã¼ã«ãããã
ä¸ã®read,writeã¯
sendfile(out_fd, in_fd, NULL, 4096);
ã¨ãæ¸ãã¨ãã«ã¼ãã«å
ã®ãã¼ã¸ããªãããã¾ããã£ã¦ãããã
ä¾ãã°ãin_fd ãregular ãã¡ã¤ã«ã§ãout_fd ãã½ã±ããã ã£ãå ´åããã¡ã¤ã«ã·ã¹ãã ãã£ãã·ã¥ã«ä½¿ããã¦ããã¼ã¸ã¡ã¢ãªãããã®ã¾ã¾ã¤ã¼ãµããããã©ã¤ãã«æ¸¡ãããã
ãã®sendfileã®å¦çãããå°ãåå²ããspliceã¨ããã·ã¹ãã ã³ã¼ã«ãããã
ãã£ãã·ã¥ã·ã¹ãã ãèªåã§æã£ã¦ãã¦ããã¡ã¤ã«ã·ã¹ãã ãã£ãã·ã¥ãå¿ è¦ç¡ãã¢ããªã±ã¼ã·ã§ã³ã®å ´åããã£ãã·ã¥ãèªåã§ç®¡çãããå ´åããããããããªããããããå ´åãLinux ã§ã¯ãPOSIX ã® pipe ãã«ã¼ãã«å ã®ãã¼ã¸ã¸ã®ãã¤ã³ã¿ã¨ãã¦ä½¿ããã¨ãã§ããã
splice ã§ãåºåå ãpipeã«ããã¨ããã®pipeããå ¥åfdã®ã«ã¼ãã«å ãã¼ã¸ãã£ãã·ã¥ã®ãã¼ã¸ãä¿æããããã«ãªãã
splice ã§ãå ¥åå ãpipeã«ããã¨ãpipeãä¿æãã¦ãããã¤ã³ã¿ããã©ã¤ãã¨ãã«ç´æ¥éããã
vmsplice ããã¨ãã¦ã¼ã¶ç©ºéã«ç½®ãã¦ããã¡ã¢ãªããã«ã¼ãã«å ããpipeã§åç §ã§ããããã«ãªãã
tee ããã¨pipeãæãã¦ããã¤ã³ã¿ãå¥ã®pipeã«ã³ãã¼ã§ããã
ä¸åã®pipeãä¿æã§ãããããã¡ãµã¤ãºã¯æ¨æºã ã¨64KBã ãã©ãfcntl(pipe, F_SETPIPE_SZ, 1024*1024) ã¨ãããã¨å¤ãããã(CAP_SYS_RESOURCE 権éãç¡ãã¨ãµã¤ãºå¶éãä»ã)
sendfileã¯å®éã«ã¯ã
splice(in_fd, NULL, current->pipe, NULL, 4096, 0); // current->pipe ã in_fd ã®ãã¼ã¸ãã£ãã·ã¥ãä¿æãã splice(current->pipe, NULL, out_fd, NULL, 4096, 0); // current->pipe ãä¿æãã¦ãããã¼ã¸ã out_fd ã¸
ã¿ãããªå¦çã«ãªã£ã¦ããã
(ãã¨ã§è¨æ¸¬ããã)