Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
K
kernel
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
redox-os
kernel
Commits
853b77e3
Verified
Commit
853b77e3
authored
4 years ago
by
Jeremy Soller
Browse files
Options
Downloads
Patches
Plain Diff
Unmap owned grants, use owned grants to calculate memory usage
parent
4e3df8b9
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/context/memory.rs
+16
-10
16 additions, 10 deletions
src/context/memory.rs
src/scheme/sys/context.rs
+5
-0
5 additions, 0 deletions
src/scheme/sys/context.rs
with
21 additions
and
10 deletions
src/context/memory.rs
+
16
−
10
View file @
853b77e3
...
@@ -301,6 +301,10 @@ pub struct Grant {
...
@@ -301,6 +301,10 @@ pub struct Grant {
}
}
impl
Grant
{
impl
Grant
{
pub
fn
is_owned
(
&
self
)
->
bool
{
self
.owned
}
/// Get a mutable reference to the region. This is unsafe, because a bad
/// Get a mutable reference to the region. This is unsafe, because a bad
/// region could lead to the wrong addresses being unmapped.
/// region could lead to the wrong addresses being unmapped.
pub
unsafe
fn
region_mut
(
&
mut
self
)
->
&
mut
Region
{
pub
unsafe
fn
region_mut
(
&
mut
self
)
->
&
mut
Region
{
...
@@ -495,10 +499,6 @@ impl Grant {
...
@@ -495,10 +499,6 @@ impl Grant {
pub
fn
unmap
(
mut
self
)
{
pub
fn
unmap
(
mut
self
)
{
assert!
(
self
.mapped
);
assert!
(
self
.mapped
);
if
self
.owned
{
println!
(
"Grant::unmap: leaked {:?}"
,
self
);
}
let
mut
active_table
=
unsafe
{
ActivePageTable
::
new
()
};
let
mut
active_table
=
unsafe
{
ActivePageTable
::
new
()
};
let
mut
flush_all
=
MapperFlushAll
::
new
();
let
mut
flush_all
=
MapperFlushAll
::
new
();
...
@@ -506,13 +506,18 @@ impl Grant {
...
@@ -506,13 +506,18 @@ impl Grant {
let
start_page
=
Page
::
containing_address
(
self
.start_address
());
let
start_page
=
Page
::
containing_address
(
self
.start_address
());
let
end_page
=
Page
::
containing_address
(
self
.final_address
());
let
end_page
=
Page
::
containing_address
(
self
.final_address
());
for
page
in
Page
::
range_inclusive
(
start_page
,
end_page
)
{
for
page
in
Page
::
range_inclusive
(
start_page
,
end_page
)
{
let
(
result
,
_frame
)
=
active_table
.unmap_return
(
page
,
false
);
let
(
result
,
frame
)
=
active_table
.unmap_return
(
page
,
false
);
if
self
.owned
{
//TODO: make sure this frame can be safely freed, physical use counter
crate
::
memory
::
deallocate_frames
(
frame
,
1
);
}
flush_all
.consume
(
result
);
flush_all
.consume
(
result
);
}
}
flush_all
.flush
(
&
mut
active_table
);
flush_all
.flush
(
&
mut
active_table
);
if
let
Some
(
desc
)
=
self
.desc_opt
.take
()
{
if
let
Some
(
desc
)
=
self
.desc_opt
.take
()
{
println!
(
"Grant::unmap: close desc {:?}"
,
desc
);
//TODO: This imposes a large cost on unmapping, but that cost cannot be avoided without modifying fmap and funmap
//TODO: This imposes a large cost on unmapping, but that cost cannot be avoided without modifying fmap and funmap
let
_
=
desc
.close
();
let
_
=
desc
.close
();
}
}
...
@@ -523,17 +528,17 @@ impl Grant {
...
@@ -523,17 +528,17 @@ impl Grant {
pub
fn
unmap_inactive
(
mut
self
,
new_table
:
&
mut
InactivePageTable
,
temporary_page
:
&
mut
TemporaryPage
)
{
pub
fn
unmap_inactive
(
mut
self
,
new_table
:
&
mut
InactivePageTable
,
temporary_page
:
&
mut
TemporaryPage
)
{
assert!
(
self
.mapped
);
assert!
(
self
.mapped
);
if
self
.owned
{
println!
(
"Grant::unmap_inactive: leaked {:?}"
,
self
);
}
let
mut
active_table
=
unsafe
{
ActivePageTable
::
new
()
};
let
mut
active_table
=
unsafe
{
ActivePageTable
::
new
()
};
active_table
.with
(
new_table
,
temporary_page
,
|
mapper
|
{
active_table
.with
(
new_table
,
temporary_page
,
|
mapper
|
{
let
start_page
=
Page
::
containing_address
(
self
.start_address
());
let
start_page
=
Page
::
containing_address
(
self
.start_address
());
let
end_page
=
Page
::
containing_address
(
self
.final_address
());
let
end_page
=
Page
::
containing_address
(
self
.final_address
());
for
page
in
Page
::
range_inclusive
(
start_page
,
end_page
)
{
for
page
in
Page
::
range_inclusive
(
start_page
,
end_page
)
{
let
(
result
,
_frame
)
=
mapper
.unmap_return
(
page
,
false
);
let
(
result
,
frame
)
=
mapper
.unmap_return
(
page
,
false
);
if
self
.owned
{
//TODO: make sure this frame can be safely freed, physical use counter
crate
::
memory
::
deallocate_frames
(
frame
,
1
);
}
// This is not the active table, so the flush can be ignored
// This is not the active table, so the flush can be ignored
unsafe
{
result
.ignore
();
}
unsafe
{
result
.ignore
();
}
}
}
...
@@ -542,6 +547,7 @@ impl Grant {
...
@@ -542,6 +547,7 @@ impl Grant {
ipi
(
IpiKind
::
Tlb
,
IpiTarget
::
Other
);
ipi
(
IpiKind
::
Tlb
,
IpiTarget
::
Other
);
if
let
Some
(
desc
)
=
self
.desc_opt
.take
()
{
if
let
Some
(
desc
)
=
self
.desc_opt
.take
()
{
println!
(
"Grant::unmap_inactive: close desc {:?}"
,
desc
);
//TODO: This imposes a large cost on unmapping, but that cost cannot be avoided without modifying fmap and funmap
//TODO: This imposes a large cost on unmapping, but that cost cannot be avoided without modifying fmap and funmap
let
_
=
desc
.close
();
let
_
=
desc
.close
();
}
}
...
...
This diff is collapsed.
Click to expand it.
src/scheme/sys/context.rs
+
5
−
0
View file @
853b77e3
...
@@ -96,6 +96,11 @@ pub fn resource() -> Result<Vec<u8>> {
...
@@ -96,6 +96,11 @@ pub fn resource() -> Result<Vec<u8>> {
if
let
Some
(
ref
sigstack
)
=
context
.sigstack
{
if
let
Some
(
ref
sigstack
)
=
context
.sigstack
{
memory
+=
sigstack
.size
();
memory
+=
sigstack
.size
();
}
}
for
grant
in
context
.grants
.lock
()
.iter
()
{
if
grant
.is_owned
()
{
memory
+=
grant
.size
();
}
}
let
memory_string
=
if
memory
>=
1024
*
1024
*
1024
{
let
memory_string
=
if
memory
>=
1024
*
1024
*
1024
{
format!
(
"{} GB"
,
memory
/
1024
/
1024
/
1024
)
format!
(
"{} GB"
,
memory
/
1024
/
1024
/
1024
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment