Where did my memory go? (10-12M non malloc'able)

Discuss the development of new homebrew software, tools and libraries.

Moderators: cheriff, TyRaNiD

Post Reply
Beuc
Posts: 33
Joined: Thu Mar 26, 2009 5:04 am
Location: holland

Where did my memory go? (10-12M non malloc'able)

Post by Beuc »

Hi,

I was investigating an out-of-memory crash, and I found that malloc doesn't alloc all available memory:

Code: Select all

  int tmalloc = 0;
  while (malloc(1024) != NULL)
    tmalloc += 1024;
/*   while (malloc(1024*1024) != NULL) */
/*     tmalloc += 1024*1024; */
  printf("tmalloc = %d\n", tmalloc);
  /* FW 1.50 => 10910720 / 10485760 (normally 24000kB) */
  /* FW 5.00 => 39819264 / 39845888 (normally 52500kB) */
The test, by malloc'ing blocks of 1kB or 1MB, always leaves a good 10-12MB untouched.

I'm running the tests on a PSP2, first with firmware 1.50(+3.40hw), then from 5.00 M33-6, compiled as .prx and run from PSPLink.

My .prx is around 2.2.MB.
When I strip my application to get a minimal main that only does the test, I go back to 53000k.

Any clue? :)


Btw, even with a minimal program and just checking sceKernelTotalFreeMemSize(), we loose 8-10MB from the start (24M PSP1 / 53M PSP2). How comes? :/
J.F.
Posts: 2906
Joined: Sun Feb 22, 2004 11:41 am

Post by J.F. »

Like most OSes, the OS in the PSP is loaded from rom into ram. So that "missing" 8 to 10 MB is mostly kernel code and data. Some of the rest is the size of the app loaded. The rest are the user mode PRXs loaded that allow your app to load, run, and call the kernel.

As to the first part, what are you using to define the heap size in the app? I normally use something like "PSP_HEAP_SIZE_KB(-256);", which means gimme everything except for 256 KB.
Beuc
Posts: 33
Joined: Thu Mar 26, 2009 5:04 am
Location: holland

Post by Beuc »

J.F. wrote:As to the first part, what are you using to define the heap size in the app? I normally use something like "PSP_HEAP_SIZE_KB(-256);", which means gimme everything except for 256 KB.
I found that I have 10M of data segment (.bss) in my executable (e.g. static struct arrays), which looks like the main culprit here :)

I'm still puzzled at why the missing size is different when running under 1.50 and 5.00.
J.F. wrote:Like most OSes, the OS in the PSP is loaded from rom into ram. So that "missing" 8 to 10 MB is mostly kernel code and data. Some of the rest is the size of the app loaded. The rest are the user mode PRXs loaded that allow your app to load, run, and call the kernel.
Thanks. I was under the impression that the main OS was unloading itself before running a homebrew, but maybe that's just an impression :/

And there's the additional SEPLUGINS, indeed.
Post Reply