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
294f8d35
Commit
294f8d35
authored
Mar 18, 2008
by
Rusty Russell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Allocate backwards, ready for metadata.
parent
e5ca6bcf
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
9 additions
and
6 deletions
+9
-6
alloc/alloc.c
alloc/alloc.c
+9
-6
No files found.
alloc/alloc.c
View file @
294f8d35
...
...
@@ -48,7 +48,8 @@ static unsigned long metadata_length(void *pool, unsigned long poolsize)
void
*
alloc_get
(
void
*
pool
,
unsigned
long
poolsize
,
unsigned
long
size
,
unsigned
long
align
)
{
unsigned
long
i
,
free
,
want
,
metalen
;
long
i
;
unsigned
long
free
,
want
,
metalen
;
if
(
poolsize
<
MIN_SIZE
)
return
NULL
;
...
...
@@ -61,20 +62,22 @@ void *alloc_get(void *pool, unsigned long poolsize,
metalen
=
metadata_length
(
pool
,
poolsize
);
free
=
0
;
for
(
i
=
0
;
i
<
(
poolsize
-
metalen
)
/
getpagesize
();
i
++
)
{
/* We allocate from far end, to increase ability to expand metadata. */
for
(
i
=
(
poolsize
-
metalen
)
/
getpagesize
()
-
1
;
i
>=
0
;
i
--
)
{
switch
(
get_page_state
(
pool
,
i
))
{
case
FREE
:
if
(
++
free
>=
want
)
{
unsigned
int
j
;
unsigned
long
j
;
char
*
ret
=
(
char
*
)
pool
+
metalen
+
(
i
-
want
+
1
)
*
getpagesize
();
+
i
*
getpagesize
();
/* They might ask for multi-page alignment. */
if
((
unsigned
long
)
ret
%
align
)
continue
;
for
(
j
=
i
;
j
>
i
-
want
+
1
;
j
--
)
for
(
j
=
i
+
1
;
j
<
i
+
want
;
j
++
)
set_page_state
(
pool
,
j
,
TAKEN
);
set_page_state
(
pool
,
i
-
want
+
1
,
TAKEN_START
);
set_page_state
(
pool
,
i
,
TAKEN_START
);
return
ret
;
}
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