Changeset 24517 in vbox
- Timestamp:
- Nov 9, 2009 4:03:09 PM (15 years ago)
- Location:
- trunk/src/VBox/VMM
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/VMM/PDMAsyncCompletionFileCache.cpp
r24415 r24517 232 232 * @param pGhostListSrc The ghost list removed entries should be moved to 233 233 * NULL if the entry should be freed. 234 * @param fReuseBuffer Flag whether a buffer should be reused if it has the same size 235 * @param ppbBuf Where to store the address of the buffer if an entry with the 236 * same size was found and fReuseBuffer is true. 234 237 * 235 238 * @notes This function may return fewer bytes than requested because entries … … 237 240 */ 238 241 static size_t pdmacFileCacheEvictPagesFrom(PPDMACFILECACHEGLOBAL pCache, size_t cbData, 239 PPDMACFILELRULIST pListSrc, PPDMACFILELRULIST pGhostListDst) 242 PPDMACFILELRULIST pListSrc, PPDMACFILELRULIST pGhostListDst, 243 bool fReuseBuffer, uint8_t **ppbBuffer) 240 244 { 241 245 size_t cbEvicted = 0; … … 248 252 || (pGhostListDst == &pCache->LruFrequentlyGhost), 249 253 ("Destination list must be NULL or one of the ghost lists\n")); 254 255 if (fReuseBuffer) 256 { 257 AssertPtr(ppbBuffer); 258 *ppbBuffer = NULL; 259 } 250 260 251 261 /* Start deleting from the tail. */ … … 276 286 LogFlow(("Evicting entry %#p (%u bytes)\n", pCurr, pCurr->cbData)); 277 287 278 if ( pCurr->pbData)288 if (fReuseBuffer && (pCurr->cbData == cbData)) 279 289 { 290 STAM_COUNTER_INC(&pCache->StatBuffersReused); 291 *ppbBuffer = pCurr->pbData; 292 } 293 else if (pCurr->pbData) 280 294 RTMemPageFree(pCurr->pbData); 281 pCurr->pbData = NULL; 282 } 283 295 296 pCurr->pbData = NULL; 284 297 cbEvicted += pCurr->cbData; 285 298 … … 310 323 } 311 324 312 static size_t pdmacFileCacheReplace(PPDMACFILECACHEGLOBAL pCache, size_t cbData, PPDMACFILELRULIST pEntryList) 325 static size_t pdmacFileCacheReplace(PPDMACFILECACHEGLOBAL pCache, size_t cbData, PPDMACFILELRULIST pEntryList, 326 bool fReuseBuffer, uint8_t **ppbBuffer) 313 327 { 314 328 PDMACFILECACHE_IS_CRITSECT_OWNER(pCache); … … 322 336 return pdmacFileCacheEvictPagesFrom(pCache, cbData, 323 337 &pCache->LruRecentlyUsed, 324 &pCache->LruRecentlyGhost); 338 &pCache->LruRecentlyGhost, 339 fReuseBuffer, ppbBuffer); 325 340 } 326 341 else … … 329 344 return pdmacFileCacheEvictPagesFrom(pCache, cbData, 330 345 &pCache->LruFrequentlyUsed, 331 &pCache->LruFrequentlyGhost); 346 &pCache->LruFrequentlyGhost, 347 fReuseBuffer, ppbBuffer); 332 348 } 333 349 } … … 340 356 * @param cbData Number of bytes to evict. 341 357 */ 342 static size_t pdmacFileCacheEvict(PPDMACFILECACHEGLOBAL pCache, size_t cbData )358 static size_t pdmacFileCacheEvict(PPDMACFILECACHEGLOBAL pCache, size_t cbData, bool fReuseBuffer, uint8_t **ppbBuffer) 343 359 { 344 360 size_t cbRemoved = ~0; … … 353 369 cbRemoved = pdmacFileCacheEvictPagesFrom(pCache, cbData, 354 370 &pCache->LruRecentlyGhost, 355 NULL); 371 NULL, 372 fReuseBuffer, ppbBuffer); 356 373 } 357 374 else … … 359 376 cbRemoved = pdmacFileCacheEvictPagesFrom(pCache, cbData, 360 377 &pCache->LruRecentlyUsed, 361 NULL); 378 NULL, 379 fReuseBuffer, ppbBuffer); 362 380 } 363 381 } … … 372 390 cbRemoved = pdmacFileCacheEvictPagesFrom(pCache, cbData, 373 391 &pCache->LruFrequentlyGhost, 374 NULL); 392 NULL, 393 fReuseBuffer, ppbBuffer); 375 394 376 395 if (cbRemoved >= cbData) 377 cbRemoved = pdmacFileCacheReplace(pCache, cbData, NULL );396 cbRemoved = pdmacFileCacheReplace(pCache, cbData, NULL, fReuseBuffer, ppbBuffer); 378 397 } 379 398 } … … 677 696 "/PDM/AsyncCompletion/File/CacheTreeRemove", 678 697 STAMUNIT_TICKS_PER_CALL, "Time taken to remove an entry an the tree"); 698 STAMR3Register(pClassFile->Core.pVM, &pCache->StatBuffersReused, 699 STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, 700 "/PDM/AsyncCompletion/File/CacheBuffersReused", 701 STAMUNIT_COUNT, "Number of times a buffer could be reused"); 679 702 #endif 680 703 … … 866 889 * @param off Start offset. 867 890 * @param cbData Size of the cache entry. 891 * @param pbBuffer Pointer to the buffer to use. 892 * NULL if a new buffer should be allocated. 893 * The buffer needs to have the same size of the entry. 868 894 */ 869 895 static PPDMACFILECACHEENTRY pdmacFileCacheEntryAlloc(PPDMACFILECACHEGLOBAL pCache, 870 896 PPDMASYNCCOMPLETIONENDPOINTFILE pEndpoint, 871 RTFOFF off, size_t cbData )897 RTFOFF off, size_t cbData, uint8_t *pbBuffer) 872 898 { 873 899 PPDMACFILECACHEENTRY pEntryNew = (PPDMACFILECACHEENTRY)RTMemAllocZ(sizeof(PDMACFILECACHEENTRY)); … … 887 913 pEntryNew->pWaitingTail = NULL; 888 914 pEntryNew->pbDataReplace = NULL; 889 pEntryNew->pbData = (uint8_t *)RTMemPageAlloc(cbData); 915 if (pbBuffer) 916 pEntryNew->pbData = pbBuffer; 917 else 918 pEntryNew->pbData = (uint8_t *)RTMemPageAlloc(cbData); 890 919 891 920 if (RT_UNLIKELY(!pEntryNew->pbData)) … … 1124 1153 else 1125 1154 { 1155 uint8_t *pbBuffer = NULL; 1156 1126 1157 LogFlow(("Fetching data for ghost entry %#p from file\n", pEntry)); 1127 1158 1128 1159 RTCritSectEnter(&pCache->CritSect); 1129 1160 pdmacFileCacheUpdate(pCache, pEntry); 1130 pdmacFileCacheReplace(pCache, pEntry->cbData, pEntry->pList );1161 pdmacFileCacheReplace(pCache, pEntry->cbData, pEntry->pList, true, &pbBuffer); 1131 1162 1132 1163 /* Move the entry to T2 and fetch it to the cache. */ … … 1134 1165 RTCritSectLeave(&pCache->CritSect); 1135 1166 1136 pEntry->pbData = (uint8_t *)RTMemPageAlloc(pEntry->cbData); 1167 if (pbBuffer) 1168 pEntry->pbData = pbBuffer; 1169 else 1170 pEntry->pbData = (uint8_t *)RTMemPageAlloc(pEntry->cbData); 1137 1171 AssertPtr(pEntry->pbData); 1138 1172 … … 1206 1240 STAM_COUNTER_INC(&pCache->cPartialHits); 1207 1241 1242 uint8_t *pbBuffer = NULL; 1243 1208 1244 RTCritSectEnter(&pCache->CritSect); 1209 size_t cbRemoved = pdmacFileCacheEvict(pCache, cbToReadAligned );1245 size_t cbRemoved = pdmacFileCacheEvict(pCache, cbToReadAligned, true, &pbBuffer); 1210 1246 RTCritSectLeave(&pCache->CritSect); 1211 1247 … … 1213 1249 { 1214 1250 LogFlow(("Evicted %u bytes (%u requested). Creating new cache entry\n", cbRemoved, cbToReadAligned)); 1215 PPDMACFILECACHEENTRY pEntryNew = pdmacFileCacheEntryAlloc(pCache, pEndpoint, off, cbToReadAligned );1251 PPDMACFILECACHEENTRY pEntryNew = pdmacFileCacheEntryAlloc(pCache, pEndpoint, off, cbToReadAligned, pbBuffer); 1216 1252 AssertPtr(pEntryNew); 1217 1253 … … 1517 1553 else 1518 1554 { 1555 uint8_t *pbBuffer = NULL; 1556 1519 1557 RTCritSectEnter(&pCache->CritSect); 1520 1558 pdmacFileCacheUpdate(pCache, pEntry); 1521 pdmacFileCacheReplace(pCache, pEntry->cbData, pEntry->pList );1559 pdmacFileCacheReplace(pCache, pEntry->cbData, pEntry->pList, true, &pbBuffer); 1522 1560 1523 1561 /* Move the entry to T2 and fetch it to the cache. */ … … 1525 1563 RTCritSectLeave(&pCache->CritSect); 1526 1564 1527 pEntry->pbData = (uint8_t *)RTMemPageAlloc(pEntry->cbData); 1565 if (pbBuffer) 1566 pEntry->pbData = pbBuffer; 1567 else 1568 pEntry->pbData = (uint8_t *)RTMemPageAlloc(pEntry->cbData); 1528 1569 AssertPtr(pEntry->pbData); 1529 1570 … … 1586 1627 STAM_COUNTER_ADD(&pCache->StatWritten, cbToWrite); 1587 1628 1629 uint8_t *pbBuffer = NULL; 1630 1588 1631 RTCritSectEnter(&pCache->CritSect); 1589 size_t cbRemoved = pdmacFileCacheEvict(pCache, cbToWrite );1632 size_t cbRemoved = pdmacFileCacheEvict(pCache, cbToWrite, true, &pbBuffer); 1590 1633 RTCritSectLeave(&pCache->CritSect); 1591 1634 … … 1597 1640 LogFlow(("Evicted %u bytes (%u requested). Creating new cache entry\n", cbRemoved, cbToWrite)); 1598 1641 1599 pEntryNew = pdmacFileCacheEntryAlloc(pCache, pEndpoint, off, cbToWrite );1642 pEntryNew = pdmacFileCacheEntryAlloc(pCache, pEndpoint, off, cbToWrite, pbBuffer); 1600 1643 AssertPtr(pEntryNew); 1601 1644 -
trunk/src/VBox/VMM/PDMAsyncCompletionFileInternal.h
r24442 r24517 249 249 #define PDMACFILECACHE_ENTRY_IS_DEPRECATED RT_BIT(3) 250 250 /** Entry is not evictable. */ 251 #define PDMACFILECACHE_NOT_EVICTABLE (PDMACFILECACHE_ENTRY_LOCKED | PDMACFILECACHE_IO_IN_PROGRESS )251 #define PDMACFILECACHE_NOT_EVICTABLE (PDMACFILECACHE_ENTRY_LOCKED | PDMACFILECACHE_IO_IN_PROGRESS | PDMACFILECACHE_ENTRY_IS_DEPRECATED) 252 252 253 253 /** … … 302 302 /** Time spend to remove an entry in the AVL tree. */ 303 303 STAMPROFILEADV StatTreeRemove; 304 /** Number of times a buffer could be reused. */ 305 STAMCOUNTER StatBuffersReused; 304 306 #endif 305 307 } PDMACFILECACHEGLOBAL;
Note:
See TracChangeset
for help on using the changeset viewer.