summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Adithya Srinivasan <adsrini@google.com> 2021-03-05 20:43:32 +0000
committer Adithya Srinivasan <adsrini@google.com> 2021-03-05 23:03:27 +0000
commitd17c7da60c76150cff134bd1920499bfbfbd6ba3 (patch)
treeec38ab27712df8f6d4cd231c7cbf8a6df1879644
parent8503741e01bc6464974eec29690766860ee4ff69 (diff)
Fix a memory leak with pending jank classifications
If the front of the pendingJankClassification deque is stuck(FrameTimeline never received it) for some reason, the current logic never releases it and the deque keeps growing in size until the layer itself is destroyed. This has resulted in some memory leaks recently. Bug: 181328447 Test: heap_prof trace Change-Id: If71225f52da3bbd9b0b0d46af75f933fd48d5bd5
-rw-r--r--services/surfaceflinger/BufferStateLayer.cpp8
-rw-r--r--services/surfaceflinger/BufferStateLayer.h2
2 files changed, 10 insertions, 0 deletions
diff --git a/services/surfaceflinger/BufferStateLayer.cpp b/services/surfaceflinger/BufferStateLayer.cpp
index 3137ee72fe..4724ef8b8a 100644
--- a/services/surfaceflinger/BufferStateLayer.cpp
+++ b/services/surfaceflinger/BufferStateLayer.cpp
@@ -171,6 +171,14 @@ void BufferStateLayer::onLayerDisplayed(const sp<Fence>& releaseFence) {
void BufferStateLayer::onSurfaceFrameCreated(
const std::shared_ptr<frametimeline::SurfaceFrame>& surfaceFrame) {
+ while (mPendingJankClassifications.size() >= kPendingClassificationMaxSurfaceFrames) {
+ // Too many SurfaceFrames pending classification. The front of the deque is probably not
+ // tracked by FrameTimeline and will never be presented. This will only result in a memory
+ // leak.
+ ALOGW("Removing the front of pending jank deque from layer - %s to prevent memory leak",
+ mName.c_str());
+ mPendingJankClassifications.pop_front();
+ }
mPendingJankClassifications.emplace_back(surfaceFrame);
}
diff --git a/services/surfaceflinger/BufferStateLayer.h b/services/surfaceflinger/BufferStateLayer.h
index 175a40b80e..44a7bb53db 100644
--- a/services/surfaceflinger/BufferStateLayer.h
+++ b/services/surfaceflinger/BufferStateLayer.h
@@ -173,6 +173,8 @@ private:
nsecs_t mCallbackHandleAcquireTime = -1;
std::deque<std::shared_ptr<android::frametimeline::SurfaceFrame>> mPendingJankClassifications;
+ // An upper bound on the number of SurfaceFrames in the pending classifications deque.
+ static constexpr int kPendingClassificationMaxSurfaceFrames = 25;
const std::string mBlastTransactionName{"BufferTX - " + mName};
// This integer is incremented everytime a buffer arrives at the server for this layer,