Jump to content

  • Log In with Google      Sign In   
  • Create Account

#Actualcr88192

Posted 13 July 2013 - 03:28 PM

Thanks for your answers.
 

for example, I do most of my general-purpose memory allocation via a custom heap-style allocator, rather than using pool-based or region-based allocators.


Using an heap (free list) allocator don't you have fragmentation problems? After a while of loading/unloading of different sizes the memory will most likely become fragmented, how do you deal with it?

 


for the most part, I don't (I don't really try to deal with it, but it doesn't really seem to be too big of an issue either, at least vs general memory usage).


however, after a while, one may observe a pattern:
for the most part, the various sizes of free-lists will become filled with various amounts of various-sized memory objects, and (assuming that leaks are not present), will often eventually tend towards stabilizing (few or no general-purpose allocations of new memory objects in this size range, though with large numbers of allocations/frees within a given size of free-list).

typically, the existence of memory objects of various sizes (allocated and available) tends to resemble a histogram (roughly following a Gaussian distribution), with very large numbers of small objects (< 4kB), followed by progressive decreases as sizes get larger, though often with a few spikes (for example, in my engine, there is typically a fairly big spike around 32kB, which is the natural size of an uncompressed voxel chunk). larger memory objects tend to be fairly sparse.

as-is, objects < 4kB comprise around 30-40% of the total memory use in my case, with 32kB chunks and occasional large objects making up most of the rest. of these small objects, the number of objects is roughly inversely related to size (with 0-15 and 16-31 byte objects having object-counts in the millions).

objects under 64kB in-general tend to represent the majority (around 80%) of total memory use in my engine.

above this tends mostly to be largish semi-permanent data structures (such as PAK-files, video files, region files, buffers for decoded video frames, the console buffer, ...), and occasionally temporary buffers. many of these tend to range between 100s of KB and into the MB range.

granted, these dumps were usually made in cases where the engine was low on memory (typically because the available 32-bit address space was pretty much used up...).


some specific types of small memory objects are also handled specially (namely things like cons-cells and boxed-values).
a cons cell is basically a pair of tagged-pointers (traditionally called 'car' and 'cdr'), and typically boxed values are things like boxed-longs and boxed-doubles. in the former case, the MM manages these specially (they have their own heap), and boxed-values in general use slab allocation (and lack individual headers). these are not counted in the above stats (which were for the general allocator), but likewise tend to have fairly high allocation counts (also in the millions).

most other things are mostly things like strings and various small structures and similar.


having all objects in a given free list be the same size also helps some.
if each object has to be an exact number of bytes, this creates a mess.
however, with a given number of cells, the same object may hold a certain range of memory-object sizes.

say, we have a 17x16-cell object:
it can hold an allocation anywhere from 240-256 bytes.

typically, after a little while, one then hits a plateau of the number of objects of that given size range.


fragmentation is potentially still an issue for larger objects, but luckily these are relatively uncommon.

a lot of this is likely to depend a lot on the specific engine though.
 

 

ADD (specifics):

while each free list contains fixed size objects, there are a fair number of free lists:

256 free-lists for small objects (in increments of 16 bytes);

256 free-lists for medium objects (in increments of 256 bytes);

...

 

small/medium objects, as noted, can have their background memory managed by by cells and bitmaps;

large objects are generally managed by sorted arrays (managed via binary searches and positional inserts).

 

there is actually a fairly involved set of algorithms responsible for dealing with the case where the relevant free-list is empty, and linearly scanning for a sufficient span of free cells fails to find free memory (it tries to reclaim memory from other free-lists, considers trying to expand the heap, ...).

 

in a few cases, "memory usage probes" are used by some logic to evaluate some decisions, like whether or not to load voxel-chunks, as well as temporarily reducing the view radius (to try to reduce memory pressure by forcing distant chunks to be unloaded). this basically means, for example, that if memory-usage exceeds 65% of maximum, then the view radius drops to 192 meters, and then to 128 meters at 70%.

 

