Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
allocbench
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
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Florian Fischer
allocbench
Commits
0de850f8
Commit
0de850f8
authored
5 years ago
by
Florian Fischer
Browse files
Options
Downloads
Patches
Plain Diff
fix use of ltls after init_tls and further reduce tsd use
parent
27e9fb35
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/speedymalloc_2.c
+19
-17
19 additions, 17 deletions
src/speedymalloc_2.c
with
19 additions
and
17 deletions
src/speedymalloc_2.c
+
19
−
17
View file @
0de850f8
...
...
@@ -48,7 +48,10 @@ typedef struct TLStates {
__thread
tls_t
*
tls
;
static
inline
int
size2bin
(
size_t
size
)
{
assert
(
size
>
0
&&
size
<
CACHE_BINS
*
CACHE_BIN_SEPERATION
);
assert
(
size
<
CACHE_BINS
*
CACHE_BIN_SEPERATION
);
if
(
size
==
0
)
return
0
;
return
(
size
-
1
)
/
CACHE_BIN_SEPERATION
;
}
...
...
@@ -57,7 +60,7 @@ static inline size_t bin2size(int bin) {
return
(
bin
+
1
)
*
CACHE_BIN_SEPERATION
;
}
static
void
init_tls
(
void
)
{
static
tls_t
*
init_tls
(
void
)
{
void
*
mem
=
mmap
(
NULL
,
MEMSIZE
,
PROT_READ
|
PROT_WRITE
,
MAP_PRIVATE
|
MAP_ANONYMOUS
,
-
1
,
0
);
if
(
mem
==
MAP_FAILED
)
{
perror
(
"mmap"
);
...
...
@@ -67,13 +70,12 @@ static void init_tls(void) {
tls
->
ptr
=
((
uintptr_t
)
tls
)
+
sizeof
(
tls_t
);
tls
->
end
=
(
uintptr_t
)
tls
+
MEMSIZE
;
return
(
tls_t
*
)
mem
;
}
inline
static
void
*
bump_alloc
(
size_t
size
,
size_t
align
)
{
inline
static
void
*
bump_alloc
(
tls_t
*
ltls
,
size_t
size
,
size_t
align
)
{
assert
(
align
%
2
==
0
);
tls_t
*
ltls
=
tls
;
// allocate size header
uintptr_t
ptr_w_header
=
ltls
->
ptr
+
sizeof
(
size_t
);
...
...
@@ -95,9 +97,8 @@ inline static void* bump_alloc(size_t size, size_t align) {
void
*
malloc
(
size_t
size
)
{
tls_t
*
ltls
=
tls
;
if
(
unlikely
(
ltls
==
NULL
))
{
init_tls
();
ltls
=
init_tls
();
}
// cached sizes
...
...
@@ -109,22 +110,22 @@ void* malloc(size_t size) {
ltls
->
bins
[
bin
]
=
chunk
->
next
;
return
chunk2ptr
(
chunk
);
}
return
bump_alloc
(
bin2size
(
bin
),
MIN_ALIGNMENT
);
return
bump_alloc
(
ltls
,
bin2size
(
bin
),
MIN_ALIGNMENT
);
}
return
bump_alloc
(
size
,
MIN_ALIGNMENT
);
return
bump_alloc
(
ltls
,
size
,
MIN_ALIGNMENT
);
}
void
free
(
void
*
ptr
)
{
tls_t
*
ltls
=
tls
;
if
(
unlikely
(
ltls
==
NULL
))
{
init_tls
();
}
if
(
ptr
==
NULL
)
{
return
;
}
tls_t
*
ltls
=
tls
;
if
(
unlikely
(
ltls
==
NULL
))
{
ltls
=
init_tls
();
}
chunk_t
*
chunk
=
ptr2chunk
(
ptr
);
if
(
chunk
->
size
<
CACHE_BINS
*
CACHE_BIN_SEPERATION
)
{
...
...
@@ -155,11 +156,12 @@ void* memalign(size_t alignment, size_t size) {
return
NULL
;
}
if
(
unlikely
(
tls
==
NULL
))
{
init_tls
();
tls_t
*
ltls
=
tls
;
if
(
unlikely
(
ltls
==
NULL
))
{
ltls
=
init_tls
();
}
return
bump_alloc
(
size
,
alignment
);
return
bump_alloc
(
ltls
,
size
,
alignment
);
}
int
posix_memalign
(
void
**
memptr
,
size_t
alignment
,
size_t
size
)
...
...
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