You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
For a port of TLSF to our systems programming language, I had the requirement to be able to recover the requested size from a block, rather than the adjusted size. I implemented it in my port, and so far it turns out to work well, with no new spatial overhead added. I thought I'd let you know how it works, in case you (maintainer or user) are interested in replicating it:
block.size now stores the requested size shifted by two bits - for 64-bit that's no problem, but for 32-bit we'd truncate two bits (though I see the implementation has a 30-bit limit there anyway).
block_set_size() now accepts the requested size rather than the adjusted size.
block_size() transparently aligns the returned size by ALIGN_SIZE; since in all previous adjustments, adjust == align_up(size, ALIGN_SIZE), this effectively has block_size() work as it did before.
block_absorb() uses block_set_size(block_size(prev) + block_size(block) + block_header_overhead) rather than offsetting prev.size directly, which fixes the operation for the new format and also quantizes the block size of free blocks.
block_split() receives both adjusted and requested size; adjust is used for all calculations; request is passed to block_set_size().
likewise, block_trim_free(), block_trim_used(), block_prepare_used() forward the requested size along with the adjusted size.
block_trim_free_leading() just passes the same remaining size to both adjusted and requested size.
malloc() and memalign() pass the requested size to block_prepare_used() along with the adjusted size.
tlsf_realloc() passes the requested size to block_trim_used() along with the adjusted size.
a new API function tlsf_block_request_size() retrieves the requested size from block.size, without aligning it.
The text was updated successfully, but these errors were encountered:
paniq
changed the title
Feature: query requested size from block
Feature: query requested size from block (with recipe)
Feb 20, 2024
This seems well researched and magically delicious. It would be a great boon to the library if this works. It's a great slide at the end of a presentation "Oh and by the way, you don't have to remember how big your allocations are... we do." and then it's a dropped mic and a standing ovation. Definitely worth further investigation.
For a port of TLSF to our systems programming language, I had the requirement to be able to recover the requested size from a block, rather than the adjusted size. I implemented it in my port, and so far it turns out to work well, with no new spatial overhead added. I thought I'd let you know how it works, in case you (maintainer or user) are interested in replicating it:
block.size
now stores the requested size shifted by two bits - for 64-bit that's no problem, but for 32-bit we'd truncate two bits (though I see the implementation has a 30-bit limit there anyway).block_set_size()
now accepts the requested size rather than the adjusted size.block_size()
transparently aligns the returned size byALIGN_SIZE
; since in all previous adjustments,adjust == align_up(size, ALIGN_SIZE)
, this effectively hasblock_size()
work as it did before.block_absorb()
usesblock_set_size(block_size(prev) + block_size(block) + block_header_overhead)
rather than offsettingprev.size
directly, which fixes the operation for the new format and also quantizes the block size of free blocks.block_split()
receives both adjusted and requested size;adjust
is used for all calculations;request
is passed toblock_set_size()
.block_trim_free()
,block_trim_used()
,block_prepare_used()
forward the requested size along with the adjusted size.block_trim_free_leading()
just passes the same remaining size to both adjusted and requested size.malloc()
andmemalign()
pass the requested size toblock_prepare_used()
along with the adjusted size.tlsf_realloc()
passes the requested size toblock_trim_used()
along with the adjusted size.tlsf_block_request_size()
retrieves the requested size fromblock.size
, without aligning it.The text was updated successfully, but these errors were encountered: