summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2019-07-06 23:52:31 +0200
committerwm4 <wm4@nowhere>2019-09-19 20:37:05 +0200
commit11027e99f246371837f9d866936066282da11b9f (patch)
treef3ad4512fec7732a6b8f0a2b5a5d44226b66cea3
parent3cea180cc05cbf5f270e171f710f11288a1d2dfe (diff)
downloadmpv-11027e99f246371837f9d866936066282da11b9f.tar.bz2
mpv-11027e99f246371837f9d866936066282da11b9f.tar.xz
packet: change memory estimation heuristics
Determining how much memory something uses is very hard, especially in high level code (yes we call code using malloc high level). There's no way to get an exact amount, especially since the malloc arena is shared with the entire process anyway. So the demuxer packet cache tries to get by with an estimate using a number of rough guesses. It seems this wasn't quite good. In some ways, it was too optimistic, in others it seemed to account for too much data. Try to get it closer to what malloc and ta probably do. In particular, talloc adds some singificant overhead (using talloc for mass-data was a mistake, and it's even my fault). The result appears to match better with measured memory usage. This is still extremely dependent on malloc implementation and so on. The effect is that you may need to adjust the demuxer cache limits to cache as much data as it did before this commit. In any case, seems to be better for me.
-rw-r--r--demux/packet.c7
1 files changed, 5 insertions, 2 deletions
diff --git a/demux/packet.c b/demux/packet.c
index d4060c12a2..b456df4ab2 100644
--- a/demux/packet.c
+++ b/demux/packet.c
@@ -164,7 +164,7 @@ struct demux_packet *demux_copy_packet(struct demux_packet *dp)
return new;
}
-#define ROUND_ALLOC(s) MP_ALIGN_UP(s, 64)
+#define ROUND_ALLOC(s) MP_ALIGN_UP((s), 16)
// Attempt to estimate the total memory consumption of the given packet.
// This is important if we store thousands of packets and not to exceed
@@ -177,12 +177,15 @@ struct demux_packet *demux_copy_packet(struct demux_packet *dp)
size_t demux_packet_estimate_total_size(struct demux_packet *dp)
{
size_t size = ROUND_ALLOC(sizeof(struct demux_packet));
+ size += 8 * sizeof(void *); // ta overhead
+ size += 10 * sizeof(void *); // additional estimate for ta_ext_header
if (dp->avpacket) {
assert(!dp->is_cached);
size += ROUND_ALLOC(dp->len);
size += ROUND_ALLOC(sizeof(AVPacket));
+ size += 8 * sizeof(void *); // ta overhead
size += ROUND_ALLOC(sizeof(AVBufferRef));
- size += 64; // upper bound estimate on sizeof(AVBuffer)
+ size += ROUND_ALLOC(64); // upper bound estimate on sizeof(AVBuffer)
size += ROUND_ALLOC(dp->avpacket->side_data_elems *
sizeof(dp->avpacket->side_data[0]));
for (int n = 0; n < dp->avpacket->side_data_elems; n++)