Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
N
nghttp2
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
Libraries
nghttp2
Commits
fa601e5b
Commit
fa601e5b
authored
Mar 09, 2016
by
Tatsuhiro Tsujikawa
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add isolation_threshold, use field to store block size rather than template parameter
parent
bae37e3e
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
24 additions
and
17 deletions
+24
-17
src/allocator.h
src/allocator.h
+13
-6
src/shrpx_downstream.cc
src/shrpx_downstream.cc
+5
-5
src/shrpx_downstream.h
src/shrpx_downstream.h
+6
-6
No files found.
src/allocator.h
View file @
fa601e5b
...
...
@@ -36,8 +36,12 @@ struct MemBlock {
uint8_t
*
begin
,
*
last
,
*
end
;
};
template
<
size_t
BLOCK_SIZE
>
struct
BlockAllocator
{
BlockAllocator
()
:
retain
(
nullptr
),
head
(
nullptr
)
{}
struct
BlockAllocator
{
BlockAllocator
(
size_t
block_size
,
size_t
isolation_threshold
)
:
retain
(
nullptr
),
head
(
nullptr
),
block_size
(
block_size
),
isolation_threshold
(
std
::
min
(
block_size
,
isolation_threshold
))
{}
~
BlockAllocator
()
{
for
(
auto
mb
=
retain
;
mb
;)
{
...
...
@@ -59,14 +63,14 @@ template <size_t BLOCK_SIZE> struct BlockAllocator {
}
void
*
alloc
(
size_t
size
)
{
if
(
size
>=
BLOCK_SIZE
)
{
if
(
size
>=
isolation_threshold
)
{
auto
mb
=
alloc_mem_block
(
size
);
mb
->
last
=
mb
->
end
;
return
mb
->
begin
;
}
if
(
!
head
||
head
->
end
-
head
->
last
<
static_cast
<
ssize_t
>
(
size
))
{
head
=
alloc_mem_block
(
BLOCK_SIZE
);
head
=
alloc_mem_block
(
block_size
);
}
auto
res
=
head
->
last
;
...
...
@@ -79,6 +83,11 @@ template <size_t BLOCK_SIZE> struct BlockAllocator {
MemBlock
*
retain
;
MemBlock
*
head
;
// size of single memory block
size_t
block_size
;
// if allocation greater or equal to isolation_threshold bytes is
// requested, allocate dedicated block.
size_t
isolation_threshold
;
};
template
<
typename
BlockAllocator
>
...
...
@@ -101,8 +110,6 @@ StringRef concat_string_ref(BlockAllocator &alloc, const StringRef &a,
return
StringRef
{
dst
,
a
.
size
()
+
b
.
size
()};
}
using
DefaultBlockAllocator
=
BlockAllocator
<
1024
>
;
}
// namespace aria2
#endif // ALLOCATOR_H
src/shrpx_downstream.cc
View file @
fa601e5b
...
...
@@ -116,6 +116,7 @@ Downstream::Downstream(Upstream *upstream, MemchunkPool *mcpool,
:
dlnext
(
nullptr
),
dlprev
(
nullptr
),
response_sent_body_length
(
0
),
balloc_
(
1024
,
1024
),
req_
(
balloc_
),
resp_
(
balloc_
),
request_start_time_
(
std
::
chrono
::
high_resolution_clock
::
now
()),
...
...
@@ -357,9 +358,8 @@ void add_header(size_t &sum, HeaderRefs &headers, const StringRef &name,
}
// namespace
namespace
{
void
append_last_header_key
(
DefaultBlockAllocator
&
balloc
,
bool
&
key_prev
,
size_t
&
sum
,
HeaderRefs
&
headers
,
const
char
*
data
,
size_t
len
)
{
void
append_last_header_key
(
BlockAllocator
&
balloc
,
bool
&
key_prev
,
size_t
&
sum
,
HeaderRefs
&
headers
,
const
char
*
data
,
size_t
len
)
{
assert
(
key_prev
);
sum
+=
len
;
auto
&
item
=
headers
.
back
();
...
...
@@ -371,7 +371,7 @@ void append_last_header_key(DefaultBlockAllocator &balloc, bool &key_prev,
}
// namespace
namespace
{
void
append_last_header_value
(
Default
BlockAllocator
&
balloc
,
bool
&
key_prev
,
void
append_last_header_value
(
BlockAllocator
&
balloc
,
bool
&
key_prev
,
size_t
&
sum
,
HeaderRefs
&
headers
,
const
char
*
data
,
size_t
len
)
{
key_prev
=
false
;
...
...
@@ -926,6 +926,6 @@ void Downstream::set_assoc_stream_id(int32_t stream_id) {
int32_t
Downstream
::
get_assoc_stream_id
()
const
{
return
assoc_stream_id_
;
}
Default
BlockAllocator
&
Downstream
::
get_block_allocator
()
{
return
balloc_
;
}
BlockAllocator
&
Downstream
::
get_block_allocator
()
{
return
balloc_
;
}
}
// namespace shrpx
src/shrpx_downstream.h
View file @
fa601e5b
...
...
@@ -52,7 +52,7 @@ struct BlockedLink;
class
FieldStore
{
public:
FieldStore
(
Default
BlockAllocator
&
balloc
,
size_t
headers_initial_capacity
)
FieldStore
(
BlockAllocator
&
balloc
,
size_t
headers_initial_capacity
)
:
content_length
(
-
1
),
balloc_
(
balloc
),
buffer_size_
(
0
),
...
...
@@ -112,7 +112,7 @@ public:
int64_t
content_length
;
private:
Default
BlockAllocator
&
balloc_
;
BlockAllocator
&
balloc_
;
HeaderRefs
headers_
;
// trailer fields. For HTTP/1.1, trailer fields are only included
// with chunked encoding. For HTTP/2, there is no such limit.
...
...
@@ -126,7 +126,7 @@ private:
};
struct
Request
{
Request
(
Default
BlockAllocator
&
balloc
)
Request
(
BlockAllocator
&
balloc
)
:
fs
(
balloc
,
16
),
recv_body_length
(
0
),
unconsumed_body_length
(
0
),
...
...
@@ -182,7 +182,7 @@ struct Request {
};
struct
Response
{
Response
(
Default
BlockAllocator
&
balloc
)
Response
(
BlockAllocator
&
balloc
)
:
fs
(
balloc
,
32
),
recv_body_length
(
0
),
unconsumed_body_length
(
0
),
...
...
@@ -376,7 +376,7 @@ public:
DefaultMemchunks
pop_response_buf
();
Default
BlockAllocator
&
get_block_allocator
();
BlockAllocator
&
get_block_allocator
();
enum
{
EVENT_ERROR
=
0x1
,
...
...
@@ -397,7 +397,7 @@ public:
int64_t
response_sent_body_length
;
private:
Default
BlockAllocator
balloc_
;
BlockAllocator
balloc_
;
Request
req_
;
Response
resp_
;
...
...
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