DSASȯԤ:VirtualBoxΥե륷ƥ10® ~ find ~
2015ǯ1009

VirtualBoxΥե륷ƥ10® ~ find ~

ϤƤʥ֥åޡϿ

⤦äȤȤޤǿƩƤ۴Ķߤʤޤϲ򤪻ȤǤ礦?

μդǤVirtualBox褯ȤƤޤ

ŵŪʻȤȤƤϡ ʲΤ褦ʴǤ

  • ۥOSˤϡmac/windowsĤ
  • OSˤϡLinuxȤ
  • ͭեȤäơۥȤȥȤǥեͭ

Ǥ̣˽פʤΤͭե

ͭեȤϡۥOSΥե륷ƥ򥲥OSޥȤ뤿ΡVirtualBox󶡤ƤȤߤǤ

ȿ̡ե륢٤Ȥ褯ʹޤ

findʤȤgit status٤Ȥ...

ؤкõƤߤȡΤ褦ʪߤĤޤ

vboxsfΤΤؤкϼƤʤ褦Ǥ

ǡvboxsf¾Υե륷ƥȤεưΰ㤤Ĵ١vboxsf®Ƥߤ褦Ȼפޤ

ΤĤҲ𤷤ƤȻפޤ

夲Τϡfind٤ˤĤơ

ڤĶ

ڤĶȤƤϰʲ̤Ǥ

ޤĴоݤˤǥ쥯ȥϡե̤4GBȤʤäƤޤ

Ķ ġ version
VirualBox 4.3.28
VMWare Fusion 7.1.2
ۥOS OS X Yosemite 10.10.2
OS Debian 8.1 (Jessie)
findutils GNU findutils 4.4.2
coreutils GNU coreutils 8.23
glibc 2.19
linux kernel 3.16.0-4-amd64
VBoxGuestAdditions 4.3.18
VMwareTools 9.9.3

ݤǧ

ޤϡfindޥɤ٤Τ¾Υե륷ƥӤƤߤ뤳Ȥˤޤ

оݤˤϡVMWareΥۥ-ȴ֤Υե붦ͭǻȤƤvmhgfsӤޤ

ͳϡvboxsfȻȤߤɤƤ뤳ȤǤ

vboxsfvmhgfs줾ǡfindޥɼ¹ԤȤtime/straceη̤򲼤˼ޤ

timeη̤򸫤ȡΤvboxsf٤ʤäƤ뤳ȤǧǤޤ

ޤstraceǡ¹ԤƤ륷ƥॳǧƤߤȡvboxsfˤƺǤ֤ΤäƤ륷ƥॳnewfstatatǡμ¹Բvmhgfs礭ۤʤ狼ޤ

vboxsf/vmhgfsβ餫ΰ㤤ˤäfindޥǼ¹ԤۤʤäƤȤ狼ޤ

parameter vmhgfs vboxsf
time(real) 0m7.205s 0m19.774s
time(sys) 0m5.740s 0m8.088s
// vboxsf
$ strace -c find .
% time     seconds  usecs/call     calls    errors syscall
------ ----------- ----------- --------- --------- ----------------
 76.59    0.509083          15     34145           newfstatat   <-
 10.86    0.072196          73       993           openat
 10.24    0.068043          68      1005         6 open
  2.14    0.014249           0     34145           write
  0.14    0.000952           1       998           fstat
  0.03    0.000173           0      2013           getdents
  (ά)
// vmhgfs
$ strace -c find .
% time     seconds  usecs/call     calls    errors syscall
------ ----------- ----------- --------- --------- ----------------
 94.99    3.207002        1593      2013           getdents
  2.36    0.079565          79      1005         6 open
  1.96    0.066032          66       993           openat
  0.38    0.012751          13       993           newfstatat   <-
  0.19    0.006551           0     34145           write
  0.12    0.004198           2      1993           close
  0.00    0.000139           0       998           fstat
  (ά)

ɤɤ

Ĥˡʤvboxsf/vmhgfsnewfstatatθƤӽФۤʤΤĴ٤Ƥߤޤ

findΥ

