Skip to content

Make LeafNode aligned to memory pages. - #2348

Merged
TheMarex merged 3 commits into
Project-OSRM:optimizefrom
oxidase:optimize
May 2, 2016
Merged

TheMarex merged 3 commits into
Project-OSRM:optimizefrom
oxidase:optimize

Conversation

@oxidase

@oxidase oxidase commented May 1, 2016

Copy link
Copy Markdown
Contributor

Hi, i would like to propose the following PR

  • LeafNode is aligned to LEAF_PAGE_SIZE.
    Alignment brings 24 bytes memory overhead for 4096, but reduces
    cache misses rate. It will not be seen on small benchmarks, but for large memory consumptions it will be require less systems works to drop least recently used pages.
  • Removed unused m_element_count from leaf nodes file.
    The size is computed as m_leaves_region.size() / LEAF_PAGE_SIZE.
  • Added try/catch for mmap exceptions messages.
    Exceptions will cover non-existing and empty files, but also permissions, memory errors etc

@oxidase oxidase mentioned this pull request May 1, 2016
@oxidase
oxidase force-pushed the optimize branch 2 times, most recently from cb0ba0b to 1eef691 Compare May 1, 2016 19:43
candidate_cache is removed because of failing test
make util-tests && ./unit_tests/util-tests --run_test=*/construct_multiple_levels_test
first bad commit: [9692be6] Add cache for CandidateSegments to reduce heap worke even more

Now SegmentIndex contains leaf index, object index and fixed_projected_coordinate
Comment thread include/util/static_rtree.hpp Outdated
LeafNode() : object_count(0), objects() {}
uint32_t object_count;
std::array<EdgeDataT, LEAF_NODE_SIZE> objects;
unsigned char __alignment[LEAF_PAGE_SIZE - sizeof(uint32_t) - sizeof(EdgeDataT) * LEAF_NODE_SIZE];

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you change the naming for __alignment. Symbols starting with _ _ are reserved for the stdlib implementation and I feel like "alignment" is generic enough that there is the probability for a clash somewhere somehow.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I will change to leaf_page_padding

@TheMarex

TheMarex commented May 2, 2016

Copy link
Copy Markdown
Member

👍 Good idea, it makes a lot more sense to give the actual page size.

Would be great if you could clarify some of the changes I commented on.

Changes:
* LeafNode is aligned to LEAF_PAGE_SIZE.
  Alignment brings 24 bytes memory overhead for 4096, but reduces
  cache misses rate.
* Unused m_element_count from leaf nodes file.
  The size is computed as m_leaves_region.size() / LEAF_PAGE_SIZE.
* Added try/catch for mmap exceptions messages.
@TheMarex
TheMarex merged commit 5b60fd7 into Project-OSRM:optimize May 2, 2016
@TheMarex

TheMarex commented May 2, 2016

Copy link
Copy Markdown
Member

Great work. Merged it in my branch so I can rebase on master.

@daniel-j-h

Copy link
Copy Markdown
Member

I just stumbled upon this again and was wondering if we simply can use

struct alignas(pageSize) LeafNode { .. }

instead of manually computing the padding. Probably less error prone and shows intent.

@oxidase

oxidase commented May 18, 2016

Copy link
Copy Markdown
Contributor Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants