Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add clean_up and clean_up_with_filter #264

Merged
merged 20 commits into from
Sep 5, 2021

Conversation

Freax13
Copy link
Member

@Freax13 Freax13 commented Jun 4, 2021

This pr adds support for deallocating unused page tables.

Closes #238

@Freax13
Copy link
Member Author

Freax13 commented Jun 4, 2021

I just noticed PageRange in the docs. I'll change my pr to use this later

Copy link
Member

@phil-opp phil-opp left a comment

Choose a reason for hiding this comment

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

Looks good to me overall, thanks a lot! Two things I noticed:

  • Right now this is only implemented for the MappedPageTable type (and the derived OffsetPageTable), but not for the RecursivePageTable. If possible, I think it would be a good idea to make the method generic on the Mapper trait and implement it for the recursive page table type too.
  • What are the use cases for clean_up_with_filter method? Its interface is quite complex with the filter function, so I wonder if a simpler interface based on an address range would be better (e.g. clean_up_addr_range). Or would it be too restricting? (Internally, we could of course still keep the filter-based function, so no change of the implementation would be necessary for this).

@josephlr Perhaps you could take a quick look at this too?

@Freax13
Copy link
Member Author

Freax13 commented Jun 5, 2021

Right now this is only implemented for the MappedPageTable type (and the derived OffsetPageTable), but not for the RecursivePageTable. If possible, I think it would be a good idea to make the method generic on the Mapper trait and implement it for the recursive page table type too.

I don't think it's possible to make this generic on Mapper alone because it's very high-level and doesn't support walking the page tables. It would be possible to do this with PageTableFrameMapping but there are no public implementations and RecursivePageTable doesn't implement it either.

I'm not entirely comfortable with recursive page tables just yet, so that's why I haven't implemented anything for them.

So I think there are three options:

  1. just implement this for certain types like I already did
  2. make it generic on PageTableFrameMapping, implement PageTableFrameMapping for RecursivePageTable and make those implementations public (don't implement them only on internal types)
  3. Do something entirely different

What are the use cases for clean_up_with_filter method? Its interface is quite complex with the filter function, so I wonder if a simpler interface based on an address range would be better (e.g. clean_up_addr_range). Or would it be too restricting? (Internally, we could of course still keep the filter-based function, so no change of the implementation would be necessary for this).

In your comment on the initial issue (#238) you mention that the user should be able to integrate their own logic, so I tried to make it as customizable as possible. In hindsight I agree that this was perhaps needlessly over engineered. I like the idea of replacing clean_up_with_filter with clean_up_addr_range especially because it would also probably make the implementation much more readable. clean_up can also be implemented with clean_up_addr_range so there wouldn't be a need for an internal clean_up_with_filter.

@Freax13
Copy link
Member Author

Freax13 commented Jun 6, 2021

Right now this is only implemented for the MappedPageTable type (and the derived OffsetPageTable), but not for the RecursivePageTable. If possible, I think it would be a good idea to make the method generic on the Mapper trait and implement it for the recursive page table type too.

RecursivePageTables need their own implementation: They will never be completely empty because they always have an entry pointing to themselves.

EDIT:
I just started working on the implementation for RecursivePageTable and it turns out I misunderstood them before. I guess they still need some custom logic though because a clean up in a certain region should probably also clean up the corresponding recursive page table entries.

@Freax13
Copy link
Member Author

Freax13 commented Jun 6, 2021

I guess they still need some custom logic though because a clean up in a certain region should probably also clean up the corresponding recursive page table entries.

Or maybe not? Still struggling to wrap my head around this

Copy link
Contributor

@josephlr josephlr left a comment

Choose a reason for hiding this comment

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

Added mostly minor nits, I'm not super familiar with the page-table code of this crate though.

src/structures/paging/mapper/mapped_page_table.rs Outdated Show resolved Hide resolved
src/structures/paging/mapper/mapped_page_table.rs Outdated Show resolved Hide resolved
src/addr.rs Outdated Show resolved Hide resolved
src/addr.rs Outdated Show resolved Hide resolved
src/structures/paging/mapper/recursive_page_table.rs Outdated Show resolved Hide resolved
Copy link
Member

@phil-opp phil-opp left a comment

Choose a reason for hiding this comment

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

I'm very sorry for the long delay on this, @Freax13! This is some great work and I should have reviewed it way sooner.

I added some more comments, otherwise this looks good to me. Given the long delay, I would understand if you don't want to work into this anymore. Please let me know in that case, then I'll try to fix the remaining things myself.

src/addr.rs Outdated Show resolved Hide resolved
src/addr.rs Outdated Show resolved Hide resolved
src/structures/paging/page.rs Outdated Show resolved Hide resolved
src/structures/paging/mapper/mapped_page_table.rs Outdated Show resolved Hide resolved
src/structures/paging/mapper/offset_page_table.rs Outdated Show resolved Hide resolved
src/structures/paging/mapper/offset_page_table.rs Outdated Show resolved Hide resolved
src/structures/paging/mapper/recursive_page_table.rs Outdated Show resolved Hide resolved
src/structures/paging/mapper/recursive_page_table.rs Outdated Show resolved Hide resolved
src/structures/paging/mapper/recursive_page_table.rs Outdated Show resolved Hide resolved
@Freax13
Copy link
Member Author

Freax13 commented Sep 4, 2021

I'm not sure why CI is failing, but I'm pretty sure it's unrelated to this pr.

@phil-opp
Copy link
Member

phil-opp commented Sep 4, 2021

Thanks a lot for the quick changes!

The CI failure was fixed on master already, so updating your PR to the latest master should fix it. Given that this PR is quite old already, I would recommend to just merge master into your branch instead of attempting a rebase.

@Freax13 Freax13 changed the base branch from next to master September 4, 2021 14:19
@Freax13
Copy link
Member Author

Freax13 commented Sep 4, 2021

I saw that you no longer use the next branch, so I changed the base branch to master.

@phil-opp
Copy link
Member

phil-opp commented Sep 4, 2021

Yeah, I just noticed that as well. We normally only use it for PRs with breaking changes, other changes can be merged directly into master. I don't think that this contains any breaking changes, so I just wanted to propose changing the base branch. Thanks!

testing/Cargo.toml Outdated Show resolved Hide resolved
Copy link
Member

@phil-opp phil-opp left a comment

Choose a reason for hiding this comment

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

Thanks a lot!

@phil-opp phil-opp merged commit cd4d3c2 into rust-osdev:master Sep 5, 2021
phil-opp added a commit that referenced this pull request Sep 5, 2021
@phil-opp phil-opp mentioned this pull request Sep 5, 2021
josephlr pushed a commit that referenced this pull request Sep 13, 2021
@Freax13 Freax13 deleted the page-table-clean-up branch October 27, 2021 18:36
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.

Unmapping unused frames in page tables
3 participants