Package Kit: Use an object_cache in kernel mode for decompression buffers.

The kernel heap only uses object caches for objects up to size 8192.
Larger allocations have to go through the raw allocator. That can
get pretty expensive.

Adding instrumentation around the malloc/free calls in this function
showed that on my machine, some 596ms during boot were spent on
*malloc/free alone*, all else aside. After this change, we are at
around 110ms, or a >5x improvement. Running an fgrep -R on /system/
after boot increased the cumulative time in memory functions to over
5 seconds, while after this change it is "only" 1170ms.

Honestly, it seems like the object depots should be able to be faster
than that, even if this function is called thousands of times. But that
is a problem for a different investigation.

It would be even faster for every consumer of this data in
packagefs just allocated one set of buffers up front, or at least
for a single "read session", but plumbing that all the way
through the myriad abstractions of the Package Kit will
not be easy, and is left for another time, as well.
This commit is contained in:
Augustin Cavalier
2023-02-28 13:49:00 -05:00
parent 4e51d4b707
commit 0ecd7516de
3 changed files with 61 additions and 4 deletions
@@ -98,6 +98,9 @@ public:
public:
static const size_t kChunkSize = 64 * 1024;
#if defined(_KERNEL_MODE)
static void* sChunkCache;
#endif
protected:
virtual status_t ReadAndDecompressChunk(size_t chunkIndex,