newlib malloc updated to prevent memory fragment

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

Moderators: cheriff, TyRaNiD

Post Reply
hrimfaxi
Posts: 20
Joined: Thu Nov 23, 2006 5:40 pm

newlib malloc updated to prevent memory fragment

Post by hrimfaxi »

Hi, folks. Recently I found out if we update newlib-psp malloc version to the latest malloc-2.8.4, the memory fragment after a mass of allocating-and-freeing memory operations will significantly reduce.

I ported it to newlib-psp-1.17.0. If anyone who suffered from the memory fragment should test this patch.

Note:
1. Already use a spinlock to guarantee thread-safety, no need to define __malloc_lock.
2. Can be slightly slower than original. Or you can define INSECURE to 1 to skip the sanity check for speed.

Install:

wget ftp://sources.redhat.com/pub/newlib/new ... 7.0.tar.gz
tar -zxvf newlib-1.17.0.tar.gz
cd newlib-1.17.0
patch -p1 < ../newlib-1.17.0-psp-malloc-2.8.4.patch
./configure --prefix=$PSPDEV --target=psp && make && make install

patch download: http://ifile.it/kt2pqi9
coolkehon
Posts: 355
Joined: Mon Oct 20, 2008 5:44 am

Post by coolkehon »

link is down
User avatar
Wally
Posts: 663
Joined: Mon Sep 26, 2005 11:25 am

Post by Wally »

coolkehon wrote:link is down
No its not, quite a complicated site.
coolkehon
Posts: 355
Joined: Mon Oct 20, 2008 5:44 am

Post by coolkehon »

Wally wrote:
coolkehon wrote:link is down
No its not, quite a complicated site.
what?
what are you trying to do?
User avatar
Wally
Posts: 663
Joined: Mon Sep 26, 2005 11:25 am

Post by Wally »

I've rehosted the script at

www.spiffup.org/newlib-1.17.0-psp-malloc-2.8.4.rar

Enjoy!
coolkehon
Posts: 355
Joined: Mon Oct 20, 2008 5:44 am

Post by coolkehon »

thanks
SamuraiX
Posts: 76
Joined: Tue Jan 31, 2006 6:28 am
Location: USA
Contact:

Post by SamuraiX »

Has the toolchain been updated to include this new patch, should i update my svn view and rebuild the SDK? I guess what I mean is.... has it been checked in yet as this would prove to be very handy update for my development.
hrimfaxi
Posts: 20
Joined: Thu Nov 23, 2006 5:40 pm

Post by hrimfaxi »

SamuraiX wrote:Has the toolchain been updated to include this new patch, should i update my svn view and rebuild the SDK? I guess what I mean is.... has it been checked in yet as this would prove to be very handy update for my development.
No, you needn't.
SamuraiX
Posts: 76
Joined: Tue Jan 31, 2006 6:28 am
Location: USA
Contact:

Post by SamuraiX »

I've gotten around to compiling this version of newlib using the following instructions above.

The Good News:
I went from 6246484 Bytes of fragmented memory to 4759612 Bytes. Thats about 23.8% Savings!

The Bad News:
I still have quite a bit of fragmented memory...


If anyone has any suggestions on how to lower fragmented memory or suggest another type of malloc where fragmented memory is even lower then please let me know.
fungos
Posts: 41
Joined: Wed Oct 31, 2007 10:43 am
Location: cwb br
Contact:

Post by fungos »

@SamuraiX try to use pools, it will reduce a lot your fragmentation if you have a lot of tiny allocations (ie. strings and structs/classes).
Another thing is to reduce your allocations, we are used to alloc much more than we really need.
My games have _almost_ none alloc/new (resource loading ONLY) and I have almost no fragmentation as all my resources are loaded at beginning of a game state and automatically unloaded when switching to another state. These basic things saved me from so much trouble.
Post Reply