Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ruanhaishen
redis
Commits
7d30035d
Commit
7d30035d
authored
Jan 05, 2010
by
antirez
Browse files
VM internals bugfixes, set 1
parent
55cf8433
Changes
1
Hide whitespace changes
Inline
Side-by-side
redis.c
View file @
7d30035d
...
@@ -6653,8 +6653,8 @@ static void vmInit(void) {
...
@@ -6653,8 +6653,8 @@ static void vmInit(void) {
}
else
{
}
else
{
redisLog
(
REDIS_NOTICE
,
"Swap file allocated with success"
);
redisLog
(
REDIS_NOTICE
,
"Swap file allocated with success"
);
}
}
server
.
vm_bitmap
=
zmalloc
((
server
.
vm_
near_
pages
+
7
)
/
8
);
server
.
vm_bitmap
=
zmalloc
((
server
.
vm_pages
+
7
)
/
8
);
memset
(
server
.
vm_bitmap
,
0
,(
server
.
vm_
near_
pages
+
7
)
/
8
);
memset
(
server
.
vm_bitmap
,
0
,(
server
.
vm_pages
+
7
)
/
8
);
/* Try to remove the swap file, so the OS will really delete it from the
/* Try to remove the swap file, so the OS will really delete it from the
* file system when Redis exists. */
* file system when Redis exists. */
unlink
(
"/tmp/redisvm"
);
unlink
(
"/tmp/redisvm"
);
...
@@ -6665,6 +6665,7 @@ static void vmMarkPageUsed(off_t page) {
...
@@ -6665,6 +6665,7 @@ static void vmMarkPageUsed(off_t page) {
off_t
byte
=
page
/
8
;
off_t
byte
=
page
/
8
;
int
bit
=
page
&
7
;
int
bit
=
page
&
7
;
server
.
vm_bitmap
[
byte
]
|=
1
<<
bit
;
server
.
vm_bitmap
[
byte
]
|=
1
<<
bit
;
printf
(
"Mark used: %lld (byte:%d bit:%d)
\n
"
,
(
long
long
)
page
,
byte
,
bit
);
}
}
/* Mark N contiguous pages as used, with 'page' being the first. */
/* Mark N contiguous pages as used, with 'page' being the first. */
...
@@ -6672,7 +6673,7 @@ static void vmMarkPagesUsed(off_t page, off_t count) {
...
@@ -6672,7 +6673,7 @@ static void vmMarkPagesUsed(off_t page, off_t count) {
off_t
j
;
off_t
j
;
for
(
j
=
0
;
j
<
count
;
j
++
)
for
(
j
=
0
;
j
<
count
;
j
++
)
vmMarkPageUsed
(
page
+
count
);
vmMarkPageUsed
(
page
+
j
);
}
}
/* Mark the page as free */
/* Mark the page as free */
...
@@ -6687,14 +6688,14 @@ static void vmMarkPagesFree(off_t page, off_t count) {
...
@@ -6687,14 +6688,14 @@ static void vmMarkPagesFree(off_t page, off_t count) {
off_t
j
;
off_t
j
;
for
(
j
=
0
;
j
<
count
;
j
++
)
for
(
j
=
0
;
j
<
count
;
j
++
)
vmMarkPageFree
(
page
+
count
);
vmMarkPageFree
(
page
+
j
);
}
}
/* Test if the page is free */
/* Test if the page is free */
static
int
vmFreePage
(
off_t
page
)
{
static
int
vmFreePage
(
off_t
page
)
{
off_t
byte
=
page
/
8
;
off_t
byte
=
page
/
8
;
int
bit
=
page
&
7
;
int
bit
=
page
&
7
;
return
server
.
vm_bitmap
[
byte
]
&
bit
;
return
(
server
.
vm_bitmap
[
byte
]
&
(
1
<<
bit
))
==
0
;
}
}
/* Find N contiguous free pages storing the first page of the cluster in *first.
/* Find N contiguous free pages storing the first page of the cluster in *first.
...
@@ -6729,6 +6730,7 @@ static int vmFindContiguousPages(off_t *first, int n) {
...
@@ -6729,6 +6730,7 @@ static int vmFindContiguousPages(off_t *first, int n) {
while
(
offset
<
server
.
vm_pages
)
{
while
(
offset
<
server
.
vm_pages
)
{
off_t
this
=
base
+
offset
;
off_t
this
=
base
+
offset
;
printf
(
"THIS: %lld (%c)
\n
"
,
(
long
long
)
this
,
vmFreePage
(
this
)
?
'F'
:
'X'
);
/* If we overflow, restart from page zero */
/* If we overflow, restart from page zero */
if
(
this
>=
server
.
vm_pages
)
{
if
(
this
>=
server
.
vm_pages
)
{
this
-=
server
.
vm_pages
;
this
-=
server
.
vm_pages
;
...
@@ -6743,7 +6745,8 @@ static int vmFindContiguousPages(off_t *first, int n) {
...
@@ -6743,7 +6745,8 @@ static int vmFindContiguousPages(off_t *first, int n) {
numfree
++
;
numfree
++
;
/* Already got N free pages? Return to the caller, with success */
/* Already got N free pages? Return to the caller, with success */
if
(
numfree
==
n
)
{
if
(
numfree
==
n
)
{
*
first
=
this
;
*
first
=
this
-
(
n
-
1
);
server
.
vm_next_page
=
this
+
1
;
return
REDIS_OK
;
return
REDIS_OK
;
}
}
}
else
{
}
else
{
...
@@ -6790,6 +6793,9 @@ static int vmSwapObject(robj *key, robj *val) {
...
@@ -6790,6 +6793,9 @@ static int vmSwapObject(robj *key, robj *val) {
key
->
storage
=
REDIS_VM_SWAPPED
;
key
->
storage
=
REDIS_VM_SWAPPED
;
decrRefCount
(
val
);
/* Deallocate the object from memory. */
decrRefCount
(
val
);
/* Deallocate the object from memory. */
vmMarkPagesUsed
(
page
,
pages
);
vmMarkPagesUsed
(
page
,
pages
);
redisLog
(
REDIS_DEBUG
,
"VM: object %s swapped out at %lld (%lld pages)"
,
(
unsigned
char
*
)
key
->
ptr
,
(
unsigned
long
long
)
page
,
(
unsigned
long
long
)
pages
);
return
REDIS_OK
;
return
REDIS_OK
;
}
}
...
@@ -6813,6 +6819,8 @@ static robj *vmLoadObject(robj *key) {
...
@@ -6813,6 +6819,8 @@ static robj *vmLoadObject(robj *key) {
key
->
storage
=
REDIS_VM_MEMORY
;
key
->
storage
=
REDIS_VM_MEMORY
;
key
->
vm
.
atime
=
server
.
unixtime
;
key
->
vm
.
atime
=
server
.
unixtime
;
vmMarkPagesFree
(
key
->
vm
.
page
,
key
->
vm
.
usedpages
);
vmMarkPagesFree
(
key
->
vm
.
page
,
key
->
vm
.
usedpages
);
redisLog
(
REDIS_DEBUG
,
"VM: object %s loaded from disk"
,
(
unsigned
char
*
)
key
->
ptr
);
return
val
;
return
val
;
}
}
...
@@ -6855,9 +6863,31 @@ static void debugCommand(redisClient *c) {
...
@@ -6855,9 +6863,31 @@ static void debugCommand(redisClient *c) {
"+Key at:%p refcount:%d, value at:%p refcount:%d encoding:%d serializedlength:%lld
\r\n
"
,
"+Key at:%p refcount:%d, value at:%p refcount:%d encoding:%d serializedlength:%lld
\r\n
"
,
(
void
*
)
key
,
key
->
refcount
,
(
void
*
)
val
,
val
->
refcount
,
(
void
*
)
key
,
key
->
refcount
,
(
void
*
)
val
,
val
->
refcount
,
val
->
encoding
,
rdbSavedObjectLen
(
val
)));
val
->
encoding
,
rdbSavedObjectLen
(
val
)));
}
else
if
(
!
strcasecmp
(
c
->
argv
[
1
]
->
ptr
,
"swapout"
)
&&
c
->
argc
==
3
)
{
dictEntry
*
de
=
dictFind
(
c
->
db
->
dict
,
c
->
argv
[
2
]);
robj
*
key
,
*
val
;
if
(
!
server
.
vm_enabled
)
{
addReplySds
(
c
,
sdsnew
(
"-ERR Virtual Memory is disabled
\r\n
"
));
return
;
}
if
(
!
de
)
{
addReply
(
c
,
shared
.
nokeyerr
);
return
;
}
key
=
dictGetEntryKey
(
de
);
val
=
dictGetEntryVal
(
de
);
if
(
key
->
storage
!=
REDIS_VM_MEMORY
)
{
addReplySds
(
c
,
sdsnew
(
"-ERR This key is not in memory
\r\n
"
));
}
else
if
(
vmSwapObject
(
key
,
val
)
==
REDIS_OK
)
{
dictGetEntryVal
(
de
)
=
NULL
;
addReply
(
c
,
shared
.
ok
);
}
else
{
addReply
(
c
,
shared
.
err
);
}
}
else
{
}
else
{
addReplySds
(
c
,
sdsnew
(
addReplySds
(
c
,
sdsnew
(
"-ERR Syntax error, try DEBUG [SEGFAULT|OBJECT <key>|RELOAD]
\r\n
"
));
"-ERR Syntax error, try DEBUG [SEGFAULT|OBJECT
<key>|SWAPOUT
<key>|RELOAD]
\r\n
"
));
}
}
}
}
...
...
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