Skip to content
This repository has been archived by the owner on Nov 4, 2024. It is now read-only.

RFC: Refine sdsmvtonvm(...) function to return more information when nvm_malloc failed. #13

Open
BrytonLee opened this issue Sep 24, 2019 · 1 comment

Comments

@BrytonLee
Copy link
Contributor

sds sdsmvtonvm(const sds s)

 106 sds sdsmvtonvm(const sds s)
 107 {
 108     if(server.nvm_base && !is_nvm_addr(s))
 109     {
 110         size_t header_size = sdsheadersize(s);
 111         size_t total_size = header_size + sdsalloc(s) + 1;
 112         if(total_size >= server.sdsmv_threshold)
 113         {
 114             void* new_sh = nvm_malloc(total_size);
 115             if(!new_sh)
 116             {
 117                 //serverLog(LL_WARNING, "Can't allocate on NVM. Keep data in memory.");
 118                 return s;
 119             }
 120             void* sh = s - header_size;
 121             size_t used_size = header_size + sdslen(s) + 1;
 122             pmem_memcpy_persist(new_sh, sh, used_size);
 123             zfree(sh);
 124             return (char*)new_sh + header_size;
 125         }
 126     }
 127     return s;
 128 }

I would like to change the sdsmvtonvm() signature to return an error message when nvm_malloc failed. Otherwise, users who calls sdsmvtonvm() have no chance to check if it succeed or not.

Would you like to shed a light on that?

@peifengsi
Copy link
Contributor

Hi, BrytonLee
One alternative way is to check whether the return address belongs to nvm or not by calling is_nvm_addr().

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants