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