Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
S
slash
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
uplex-varnish
slash
Commits
d1d23704
Unverified
Commit
d1d23704
authored
Jul 21, 2023
by
Nils Goroll
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add cramlimit function
parent
1652b41b
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
57 additions
and
0 deletions
+57
-0
buddy.c
src/buddy.c
+56
-0
buddy.h
src/buddy.h
+1
-0
No files found.
src/buddy.c
View file @
d1d23704
...
@@ -194,6 +194,27 @@ npages(size_t size, unsigned bits)
...
@@ -194,6 +194,27 @@ npages(size_t size, unsigned bits)
return
(
s
);
return
(
s
);
}
}
/*
* limit a cram value such that an allocation returned by buddy can
* not be smaller than 1<<bits
*/
int8_t
BUDDYF
(
cramlimit_bits
)(
size_t
sz
,
int8_t
cram
,
int8_t
bits
)
{
int8_t
up
;
assert
(
sz
>=
(
size_t
)
1
<<
bits
);
if
(
cram
==
0
)
return
(
cram
);
up
=
(
int8_t
)(
uint8_t
)
log2up
(
sz
);
assert
(
up
>=
bits
);
up
-=
bits
;
if
(
abs
(
cram
)
<=
up
)
return
(
cram
);
return
(
cram
<
0
?
0
-
up
:
up
);
}
/************************************************************
/************************************************************
* init free map
* init free map
*
*
...
@@ -2030,6 +2051,40 @@ BUDDYF(return)(struct buddy_returns *rets)
...
@@ -2030,6 +2051,40 @@ BUDDYF(return)(struct buddy_returns *rets)
/************************************************************
/************************************************************
* tests
* tests
*/
*/
static
void
t_cramlimit
(
void
)
{
const
int8_t
min
=
12
;
int8_t
cram
,
t
,
bits
,
l
;
size_t
sz
;
for
(
cram
=
-
10
;
cram
<=
10
;
cram
++
)
{
for
(
bits
=
min
;
bits
<
20
;
bits
++
)
{
// valid cram is bits - min
sz
=
(
size_t
)
1
<<
bits
;
t
=
BUDDYF
(
cramlimit_bits
)(
sz
,
cram
,
min
);
l
=
bits
-
min
;
assert
(
abs
(
t
)
<=
l
);
assert
(
t
==
0
||
(
t
<
0
)
==
(
cram
<
0
));
// test round up from pow2 + 1
sz
++
;
l
++
;
t
=
BUDDYF
(
cramlimit_bits
)(
sz
,
cram
,
min
);
assert
(
abs
(
t
)
<=
l
);
assert
(
t
==
0
||
(
t
<
0
)
==
(
cram
<
0
));
// test round up from (pow2 + 1) - 1
sz
=
(
size_t
)
1
<<
(
bits
+
1
);
sz
--
;
t
=
BUDDYF
(
cramlimit_bits
)(
sz
,
cram
,
min
);
assert
(
abs
(
t
)
<=
l
);
assert
(
t
==
0
||
(
t
<
0
)
==
(
cram
<
0
));
}
}
}
int
t
[]
=
{
int
t
[]
=
{
-
1
,
-
1
,
255
,
255
,
...
@@ -2732,6 +2787,7 @@ t_buddy(size_t free)
...
@@ -2732,6 +2787,7 @@ t_buddy(size_t free)
int
main
(
void
)
int
main
(
void
)
{
{
t_cramlimit
();
t_bitf
();
t_bitf
();
t_buddy
(
1
<<
15
);
t_buddy
(
1
<<
15
);
t_buddy
((
1
<<
15
)
-
1
);
t_buddy
((
1
<<
15
)
-
1
);
...
...
src/buddy.h
View file @
d1d23704
...
@@ -86,6 +86,7 @@ typedef struct BUDDY buddy_t;
...
@@ -86,6 +86,7 @@ typedef struct BUDDY buddy_t;
*/
*/
void
*
BUDDYF
(
mmap
)(
size_t
*
,
void
*
);
void
*
BUDDYF
(
mmap
)(
size_t
*
,
void
*
);
void
BUDDYF
(
unmap
)(
void
**
,
size_t
,
void
**
);
void
BUDDYF
(
unmap
)(
void
**
,
size_t
,
void
**
);
int8_t
BUDDYF
(
cramlimit_bits
)(
size_t
,
int8_t
,
int8_t
);
static
inline
int
static
inline
int
abslimit
(
int
val
,
int
lim
)
abslimit
(
int
val
,
int
lim
)
{
{
...
...
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