this policy was itself fairly effective in helping reduce the problem the engine running out of memory.

 

note that the (combined) heap limit for 32-bit processes is currently limited to around 2GB (though this is partly subdivided between the different kinds of heap memory). the remaining address space is left for "pretty much everything else".

 

 

 

 

 

1 - From what I've been reading every resource should be divided in fixed-size chunks and stored using a pool allocator. But how should the resources be divided? I need meshes and textures to be stored continuously so I can create GPU resources. The solution I found is to load the whole resource using a temporary allocator, create the GPU resource, store resource info in chunks, and clear the temporary allocator. But what if the resource info doesn't fit in a single chunk?

I disagree. Every resource with a RAM cost too high should be divided, and that's a big difference.
Strangely enough, I did have streaming support in the past. I don't have it now. Why? Because right now 2GiBs are becoming commonplace... on video cards. I once estimated I could load my whole game in RAM - all the levels - and it would still fit. So there was no chance to really tune the streaming methods. Latency on real world data is a different thing.

 


I would rather have a more flexible (streaming) solution than have to limit levels size.

 


likewise.

then again, I am using voxels, which if handled naively can use up all the RAM within a fairly short view radius.

if the worlds were Quake style, you could probably actually fit a "pretty damn big world" in a single giant BSP, and would more likely run into floating-point precision issues before running into memory issues. not that this would necessarily be practical though (there are likely to be other limiting factors before this, namely performance and map-creation issues, and dividing the world into a regular grid would probably make more sense).


 

 

I am surprised someone just waited for textures "to become visible" to load them - that would have been unacceptable for me even with async loading.


I agree. My plan is to be able to define areas in the world editor where streaming of other zones should start.
 
 
For games with large levels (open world), that use streaming, is it "ok" to limit the number of resources loaded to a fixed number? Bitsquid (for example) limits the number of units to 65k, is it usual to put limits in an engine like that? How should the limit be calculated or are there more dynamic solutions?
 
Having a maximum number of resources/world objects allows me to use linear arrays increasing simplicity and most likely performance.
 
EDIT: After thinking a bit about it limiting the number of resources shouldn't cause any issue since I would need less than 16 MiB to store the info of 1 million resources (hashed name, reference count and pointer to resource data), and it is highly unlikely that I'll ever need that many resources in memory simultaneously happy.png .

 


yeah, as long as the limit is higher than what is likely to be needed, and doesn't pose some strict architectural limit (IOW: like say using 16-bits in a file-format for something that may need more bits later and can't be easily expanded), it typically doesn't matter too much.


#5cr88192

Posted 13 July 2013 - 12:18 PM

Thanks for your answers.
 

for example, I do most of my general-purpose memory allocation via a custom heap-style allocator, rather than using pool-based or region-based allocators.


Using an heap (free list) allocator don't you have fragmentation problems? After a while of loading/unloading of different sizes the memory will most likely become fragmented, how do you deal with it?

 


for the most part, I don't.


however, after a while, one may observe a pattern:
for the most part, the various sizes of free-lists will become filled with various amounts of various-sized memory objects, and (assuming that leaks are not present), will often eventually tend towards stabilizing (few or no general-purpose allocations of new memory objects in this size range, though with large numbers of allocations/frees within a given size of free-list).

typically, the existence of memory objects of various sizes (allocated and available) tends to resemble a histogram (roughly following a Gaussian distribution), with very large numbers of small objects (< 4kB), followed by progressive decreases as sizes get larger, though often with a few spikes (for example, in my engine, there is typically a fairly big spike around 32kB, which is the natural size of an uncompressed voxel chunk). larger memory objects tend to be fairly sparse.

as-is, objects < 4kB comprise around 30-40% of the total memory use in my case, with 32kB chunks and occasional large objects making up most of the rest. of these small objects, the number of objects is roughly inversely related to size (with 0-15 and 16-31 byte objects having object-counts in the millions).

