Skip to content

changes to vmem physical page allocation policy#666

Open
eshaanmandal wants to merge 5 commits intoChampSim:developfrom
eshaanmandal:feature/hashed_vmem_mapping
Open

changes to vmem physical page allocation policy#666
eshaanmandal wants to merge 5 commits intoChampSim:developfrom
eshaanmandal:feature/hashed_vmem_mapping

Conversation

@eshaanmandal
Copy link
Copy Markdown

This PR updates the virtual-to-physical page allocation policy to use a hash-based index instead of sequential allocation. This makes physical page selection deterministic and reproducible across runs, addressing variability discussed in #656

Sequential allocation caused differences in mappings depending on timing/order of page faults, leading to inconsistent behavior even with identical seeds. A hash-based mapping stabilizes this.

Copy link
Copy Markdown
Collaborator

@ngober ngober left a comment

Choose a reason for hiding this comment

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

This looks like it will do what the issue suggests. I have some code cleanliness comments.

Comment thread src/vmem.cc Outdated
Comment on lines +70 to +82
// void VirtualMemory::populate_pages()
// {
// assert(dram.size() > 1_MiB);
// ppage_free_list.resize(((dram.size() - 1_MiB) / PAGE_SIZE).count());
// assert(ppage_free_list.size() != 0);
// champsim::page_number base_address =
// champsim::page_number{champsim::lowest_address_for_size(std::max<champsim::data::mebibytes>(champsim::data::bytes{PAGE_SIZE}, 1_MiB))};
// for (auto it = ppage_free_list.begin(); it != ppage_free_list.end(); it++) {
// *it = base_address;
// base_address++;
// }
// }

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Please remove all of the commented code here. The source code is under version control, so we can easily go back and see old behavior.

Comment thread src/vmem.cc Outdated
// }


std::deque<std::pair<champsim::page_number, bool>>::iterator
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This should just be auto. There's no point in spelling it out.

Copy link
Copy Markdown
Author

@eshaanmandal eshaanmandal Nov 7, 2025

Choose a reason for hiding this comment

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

I will apply the changes, also I had one more thing to report. So when doing make test, one of the test fails. The test started with the number 802. The reason being that the original algo removed the pages from the free_pa_list, and this algo doesn't. And the test checks for the fact if x pages have been removed from the free list after allocation. So, if we go ahead with this change, do we need to modify the test as
well?

test/cpp/src/801-vmem-duplicated.cc:51: FAILED: REQUIRE( original_size - 2 == uut.available_ppages() ) with expansion: 130814 (0x1fefe) == 130816 (0x1ff00)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Also could i keep the return type the way it is rather than "auto", as it makes it easier to understand what data type is being returned?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

The return type is a contract with the calling code. If you say "this function returns a std::deque<std::pair<champsim::page_number, bool>>::iterator", then the calling code can depend on any of the following:

  • The container is a std::deque, and not a std::vector.
  • The value type is a std::pair and not a structural type with two members
  • The pair contains a champsim::page_number and not a champsim::address.
  • The return type gives a view into an underlying range structure, that is, that I can increment it and maybe decrement it to move around in the range.

None of that is what the function is meant to do. What the function actually does is return a handle to a value that can be popped. Maybe it should just return a std::pair<champsim::page_number, bool>&.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I will apply the changes, also I had one more thing to report. So when doing make test, one of the test fails. The test started with the number 802. The reason being that the original algo removed the pages from the free_pa_list, and this algo doesn't. And the test checks for the fact if x pages have been removed from the free list after allocation. So, if we go ahead with this change, do we need to modify the test as well?

test/cpp/src/801-vmem-duplicated.cc:51: FAILED: REQUIRE( original_size - 2 == uut.available_ppages() ) with expansion: 130814 (0x1fefe) == 130816 (0x1ff00)

All of the tests should pass before we can merge the changes. If you make changes to the tests, we should all understand why these changes reflect more correct behavior.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

That makes sense, i did change it to auto. Regarding the test, all the other tests pass except one (the one for vmem). Since the list size remains fixed. Should I update the ppages_available() function so that it returns how many unoccupied locations are there in the dequeue?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Yes. You have changed how the underlying structures work. You will need to make sure that ppages_available() reports the number of available pages remain. That's what the tests are there to catch.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

You could just use a counter to track pages that have been allocated so far. Initialize to total free pages, then decrement when a page is allocated. Report that from those functions.

Comment thread src/vmem.cc
Comment on lines +129 to +135
auto it = ppage_free_list.begin() + idx;

// for keeping track of the original ptr
auto start_itr = it;
while(it != ppage_free_list.end() && it->second){
it++;
}
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Suggested change
auto it = ppage_free_list.begin() + idx;
// for keeping track of the original ptr
auto start_itr = it;
while(it != ppage_free_list.end() && it->second){
it++;
}
auto start_itr = ppage_free_list.begin() + idx;
auto it = std::find_if(start_itr, ppage_free_list.end(), [](const auto& free_list_entry) { return !free_list_entry.second; });

There's a standard library function for what you're doing here.

Comment thread src/vmem.cc Outdated
Comment thread src/vmem.cc Outdated
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