mirror of
https://codeberg.org/redict/redict.git
synced 2025-01-23 00:28:26 -05:00
Swap file is now locked
This commit is contained in:
parent
f424d5f398
commit
8b5bb414f1
5
TODO
5
TODO
@ -15,10 +15,7 @@ Virtual Memory sub-TODO:
|
|||||||
* Check if the page selection algorithm is working well
|
* Check if the page selection algorithm is working well
|
||||||
* Divide swappability of objects by refcount
|
* Divide swappability of objects by refcount
|
||||||
* Use multiple open FDs against the VM file, one for thread.
|
* Use multiple open FDs against the VM file, one for thread.
|
||||||
* it should be possible to give the vm-max-memory option in megabyte, gigabyte, ..., just using 2GB, 100MB, and so forth.
|
* EXISTS should avoid loading the object if possible without making the code too specialized.
|
||||||
* Try to understand what can be moved into I/O threads that currently is instead handled by the main thread. For instance swapping file table scannig to find contiguous page could be a potential candidate (but I'm not convinced it's a good idea, better to improve the algorithm, for instance double the fast forward at every step?).
|
|
||||||
* Possibly decrRefCount() against swapped objects can be moved into I/O threads, as it's a slow operation against million elements list, and in general consumes CPU time that can be consumed by other threads (and cores).
|
|
||||||
* EXISTS should avoid loading the object if possible without too make the code too specialized.
|
|
||||||
* vm-min-age <seconds> option
|
* vm-min-age <seconds> option
|
||||||
* Make sure objects loaded from the VM are specially encoded when possible.
|
* Make sure objects loaded from the VM are specially encoded when possible.
|
||||||
* Check what happens performance-wise if instead to create threads again and again the same threads are reused forever. Note: this requires a way to disable this clients in the child, but waiting for empty new jobs queue can be enough.
|
* Check what happens performance-wise if instead to create threads again and again the same threads are reused forever. Note: this requires a way to disable this clients in the child, but waiting for empty new jobs queue can be enough.
|
||||||
|
15
redis.c
15
redis.c
@ -8604,22 +8604,35 @@ static void vmInit(void) {
|
|||||||
off_t totsize;
|
off_t totsize;
|
||||||
int pipefds[2];
|
int pipefds[2];
|
||||||
size_t stacksize;
|
size_t stacksize;
|
||||||
|
struct flock fl;
|
||||||
|
|
||||||
if (server.vm_max_threads != 0)
|
if (server.vm_max_threads != 0)
|
||||||
zmalloc_enable_thread_safeness(); /* we need thread safe zmalloc() */
|
zmalloc_enable_thread_safeness(); /* we need thread safe zmalloc() */
|
||||||
|
|
||||||
expandVmSwapFilename();
|
expandVmSwapFilename();
|
||||||
redisLog(REDIS_NOTICE,"Using '%s' as swap file",server.vm_swap_file);
|
redisLog(REDIS_NOTICE,"Using '%s' as swap file",server.vm_swap_file);
|
||||||
|
/* Try to open the old swap file, otherwise create it */
|
||||||
if ((server.vm_fp = fopen(server.vm_swap_file,"r+b")) == NULL) {
|
if ((server.vm_fp = fopen(server.vm_swap_file,"r+b")) == NULL) {
|
||||||
server.vm_fp = fopen(server.vm_swap_file,"w+b");
|
server.vm_fp = fopen(server.vm_swap_file,"w+b");
|
||||||
}
|
}
|
||||||
if (server.vm_fp == NULL) {
|
if (server.vm_fp == NULL) {
|
||||||
redisLog(REDIS_WARNING,
|
redisLog(REDIS_WARNING,
|
||||||
"Impossible to open the swap file: %s. Exiting.",
|
"Can't open the swap file: %s. Exiting.",
|
||||||
strerror(errno));
|
strerror(errno));
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
server.vm_fd = fileno(server.vm_fp);
|
server.vm_fd = fileno(server.vm_fp);
|
||||||
|
/* Lock the swap file for writing, this is useful in order to avoid
|
||||||
|
* another instance to use the same swap file for a config error. */
|
||||||
|
fl.l_type = F_WRLCK;
|
||||||
|
fl.l_whence = SEEK_SET;
|
||||||
|
fl.l_start = fl.l_len = 0;
|
||||||
|
if (fcntl(server.vm_fd,F_SETLK,&fl) == -1) {
|
||||||
|
redisLog(REDIS_WARNING,
|
||||||
|
"Can't lock the swap file at '%s': %s. Make sure it is not used by another Redis instance.", server.vm_swap_file, strerror(errno));
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
/* Initialize */
|
||||||
server.vm_next_page = 0;
|
server.vm_next_page = 0;
|
||||||
server.vm_near_pages = 0;
|
server.vm_near_pages = 0;
|
||||||
server.vm_stats_used_pages = 0;
|
server.vm_stats_used_pages = 0;
|
||||||
|
Loading…
Reference in New Issue
Block a user