diff --git a/doc/rxvtd.1.pod b/doc/rxvtd.1.pod
index 60c54d3..7c91939 100644
--- a/doc/rxvtd.1.pod
+++ b/doc/rxvtd.1.pod
@@ -4,7 +4,7 @@
 
 =head1 SYNOPSIS
 
-B<@@RXVT_NAME@@d> [-q|--quiet] [-o|--opendisplay] [-f|--fork]
+B<@@RXVT_NAME@@d> [-q|--quiet] [-o|--opendisplay] [-f|--fork] [-m|--mlock]
 
 B<@@RXVT_NAME@@d> -q -o -f    # for .xsession use
 
@@ -40,7 +40,7 @@ Normally, B<@@RXVT_NAME@@d> outputs the message C<< rxvt-unicode daemon
 listening on <path> >> after binding to its control socket. This option
 will suppress this message (errors and warnings will still be logged).
 
-=item B<-o>, B<--opendisplay>
+=item B<-o>, B<--open-display>
 
 This forces B<@@RXVT_NAME@@d> to open a connection to the current
 C<$DISPLAY> and keep it open.
@@ -54,6 +54,15 @@ B<@@RXVT_NAME@@d> will be killed automatically.
 This makes B<@@RXVT_NAME@@d> fork after it has bound itself to its control
 socket.
 
+=item B<-m>, B<--mlock>
+
+This makes B<@@RXVT_NAME@@d> call mlockall(2) on itself. This locks 
+B<@@RXVT_NAME@@d> in RAM and prevents it from being swapped out to disk.
+
+Note: In order to use this feature, your system administrator must have set
+your user's RLIMIT_MEMLOCK to a size greater than or equal to the size of the
+B<@@RXVT_NAME@@d> binary (or to unlimited). See /etc/security/limits.conf
+
 =back
 
 =head1 EXAMPLES
diff --git a/src/rxvtd.C b/src/rxvtd.C
index 5642827..6dbd402 100644
--- a/src/rxvtd.C
+++ b/src/rxvtd.C
@@ -33,6 +33,14 @@
 #include <sys/socket.h>
 #include <sys/un.h>
 
+#if ! ( ( defined(__GLIBC__) && defined(__GLIBC_MINOR__) ) && ( __GLIBC__ > 2 || ( __GLIBC__ == 2 && __GLIBC_MINOR__ >= 5 ) ) )
+#define ENABLE_MLOCK
+#endif
+
+#ifdef ENABLE_MLOCK
+#include <sys/mman.h>
+#endif
+
 #include <cerrno>
 
 #include "rxvt.h"
@@ -217,6 +225,9 @@ void server::read_cb (ev::io &w, int revents)
 }
 
 int opt_fork, opt_opendisplay, opt_quiet;
+#ifdef ENABLE_MLOCK
+int opt_lock;
+#endif
 
 int
 main (int argc, const char *const *argv)
@@ -227,10 +238,15 @@ main (int argc, const char *const *argv)
     {
       if (!strcmp (argv [i], "-f") || !strcmp (argv [i], "--fork"))
         opt_fork = 1;
-      else if (!strcmp (argv [i], "-o") || !strcmp (argv [i], "--opendisplay"))
+      else if (!strcmp (argv [i], "-o") || !strcmp (argv [i], "--opendisplay") 
+          || !strcmp (argv [i], "--open-display"))
         opt_opendisplay = 1;
       else if (!strcmp (argv [i], "-q") || !strcmp (argv [i], "--quiet"))
         opt_quiet = 1;
+#ifdef ENABLE_MLOCK
+      else if (!strcmp (argv [i], "-m") || !strcmp (argv [i], "--mlock"))
+        opt_lock = 1;
+#endif
       else
         {
           rxvt_log ("%s: unknown option '%s', aborting.\n", argv [0], argv [i]);
@@ -256,10 +272,21 @@ main (int argc, const char *const *argv)
 
   free (sockname);
 
+  pid_t pid = 0;
   if (opt_fork)
     {
-      pid_t pid = fork ();
+      pid = fork ();
+    }
 
+#ifdef ENABLE_MLOCK
+  // Optionally preform a mlockall so this process does not get swapped out.
+  if (opt_lock && pid == 0)
+    if (mlockall(MCL_CURRENT | MCL_FUTURE) == -1)
+      perror("unable to lock into ram");
+#endif
+
+  if (opt_fork)
+    {
       if (pid < 0)
         {
           rxvt_log ("unable to fork daemon, aborting.\n");
