initialize the memory subsystem. NOTE: This may be called twice, first with NULL specifying we should use ram later, after the configuration file is loaded with a path to where we should place our temporary file.
| 139 | // later, after the configuration file is loaded with a path to where we should |
| 140 | // place our temporary file. |
| 141 | void storage_init(const char *tmpfilePath, size_t cbFileReserve) |
| 142 | { |
| 143 | if (tmpfilePath == NULL) |
| 144 | { |
| 145 | serverAssert(mkdisk == NULL); |
| 146 | mkdisk = MEMKIND_DEFAULT; |
| 147 | pool_initialize(&poolobj, sizeof(robj)); |
| 148 | pool_initialize(&poolembstrobj, EMBSTR_ROBJ_SIZE); |
| 149 | } |
| 150 | else |
| 151 | { |
| 152 | // First create the file |
| 153 | serverAssert(mkdisk == MEMKIND_DEFAULT); |
| 154 | PMEM_DIR = (char*)memkind_malloc(MEMKIND_DEFAULT, strlen(tmpfilePath)); |
| 155 | strcpy((char*)PMEM_DIR, tmpfilePath); |
| 156 | int errv = memkind_create_pmem(PMEM_DIR, 0, &mkdisk); |
| 157 | if (errv == MEMKIND_ERROR_INVALID) |
| 158 | { |
| 159 | serverLog(LL_WARNING, "Memory pool creation failed: %s", strerror(errno)); |
| 160 | exit(EXIT_FAILURE); |
| 161 | } |
| 162 | else if (errv) |
| 163 | { |
| 164 | char msgbuf[1024]; |
| 165 | memkind_error_message(errv, msgbuf, 1024); |
| 166 | serverLog(LL_WARNING, "Memory pool creation failed: %s", msgbuf); |
| 167 | exit(EXIT_FAILURE); |
| 168 | } |
| 169 | |
| 170 | // Next test if COW is working |
| 171 | int fdTest = forkFile(); |
| 172 | if (fdTest < 0) |
| 173 | { |
| 174 | serverLog(LL_WARNING, "Scratch file system does not support Copy on Write. To fix this scratch-file-path must point to a path on a filesystem which supports copy on write, such as btrfs."); |
| 175 | exit(EXIT_FAILURE); |
| 176 | } |
| 177 | close(fdTest); |
| 178 | |
| 179 | // Now lets make the file big |
| 180 | if (cbFileReserve == 0) |
| 181 | cbFileReserve = 1*1024*1024*1024; // 1 GB (enough to be interesting) |
| 182 | posix_fallocate64(memkind_fd(mkdisk), 0, cbFileReserve); |
| 183 | |
| 184 | pthread_atfork(handle_prefork, handle_postfork_parent, handle_postfork_child); |
| 185 | } |
| 186 | } |
| 187 | |
| 188 | |
| 189 |
no test coverage detected