Dissected Redis VMS

Source: Internet
Author: User

When the value of a Redis key is swap to a file, the value of the key to the Redisobject will be changed to Vmpointer,vmpointer to save the value on the disk file. This includes the offset of the start page and the number of consecutive pages.


[HTML]View Plaincopy
  1. typedef struct REDISOBJECT {
  2. unsigned type:4;
  3. unsigned storage:2; /* Redis_vm_memory or redis_vm_swapping */
  4. unsigned encoding:4;
  5. unsigned lru:22; /* LRU time (relative to Server.lruclock) */
  6. int refcount;
  7. void *ptr;
  8. /* VM Fields was only allocated if VM is active, otherwise the
  9. * Object allocation function would just allocate
  10. * sizeof (REDISOBJCT) minus sizeof (REDISOBJECTVM), so using
  11. * Redis without VM active is not having any overhead. */
  12. } robj;


[HTML]View Plaincopy
  1. typedef struct VMPOINTER {
  2. unsigned type:4;
  3. unsigned storage:2; /* redis_vm_swapped or redis_vm_loading */
  4. unsigned notused:26;
  5. unsigned int vtype; /* Type of the object stored in the swap file */
  6. off_t page; /* The page at witch the object was stored on disk */
  7. off_t usedpages; /* Number of pages used on disk */
  8. } Vmpointer;


The logic to import the key's value into memory is as follows:

[HTML]View Plaincopy
  1. RobJ *vmreadobjectfromswap (off_t page, int type) {
  2. RobJ *o;
  3. if (server.vm_enabled) Pthread_mutex_lock (&server.io_swapfile_mutex);
  4. if (Fseeko (server.vm_fp,page*server.vm_page_size,seek_set) = =-1) {
  5. Redislog (Redis_warning,
  6. "Unrecoverable VM problem in Vmreadobjectfromswap (): Can ' t seek:%s",
  7. Strerror (errno));
  8. _exit (1);
  9. }
  10. o = rdbloadobject (TYPE,SERVER.VM_FP);
  11. if (o = = NULL) {
  12. Redislog (redis_warning, "unrecoverable VM problem in Vmreadobjectfromswap (): Can ' t load object from swap file:%s", Strerr or (errno));
  13. _exit (1);
  14. }
  15. if (server.vm_enabled) Pthread_mutex_unlock (&server.io_swapfile_mutex);
  16. return o;
  17. }



Dissected Redis VMS

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.