ɤɤ߿ʤƤä̡newfstatat¹Ԥ뤫ݤϡʲǷƤ狼ޤ

// findutils-4.4.2/gnulib/lib/fts.c 1135-1140
            bool skip_stat = (ISSET(FTS_PHYSICAL)
                      && ISSET(FTS_NOSTAT)
                      && DT_IS_KNOWN(dp)
                      && ! DT_MUST_BE(dp, DT_DIR));
            p->fts_info = FTS_NSOK;
            fts_set_stat_required(p, !skip_stat);

dpglibcδؿreaddirȤäƼdirent ¤ΤǤ

dirent ¤Τϡեѥinodeֹ򥭥å夷ƤΤǡ˥ѥinodeֹؤѴ˻ȤƤޤ

ȽǤd_typeǧDT_UNKNOWN,DT_DIRǤäˡstat¹Ԥ뤳ȤˤʤäƤޤ

ޤgdbvboxsf/vmhgfsǤλͤǧƤߤȡvboxsfǤϾdp->d_type=0 (DT_UNKNOWN)ǤФơvmhgfsǤdp->d_type=4 (DT_DIR)dp->d_type=8 (DT_REG)֤Ƥ狼ޤ

Τ readdirˤʲΤ褦˵Ƥޤ

d_type եɤ Linux ʳǤ BSD ϤΥƥˤ¸ߤ. ΥեɤȤ θưեμ̤ˤޤ lstat(2) ƤӽФȤ򤱤뤳ȤǤ. ǽޥ BSDSOURCE 줿 glibc d_type ֤ͤȤưʲΥޥ.

ĤޤꤳϡvboxsfǤd_typeDT_UNKOWN֤Ƥ뤿ˡstat;פ˼¹Ԥɬפꡢʬvmhgfs٤ʤäƤǤȤޤ

glibc / linux kernelΥ

³ơʤvboxsfd_typeDT_UNKOWN֤ƤΤĴ٤Ƥߤޤ

ΤˡreaddirɤΤ褦˥ե륷ƥफƤΤɤɬפޤ

readdirϡglibcƤꡢʲΤ褦syscall getdentsƤǤ뤳Ȥ狼ޤ

# glibc-2.19/sysdeps/posix/readdir.c
      bytes = __GETDENTS (dirp->fd, dirp->data, maxread);

ޤgetdentsϡlinux kernelƤꡢ椫file->f_op->iterateƤӽФƤޤ

// linux/fs/readdir.c
    if (!IS_DEADDIR(inode)) {
        ctx->pos = file->f_pos;
        res = file->f_op->iterate(file, ctx);
        file->f_pos = ctx->pos;
        fsnotify_access(file);
        file_accessed(file);
    }

file->f_opϥեԤ᥽åɷǡե륷ƥऴȤƤޤ

vboxsfΥ

file->f_opϥե륷ƥƤΤǡvboxsfμߤƤޤ

vboxsfˤơfile->f_op->iterateϰʲΤ褦Ƥޤ

¾Υե륷ƥǤ⡢Ŭgrepдñ˸ĤǤ礦

// VirtualBox-4.3.28/src/VBox/Additions/linux/sharedfolders/dirops.c
struct file_operations sf_dir_fops =
{
    .open    = sf_dir_open,
    .iterate = sf_dir_iterate,
    .release = sf_dir_release,
    .read    = generic_read_dir,
    .llseek  = generic_file_llseek
};

ơvboxsfsf_dir_iterateɤäƤȡʲεҤĤޤ

// VirtualBox-4.3.28/src/VBox/Additions/linux/sharedfolders/dirops.c
        if (!dir_emit(ctx, d_name, strlen(d_name), fake_ino, DT_UNKNOWN))
        {
            LogFunc(("dir_emit failed\n"));
            return 0;
        }

dir_emitϡե̾inodeֹǥ쥯ȥꥨȥȤơϿ뤿δؿǤ

Τ褦vboxsfǤϡgetdents¹Ԥ̤Ȥơinodeֹȥե֤̾Ƥꡢd_typeˤDT_UNKNOWN֤Ƥ뤳Ȥ狼ޤ

