Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
R
redoxfs
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
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
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
James Matlik
redoxfs
Commits
0bb53636
Commit
0bb53636
authored
8 years ago
by
Jeremy Soller
Browse files
Options
Downloads
Patches
Plain Diff
Faster read from disk if cache miss
parent
dc5326a1
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
scheme/cache/mod.rs
+16
-6
16 additions, 6 deletions
scheme/cache/mod.rs
with
16 additions
and
6 deletions
scheme/cache/mod.rs
+
16
−
6
View file @
0bb53636
...
@@ -35,6 +35,7 @@ impl<T: Disk> Disk for Cache<T> {
...
@@ -35,6 +35,7 @@ impl<T: Disk> Disk for Cache<T> {
// println!("Cache read at {}", block);
// println!("Cache read at {}", block);
let
mut
read
=
0
;
let
mut
read
=
0
;
let
mut
failed
=
false
;
for
i
in
0
..
(
buffer
.len
()
+
511
)
/
512
{
for
i
in
0
..
(
buffer
.len
()
+
511
)
/
512
{
let
block_i
=
block
+
i
as
u64
;
let
block_i
=
block
+
i
as
u64
;
...
@@ -42,18 +43,27 @@ impl<T: Disk> Disk for Cache<T> {
...
@@ -42,18 +43,27 @@ impl<T: Disk> Disk for Cache<T> {
let
buffer_j
=
cmp
::
min
(
buffer_i
+
512
,
buffer
.len
());
let
buffer_j
=
cmp
::
min
(
buffer_i
+
512
,
buffer
.len
());
let
buffer_slice
=
&
mut
buffer
[
buffer_i
..
buffer_j
];
let
buffer_slice
=
&
mut
buffer
[
buffer_i
..
buffer_j
];
//Just to fix the borrow checker in the else
let
mut
failed
=
false
;
if
let
Some
(
cache_buf
)
=
self
.cache
.get_mut
(
&
block_i
)
{
if
let
Some
(
cache_buf
)
=
self
.cache
.get_mut
(
&
block_i
)
{
read
+=
copy_memory
(
cache_buf
,
buffer_slice
);
read
+=
copy_memory
(
cache_buf
,
buffer_slice
);
}
else
{
}
else
{
failed
=
true
;
failed
=
true
;
break
;
}
}
}
if
failed
{
try
!
(
self
.inner
.read_at
(
block
,
buffer
));
read
=
0
;
for
i
in
0
..
(
buffer
.len
()
+
511
)
/
512
{
let
block_i
=
block
+
i
as
u64
;
let
buffer_i
=
i
*
512
;
let
buffer_j
=
cmp
::
min
(
buffer_i
+
512
,
buffer
.len
());
let
buffer_slice
=
&
buffer
[
buffer_i
..
buffer_j
];
if
failed
{
let
mut
cache_buf
=
[
0
;
512
];
let
mut
cache_buf
=
[
0
;
512
];
try
!
(
self
.inner
.read_at
(
block_i
,
&
mut
cache_buf
));
read
+=
copy_memory
(
buffer_slice
,
&
mut
cache_buf
);
read
+=
copy_memory
(
&
cache_buf
,
buffer_slice
);
self
.cache
.insert
(
block_i
,
cache_buf
);
self
.cache
.insert
(
block_i
,
cache_buf
);
}
}
}
}
...
@@ -64,7 +74,7 @@ impl<T: Disk> Disk for Cache<T> {
...
@@ -64,7 +74,7 @@ impl<T: Disk> Disk for Cache<T> {
fn
write_at
(
&
mut
self
,
block
:
u64
,
buffer
:
&
[
u8
])
->
Result
<
usize
>
{
fn
write_at
(
&
mut
self
,
block
:
u64
,
buffer
:
&
[
u8
])
->
Result
<
usize
>
{
// println!("Cache write at {}", block);
// println!("Cache write at {}", block);
try
!
(
self
.inner
.write_at
(
block
,
&
buffer
));
try
!
(
self
.inner
.write_at
(
block
,
buffer
));
let
mut
written
=
0
;
let
mut
written
=
0
;
for
i
in
0
..
(
buffer
.len
()
+
511
)
/
512
{
for
i
in
0
..
(
buffer
.len
()
+
511
)
/
512
{
...
...
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