packagefs: Add caching for the package file heap reader

* ReaderImplBase:
  - Add virtual CreateCachedHeapReader() which can create a cached
    reader based on the given heap reader.
  - Rename HeapReader() to RawHeapReader() and add HeapReader() for the
    cached heap reader.
  - Add DetachHeapReader() to allow a clients to remove the heap
    reader(s) after deleting the ReaderImplBase object.
* packagefs:
  - Add CachedDataReader class, which wraps a given
    BAbstractBufferedDataReader and provides caching for it using a
    VMCache. The implementation is based on the IOCache implementation.
  - Use CachedDataReader to wrap the heap reader. For file data that
    means they are cached twice -- in the heap reader cache and in the
    file cache -- but due to the heap reader using a VMCache as well,
    the pages will be recycled automatically anyway. For attribute data
    the cache should be very helpful, since they weren't cached at all
    before.
This commit is contained in:
Ingo Weinhold
2013-05-25 01:12:32 +02:00
parent 69a1f1f53f
commit 46122852f1
12 changed files with 757 additions and 51 deletions
@@ -40,7 +40,9 @@ public:
uint64 HeapOffset() const;
uint64 HeapSize() const;
PackageFileHeapReader* HeapReader() const
PackageFileHeapReader* RawHeapReader() const
{ return inherited::RawHeapReader(); }
BAbstractBufferedDataReader* HeapReader() const
{ return inherited::HeapReader(); }
protected:
+23 -2
View File
@@ -26,6 +26,7 @@ namespace BPackageKit {
namespace BHPKG {
class BAbstractBufferedDataReader;
class BErrorOutput;
@@ -71,8 +72,23 @@ protected:
BErrorOutput* ErrorOutput() const;
PackageFileHeapReader* HeapReader() const
uint64 UncompressedHeapSize() const;
PackageFileHeapReader* RawHeapReader() const
{ return fRawHeapReader; }
BAbstractBufferedDataReader* HeapReader() const
{ return fHeapReader; }
// equals RawHeapReader(), if uncached
BAbstractBufferedDataReader* DetachHeapReader(
PackageFileHeapReader** _rawHeapReader
= NULL);
// Detaches both raw and (if applicable)
// cached heap reader. The called gains
// ownership. The FD may need to be set on
// the raw heap reader, if it shall be used
// after destroying this object and Init()
// has been called with keepFD == true.
protected:
class AttributeHandlerContext;
@@ -95,6 +111,10 @@ protected:
uint32 chunkSize, off_t offset,
uint64 compressedSize,
uint64 uncompressedSize);
virtual status_t CreateCachedHeapReader(
PackageFileHeapReader* heapReader,
BAbstractBufferedDataReader*&
_cachedReader);
status_t InitSection(PackageFileSection& section,
uint64 endOffset, uint64 length,
uint64 maxSaneLength, uint64 stringsLength,
@@ -156,7 +176,8 @@ private:
int fFD;
bool fOwnsFD;
PackageFileHeapReader* fHeapReader;
PackageFileHeapReader* fRawHeapReader;
BAbstractBufferedDataReader* fHeapReader;
PackageFileSection* fCurrentSection;