objects under 64kB in-general tend to represent the majority (around 80%) of total memory use in my engine.

above this tends mostly to be largish semi-permanent data structures (such as PAK-files, video files, region files, buffers for decoded video frames, the console buffer, ...), and occasionally temporary buffers. many of these tend to range between 100s of KB and into the MB range.

granted, these dumps were usually made in cases where the engine was low on memory (typically because the available 32-bit address space was pretty much used up...).


some specific types of small memory objects are also handled specially (namely things like cons-cells and boxed-values).
a cons cell is basically a pair of tagged-pointers (traditionally called 'car' and 'cdr'), and typically boxed values are things like boxed-longs and boxed-doubles. in the former case, the MM manages these specially (they have their own heap), and boxed-values in general use slab allocation (and lack individual headers). these are not counted in the above stats (which were for the general allocator), but likewise tend to have fairly high allocation counts (also in the millions).

most other things are mostly things like strings and various small structures and similar.


having all objects in a given free list be the same size also helps some.
if each object has to be an exact number of bytes, this creates a mess.
however, with a given number of cells, the same object may hold a certain range of memory-object sizes.

say, we have a 17x16-cell object:
it can hold an allocation anywhere from 240-256 bytes.

typically, after a little while, one then hits a plateau of the number of objects of that given size range.


fragmentation is potentially still an issue for larger objects, but luckily these are relatively uncommon.

a lot of this is likely to depend a lot on the specific engine though.


 

 

 

1 - From what I've been reading every resource should be divided in fixed-size chunks and stored using a pool allocator. But how should the resources be divided? I need meshes and textures to be stored continuously so I can create GPU resources. The solution I found is to load the whole resource using a temporary allocator, create the GPU resource, store resource info in chunks, and clear the temporary allocator. But what if the resource info doesn't fit in a single chunk?

I disagree. Every resource with a RAM cost too high should be divided, and that's a big difference.
Strangely enough, I did have streaming support in the past. I don't have it now. Why? Because right now 2GiBs are becoming commonplace... on video cards. I once estimated I could load my whole game in RAM - all the levels - and it would still fit. So there was no chance to really tune the streaming methods. Latency on real world data is a different thing.

 


I would rather have a more flexible (streaming) solution than have to limit levels size.

 


likewise.

then again, I am using voxels, which if handled naively can use up all the RAM within a fairly short view radius.

if the worlds were Quake style, you could probably actually fit a "pretty damn big world" in a single giant BSP, and would more likely run into floating-point precision issues before running into memory issues. not that this would necessarily be practical though (there are likely to be other limiting factors before this, namely performance and map-creation issues, and dividing the world into a regular grid would probably make more sense).


 

 

I am surprised someone just waited for textures "to become visible" to load them - that would have been unacceptable for me even with async loading.


I agree. My plan is to be able to define areas in the world editor where streaming of other zones should start.
 
 
For games with large levels (open world), that use streaming, is it "ok" to limit the number of resources loaded to a fixed number? Bitsquid (for example) limits the number of units to 65k, is it usual to put limits in an engine like that? How should the limit be calculated or are there more dynamic solutions?
 
Having a maximum number of resources/world objects allows me to use linear arrays increasing simplicity and most likely performance.
 
EDIT: After thinking a bit about it limiting the number of resources shouldn't cause any issue since I would need less than 16 MiB to store the info of 1 million resources (hashed name, reference count and pointer to resource data), and it is highly unlikely that I'll ever need that many resources in memory simultaneously happy.png .

 


yeah, as long as the limit is higher than what is likely to be needed, and doesn't pose some strict architectural limit (IOW: like say using 16-bits in a file-format for something that may need more bits later and can't be easily expanded), it typically doesn't matter too much.


#4cr88192

Posted 13 July 2013 - 11:20 AM

Thanks for your answers.
 

for example, I do most of my general-purpose memory allocation via a custom heap-style allocator, rather than using pool-based or region-based allocators.


