Changeset 22310 in vbox for trunk/src/VBox/VMM
- Timestamp:
- Aug 17, 2009 10:11:17 PM (16 years ago)
- svn:sync-xref-src-repo-rev:
- 51184
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/VMM/PDMAsyncCompletionFileCache.cpp
r22309 r22310 20 20 * additional information or have any questions. 21 21 */ 22 23 /** @page pg_pdm_async_completion_cache PDM Async Completion Cache - The file I/O cache 24 * This component implements an I/O cache for file endpoints based on the ARC algorithm. 25 * http://en.wikipedia.org/wiki/Adaptive_Replacement_Cache 26 * 27 * The algorithm uses for LRU (Least frequently used) lists to store data in the cache. 28 * Two of them contain data where one stores entries which were accessed recently and one 29 * which is used for frequently accessed data. 30 * The other two lists are called ghost lists and store information about the accessed range 31 * but do not contain data. They are used to track data access. If these entries are accessed 32 * they will push the data to a higher position in the cache preventing it from getting removed 33 * quickly again. 34 * 35 * The algorithm needs to be modified to meet our requirements. Like the implementation 36 * for the ZFS filesystem we need to handle pages with a variable size. It would 37 * be possible to use a fixed size but would increase the computational 38 * and memory overhead. 39 * Because we do I/O asynchronously we also need to mark entries which are currently accessed 40 * as non evictable to prevent removal of the entry while the data is being accessed. 41 */ 42 43 /******************************************************************************* 44 * Header Files * 45 *******************************************************************************/ 22 46 #define LOG_GROUP LOG_GROUP_PDM_ASYNC_COMPLETION 23 47 #include <iprt/types.h> … … 28 52 #include "PDMAsyncCompletionFileInternal.h" 29 53 54 /******************************************************************************* 55 * Internal Functions * 56 *******************************************************************************/ 30 57 static void pdmacFileCacheTaskCompleted(PPDMACTASKFILE pTask, void *pvUser); 31 58 59 /** 60 * Checks consistency of a LRU list. 61 * 62 * @returns nothing 63 * @param pList The LRU list to check. 64 * @param pNotInList Element which is not allowed to occur in the list. 65 */ 32 66 static void pdmacFileCacheCheckList(PPDMACFILELRULIST pList, PPDMACFILECACHEENTRY pNotInList) 33 67 { … … 58 92 } 59 93 94 /** 95 * Unlinks a cache entry from the LRU list it is assigned to. 96 * 97 * @returns nothing. 98 * @param pEntry The entry to unlink. 99 */ 60 100 static void pdmacFileCacheEntryRemoveFromList(PPDMACFILECACHEENTRY pEntry) 61 101 { … … 101 141 } 102 142 143 /** 144 * Adds a cache entry to the given LRU list unlinking it from the currently 145 * assigned list if needed. 146 * 147 * @returns nothing. 148 * @param pList List to the add entry to. 149 * @param pEntry Entry to add. 150 */ 103 151 static void pdmacFileCacheEntryAddToList(PPDMACFILELRULIST pList, PPDMACFILECACHEENTRY pEntry) 104 152 { … … 150 198 } 151 199 200 /** 201 * Tries to remove the given amount of bytes from a given list in the cache 202 * moving the entries to one of the given ghosts lists 203 * 204 * @returns Amount of data which could be freed. 205 * @param pCache Pointer to the global cache data. 206 * @param cbData The amount of the data to free. 207 * @param pListSrc The source list to evict data from. 208 * @param pGhostListSrc The ghost list removed entries should be moved to 209 * NULL if the entry should be freed. 210 * 211 * @notes This function may return fewer bytes than requested because entries 212 * may be marked as non evictable if they are used for I/O at the moment. 213 */ 152 214 static size_t pdmacFileCacheEvictPagesFrom(PPDMACFILECACHEGLOBAL pCache, size_t cbData, 153 215 PPDMACFILELRULIST pListSrc, PPDMACFILELRULIST pGhostListDst) … … 226 288 } 227 289 290 /** 291 * Tries to evict the given amount of the data from the cache. 292 * 293 * @returns Bytes removed. 294 * @param pCache The global cache data. 295 * @param cbData Number of bytes to evict. 296 */ 228 297 static size_t pdmacFileCacheEvict(PPDMACFILECACHEGLOBAL pCache, size_t cbData) 229 298 { … … 266 335 } 267 336 337 /** 338 * Updates the cache parameters 339 * 340 * @returns nothing. 341 * @param pCache The global cache data. 342 * @param pEntry The entry usign for the update. 343 */ 268 344 static void pdmacFileCacheUpdate(PPDMACFILECACHEGLOBAL pCache, PPDMACFILECACHEENTRY pEntry) 269 345 { … … 293 369 } 294 370 371 /** 372 * Initiates a read I/O task for the given entry. 373 * 374 * @returns nothing. 375 * @param pEntry The entry to fetch the data to. 376 */ 295 377 static void pdmacFileCacheReadFromEndpoint(PPDMACFILECACHEENTRY pEntry) 296 378 { … … 315 397 } 316 398 399 /** 400 * Initiates a write I/O task for the given entry. 401 * 402 * @returns nothing. 403 * @param pEntry The entry to read the data from. 404 */ 317 405 static void pdmacFileCacheWriteToEndpoint(PPDMACFILECACHEENTRY pEntry) 318 406 { … … 337 425 } 338 426 427 /** 428 * Completion callback for I/O tasks. 429 * 430 * @returns nothing. 431 * @param pTask The completed task. 432 * @param pvUser Opaque user data. 433 */ 339 434 static void pdmacFileCacheTaskCompleted(PPDMACTASKFILE pTask, void *pvUser) 340 435 { … … 411 506 } 412 507 508 /** 509 * Initializies the I/O cache. 510 * 511 * returns VBox status code. 512 * @param pClassFile The global class data for file endpoints. 513 * @param pCfgNode CFGM node to query configuration data from. 514 */ 413 515 int pdmacFileCacheInit(PPDMASYNCCOMPLETIONEPCLASSFILE pClassFile, PCFGMNODE pCfgNode) 414 516 { … … 510 612 } 511 613 614 /** 615 * Destroysthe cache freeing all data. 616 * 617 * returns nothing. 618 * @param pClassFile The global class data for file endpoints. 619 */ 512 620 void pdmacFileCacheDestroy(PPDMASYNCCOMPLETIONEPCLASSFILE pClassFile) 513 621 { … … 528 636 } 529 637 638 /** 639 * Initializes per endpoint cache data 640 * like the AVL tree used to access cached entries. 641 * 642 * @returns VBox status code. 643 * @param pEndpoint The endpoint to init the cache for, 644 * @param pClassFile The global class data for file endpoints. 645 */ 530 646 int pdmacFileEpCacheInit(PPDMASYNCCOMPLETIONENDPOINTFILE pEndpoint, PPDMASYNCCOMPLETIONEPCLASSFILE pClassFile) 531 647 { … … 538 654 } 539 655 656 /** 657 * Callback for the AVL destroy routine. Frees a cache entry for this endpoint. 658 * 659 * @returns IPRT status code. 660 * @param pNode The node to destroy. 661 * @param pvUser Opaque user data. 662 */ 540 663 static int pdmacFileEpCacheEntryDestroy(PAVLRFOFFNODECORE pNode, void *pvUser) 541 664 { … … 555 678 } 556 679 680 /** 681 * Destroys all cache ressources used by the given endpoint. 682 * 683 * @returns nothing. 684 * @param pEndpoint The endpoint to the destroy. 685 */ 557 686 void pdmacFileEpCacheDestroy(PPDMASYNCCOMPLETIONENDPOINTFILE pEndpoint) 558 687 { … … 585 714 while (0); 586 715 716 /** 717 * Reads the specified data from the endpoint using the cache if possible. 718 * 719 * @returns VBox status code. 720 * @param pEndpoint The endpoint to read from. 721 * @param pTask The task structure used as identifier for this request. 722 * @param off The offset to start reading from. 723 * @param paSegments Pointer to the array holding the destination buffers. 724 * @param cSegments Number of segments in the array. 725 * @param cbRead Number of bytes to read. 726 */ 587 727 int pdmacFileEpCacheRead(PPDMASYNCCOMPLETIONENDPOINTFILE pEndpoint, PPDMASYNCCOMPLETIONTASKFILE pTask, 588 728 RTFOFF off, PCPDMDATASEG paSegments, size_t cSegments, … … 852 992 } 853 993 994 /** 995 * Writes the given data to the endpoint using the cache if possible. 996 * 997 * @returns VBox status code. 998 * @param pEndpoint The endpoint to write to. 999 * @param pTask The task structure used as identifier for this request. 1000 * @param off The offset to start writing to 1001 * @param paSegments Pointer to the array holding the source buffers. 1002 * @param cSegments Number of segments in the array. 1003 * @param cbWrite Number of bytes to write. 1004 */ 854 1005 int pdmacFileEpCacheWrite(PPDMASYNCCOMPLETIONENDPOINTFILE pEndpoint, PPDMASYNCCOMPLETIONTASKFILE pTask, 855 1006 RTFOFF off, PCPDMDATASEG paSegments, size_t cSegments,
Note:
See TracChangeset
for help on using the changeset viewer.