Reduces memory usage, with new array growing by fixed size and not exponential.

This commit is contained in:
Andrea Mazzoleni 2013-09-28 09:40:08 +02:00
parent 7f02cd068f
commit d525b4a14a
18 changed files with 497 additions and 53 deletions

View file

@ -79,6 +79,15 @@ void usage(void)
printf(" " SWITCH_GETOPT_LONG("-V, --version ", "-V") " Version\n");
}
void memory(struct snapraid_state* state)
{
if (state->opt.gui) {
fprintf(stdlog, "memory:used:%"PRIu64"\n", (uint64_t)malloc_counter());
} else {
printf("Using %u MiB of memory.\n", (unsigned)(malloc_counter() / 1024 / 1024));
}
}
#define OPT_TEST_SKIP_SELF 256
#define OPT_TEST_KILL_AFTER_SYNC 257
#define OPT_TEST_EXPECT_UNRECOVERABLE 258
@ -564,11 +573,15 @@ int main(int argc, char* argv[])
state_read(&state);
state_scan(&state, 1);
memory(&state);
} else if (operation == OPERATION_SYNC) {
state_read(&state);
state_scan(&state, 0);
memory(&state);
/* intercept Ctrl+C */
signal(SIGINT, &signal_handler);
@ -614,6 +627,8 @@ int main(int argc, char* argv[])
/* apply the command line filter */
state_filter(&state, &filterlist_file, &filterlist_disk, filter_missing, filter_error);
memory(&state);
/* intercept Ctrl+C */
signal(SIGINT, &signal_handler);
@ -632,6 +647,8 @@ int main(int argc, char* argv[])
} else if (operation == OPERATION_SCRUB) {
state_read(&state);
memory(&state);
/* intercept Ctrl+C */
signal(SIGINT, &signal_handler);
@ -648,9 +665,13 @@ int main(int argc, char* argv[])
state_read(&state);
state_write(&state);
memory(&state);
} else if (operation == OPERATION_STATUS) {
state_read(&state);
memory(&state);
state_status(&state);
} else if (operation == OPERATION_DUP) {
state_read(&state);
@ -669,6 +690,8 @@ int main(int argc, char* argv[])
/* apply the command line filter */
state_filter(&state, &filterlist_file, &filterlist_disk, filter_missing, filter_error);
memory(&state);
/* intercept Ctrl+C */
signal(SIGINT, &signal_handler);