Using an heap (free list) allocator don't you have fragmentation problems? After a while of loading/unloading of different sizes the memory will most likely become fragmented, how do you deal with it?


for the most part, I don't.


however, after a while, one may observe a pattern:
for the most part, the various sizes of free-lists will become filled with various amounts of various-sized memory objects, and (assuming that leaks are not present), will often eventually tend towards stabilizing (few or no general-purpose allocations of new memory objects in this size range, though with large numbers of allocations/frees within a given size of free-list).

typically, the existence of memory objects of various sizes (allocated and available) tends to resemble a histogram (roughly following a Gaussian distribution), with very large numbers of small objects (< 4kB), followed by progressive decreases as sizes get larger, though often with a few spikes (for example, in my engine, there is typically a fairly big spike around 32kB, which is the natural size of an uncompressed voxel chunk). larger memory objects tend to be fairly sparse.

as-is, objects < 4kB comprise around 30-40% of the total memory use in my case, with 32kB chunks and occasional large objects making up most of the rest. of these small objects, the number of objects is roughly inversely related to size (with 0-15 and 16-31 byte objects having object-counts in the millions).

objects under 64kB in-general tend to represent the majority (around 80%) of total memory use in my engine.

above this tends mostly to be largish semi-permanent data structures (such as PAK-files, video files, region files, buffers for decoded video frames, the console buffer, ...), and occasionally temporary buffers. many of these tend to range between 100s of KB and into the MB range.

granted, these dumps were usually made in cases where the engine was low on memory (typically because the available 32-bit address space was pretty much used up...).


some specific types of small memory objects are also handled specially (namely things like cons-cells and boxed-values).
a cons cell is basically a pair of tagged-pointers (traditionally called 'car' and 'cdr'), and typically boxed values are things like boxed-longs and boxed-doubles. in the former case, the MM manages these specially (they have their own heap), and boxed-values in general use slab allocation (and lack individual headers). these are not counted in the above stats (which were for the general allocator), but likewise tend to have fairly high allocation counts (also in the millions).

most other things are mostly things like strings and various small structures and similar.


having all objects in a given free list be the same size also helps some.
if each object has to be an exact number of bytes, this creates a mess.
however, with a given number of cells, the same object may hold a certain range of memory-object sizes.

say, we have a 17x16-cell object:
it can hold an allocation anywhere from 240-256 bytes.

typically, after a little while, one then hits a plateau of the number of objects of that given size range.


fragmentation is potentially still an for larger objects, but luckily these are relatively uncommon.

a lot of this is likely to depend a lot on the specific engine though.


 

1 - From what I've been reading every resource should be divided in fixed-size chunks and stored using a pool allocator. But how should the resources be divided? I need meshes and textures to be stored continuously so I can create GPU resources. The solution I found is to load the whole resource using a temporary allocator, create the GPU resource, store resource info in chunks, and clear the temporary allocator. But what if the resource info doesn't fit in a single chunk?

I disagree. Every resource with a RAM cost too high should be divided, and that's a big difference.
Strangely enough, I did have streaming support in the past. I don't have it now. Why? Because right now 2GiBs are becoming commonplace... on video cards. I once estimated I could load my whole game in RAM - all the levels - and it would still fit. So there was no chance to really tune the streaming methods. Latency on real world data is a different thing.


I would rather have a more flexible (streaming) solution than have to limit levels size.


likewise.

then again, I am using voxels, which if handled naively can use up all the RAM within a fairly short view radius.

if the worlds were Quake style, you could probably actually fit a "pretty damn big world" in a single giant BSP, and would more likely run into floating-point precision issues before running into memory issues. not that this would necessarily be practical though (there are likely to be other limiting factors before this, namely performance and map-creation issues, and dividing the world into a regular grid would probably make more sense).


 

I am surprised someone just waited for textures "to become visible" to load them - that would have been unacceptable for me even with async loading.


