* Only start recycling oschunks once MaxKeptOSChunks chuncks have

been allocated. E.g. allocate 100 blocks of 80 bytes and free them
    all, then the same with blocks of 96, 112, 128, 144, 160 and 176
    bytes, after which again 80 bytes -> previously, regardless of
    the value of MaxKeptOSChunks, the empty block for 80 bytes was
    reformatted for those of 96 bytes, then for 112 bytes etc. Now,
    if MaxKeptOSChunks is set to 7, none will ever be reformatted
    because enough chunks will be allocated from the OS.

git-svn-id: trunk@9696 -
This commit is contained in:
Jonas Maebe 2008-01-09 20:39:59 +00:00
parent 588822b14d
commit eb83213f10

View File

@ -729,36 +729,40 @@ begin
maxsize := 1 shl (32-fixedoffsetshift)
else
maxsize := high(ptruint);
{ blocks available in freelist? }
poc := find_free_oschunk(loc_freelists, minsize, maxsize, size);
if not assigned(poc) and (assigned(orphaned_freelists.waitfixed)
or assigned(orphaned_freelists.waitvar) or (orphaned_freelists.oscount > 0)) then
poc:=nil;
if (loc_freelists^.oscount>=MaxKeptOSChunks) then
begin
entercriticalsection(heap_lock);
finish_waitfixedlist(@orphaned_freelists);
finish_waitvarlist(@orphaned_freelists);
if orphaned_freelists.oscount > 0 then
{ blocks available in freelist? }
poc := find_free_oschunk(loc_freelists, minsize, maxsize, size);
if not assigned(poc) and (assigned(orphaned_freelists.waitfixed)
or assigned(orphaned_freelists.waitvar) or (orphaned_freelists.oscount > 0)) then
begin
{ blocks available in orphaned freelist ? }
poc := find_free_oschunk(@orphaned_freelists, minsize, maxsize, size);
if assigned(poc) then
entercriticalsection(heap_lock);
finish_waitfixedlist(@orphaned_freelists);
finish_waitvarlist(@orphaned_freelists);
if orphaned_freelists.oscount > 0 then
begin
{ adopt this os chunk }
poc^.freelists := loc_freelists;
if assigned(poc^.prev_any) then
poc^.prev_any^.next_any := poc^.next_any
else
orphaned_freelists.oslist_all := poc^.next_any;
if assigned(poc^.next_any) then
poc^.next_any^.prev_any := poc^.prev_any;
poc^.next_any := loc_freelists^.oslist_all;
if assigned(loc_freelists^.oslist_all) then
loc_freelists^.oslist_all^.prev_any := poc;
poc^.prev_any := nil;
loc_freelists^.oslist_all := poc;
{ blocks available in orphaned freelist ? }
poc := find_free_oschunk(@orphaned_freelists, minsize, maxsize, size);
if assigned(poc) then
begin
{ adopt this os chunk }
poc^.freelists := loc_freelists;
if assigned(poc^.prev_any) then
poc^.prev_any^.next_any := poc^.next_any
else
orphaned_freelists.oslist_all := poc^.next_any;
if assigned(poc^.next_any) then
poc^.next_any^.prev_any := poc^.prev_any;
poc^.next_any := loc_freelists^.oslist_all;
if assigned(loc_freelists^.oslist_all) then
loc_freelists^.oslist_all^.prev_any := poc;
poc^.prev_any := nil;
loc_freelists^.oslist_all := poc;
end;
end;
leavecriticalsection(heap_lock);
end;
leavecriticalsection(heap_lock);
end;
if poc = nil then
begin
@ -1050,7 +1054,7 @@ begin
end;
dec(loc_freelists^.internal_status.currheapused, chunksize);
{ insert the block in it's freelist }
{ insert the block in its freelist }
chunkindex := chunksize shr blockshift;
pmc_next := loc_freelists^.fixedlists[chunkindex];
pmc^.prev_fixed := nil;