Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
ccan
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
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
mirror
ccan
Commits
b4be5752
Commit
b4be5752
authored
May 18, 2008
by
Rusty Russell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Neaten definitions a little.
parent
cf808b83
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
13 additions
and
11 deletions
+13
-11
alloc/alloc.c
alloc/alloc.c
+13
-11
No files found.
alloc/alloc.c
View file @
b4be5752
...
...
@@ -102,6 +102,9 @@ enum sub_metadata_type
/* Page states are represented by bitpairs, at the start of the pool. */
#define BITS_PER_PAGE 2
/* How much metadata info per byte? */
#define METADATA_PER_BYTE (CHAR_BIT / 2)
static
uint8_t
*
get_page_statebits
(
const
void
*
pool
)
{
return
(
uint8_t
*
)
pool
+
sizeof
(
struct
uniform_cache
);
...
...
@@ -291,7 +294,7 @@ static unsigned int uniform_metalen(unsigned int usize)
/* Two bits for the header, 14 bits for size, then one bit for each
* element the page can hold. Round up to number of bytes. */
metalen
=
div_up
(
2
*
CHAR_BIT
+
SUBPAGE_METAOFF
/
usize
,
CHAR_BIT
);
metalen
=
div_up
(
2
+
14
+
SUBPAGE_METAOFF
/
usize
,
CHAR_BIT
);
/* To ensure metaheader is always aligned, round bytes up. */
metalen
=
align_up
(
metalen
,
ALIGNOF
(
struct
metaheader
));
...
...
@@ -320,27 +323,26 @@ static uint8_t *alloc_metaspace(void *pool, unsigned long poolsize,
metalen
=
get_metalen
(
pool
,
poolsize
,
mh
);
/* Walk through metadata looking for free. */
for
(
i
=
0
;
i
<
metalen
*
CHAR_BIT
/
BITS_PER_PAG
E
;
i
+=
len
)
{
for
(
i
=
0
;
i
<
metalen
*
METADATA_PER_BYT
E
;
i
+=
len
)
{
switch
(
get_bit_pair
(
meta
,
i
))
{
case
FREE
:
len
=
1
;
free
++
;
if
(
free
==
bytes
*
CHAR_BIT
/
BITS_PER_PAG
E
)
{
if
(
free
==
bytes
*
METADATA_PER_BYT
E
)
{
/* Mark this as a bitmap. */
set_bit_pair
(
meta
,
i
-
free
+
1
,
type
);
return
meta
+
(
i
-
free
+
1
)
/
(
CHAR_BIT
/
BITS_PER_PAGE
);
return
meta
+
(
i
-
free
+
1
)
/
METADATA_PER_BYTE
;
}
break
;
case
BITMAP
:
/* Skip over this allocated part. */
len
=
BITMAP_METALEN
*
CHAR_BIT
/
BITS_PER_PAG
E
;
len
=
BITMAP_METALEN
*
METADATA_PER_BYT
E
;
free
=
0
;
break
;
case
UNIFORM
:
/* Figure metalen given usize. */
len
=
decode_usize
(
meta
+
i
*
BITS_PER_PAGE
/
CHAR_BIT
);
len
=
uniform_metalen
(
len
)
*
CHAR_BIT
/
BITS_PER_PAG
E
;
len
=
decode_usize
(
meta
+
i
/
METADATA_PER_BYTE
);
len
=
uniform_metalen
(
len
)
*
METADATA_PER_BYT
E
;
free
=
0
;
break
;
default:
...
...
@@ -1043,7 +1045,7 @@ void alloc_visualize(FILE *out, void *pool, unsigned long poolsize)
metalen
=
get_metalen
(
pool
,
poolsize
,
mh
);
metadata_pages
+=
(
sizeof
(
*
mh
)
+
metalen
)
/
getpagesize
();
for
(
i
=
0
;
i
<
metalen
*
CHAR_BIT
/
BITS_PER_PAG
E
;
i
+=
len
)
{
for
(
i
=
0
;
i
<
metalen
*
METADATA_PER_BYT
E
;
i
+=
len
)
{
switch
(
get_bit_pair
(
meta
,
i
))
{
case
FREE
:
len
=
1
;
...
...
@@ -1057,8 +1059,8 @@ void alloc_visualize(FILE *out, void *pool, unsigned long poolsize)
break
;
case
UNIFORM
:
/* Skip over this part. */
len
=
decode_usize
(
meta
+
i
*
BITS_PER_PAGE
/
CHAR_BIT
);
len
=
uniform_metalen
(
len
)
*
CHAR_BIT
/
BITS_PER_PAG
E
;
len
=
decode_usize
(
meta
+
i
/
METADATA_PER_BYTE
);
len
=
uniform_metalen
(
len
)
*
METADATA_PER_BYT
E
;
uniformblocks
++
;
uniformlen
+=
len
;
break
;
...
...
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