I agree. My plan is to be able to define areas in the world editor where streaming of other zones should start.
 
 
For games with large levels (open world), that use streaming, is it "ok" to limit the number of resources loaded to a fixed number? Bitsquid (for example) limits the number of units to 65k, is it usual to put limits in an engine like that? How should the limit be calculated or are there more dynamic solutions?
 
Having a maximum number of resources/world objects allows me to use linear arrays increasing simplicity and most likely performance.
 
EDIT: After thinking a bit about it limiting the number of resources shouldn't cause any issue since I would need less than 16 MiB to store the info of 1 million resources (hashed name, reference count and pointer to resource data), and it is highly unlikely that I'll ever need that many resources in memory simultaneously happy.png .


yeah, as long as the limit is higher than what is likely to be needed, and doesn't pose some strict architectural limit (IOW: like say using 16-bits in a file-format for something that may need more bits later and can't be easily expanded), it typically doesn't matter too much.

#3cr88192

Posted 13 July 2013 - 11:08 AM

Thanks for your answers.
 

for example, I do most of my general-purpose memory allocation via a custom heap-style allocator, rather than using pool-based or region-based allocators.


Using an heap (free list) allocator don't you have fragmentation problems? After a while of loading/unloading of different sizes the memory will most likely become fragmented, how do you deal with it?


for the most part, I don't.


however, after a while, one may observe a pattern:
for the most part, the various sizes of free-lists will become filled with various amounts of various-sized memory objects, and (assuming that leaks are not present), will often eventually tend towards stabilizing (few or no general-purpose allocations of new memory objects in this size range, though with large numbers of allocations/frees within a given size of free-list).

typically, the existence of memory objects of various sizes (allocated and available) tends to resemble a histogram, with very large numbers of small objects (< 4kB), followed by progressive decreases as sizes get larger, though often with a few spikes (for example, in my engine, there is typically a fairly big spike around 32kB, which is the natural size of an uncompressed voxel chunk). larger memory objects tend to be fairly sparse.

as-is, objects < 4kB comprise around 30-40% of the total memory use in my case, with 32kB chunks and occasional large objects making up most of the rest. of these small objects, the number of objects is roughly inversely related to size (with 0-15 and 16-31 byte objects having object-counts in the millions).

objects under 64kB in-general tend to represent the majority (around 80%) of total memory use in my engine.

above this tends mostly to be largish semi-permanent data structures (such as PAK-files, video files, region files, buffers for decoded video frames, the console buffer, ...), and occasionally temporary buffers. many of these tend to range between 100s of KB and into the MB range.

granted, these dumps were usually made in cases where the engine was low on memory (typically because the available 32-bit address space was pretty much used up...).


some specific types of small memory objects are also handled specially (namely things like cons-cells and boxed-values).
a cons cell is basically a pair of tagged-pointers (traditionally called 'car' and 'cdr'), and typically boxed values are things like boxed-longs and boxed-doubles. in the former case, the MM manages these specially (they have their own heap), and boxed-values in general use slab allocation (and lack individual headers). these are not counted in the above stats (which were for the general allocator), but likewise tend to have fairly high allocation counts (also in the millions).

most other things are mostly things like strings and various small structures and similar.


having all objects in a given free list be the same size also helps some.
if each object has to be an exact number of bytes, this creates a mess.
however, with a given number of cells, the same object may hold a certain range of memory-object sizes.

say, we have a 17x16-cell object:
it can hold an allocation anywhere from 240-256 bytes.

typically, after a little while, one then hits a plateau of the number of objects of that given size range.


fragmentation is potentially still an for larger objects, but luckily these are relatively uncommon.

a lot of this is likely to depend a lot on the specific engine though.


 

1 - From what I've been reading every resource should be divided in fixed-size chunks and stored using a pool allocator. But how should the resources be divided? I need meshes and textures to be stored continuously so I can create GPU resources. The solution I found is to load the whole resource using a temporary allocator, create the GPU resource, store resource info in chunks, and clear the temporary allocator. But what if the resource info doesn't fit in a single chunk?

