util/nvmutil: cmd_swap(): write sequentually
the current code writes part 1 first, and part 0 next, on the disk, due to the way the swap works. with this change, swap still swaps the two parts of the file, on disk, but writes the new file sequentially. this change might speed up i/o on the file system, on HDDs. on SSDs, this change likely makes no difference at all.fsdg20230625
parent
7e3a73558e
commit
3e150bf303
|
@ -438,16 +438,21 @@ writeGbeFile(int *fd, const char *filename)
|
||||||
nw = 128;
|
nw = 128;
|
||||||
|
|
||||||
for (p = 0; p < 2; p++) {
|
for (p = 0; p < 2; p++) {
|
||||||
|
if (gbe[0] > gbe[1])
|
||||||
|
p ^= 1;
|
||||||
if (nvmPartModified[p]) {
|
if (nvmPartModified[p]) {
|
||||||
printf("Part %d modified\n", p);
|
printf("Part %d modified\n", p);
|
||||||
} else {
|
} else {
|
||||||
fprintf (stderr,
|
fprintf (stderr,
|
||||||
"Part %d NOT modified\n", p);
|
"Part %d NOT modified\n", p);
|
||||||
continue;
|
goto next_part;
|
||||||
}
|
}
|
||||||
if (pwrite((*fd), (uint8_t *) gbe[p], nw, p << 12) != nw)
|
if (pwrite((*fd), (uint8_t *) gbe[p], nw, p << 12) != nw)
|
||||||
err(errno, "%s", filename);
|
err(errno, "%s", filename);
|
||||||
tw += nw;
|
tw += nw;
|
||||||
|
next_part:
|
||||||
|
if (gbe[0] > gbe[1])
|
||||||
|
p ^= 1;
|
||||||
}
|
}
|
||||||
if (close((*fd)))
|
if (close((*fd)))
|
||||||
err(errno, "%s", filename);
|
err(errno, "%s", filename);
|
||||||
|
|
Loading…
Reference in New Issue