Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
N
neoppod
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Levin Zimmermann
neoppod
Commits
4e15d38b
Commit
4e15d38b
authored
Jan 12, 2018
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
.
parent
511c3c3b
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
10 additions
and
11 deletions
+10
-11
go/xcommon/xbufio/seqbuf_ioat.go
go/xcommon/xbufio/seqbuf_ioat.go
+6
-5
go/xcommon/xbufio/seqbuf_ioat_test.go
go/xcommon/xbufio/seqbuf_ioat_test.go
+4
-6
No files found.
go/xcommon/xbufio/seqbuf_ioat.go
View file @
4e15d38b
...
...
@@ -18,7 +18,7 @@
// See https://www.nexedi.com/licensing for rationale and options.
package
xbufio
// buffer
r
ing for io.ReaderAt optimized for sequential access
// buffering for io.ReaderAt optimized for sequential access
import
(
"io"
...
...
@@ -49,13 +49,14 @@ type SeqReaderAt struct {
//posLastIO int64
}
// TODO text about syscall / memcpy etc
const
defaultSeqBufSize
=
8192
// XXX retune - must be <= size(L1d) / 2
const
defaultSeqBufSize
=
8192
// NewSeqReaderAt wraps r with SeqReaderAt with buffer of default size.
func
NewSeqReaderAt
(
r
io
.
ReaderAt
)
*
SeqReaderAt
{
return
NewSeqReaderAtSize
(
r
,
defaultSeqBufSize
)
}
// NewSeqReaderAtSize wraps r with SeqReaderAt with buffer of specified size.
func
NewSeqReaderAtSize
(
r
io
.
ReaderAt
,
size
int
)
*
SeqReaderAt
{
sb
:=
&
SeqReaderAt
{
r
:
r
,
buf
:
make
([]
byte
,
0
,
size
)}
// all positions are zero initially
return
sb
...
...
@@ -171,7 +172,7 @@ func (sb *SeqReaderAt) ReadAt(p []byte, pos int64) (int, error) {
// backward
xpos
=
pos
// if backward trend continues and buffer
r
ing would overlap with
// if backward trend continues and buffering would overlap with
// previous backward access - shift reading up right to it.
xLastBackward
:=
posLastBackward
-
int64
(
ntail
)
// adjusted for already read from buffer
if
xpos
<
xLastBackward
&&
xLastBackward
<
xpos
+
cap64
(
sb
.
buf
)
{
...
...
@@ -210,7 +211,7 @@ func (sb *SeqReaderAt) ReadAt(p []byte, pos int64) (int, error) {
if
pBufOffset
>=
len64
(
sb
.
buf
)
{
// this can be only due to some IO error
// if original requst was narrower than buffer try to satisfy
// if original requ
e
st was narrower than buffer try to satisfy
// it once again directly
if
pos
!=
xpos
{
nn
,
err
=
sb
.
ioReadAt
(
p
,
pos
)
...
...
go/xcommon/xbufio/seqbuf_ioat_test.go
View file @
4e15d38b
...
...
@@ -27,8 +27,8 @@ import (
)
// XReader is an io.ReaderAt that reads first 256 bytes with content_i = i
// bytes in range [100, 104] give EIO on reading
// XReader is an io.ReaderAt that reads first 256 bytes with content_i = i
.
// bytes in range [100, 104] give EIO on reading
.
type
XReader
struct
{
}
...
...
@@ -56,8 +56,6 @@ func (r *XReader) ReadAt(p []byte, pos int64) (n int, err error) {
// read @pos/len -> rb.pos, len(rb.buf)
var
xSeqBufTestv
=
[]
struct
{
pos
int64
;
Len
int
;
bufPos
int64
;
bufLen
int
}
{
// TODO add trend / not trend everywhere
// TODO review
{
40
,
5
,
40
,
10
},
// 1st access, forward by default
{
45
,
7
,
50
,
10
},
// part taken from buf, part read next, forward (trend)
{
52
,
5
,
50
,
10
},
// everything taken from buf
...
...
@@ -96,7 +94,7 @@ var xSeqBufTestv = []struct {pos int64; Len int; bufPos int64; bufLen int} {
{
188
,
2
,
184
,
10
},
{
190
,
3
,
184
,
10
},
{
182
,
4
,
174
,
10
},
// trendy backward access - part taken from buffer and buf refilled adjacet to previous backward IO
{
182
,
4
,
174
,
10
},
// trendy backward access - part taken from buffer and buf refilled adjace
n
t to previous backward IO
{
168
,
1
,
168
,
10
},
// trendy backward access farther than cap(buf) - buf refilled right at @pos
...
...
@@ -129,7 +127,7 @@ var xSeqBufTestv = []struct {pos int64; Len int; bufPos int64; bufLen int} {
{
245
,
5
,
240
,
10
},
// backward @245 (4)
{
5
,
4
,
5
,
10
},
// forward near file start
{
2
,
3
,
0
,
10
},
// backward: buf does not go beyon
g
0
{
2
,
3
,
0
,
10
},
// backward: buf does not go beyon
d
0
{
40
,
0
,
0
,
10
},
// zero-sized out-of-buffer read do not change buffer
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment