VirtualBox

Changeset 78609 in vbox for trunk/src


Ignore:
Timestamp:
May 20, 2019 11:15:40 PM (6 years ago)
Author:
vboxsync
Message:

winnt/vboxsf: Don't flush and purge the cache twice on newer systems, instead do a library trick to redirect relevant imports from write.obj and read.obj to our wrappers that uses CcCoherencyFlushAndPurgeCache when possible to get better coherency between mmap regions and file content when writing and reading normally. This comes at a cost when the file has been mmapped at some point previously (or currently) and we may need to purge stuff. bugref:9172

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Additions/WINNT/SharedFolders/driver/file.cpp

    r78608 r78609  
    3434
    3535
    36 /** @name Hacks for using the better CcCoherencyFlushAndPurgeCache when
    37  *        available (>= Windows 7) and avoid flushing+puring twice.
    38  *
    39  * We change the cache flushing and purging related imports from  the write.obj
     36/** @name HACK ALERT! Using the better CcCoherencyFlushAndPurgeCache when
     37 *        available (>= Windows 7) and avoid flushing+purging cache twice.
     38 *
     39 * We change the cache flushing and purging related imports from the write.obj
    4040 * and read.obj files in the rdbsslib.lib to import so these gets redirected
    4141 * here instead of going directly to ntoskrnl.  We will use
     
    4444 * purging on newer systems.
    4545 *
     46 * If we don't use CcCoherencyFlushAndPurgeCache we end up not seeing newly
     47 * written data in memory mappings, and similarlly not seeing data from freshly
     48 * dirtied (but as yet unflushed) memory mapping pages when reading.  (Both
     49 * these scenarios are tested by FsPerf --mmap.)
     50 *
    4651 * See VBoxEditCoffLib and the Makefile.kmk for the rest of the puzzle.
    4752 *
     53 * @todo investigate whether we could do it the same way as we do on linux,
     54 *       where we iterrogate the cache and use cached data when memory mappings
     55 *       are active.  Only troubles are:
     56 *
     57 *          1. Don't know how to find out whether we've got memory mappings.
     58 *
     59 *          2. Don't know how to detect dirty pages (we should only read
     60 *             from dirty ones).
     61 *
     62 *       To really explore this, it would be best to introduce a caching mode
     63 *       mount parameter (or something) analogous to what we have on linux.  In
     64 *       the relaxed mode, we could get away with more as users could always
     65 *       disable caching...
    4866 * @{
    4967 */
    5068
     69/** For reads. */
    5170static VOID NTAPI vbsfNtReadCcFlushCache(PSECTION_OBJECT_POINTERS pSectObjPtrs, PLARGE_INTEGER poffFlush, ULONG cbFlush,
    5271                                         PIO_STATUS_BLOCK pIos)
     
    5877}
    5978
     79
     80/**
     81 * For writes with mmapping/caching section, called before the purging.
     82 *
     83 * This does both flushing and puring when CcCoherencyFlushAndPurgeCache is
     84 * available.
     85 */
    6086static VOID NTAPI vbsfNtWriteCcFlushCache(PSECTION_OBJECT_POINTERS pSectObjPtrs, PLARGE_INTEGER poffFlush, ULONG cbFlush,
    6187                                          PIO_STATUS_BLOCK pIos)
     
    6894
    6995
     96/**
     97 * For writes with mmapping/caching section, called to purge after flushing.
     98 *
     99 * We translate this to a no-op when CcCoherencyFlushAndPurgeCache is available.
     100 */
    70101static BOOLEAN NTAPI vbsfNtWriteCcPurgeCacheSection(PSECTION_OBJECT_POINTERS pSectObjPtrs, PLARGE_INTEGER poffPurge,ULONG cbPurge,
    71102#if (NTDDI_VERSION >= NTDDI_VISTA)
     
    88119
    89120extern "C" {
     121/** This is what read.obj gets instead of __imp_CcFlushCache. */
    90122decltype(CcFlushCache)        *g_pfnRdFlushCache        = vbsfNtReadCcFlushCache;
     123/** This is what write.obj gets instead of __imp_CcFlushCache. */
    91124decltype(CcFlushCache)        *g_pfnWrFlushCache        = vbsfNtWriteCcFlushCache;
     125/** This is what write.obj gets instead of __imp_CcPurgeCacheSection. */
    92126decltype(CcPurgeCacheSection) *g_pfnWrPurgeCacheSection = vbsfNtWriteCcPurgeCacheSection;
    93127}
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette