Geoff Leyland
2014-09-07 01:59:55 UTC
Hi,
I’m working with OpenStreetmap data, specifically in this case, road centrelines, and am running into LuaJIT’s memory limits.
I store centrelines of road segments, each of which is an x, y polyline, and each segment centreline is stored as a Lua table of points, where a point is also a table with two elements: {{1,2},{3,4},{4,5},...}.
The code analyses the segments, looking for segment crossings, near misses and so on, and then breaks the segments at network nodes (and joins them where there’s a break, but no actual node) and builds a routable network. It’s convenient, but not essential, to have the polylines stored in tables and garbage collected because they go through quite a lot of transformation.
This all works fine for smaller areas (I live in New Zealand), but with larger areas, I run into memory limitations. Can anybody suggest good strategies for dealing with the problem?
I could, for example, malloc the memory for each segment’s polyline, which would alleviate the problem, partly because the storage would be more compact, and also because, with a bit of luck, malloc might return addresses above 4G. Unfortunately, there’s no guarantee that malloc won’t just take up space in the precious heap below 4G. I don’t know of a way of hinting to malloc that I’d like higher memory.
For other work, where I know how much memory I need in advance, I just mmap what I need, hinting to mmap that I want the memory above 4G (and then checking and repeating until it does what I want). Since each individual polyline is fairly small and there are plenty of them, using mmap as a malloc substitute would be a fairly poor idea.
Is there perhaps a way I can induce LuaJIT to grab all the memory it can on startup, and then not release it, so that subsequent calls to malloc are forced above the memory LuaJIT wants?
Thanks for any ideas,
Geoff
I’m working with OpenStreetmap data, specifically in this case, road centrelines, and am running into LuaJIT’s memory limits.
I store centrelines of road segments, each of which is an x, y polyline, and each segment centreline is stored as a Lua table of points, where a point is also a table with two elements: {{1,2},{3,4},{4,5},...}.
The code analyses the segments, looking for segment crossings, near misses and so on, and then breaks the segments at network nodes (and joins them where there’s a break, but no actual node) and builds a routable network. It’s convenient, but not essential, to have the polylines stored in tables and garbage collected because they go through quite a lot of transformation.
This all works fine for smaller areas (I live in New Zealand), but with larger areas, I run into memory limitations. Can anybody suggest good strategies for dealing with the problem?
I could, for example, malloc the memory for each segment’s polyline, which would alleviate the problem, partly because the storage would be more compact, and also because, with a bit of luck, malloc might return addresses above 4G. Unfortunately, there’s no guarantee that malloc won’t just take up space in the precious heap below 4G. I don’t know of a way of hinting to malloc that I’d like higher memory.
For other work, where I know how much memory I need in advance, I just mmap what I need, hinting to mmap that I want the memory above 4G (and then checking and repeating until it does what I want). Since each individual polyline is fairly small and there are plenty of them, using mmap as a malloc substitute would be a fairly poor idea.
Is there perhaps a way I can induce LuaJIT to grab all the memory it can on startup, and then not release it, so that subsequent calls to malloc are forced above the memory LuaJIT wants?
Thanks for any ideas,
Geoff