I disagree. Every resource with a RAM cost too high should be divided, and that's a big difference.
Strangely enough, I did have streaming support in the past. I don't have it now. Why? Because right now 2GiBs are becoming commonplace... on video cards. I once estimated I could load my whole game in RAM - all the levels - and it would still fit. So there was no chance to really tune the streaming methods. Latency on real world data is a different thing.


I would rather have a more flexible (streaming) solution than have to limit levels size.


likewise.

then again, I am using voxels, which if handled naively can use up all the RAM within a fairly short view radius.

if the worlds were Quake style, you could probably actually fit a "pretty damn big world" in a single giant BSP, and would more likely run into floating-point precision issues before running into memory issues. not that this would necessarily be practical though (there are likely to be other limiting factors before this, namely performance and map-creation issues, and dividing the world into a regular grid would probably make more sense).


 

I am surprised someone just waited for textures "to become visible" to load them - that would have been unacceptable for me even with async loading.


I agree. My plan is to be able to define areas in the world editor where streaming of other zones should start.
 
 
For games with large levels (open world), that use streaming, is it "ok" to limit the number of resources loaded to a fixed number? Bitsquid (for example) limits the number of units to 65k, is it usual to put limits in an engine like that? How should the limit be calculated or are there more dynamic solutions?
 
Having a maximum number of resources/world objects allows me to use linear arrays increasing simplicity and most likely performance.
 
EDIT: After thinking a bit about it limiting the number of resources shouldn't cause any issue since I would need less than 16 MiB to store the info of 1 million resources (hashed name, reference count and pointer to resource data), and it is highly unlikely that I'll ever need that many resources in memory simultaneously happy.png .


yeah, as long as the limit is higher than what is likely to be needed, and doesn't pose some strict architectural limit (IOW: like say using 16-bits in a file-format for something that may need more bits later and can't be easily expanded), it typically doesn't matter too much.

#2cr88192

Posted 13 July 2013 - 11:00 AM

Thanks for your answers.
 

for example, I do most of my general-purpose memory allocation via a custom heap-style allocator, rather than using pool-based or region-based allocators.


Using an heap (free list) allocator don't you have fragmentation problems? After a while of loading/unloading of different sizes the memory will most likely become fragmented, how do you deal with it?


for the most part, I don't.


however, after a while, one may observe a pattern:
for the most part, the various sizes of free-lists will become filled with various amounts of various-sized memory objects, and (assuming that leaks are not present), will often eventually tend towards stabilizing (few or no general-purpose allocations of new memory objects in this size range, though with large numbers of allocations/frees within a given size of free-list).

typically, the existence of memory objects of various sizes (allocated and available) tends to resemble a histogram, with very large numbers of small objects (< 4kB), followed by progressive decreases as sizes get larger, though often with a few spikes (for example, in my engine, there is typically a fairly big spike around 32kB, which is the natural size of an uncompressed voxel chunk). larger memory objects tend to be fairly sparse.

as-is, objects < 4kB comprise around 30-40% of the total memory use in my case, with 32kB chunks and occasional large objects making up most of the rest. of these small objects, the number of objects is roughly inversely related to size (with 0-15 and 16-31 byte objects having object-counts in the millions).

objects under 64kB in-general tend to represent the majority (around 80%) of total memory use in my engine.

above this tends mostly to be largish semi-permanent data structures (such as PAK-files, video files, region files, buffers for decoded video frames, the console buffer, ...), and occasionally temporary buffers. many of these tend to range between 100s of KB and into the MB range.

granted, these dumps were usually made in cases where the engine was low on memory (typically because the available 32-bit address space was pretty much used up...).


some specific types of small memory objects are also handled specially (namely things like cons-cells and boxed-values).
a cons cell is basically a pair of tagged-pointers (traditionally called 'car' and 'cdr'), and typically boxed values are things like boxed-longs and boxed-doubles. in the former case, the MM manages these specially (they have their own heap), and boxed-values in general use slab allocation (and lack individual headers). these are not counted in the above stats (which were for the general allocator), but likewise tend to have fairly high allocation counts (also in the millions).

