Skip to content

Loading…

Add mlock/munlock support to peg data file into memory #39

Merged
merged 1 commit into from

2 participants

@brianm

Add a command line option to enable, and support for locking data file pages into memory

@brianm brianm Add mlock/munlock support to peg data file into memory
Add a command line option to enable, and support for locking data file pages into memory
c853e8b
@mreiferson

thanks!

@mreiferson mreiferson merged commit d95637c into bitly:master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Apr 4, 2012
  1. @brianm

    Add mlock/munlock support to peg data file into memory

    brianm committed
    Add a command line option to enable, and support for locking data file pages into memory
This page is out of date. Refresh to see the latest.
Showing with 10 additions and 1 deletion.
  1. +10 −1 sortdb/sortdb.c
View
11 sortdb/sortdb.c
@@ -328,6 +328,10 @@ void hup_handler(int signum)
void close_dbfile()
{
fprintf(stdout, "closing %s\n", db_filename);
+ if (option_get_int("memory_lock") && munlock(map_base, st.st_size)) {
+ fprintf(stderr, "munlock(%s) failed: %s\n", db_filename, strerror(errno));
+ exit(errno);
+ }
if (munmap(map_base, st.st_size) != 0) {
fprintf(stderr, "failed munmap\n");
exit(1);
@@ -356,6 +360,10 @@ void open_dbfile()
fprintf(stderr, "mmap(%s) failed: %s\n", db_filename, strerror(errno));
exit(errno);
}
+ if (option_get_int("memory_lock") && mlock(map_base, st.st_size)) {
+ fprintf(stderr, "mlock(%s) failed: %s\n", db_filename, strerror(errno));
+ exit(errno);
+ }
}
int version_cb(int value)
@@ -368,9 +376,10 @@ int main(int argc, char **argv)
{
define_simplehttp_options();
option_define_str("db_file", OPT_REQUIRED, NULL, &db_filename, NULL, NULL);
+ option_define_bool("memory_lock", OPT_OPTIONAL, 0, NULL, NULL, "lock data file pages into memory");
option_define_char("field_separator", OPT_OPTIONAL, '\0', &deliminator, NULL, "field separator (eg: comma, tab, pipe). default: TAB");
option_define_bool("version", OPT_OPTIONAL, 0, NULL, version_cb, VERSION);
-
+
if (!option_parse_command_line(argc, argv)) {
return 1;
}
Something went wrong with that request. Please try again.