MCPcopy Create free account
hub / github.com/F-Stack/f-stack / smapsGetSharedDirty

Function smapsGetSharedDirty

app/redis-6.2.6/src/server.c:5427–5453  ·  view source on GitHub ↗

Get size in kilobytes of the Shared_Dirty pages of the calling process for the * memory map corresponding to the provided address, or -1 on error. */

Source from the content-addressed store, hash-verified

5425/* Get size in kilobytes of the Shared_Dirty pages of the calling process for the
5426 * memory map corresponding to the provided address, or -1 on error. */
5427static int smapsGetSharedDirty(unsigned long addr) {
5428 int ret, in_mapping = 0, val = -1;
5429 unsigned long from, to;
5430 char buf[64];
5431 FILE *f;
5432
5433 f = fopen("/proc/self/smaps", "r");
5434 if (!f) return -1;
5435
5436 while (1) {
5437 if (!fgets(buf, sizeof(buf), f))
5438 break;
5439
5440 ret = sscanf(buf, "%lx-%lx", &from, &to);
5441 if (ret == 2)
5442 in_mapping = from <= addr && addr < to;
5443
5444 if (in_mapping && !memcmp(buf, "Shared_Dirty:", 13)) {
5445 sscanf(buf, "%*s %d", &val);
5446 /* If parsing fails, we remain with val == -1 */
5447 break;
5448 }
5449 }
5450
5451 fclose(f);
5452 return val;
5453}
5454
5455/* Older arm64 Linux kernels have a bug that could lead to data corruption
5456 * during background save in certain scenarios. This function checks if the

Callers 1

Calls 1

sscanfFunction · 0.85

Tested by

no test coverage detected