most other things are mostly things like strings and various small structures and similar.


having all objects in a given free list be the same size also helps some.
if each object has to be an exact number of bytes, this creates a mess.
however, with a given number of cells, the same object may hold a certain range of memory-object sizes.

say, we have a 17x16-cell object:
it can hold an allocation anywhere from 240-256 bytes.

typically, after a little while, one then hits a plateau of the number of objects of that given size range.


fragmentation is potentially still an for larger objects, but luckily these are relatively uncommon.

a lot of this is likely to depend a lot on the specific engine though.


 

1 - From what I've been reading every resource should be divided in fixed-size chunks and stored using a pool allocator. But how should the resources be divided? I need meshes and textures to be stored continuously so I can create GPU resources. The solution I found is to load the whole resource using a temporary allocator, create the GPU resource, store resource info in chunks, and clear the temporary allocator. But what if the resource info doesn't fit in a single chunk?

I disagree. Every resource with a RAM cost too high should be divided, and that's a big difference.
Strangely enough, I did have streaming support in the past. I don't have it now. Why? Because right now 2GiBs are becoming commonplace... on video cards. I once estimated I could load my whole game in RAM - all the levels - and it would still fit. So there was no chance to really tune the streaming methods. Latency on real world data is a different thing.


I would rather have a more flexible (streaming) solution than have to limit levels size.


likewise.

then again, I am using voxels, which if handled naively can use up all the RAM within a fairly short view radius.

if the worlds were Quake style, you could probably actually fit a "pretty damn big world" in a single giant BSP, and would more likely run into floating-point precision issues before running into memory issues. not that this would necessarily be practical though (there are likely to be other limiting factors before this, namely performance and map-creation issues, and dividing the world into a regular grid would probably make more sense).


 

I am surprised someone just waited for textures "to become visible" to load them - that would have been unacceptable for me even with async loading.


I agree. My plan is to be able to define areas in the world editor where streaming of other zones should start.
 
 
For games with large levels (open world), that use streaming, is it "ok" to limit the number of resources loaded to a fixed number? Bitsquid (for example) limits the number of units to 65k, is it usual to put limits in an engine like that? How should the limit be calculated or are there more dynamic solutions?
 
Having a maximum number of resources/world objects allows me to use linear arrays increasing simplicity and most likely performance.
 
EDIT: After thinking a bit about it limiting the number of resources shouldn't cause any issue since I would need less than 16 MiB to store the info of 1 million resources (hashed name, reference count and pointer to resource data), and it is highly unlikely that I'll ever need that many resources in memory simultaneously happy.png .


yeah, as long as the limit is higher than what is likely to be needed, and doesn't pose some strict architectural limit (IOW: like say using 16-bits in a file-format for something that may need more bits later), it typically doesn't matter too much.

#1cr88192

Posted 13 July 2013 - 10:58 AM

Thanks for your answers.
 

for example, I do most of my general-purpose memory allocation via a custom heap-style allocator, rather than using pool-based or region-based allocators.


Using an heap (free list) allocator don't you have fragmentation problems? After a while of loading/unloading of different sizes the memory will most likely become fragmented, how do you deal with it?


for the most part, I don't.


however, after a while, one may observe a pattern:
for the most part, the various sizes of free-lists will become filled with various amounts of various-sized memory objects, and (assuming that leaks are not present), will often eventually tend towards stabilizing (few or no general allocations of new memory objects in this size range).

typically, the existence of memory objects of various sizes (allocated and available) tends to resemble a histogram, with very large numbers of small objects (< 4kB), followed by progressive decreases as sizes get larger, though often with a few spikes (for example, in my engine, there is typically a fairly big spike around 32kB, which is the natural size of an uncompressed voxel chunk). larger memory objects tend to be fairly sparse.

