Skip to content

Commit

Permalink
Replace check for _POSIX_MEMLOCK w/ HAVE_MLOCKALL
Browse files Browse the repository at this point in the history
zed supports a '-M' cmdline opt to lock all pages in memory via
mlockall().  The _POSIX_MEMLOCK define is checked to determine whether
this function is supported.  The current test assumes mlockall()
is supported if _POSIX_MEMLOCK is non-zero.  However, this test is
insufficient according to mlock(2) and sysconf(3).  If _POSIX_MEMLOCK
is -1, mlockall() is not supported; but if _POSIX_MEMLOCK is 0,
availability must be checked at runtime.

This commit adds an autoconf check for mlockall() to user.m4.  The zed
code block for mlockall() is now guarded with a test for HAVE_MLOCKALL.
If defined, mlockall() will be called and its runtime availability
checked via its return value.

Signed-off-by: Chris Dunlap <[email protected]>
Signed-off-by: Brian Behlendorf <[email protected]>
Issue #2
  • Loading branch information
dun authored and behlendorf committed Apr 2, 2014
1 parent 904ea27 commit 518eba1
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
9 changes: 4 additions & 5 deletions cmd/zed/zed.c
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,7 @@ _setup_sig_handlers(void)
static void
_lock_memory(void)
{
#if ! _POSIX_MEMLOCK
zed_log_die("Failed to lock memory pages: mlockall() not supported");

#else /* _POSIX_MEMLOCK */
#if HAVE_MLOCKALL
int i = 0;
const int max_tries = 10;

Expand All @@ -114,7 +111,9 @@ _lock_memory(void)
}
zed_log_die("Failed to lock memory pages: %s", strerror(errno));

#endif /* _POSIX_MEMLOCK */
#else /* HAVE_MLOCKALL */
zed_log_die("Failed to lock memory pages: mlockall() not supported");
#endif /* HAVE_MLOCKALL */
}

/*
Expand Down
3 changes: 3 additions & 0 deletions config/user.m4
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,7 @@ AC_DEFUN([ZFS_AC_CONFIG_USER], [
ZFS_AC_CONFIG_USER_LIBBLKID
ZFS_AC_CONFIG_USER_FRAME_LARGER_THAN
ZFS_AC_CONFIG_USER_RUNSTATEDIR
dnl #
dnl # Checks for library functions
AC_CHECK_FUNCS([mlockall])
])

0 comments on commit 518eba1

Please sign in to comment.