简体   繁体   English

碎片内存是什么样的?

[英]What does fragmented memory look like?

I have a mobile application that is suffering from slow-down over time. 我有一个移动应用程序,该应用程序随着时间的推移会变慢。 My hunch, (In part fed by this article ,) is that this is due to fragmentation of memory slowing the app down, but I'm not sure. 我的直觉(部分由本文提供 )是由于内存碎片使应用程序变慢,但我不确定。 Here's a pretty graph of the app's memory use over time: 这是一段时间内应用程序的内存使用情况的漂亮图表:

fraggle rock http://kupio.com/image-dump/fragmented.png 脆弱的岩石http://kupio.com/image-dump/fragmented.png

The 4 peaks on the graph are 4 executions of the exact same task on the app. 图上的4个峰值是应用程序上完全相同的任务的4次执行。 I start the task, it allocates a bunch of memory, it sits for a bit (The flat line on top) and then I stop the task. 我开始执行任务,它分配了一堆内存,它坐了一会儿(顶部的平线),然后我停止了任务。 At that point it calls System.gc(); 那时它调用System.gc();。 and the memory gets cleaned up. 内存就被清理了

As can be seen, each of the 4 runs of the exact same task take longer to execute. 可以看出,完全相同的任务的4次运行中的每一次都需要更长的时间才能执行。 The low-points in the graph all return to the same level so there do not seem to be any memory leaks between task runs. 图中的低点全部恢复到同一级别,因此任务运行之间似乎没有任何内存泄漏。

What I want to know is, is memory fragmentation a feasible explanation or should I look elsewhere first, bearing in mind that I've already done a lot of looking? 我想知道的是,内存碎片是一个可行的解释,还是我应该首先考虑一下其他方面? The low-points on the graph are relatively low so my assumption is that in this state the memory would not be very fragmented since there can't be a lot of small memory holes to be causing problems. 图上的低点相对较低,因此我的假设是,在这种状态下内存不会非常分散,因为不会有很多小的内存孔引起问题。

I don't know how the j2me memory allocator works though, so I really don't know. 我不知道j2me内存分配器的工作原理,所以我真的不知道。 Can anyone advise? 有人可以建议吗? Has anyone else had problems with this and recognises the memory profile of the app? 还有其他人对此有疑问并可以识别应用程序的内存配置文件吗?

If you've got a little bit of time, you could test your theory by re-using the memory by using Memory Pool techniques: each run of the task uses the 'same' chunks of memory by getting them from the pool and returning them at release time. 如果您有一点时间,可以通过使用“内存池”技术重用内存来检验您的理论:每次任务运行都通过从池中获取并返回它们来使用“相同”的内存块在发布时。

If you're still seeing the degrading performance after doing this investigation, it's not memory fragmentation causing the problem. 如果进行完此调查后仍然发现性能下降,则不是内存碎片引起问题。 Let us all know your results and we can help troubleshoot further. 让我们都知道您的结果,我们可以帮助您进行进一步的故障排除。

Memory fragmentation would account for it... what is not clear is whether the Apps use of memory is causing paging? 内存碎片会造成这种情况...目前尚不清楚Apps是否使用内存导致分页? this would also slow things up.... and could cause the same issues. 这也会使事情变慢....并可能导致相同的问题。

It the problem really is memory fragmentation, there is not much you can do about it. 问题确实是内存碎片,您无能为力。

But before you give up in despair, try running your app with a execution profiler to see if it is spending a lot of time executing in an unexpected place. 但是在您绝望地放弃之前,请尝试使用执行事件探查器运行您的应用程序,以查看它是否花费大量时间在意外的地方执行。 It is possible that the slow down is actually due to a problem in your algorithms, and nothing to do with memory fragmentation. 速度减慢实际上可能是由于算法问题引起的,与内存碎片无关。 As people have already said, J2ME garbage collectors should not suffer from fragmentation issues. 正如人们已经说过的那样,J2ME垃圾收集器不应遭受碎片问题的困扰。

Consider looking at garbage collection statistics. 考虑查看垃圾收集统计信息。 You should have a lot more on the last run than the first, if your theory is to hold. 如果您的理论要坚持下去,那么您在最后一次运行中应该比第一次运行更多。 Another thought might be that something else eats your memory so your application has less. 另一个想法可能是其他东西占用了您的内存,因此您的应用程序更少了。

In other words, profiler time :) 换句话说,探查器时间:)

What OS are you running this on? 您在什么操作系统上运行它? I have some experience with Windows CE5 (or Windows Mobile) devices. 我对Windows CE5(或Windows Mobile)设备有一定的经验。 CE5's operating system level memory architecture is quite broken and will fail soon for memory intensive applications. CE5的操作系统级内存体系结构已被破坏,并且对于内存密集型应用程序将很快失效。 Your graph does not have any scales, but every process only gets 32MB of address space on CE5. 您的图形没有任何比例,但是每个进程在CE5上仅获得32MB的地址空间。 The VM and shared libraries will take their fair share of that as well, leaving you with quite little left. VM和共享库也将尽其所能,从而使您所剩无几。 The only way around this is to re-use the memory you allocated instead of giving it back to the collector and re-allocating later. 解决此问题的唯一方法是重新使用分配的内存,而不是将其返回给收集器并在以后重新分配。 This is, of course, much more low-level programming than you would usually want to do in Java, but on this platform you might be out of luck. 当然,这比您通常希望在Java中进行的底层编程要多得多,但是在此平台上,您可能会不走运。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM