Lines Matching defs:pEntry
74 static bool pdmBlkCacheAddDirtyEntry(PPDMBLKCACHE pBlkCache, PPDMBLKCACHEENTRY pEntry);
80 * @param pEntry The entry to release.
82 DECLINLINE(void) pdmBlkCacheEntryRelease(PPDMBLKCACHEENTRY pEntry)
84 AssertMsg(pEntry->cRefs > 0, ("Trying to release a not referenced entry\n"));
85 ASMAtomicDecU32(&pEntry->cRefs);
92 * @param pEntry The entry to reference.
94 DECLINLINE(void) pdmBlkCacheEntryRef(PPDMBLKCACHEENTRY pEntry)
96 ASMAtomicIncU32(&pEntry->cRefs);
192 * @param pEntry The entry to unlink.
194 static void pdmBlkCacheEntryRemoveFromList(PPDMBLKCACHEENTRY pEntry)
196 PPDMBLKLRULIST pList = pEntry->pList;
199 LogFlowFunc((": Deleting entry %#p from list %#p\n", pEntry, pList));
207 pPrev = pEntry->pPrev;
208 pNext = pEntry->pNext;
210 AssertMsg(pEntry != pPrev, ("Entry links to itself as previous element\n"));
211 AssertMsg(pEntry != pNext, ("Entry links to itself as next element\n"));
233 pEntry->pList = NULL;
234 pEntry->pPrev = NULL;
235 pEntry->pNext = NULL;
236 pdmBlkCacheListSub(pList, pEntry->cbData);
238 pdmBlkCacheCheckList(pList, pEntry);
248 * @param pEntry Entry to add.
250 static void pdmBlkCacheEntryAddToList(PPDMBLKLRULIST pList, PPDMBLKCACHEENTRY pEntry)
252 LogFlowFunc((": Adding entry %#p to list %#p\n", pEntry, pList));
258 if (pEntry->pList)
259 pdmBlkCacheEntryRemoveFromList(pEntry);
261 pEntry->pNext = pList->pHead;
263 pList->pHead->pPrev = pEntry;
267 pList->pTail = pEntry;
270 pEntry->pPrev = NULL;
271 pList->pHead = pEntry;
272 pdmBlkCacheListAdd(pList, pEntry->cbData);
273 pEntry->pList = pList;
291 PPDMBLKCACHEENTRY pEntry = pList->pHead;
293 pList->pHead = pEntry->pNext;
295 AssertMsg(!(pEntry->fFlags & (PDMBLKCACHE_ENTRY_IO_IN_PROGRESS | PDMBLKCACHE_ENTRY_IS_DIRTY)),
296 ("Entry is dirty and/or still in progress fFlags=%#x\n", pEntry->fFlags));
298 RTMemPageFree(pEntry->pbData, pEntry->cbData);
299 RTMemFree(pEntry);
341 PPDMBLKCACHEENTRY pEntry = pListSrc->pTail;
343 while ((cbEvicted < cbData) && pEntry)
345 PPDMBLKCACHEENTRY pCurr = pEntry;
347 pEntry = pEntry->pPrev;
536 * @param pEntry The entry to fetch the data to.
538 static int pdmBlkCacheEntryReadFromMedium(PPDMBLKCACHEENTRY pEntry)
540 PPDMBLKCACHE pBlkCache = pEntry->pBlkCache;
541 LogFlowFunc((": Reading data into cache entry %#p\n", pEntry));
544 pEntry->fFlags |= PDMBLKCACHE_ENTRY_IO_IN_PROGRESS;
550 AssertMsg(pEntry->pbData, ("Entry is in ghost state\n"));
553 pIoXfer->pEntry = pEntry;
554 pIoXfer->SgSeg.pvSeg = pEntry->pbData;
555 pIoXfer->SgSeg.cbSeg = pEntry->cbData;
559 return pdmBlkCacheEnqueue(pBlkCache, pEntry->Core.Key, pEntry->cbData, pIoXfer);
566 * @param pEntry The entry to read the data from.
568 static int pdmBlkCacheEntryWriteToMedium(PPDMBLKCACHEENTRY pEntry)
570 PPDMBLKCACHE pBlkCache = pEntry->pBlkCache;
571 LogFlowFunc((": Writing data from cache entry %#p\n", pEntry));
574 pEntry->fFlags |= PDMBLKCACHE_ENTRY_IO_IN_PROGRESS;
580 AssertMsg(pEntry->pbData, ("Entry is in ghost state\n"));
583 pIoXfer->pEntry = pEntry;
584 pIoXfer->SgSeg.pvSeg = pEntry->pbData;
585 pIoXfer->SgSeg.cbSeg = pEntry->cbData;
589 return pdmBlkCacheEnqueue(pBlkCache, pEntry->Core.Key, pEntry->cbData, pIoXfer);
630 * @param pEntry The entry to commit.
632 static void pdmBlkCacheEntryCommit(PPDMBLKCACHEENTRY pEntry)
634 AssertMsg( (pEntry->fFlags & PDMBLKCACHE_ENTRY_IS_DIRTY)
635 && !(pEntry->fFlags & PDMBLKCACHE_ENTRY_IO_IN_PROGRESS),
636 ("Invalid flags set for entry %#p\n", pEntry));
638 pdmBlkCacheEntryWriteToMedium(pEntry);
667 PPDMBLKCACHEENTRY pEntry = RTListGetFirst(&ListDirtyNotCommitted, PDMBLKCACHEENTRY, NodeNotCommitted);
669 while (!RTListNodeIsLast(&ListDirtyNotCommitted, &pEntry->NodeNotCommitted))
671 PPDMBLKCACHEENTRY pNext = RTListNodeGetNext(&pEntry->NodeNotCommitted, PDMBLKCACHEENTRY,
673 pdmBlkCacheEntryCommit(pEntry);
674 cbCommitted += pEntry->cbData;
675 RTListNodeRemove(&pEntry->NodeNotCommitted);
676 pEntry = pNext;
680 Assert(RTListNodeIsLast(&ListDirtyNotCommitted, &pEntry->NodeNotCommitted));
681 pdmBlkCacheEntryCommit(pEntry);
682 cbCommitted += pEntry->cbData;
683 RTListNodeRemove(&pEntry->NodeNotCommitted);
739 * @param pEntry The entry to add.
741 static bool pdmBlkCacheAddDirtyEntry(PPDMBLKCACHE pBlkCache, PPDMBLKCACHEENTRY pEntry)
749 pEntry->fFlags |= PDMBLKCACHE_ENTRY_IS_DIRTY;
750 pdmBlkCacheEntryCommit(pEntry);
752 else if (!(pEntry->fFlags & PDMBLKCACHE_ENTRY_IS_DIRTY))
754 pEntry->fFlags |= PDMBLKCACHE_ENTRY_IS_DIRTY;
757 RTListAppend(&pBlkCache->ListDirtyNotCommitted, &pEntry->NodeNotCommitted);
760 uint32_t cbDirty = ASMAtomicAddU32(&pCache->cbDirty, pEntry->cbData);
764 fDirtyBytesExceeded = (cbDirty + pEntry->cbData >= pCache->cbCommitDirtyThreshold);
824 PPDMBLKCACHEENTRY pEntry;
831 RTListForEach(&pBlkCache->ListDirtyNotCommitted, pEntry, PDMBLKCACHEENTRY, NodeNotCommitted)
839 RTListForEach(&pBlkCache->ListDirtyNotCommitted, pEntry, PDMBLKCACHEENTRY, NodeNotCommitted)
842 AssertMsg(!pEntry->cRefs, ("The entry is still referenced\n"));
843 AssertMsg(pEntry->fFlags & PDMBLKCACHE_ENTRY_IS_DIRTY, ("Entry is not dirty\n"));
844 AssertMsg(!(pEntry->fFlags & ~PDMBLKCACHE_ENTRY_IS_DIRTY), ("Invalid flags set\n"));
845 AssertMsg(!pEntry->pWaitingHead && !pEntry->pWaitingTail, ("There are waiting requests\n"));
846 AssertMsg( pEntry->pList == &pBlkCacheGlobal->LruRecentlyUsedIn
847 || pEntry->pList == &pBlkCacheGlobal->LruFrequentlyUsed,
849 AssertMsg(pEntry->cbData == pEntry->Core.KeyLast - pEntry->Core.Key + 1,
853 SSMR3PutU64(pSSM, pEntry->Core.Key);
854 SSMR3PutU32(pSSM, pEntry->cbData);
855 SSMR3PutMem(pSSM, pEntry->pbData, pEntry->cbData);
931 PPDMBLKCACHEENTRY pEntry;
938 pEntry = pdmBlkCacheEntryAlloc(pBlkCache, off, cbEntry, NULL);
939 if (!pEntry)
945 rc = SSMR3GetMem(pSSM, pEntry->pbData, cbEntry);
948 RTMemFree(pEntry->pbData);
949 RTMemFree(pEntry);
954 bool fInserted = RTAvlrU64Insert(pBlkCache->pTree, &pEntry->Core);
958 pdmBlkCacheAddDirtyEntry(pBlkCache, pEntry);
959 pdmBlkCacheEntryAddToList(&pBlkCacheGlobal->LruRecentlyUsedIn, pEntry);
961 pdmBlkCacheEntryRelease(pEntry);
1377 PPDMBLKCACHEENTRY pEntry = (PPDMBLKCACHEENTRY)pNode;
1379 PPDMBLKCACHE pBlkCache = pEntry->pBlkCache;
1381 while (ASMAtomicReadU32(&pEntry->fFlags) & PDMBLKCACHE_ENTRY_IO_IN_PROGRESS)
1384 pdmBlkCacheEntryRef(pEntry);
1393 pdmBlkCacheEntryRelease(pEntry);
1396 AssertMsg(!(pEntry->fFlags & PDMBLKCACHE_ENTRY_IO_IN_PROGRESS),
1397 ("Entry is dirty and/or still in progress fFlags=%#x\n", pEntry->fFlags));
1399 bool fUpdateCache = pEntry->pList == &pCache->LruFrequentlyUsed
1400 || pEntry->pList == &pCache->LruRecentlyUsedIn;
1402 pdmBlkCacheEntryRemoveFromList(pEntry);
1405 pdmBlkCacheSub(pCache, pEntry->cbData);
1407 RTMemPageFree(pEntry->pbData, pEntry->cbData);
1408 RTMemFree(pEntry);
1549 PPDMBLKCACHEENTRY pEntry = (PPDMBLKCACHEENTRY)RTAvlrU64RangeGet(pBlkCache->pTree, off);
1550 if (pEntry)
1551 pdmBlkCacheEntryRef(pEntry);
1556 return pEntry;
1586 static void pdmBlkCacheInsertEntry(PPDMBLKCACHE pBlkCache, PPDMBLKCACHEENTRY pEntry)
1590 bool fInserted = RTAvlrU64Insert(pBlkCache->pTree, &pEntry->Core);
1649 * @param pEntry The entry to check the flags for.
1654 PPDMBLKCACHEENTRY pEntry,
1657 uint32_t fFlags = ASMAtomicReadU32(&pEntry->fFlags);
1665 fFlags = ASMAtomicReadU32(&pEntry->fFlags);
1681 * @param pEntry The cache entry to add the segment to.
1684 DECLINLINE(void) pdmBlkCacheEntryAddWaiter(PPDMBLKCACHEENTRY pEntry,
1689 if (pEntry->pWaitingHead)
1691 AssertPtr(pEntry->pWaitingTail);
1693 pEntry->pWaitingTail->pNext = pWaiter;
1694 pEntry->pWaitingTail = pWaiter;
1698 Assert(!pEntry->pWaitingTail);
1700 pEntry->pWaitingHead = pWaiter;
1701 pEntry->pWaitingTail = pWaiter;
1710 * @param pEntry The entry to add the buffer to.
1719 static int pdmBlkCacheEntryWaitersAdd(PPDMBLKCACHEENTRY pEntry,
1736 pdmBlkCacheEntryAddWaiter(pEntry, pWaiter);
1928 PPDMBLKCACHEENTRY pEntry;
1952 pEntry = pdmBlkCacheGetCacheEntryByOffset(pBlkCache, off);
1965 if (pEntry)
1967 uint64_t offDiff = off - pEntry->Core.Key;
1969 AssertMsg(off >= pEntry->Core.Key,
1971 off, pEntry->Core.Key));
1973 AssertPtr(pEntry->pList);
1975 cbToRead = RT_MIN(pEntry->cbData - offDiff, cbRead);
1977 AssertMsg(off + cbToRead <= pEntry->Core.Key + pEntry->Core.KeyLast + 1,
1991 if ( (pEntry->pList == &pCache->LruRecentlyUsedIn)
1992 || (pEntry->pList == &pCache->LruFrequentlyUsed))
1994 if (pdmBlkCacheEntryFlagIsSetClearAcquireLock(pBlkCache, pEntry,
1999 pdmBlkCacheEntryWaitersAdd(pEntry, pReq,
2007 RTSgBufCopyFromBuf(&SgBuf, pEntry->pbData + offDiff, cbToRead);
2011 if (pEntry->pList == &pCache->LruFrequentlyUsed)
2014 pdmBlkCacheEntryAddToList(&pCache->LruFrequentlyUsed, pEntry);
2018 pdmBlkCacheEntryRelease(pEntry);
2024 LogFlow(("Fetching data for ghost entry %#p from file\n", pEntry));
2027 pdmBlkCacheEntryRemoveFromList(pEntry); /* Remove it before we remove data, otherwise it may get freed when evicting data. */
2028 bool fEnough = pdmBlkCacheReclaim(pCache, pEntry->cbData, true, &pbBuffer);
2033 pdmBlkCacheEntryAddToList(&pCache->LruFrequentlyUsed, pEntry);
2034 pdmBlkCacheAdd(pCache, pEntry->cbData);
2038 pEntry->pbData = pbBuffer;
2040 pEntry->pbData = (uint8_t *)RTMemPageAlloc(pEntry->cbData);
2041 AssertPtr(pEntry->pbData);
2043 pdmBlkCacheEntryWaitersAdd(pEntry, pReq,
2046 pdmBlkCacheEntryReadFromMedium(pEntry);
2048 pdmBlkCacheEntryRelease(pEntry);
2054 RTAvlrU64Remove(pBlkCache->pTree, pEntry->Core.Key);
2060 RTMemFree(pEntry);
2149 PPDMBLKCACHEENTRY pEntry;
2173 pEntry = pdmBlkCacheGetCacheEntryByOffset(pBlkCache, off);
2174 if (pEntry)
2177 AssertPtr(pEntry->pList);
2179 uint64_t offDiff = off - pEntry->Core.Key;
2181 AssertMsg(off >= pEntry->Core.Key,
2183 off, pEntry->Core.Key));
2185 cbToWrite = RT_MIN(pEntry->cbData - offDiff, cbWrite);
2196 if ( (pEntry->pList == &pCache->LruRecentlyUsedIn)
2197 || (pEntry->pList == &pCache->LruFrequentlyUsed))
2200 if (pdmBlkCacheEntryFlagIsSetClearAcquireLock(pBlkCache, pEntry,
2205 if (!(pEntry->fFlags & PDMBLKCACHE_ENTRY_IO_IN_PROGRESS))
2206 RTSgBufCopyToBuf(&SgBuf, pEntry->pbData + offDiff, cbToWrite);
2210 pdmBlkCacheEntryWaitersAdd(pEntry, pReq,
2224 if (pdmBlkCacheEntryFlagIsSetClearAcquireLock(pBlkCache, pEntry,
2228 pdmBlkCacheEntryWaitersAdd(pEntry, pReq,
2237 RTSgBufCopyToBuf(&SgBuf, pEntry->pbData + offDiff, cbToWrite);
2239 bool fCommit = pdmBlkCacheAddDirtyEntry(pBlkCache, pEntry);
2246 if (pEntry->pList == &pCache->LruFrequentlyUsed)
2249 pdmBlkCacheEntryAddToList(&pCache->LruFrequentlyUsed, pEntry);
2253 pdmBlkCacheEntryRelease(pEntry);
2260 pdmBlkCacheEntryRemoveFromList(pEntry); /* Remove it before we remove data, otherwise it may get freed when evicting data. */
2261 bool fEnough = pdmBlkCacheReclaim(pCache, pEntry->cbData, true, &pbBuffer);
2266 pdmBlkCacheEntryAddToList(&pCache->LruFrequentlyUsed, pEntry);
2267 pdmBlkCacheAdd(pCache, pEntry->cbData);
2271 pEntry->pbData = pbBuffer;
2273 pEntry->pbData = (uint8_t *)RTMemPageAlloc(pEntry->cbData);
2274 AssertPtr(pEntry->pbData);
2276 pdmBlkCacheEntryWaitersAdd(pEntry, pReq,
2280 pdmBlkCacheEntryReadFromMedium(pEntry);
2283 pdmBlkCacheEntryRelease(pEntry);
2289 RTAvlrU64Remove(pBlkCache->pTree, pEntry->Core.Key);
2295 RTMemFree(pEntry);
2408 PPDMBLKCACHEENTRY pEntry;
2434 pEntry = pdmBlkCacheGetCacheEntryByOffset(pBlkCache, offCur);
2436 if (pEntry)
2439 AssertPtr(pEntry->pList);
2441 uint64_t offDiff = offCur - pEntry->Core.Key;
2443 AssertMsg(offCur >= pEntry->Core.Key,
2445 offCur, pEntry->Core.Key));
2447 cbThisDiscard = RT_MIN(pEntry->cbData - offDiff, cbLeft);
2450 if ( (pEntry->pList == &pCache->LruRecentlyUsedIn)
2451 || (pEntry->pList == &pCache->LruFrequentlyUsed))
2454 if (pdmBlkCacheEntryFlagIsSetClearAcquireLock(pBlkCache, pEntry,
2459 if (!(pEntry->fFlags & PDMBLKCACHE_ENTRY_IO_IN_PROGRESS))
2462 pdmBlkCacheEntryRemoveFromList(pEntry);
2465 RTAvlrU64Remove(pBlkCache->pTree, pEntry->Core.Key);
2470 RTMemFree(pEntry);
2476 pdmBlkCacheEntryWaitersAdd(pEntry, pReq,
2484 pdmBlkCacheEntryRelease(pEntry);
2492 if(pdmBlkCacheEntryFlagIsSetClearAcquireLock(pBlkCache, pEntry,
2497 pdmBlkCacheEntryWaitersAdd(pEntry, pReq,
2503 pdmBlkCacheEntryRelease(pEntry);
2508 pdmBlkCacheEntryRemoveFromList(pEntry);
2512 RTAvlrU64Remove(pBlkCache->pTree, pEntry->Core.Key);
2518 RTMemFree(pEntry);
2525 pdmBlkCacheEntryRemoveFromList(pEntry);
2529 RTAvlrU64Remove(pBlkCache->pTree, pEntry->Core.Key);
2535 RTMemFree(pEntry);
2582 PPDMBLKCACHEENTRY pEntry = hIoXfer->pEntry;
2587 pdmBlkCacheEntryRef(pEntry);
2590 pEntry->fFlags &= ~PDMBLKCACHE_ENTRY_IO_IN_PROGRESS;
2594 PPDMBLKCACHEWAITER pComplete = pEntry->pWaitingHead;
2597 AssertMsg((pCurr && pEntry->pWaitingTail) || (!pCurr && !pEntry->pWaitingTail),
2599 pEntry->pWaitingTail = NULL;
2600 pEntry->pWaitingHead = NULL;
2613 pEntry->Core.Key, pEntry->cbData, pBlkCache->pszId, rcIoXfer));
2629 pEntry->fFlags &= ~PDMBLKCACHE_ENTRY_IS_DIRTY;
2635 RTSgBufCopyToBuf(&pCurr->SgBuf, pEntry->pbData + pCurr->offCacheEntry, pCurr->cbTransfer);
2643 AssertMsg(!(pEntry->fFlags & PDMBLKCACHE_ENTRY_IS_DIRTY),
2650 RTSgBufCopyToBuf(&pCurr->SgBuf, pEntry->pbData + pCurr->offCacheEntry, pCurr->cbTransfer);
2654 RTSgBufCopyFromBuf(&pCurr->SgBuf, pEntry->pbData + pCurr->offCacheEntry, pCurr->cbTransfer);
2662 fCommit = pdmBlkCacheAddDirtyEntry(pBlkCache, pEntry);
2667 pdmBlkCacheEntryRelease(pEntry);
2697 PPDMBLKCACHEENTRY pEntry = (PPDMBLKCACHEENTRY)pNode;
2698 PPDMBLKCACHE pBlkCache = pEntry->pBlkCache;
2701 while (ASMAtomicReadU32(&pEntry->fFlags) & PDMBLKCACHE_ENTRY_IO_IN_PROGRESS)
2704 pdmBlkCacheEntryRef(pEntry);
2711 pdmBlkCacheEntryRelease(pEntry);
2714 AssertMsg(!(pEntry->fFlags & PDMBLKCACHE_ENTRY_IO_IN_PROGRESS),
2715 ("Entry is dirty and/or still in progress fFlags=%#x\n", pEntry->fFlags));