Τᡢvboxsfǥۥ¦dentryμd_typeȤ֤ȤǤСvboxsfǤfind®뤳ȤǤȹͤޤ

vboxsf

d_typeϿ뤿ˤϡۥ¦d_typeʤФʤޤ

dentryǧȡ¦ưƤvboxsf顢ۥ¦ưƤ륵ӥ˷̤䤤碌Ƥ뤳Ȥ狼ޤ

dentryƤۥ¦ǤΥɤmac/windows줾ʲΤ褦ˤʤäƤޤ

// VirtualBox-4.3.28/src/VBox/Runtime/r3/posix/dir-posix.cpp
RTDECL(int) RTDirRead(PRTDIR pDir, PRTDIRENTRY pDirEntry, size_t *pcbDirEntry)
...
            pDirEntry->INodeId = pDir->Data.d_ino; /* may need #ifdefing later */
            pDirEntry->enmType = rtDirType(pDir->Data.d_type);
            pDirEntry->cbName  = (uint16_t)cchName;
// VirtualBox-4.3.28/src/VBox/Runtime/r3/win/direnum-win.cpp
RTDECL(int) RTDirRead(PRTDIR pDir, PRTDIRENTRY pDirEntry, size_t *pcbDirEntry)
...
    pDir->fDataUnread  = false;
    pDirEntry->INodeId = 0; /** @todo we can use the fileid here if we must (see GetFileInformationByHandle). */
    pDirEntry->enmType = pDir->Data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY
                       ? RTDIRENTRYTYPE_DIRECTORY : RTDIRENTRYTYPE_FILE;
    pDirEntry->cbName  = (uint16_t)cchName;

򸫤ȡdentryξݡd_type(pDirEntry->enmType)˼Ƥ뤳Ȥ狼ޤ

ϡ¦ޤ֤ͤƤ뤱ɤꤷƤʤǤ褦Ǥ

vboxsfǡʴǥۥ¦d_type֤褦˽Ԥޤ

νԤäǡۤɤƱͤfindޥɤ¹ԤȤtime/straceη̤ʲ˼ޤ

ʲΤ褦ˡnewfstatatθƤӽФäƤ뤳Ȥ狼ޤ

ޤʬ¹Ի֤ûʤäƤꡢvmhgfsƱ٤®٤ˤʤޤ

parameter vmhgfs vboxsf (before) vboxsf (after)
time(real) 0m7.205s 0m19.774s 0m3.385s
time(sys) 0m5.740s 0m8.088s 0m0.860s
% time     seconds  usecs/call     calls    errors syscall
------ ----------- ----------- --------- --------- ----------------
 55.75    0.090346          90      1005         6 open
 37.71    0.061110          62       993           openat
  4.58    0.007425           0     34145           write
  0.97    0.001571           2       993           newfstatat   <- 
  0.66    0.001071           1       998           fstat
  0.20    0.000326           0      1989           fchdir
  0.12    0.000194           0      2013           getdents
  0.00    0.000000           0         4           read
  (ά)

ޤȤ

vboxsfd_type֤Ƥ뤳ȤǡfindΤ褦d_typeȤäƽ︺Ƥ륳ޥɤ®뤳ȤǤޤ

ޤνϡVirtualBox 5.0.2ν˼ޤޤ

kokukuma2 at 14:17Comments(0)TrackBack(0)

ȥåХåURL

ε˥Ȥ

̾:
URL:
  򵭲: ɾ:    
 
 
 
Blog⸡
Archives
Υ֥ˤĤ
DSASȤϡKLab ۤѤƤ륳ƥĥӥѤLinux١ΥեǤ5Υǡ󥿤ˤƹۤѤƤޤ桹DSASȤ䤹ˡƤϤDZѤǤ뤳Ȥܻؤơɤ˶ФǤޤ
Υ֥Ǥϡ DSAS ǻȤäƤ뵻ѤξҲ䡢¸Ƥߤ̤𡢥ȥ֥˴ޤ줿ηи̤ʤɡ򿥤ޤƾҲ𤷤ƤȻפޤ
ǿ