This is the mail archive of the ecos-patches@sources.redhat.com mailing list for the eCos project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

redboot decompress.c fixes


Whilst playing with the new JFFS2 support in RedBoot (good stuff!) I
found that the zcalloc and zcfree routines in RedBoot's decompress.c
were leaking memory on free. This was causing the memory pool to run out
while loading large files, such as vmlinuz...

The basic problem was that on allocate the memlist pointer was moved to
the next free block -- this had the effect that blocks which were now
before the start of the list may not be added to the free list correctly
when they were free'd. There was also a bug WRT merging adjacent free
blocks on free, which could lead to fragmentation.

The first change was to make the size field in struct _block always
represent the total size of the block including the header. Previously
it was the whole block for free blocks and just the allocated size for
allocated blocks, which was confusing (and not quite correctly
implemented I think).

I then changed the semantics of the magic field. It is now
__ZLIB__MAGIC__ for allocated blocks and 0 for unallocated ones.

With these changes I made the memlist pointer always point to the start
of the memory pool and arranged things such that all blocks (not just
the free ones) appear in the list. Free blocks are selected on the basis
that their magic field is 0.

Then I replaced the self field with a prev field. The self field was not
used, except for validating a block and we already have magic for that.
Having a prev field makes merging freed blocks behind the current block
in zcalloc much more efficient since you don't need to scan from the
start of the list.

Finally, JFFS2 never calls gzip_init (I don't think...), so I added
initialisation of the pool to zlib_init (as well).

Cheers,
Ian.
-- 
Ian Campbell, Senior Design Engineer
                                        Web: http://www.arcom.com
Arcom, Clifton Road, 			Direct: +44 (0)1223 403 465
Cambridge CB1 7EA, United Kingdom	Phone:  +44 (0)1223 411 200


_____________________________________________________________________
The message in this transmission is sent in confidence for the attention of the addressee only and should not be disclosed to any other party. Unauthorised recipients are requested to preserve this confidentiality. Please advise the sender if the addressee is not resident at the receiving end.

This message has been checked for all viruses by MessageLabs Virus Control Centre.

Attachment: redboot-decompress.patch
Description: Text document


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]