Rasmus,

I've asked one of our FreeBSD gurus to shed some light on the issue you
brought with the slow performance of realpath() and stat() calls on that
OS. Hope this makes sense. ;)

-Andrei

-- 
Andrei Zmievski                 Mail:   [EMAIL PROTECTED]
Sr. Front End Software Engineer Web:    http://www.fastsearch.com/
Fast Search & Transfer Inc      Phone:  781-304-2493
93 Worcester Street             Fax:    781-304-2410
Wellesley MA 02481-9181, USA    Main:   781-304-2400
--- Begin Message ---
> Hi Tor,
> 
> I have been told that you are the FreeBSD guru at FAST, so I wanted to
> check on something with you. A thread came up recently on php-dev
> mailing list which discussed performance issues with using include()
> and require() calls in PHP on FreeBSD systems. It seems that FreeBSD
> does not implement a dcache like Linux does, so doing realpath() and
> stat() calls is very expensive. Obviously, we use PHP on FreeBSD to run
> AlltheWeb.com and it affects us as well.

FreeBSD has a namei cache, the implementation for 4.7-RELEASE is in
/usr/src/sys/kern/vfs_cache.c.

namei() calls lookup() which calls VOP_LOOKUP().  For ufs vnodes, that
means that vfs_cache_lookup is called.  vfs_cache_lookup calls
VOP_CACHEDLOOKUP() on cache misses.  For ufs vnodes, that means that
ufs_lookup() is called.

>From the namei comment in /usr/src/sys/kern/vfs_lookup.c:

 * Overall outline of namei:
 *
 *      copy in name
 *      get starting directory
 *      while (!done && !error) {
 *              call lookup to search path.
 *              if symbolic link, massage name in buffer and continue
 *      }


>From the lookup() comment in /usr/src/sys/kern/vfs_lookup.c:

 * Overall outline of lookup:
 *
 * dirloop:
 *      identify next component of name at ndp->ni_ptr
 *      handle degenerate case where name is null string
 *      if .. and crossing mount points and on mounted filesys, find parent
 *      call VOP_LOOKUP routine for next component name
 *          directory vnode returned in ni_dvp, unlocked unless LOCKPARENT set
 *          component vnode returned in ni_vp (if it exists), locked.
 *      if result vnode is mounted on and crossing mount points,
 *          find mounted on vnode
 *      if more components of name, do next level at dirloop
 *      return the answer in ni_vp, locked if LOCKLEAF set
 *          if LOCKPARENT set, return locked parent in ni_dvp
 *          if WANTPARENT set, return unlocked parent in ni_dvp

>From the vfs_cache_lookup() comment in /usr/src/sys/kern/vfs_cache.c:

 * Perform canonical checks and cache lookup and pass on to filesystem
 * through the vop_cachedlookup only if needed.


>From the ufs_lookup() comment in /usr/src/sys/ufs/ufs/ufs_lookup.c:

 * This routine is actually used as VOP_CACHEDLOOKUP method, and the
 * filesystem employs the generic vfs_cache_lookup() as VOP_LOOKUP
 * method.
 *
 * vfs_cache_lookup() performs the following for us:
 *      check that it is a directory
 *      check accessibility of directory
 *      check for modification attempts on read-only mounts
 *      if name found in cache
 *          if at end of path and deleting or creating
 *              drop it
 *           else
 *              return name.
 *      return VOP_CACHEDLOOKUP()
 *
 * Overall outline of ufs_lookup:
 *
 *      search for name in directory, to found or notfound
 * notfound:
 *      if creating, return locked directory, leaving info on available slots
 *      else return error
 * found:
 *      if at end of path and deleting, return information to allow delete
 *      if at end of path and rewriting (RENAME and LOCKPARENT), lock target
 *        inode and return info to allow rewrite
 *      if not at end, add name to cache; if at end and neither creating
 *        nor deleting, add name to cache


The command
    sysctl vfs.cache
outputs some statistics about the namei cache and can be used to measure
cache hit ratio.

The command
  systat -vmstat
provides some semi-real-time statistics.

- Tor Egge


--- End Message ---
-- 
PHP Development Mailing List <http://www.php.net/>
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to