as-is, objects < 4kB comprise around 30-40% of the total memory use in my case, with 32kB chunks and occasional large objects making up most of the rest. of these small objects, the number of objects is roughly inversely related to size (with 0-15 and 16-31 byte objects having object-counts in the millions).

objects under 64kB in-general tend to represent the majority (around 80%) of total memory use in my engine.

above this tends mostly to be largish semi-permanent data structures (such as PAK-files, video files, region files, buffers for decoded video frames, the console buffer, ...), and occasionally temporary buffers. many of these tend to range between 100s of KB and into the MB range.

granted, these dumps were usually made in cases where the engine was low on memory (typically because the available 32-bit address space was pretty much used up...).


some specific types of small memory objects are also handled specially (namely things like cons-cells and boxed-values).
a cons cell is basically a pair of tagged-pointers (traditionally called 'car' and 'cdr'), and typically boxed values are things like boxed-longs and boxed-doubles. in the former case, the MM manages these specially (they have their own heap), and boxed-values in general use slab allocation (and lack individual headers). these are not counted in the above stats (which were for the general allocator), but likewise tend to have fairly high allocation counts (also in the millions).

most other things are mostly things like strings and various small structures and similar.


having all objects in a given free list be the same size also helps some.
if each object has to be an exact number of bytes, this creates a mess.
however, with a given number of cells, the same object may hold a certain range of memory-object sizes.

say, we have a 17x16-cell object:
it can hold an allocation anywhere from 240-256 bytes.

typically, after a little while, one then hits a plateau of the number of objects of that given size range.


fragmentation is potentially still an for larger objects, but luckily these are relatively uncommon.

a lot of this is likely to depend a lot on the specific engine though.



1 - From what I've been reading every resource should be divided in fixed-size chunks and stored using a pool allocator. But how should the resources be divided? I need meshes and textures to be stored continuously so I can create GPU resources. The solution I found is to load the whole resource using a temporary allocator, create the GPU resource, store resource info in chunks, and clear the temporary allocator. But what if the resource info doesn't fit in a single chunk?

I disagree. Every resource with a RAM cost too high should be divided, and that's a big difference.
Strangely enough, I did have streaming support in the past. I don't have it now. Why? Because right now 2GiBs are becoming commonplace... on video cards. I once estimated I could load my whole game in RAM - all the levels - and it would still fit. So there was no chance to really tune the streaming methods. Latency on real world data is a different thing.


I would rather have a more flexible (streaming) solution than have to limit levels size.


likewise.

then again, I am using voxels, which if handled naively can use up all the RAM within a fairly short view radius.

if the worlds were Quake style, you could probably actually fit a "pretty damn big world" in a single giant BSP, and would more likely run into floating-point precision issues before running into memory issues. not that this would necessarily be practical though (there are likely to be other limiting factors before this, namely performance and map-creation issues, and dividing the world into a regular grid would probably make more sense).



I am surprised someone just waited for textures "to become visible" to load them - that would have been unacceptable for me even with async loading.


I agree. My plan is to be able to define areas in the world editor where streaming of other zones should start.
 
 
For games with large levels (open world), that use streaming, is it "ok" to limit the number of resources loaded to a fixed number? Bitsquid (for example) limits the number of units to 65k, is it usual to put limits in an engine like that? How should the limit be calculated or are there more dynamic solutions?
 
Having a maximum number of resources/world objects allows me to use linear arrays increasing simplicity and most likely performance.
 
EDIT: After thinking a bit about it limiting the number of resources shouldn't cause any issue since I would need less than 16 MiB to store the info of 1 million resources (hashed name, reference count and pointer to resource data), and it is highly unlikely that I'll ever need that many resources in memory simultaneously happy.png .


yeah, as long as the limit is higher than what is likely to be needed, and doesn't pose some strict architectural limit (IOW: like say using 16-bits in a file-format for something that may need more bits later), it typically doesn't matter too much.

PARTNERS