Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Z
ZEO
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
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
ZEO
Commits
be27fc06
Commit
be27fc06
authored
Sep 10, 2002
by
Guido van Rossum
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add instrumentation to the simple free list allocator.
parent
634023b0
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
42 additions
and
2 deletions
+42
-2
src/ZEO/simul.py
src/ZEO/simul.py
+42
-2
No files found.
src/ZEO/simul.py
View file @
be27fc06
...
@@ -440,6 +440,10 @@ class SimpleCacheSimulation(BuddyCacheSimulation):
...
@@ -440,6 +440,10 @@ class SimpleCacheSimulation(BuddyCacheSimulation):
def
allocatorFactory
(
self
,
size
):
def
allocatorFactory
(
self
,
size
):
return
SimpleAllocator
(
size
)
return
SimpleAllocator
(
size
)
def
finish
(
self
):
BuddyCacheSimulation
.
finish
(
self
)
self
.
allocator
.
report
()
MINSIZE
=
256
MINSIZE
=
256
class
BuddyAllocator
:
class
BuddyAllocator
:
...
@@ -535,18 +539,41 @@ class SimpleAllocator:
...
@@ -535,18 +539,41 @@ class SimpleAllocator:
self
.
rover
=
self
.
avail
self
.
rover
=
self
.
avail
node
=
BlockNode
(
None
,
arenasize
,
0
)
node
=
BlockNode
(
None
,
arenasize
,
0
)
node
.
linkbefore
(
self
.
avail
)
node
.
linkbefore
(
self
.
avail
)
# Allocator statistics
self
.
nallocs
=
0
self
.
nfrees
=
0
self
.
allocloops
=
0
self
.
freeloops
=
0
self
.
freebytes
=
arenasize
self
.
freeblocks
=
1
self
.
allocbytes
=
0
self
.
allocblocks
=
0
def
report
(
self
):
print
(
"NA=%d AL=%d NF=%d FL=%d ABy=%d ABl=%d FBy=%d FBl=%d"
%
(
self
.
nallocs
,
self
.
allocloops
,
self
.
nfrees
,
self
.
freeloops
,
self
.
allocbytes
,
self
.
allocblocks
,
self
.
freebytes
,
self
.
freeblocks
))
def
alloc
(
self
,
size
):
def
alloc
(
self
,
size
):
# Exact fit algorithm
self
.
nallocs
+=
1
# First fit algorithm
rover
=
stop
=
self
.
rover
rover
=
stop
=
self
.
rover
free
=
None
free
=
None
while
1
:
while
1
:
self
.
allocloops
+=
1
if
rover
.
size
>=
size
:
if
rover
.
size
>=
size
:
if
rover
.
size
==
size
:
if
rover
.
size
==
size
:
self
.
rover
=
rover
.
next
self
.
rover
=
rover
.
next
rover
.
unlink
()
rover
.
unlink
()
self
.
freeblocks
-=
1
self
.
allocblocks
+=
1
self
.
freebytes
-=
size
self
.
allocbytes
+=
size
return
rover
return
rover
free
=
rover
free
=
rover
break
rover
=
rover
.
next
rover
=
rover
.
next
if
rover
is
stop
:
if
rover
is
stop
:
break
break
...
@@ -556,11 +583,20 @@ class SimpleAllocator:
...
@@ -556,11 +583,20 @@ class SimpleAllocator:
assert
free
.
size
>
size
assert
free
.
size
>
size
node
=
BlockNode
(
None
,
size
,
free
.
addr
+
free
.
size
-
size
)
node
=
BlockNode
(
None
,
size
,
free
.
addr
+
free
.
size
-
size
)
free
.
size
-=
size
free
.
size
-=
size
#self.freeblocks += 0 # No change here
self
.
allocblocks
+=
1
self
.
freebytes
-=
size
self
.
allocbytes
+=
size
return
node
return
node
def
free
(
self
,
node
):
def
free
(
self
,
node
):
self
.
nfrees
+=
1
self
.
freebytes
+=
node
.
size
self
.
allocbytes
-=
node
.
size
self
.
allocblocks
-=
1
x
=
self
.
avail
.
next
x
=
self
.
avail
.
next
while
x
is
not
self
.
avail
and
x
.
addr
<
node
.
addr
:
while
x
is
not
self
.
avail
and
x
.
addr
<
node
.
addr
:
self
.
freeloops
+=
1
x
=
x
.
next
x
=
x
.
next
if
node
.
addr
+
node
.
size
==
x
.
addr
:
# Merge with next
if
node
.
addr
+
node
.
size
==
x
.
addr
:
# Merge with next
x
.
addr
-=
node
.
size
x
.
addr
-=
node
.
size
...
@@ -568,16 +604,19 @@ class SimpleAllocator:
...
@@ -568,16 +604,19 @@ class SimpleAllocator:
node
=
x
node
=
x
else
:
# Insert new node into free list
else
:
# Insert new node into free list
node
.
linkbefore
(
x
)
node
.
linkbefore
(
x
)
self
.
freeblocks
+=
1
x
=
node
.
prev
x
=
node
.
prev
if
node
.
addr
==
x
.
addr
+
x
.
size
and
x
is
not
self
.
avail
:
if
node
.
addr
==
x
.
addr
+
x
.
size
and
x
is
not
self
.
avail
:
# Merge with previous node in free list
# Merge with previous node in free list
node
.
unlink
()
node
.
unlink
()
x
.
size
+=
node
.
size
x
.
size
+=
node
.
size
node
=
x
node
=
x
self
.
freeblocks
-=
1
# It's possible that either one of the merges above invalidated
# It's possible that either one of the merges above invalidated
# the rover.
# the rover.
# It's simplest to simply reset the rover to the newly freed block.
# It's simplest to simply reset the rover to the newly freed block.
# XXX But is this optimal?
# It also seems optimal; if I only move the rover when it's
# become invalid, there performance goes way down.
self
.
rover
=
node
self
.
rover
=
node
def
dump
(
self
,
msg
=
""
):
def
dump
(
self
,
msg
=
""
):
...
@@ -591,6 +630,7 @@ class SimpleAllocator:
...
@@ -591,6 +630,7 @@ class SimpleAllocator:
count
+=
1
count
+=
1
node
=
node
.
next
node
=
node
.
next
print
count
,
"free blocks,"
,
bytes
,
"free bytes"
print
count
,
"free blocks,"
,
bytes
,
"free bytes"
self
.
report
()
class
BlockNode
(
Node
):
class
BlockNode
(
Node
):
...
...
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