LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   User level memory fragmentation problem? (https://www.linuxquestions.org/questions/linux-software-2/user-level-memory-fragmentation-problem-48688/)

DHC 03-07-2003 05:32 AM

User level memory fragmentation problem?
 
Hope someone can help with this. I've got a small program (happens to be java but the same code / jdk works fine on Solaris and windoze) that performs a lot of small mallocs. Actually my code doesn't, but putting in malloc hooks shows masses of em comming from the jre). If I run this program repeatedly eventually it'll SEGV in core_alloc ("below" malloc). (The program completes within a second and fails typically after a few hundred or thousand iterations.)

I've read a little about memory fragmentation and suspect this may be the cause. cat /proc/meminfo shows anything between 10 and 40 meg free at the time of the failure BTW...

The solutions I'm looking for therefore are:
- is memory fragmentation a likely cause of the problem?
- Presuming it is; performance isn't an issue - is there anything that can be run prior to the program on each iteration to get the system to "flush" it's pages (or whatever's required). The program is always run as root in normal operation (but also shows the same problem as a "regular" user).

Running SuSE (2.4.0-4GB kernel).

Many thanks in advance. I'm completely stuck on this so any help is very much appreciated.

loke137 03-07-2003 08:02 AM

I am a complete newbie to coding, so all I say might me BS. But I will still say it :).
When you allocate memory, you should always free it at the end of the program right?
Also what are you iterating so much(well, not that much)? Could you give us the code so we can look at it and maybe search for a more eficient algorithm?
In college, I have done stupid recursive factorials programs with Pascal, they couldnt go past 15! . So if your algorithm is factorial, that might be the problem!

DHC 03-07-2003 09:00 AM

Loke - thanks for the reply...

No - no need to free memory you've allocated in terms of "giving it back" to the system - any allocated heap memory (e.g. with malloc) is freed up when the program exits. At least in user space :O)

Having difficulty producing a small concise chunk of code that re-creates the problem as the particular code I'm using does or doesn't SEGV depending on the ordering of the .JAR files I add to the classpath. I believe that FindClass is causing a lot of memory fragmentation searching through the jars to find the class I want, so my question's more of a general one. If this is a memory fragmentation issue, a short program with lots of mallocs / frees should re-create it in theory.

BTW - the recursion you're talking about uses the stack.

Cheers.

loke137 03-07-2003 11:42 AM

Oh, I grasp the problem, but it is past my current knowledge, sorry


All times are GMT -5. The time now is 01:03 AM.