setup.sh: execute checking ulimit as a user

When using vfio a warning for memlock limit is printed.
TARGET_USER is one set by caller when executing the script,
or set to user that called the script (even when using sudo).

Yet ulimit was printed for the one executing the script,
most likely root.

This patch verifies ulimit for a particular TARGET_USER.
Along with more explicit information which user the
information pertains to.

Signed-off-by: Tomasz Zawadzki <tomasz.zawadzki@intel.com>
Change-Id: I20ad62109bc316295208e21f959ecfc263307e1c
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/1964
Community-CI: Mellanox Build Bot
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: Ben Walker <benjamin.walker@intel.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
This commit is contained in:
Tomasz Zawadzki 2020-04-21 09:09:15 -04:00
parent 887531f6a6
commit 2e55b97d96

View File

@ -417,24 +417,23 @@ function configure_linux() {
chown "$TARGET_USER" "$mount"
chmod g+w "$mount"
done
fi
MEMLOCK_AMNT=$(ulimit -l)
if [ "$MEMLOCK_AMNT" != "unlimited" ]; then
MEMLOCK_MB=$((MEMLOCK_AMNT / 1024))
echo ""
echo "Current user memlock limit: ${MEMLOCK_MB} MB"
echo ""
echo "This is the maximum amount of memory you will be"
echo "able to use with DPDK and VFIO if run as current user."
echo -n "To change this, please adjust limits.conf memlock "
echo "limit for current user."
MEMLOCK_AMNT=$(su "$TARGET_USER" -c "ulimit -l")
if [[ $MEMLOCK_AMNT != "unlimited" ]]; then
MEMLOCK_MB=$((MEMLOCK_AMNT / 1024))
cat <<- MEMLOCK
"$TARGET_USER" user memlock limit: $MEMLOCK_MB MB
if [ $MEMLOCK_AMNT -lt 65536 ]; then
echo ""
echo "## WARNING: memlock limit is less than 64MB"
echo -n "## DPDK with VFIO may not be able to initialize "
echo "if run as current user."
This is the maximum amount of memory you will be
able to use with DPDK and VFIO if run as user "$TARGET_USER".
To change this, please adjust limits.conf memlock limit for user "$TARGET_USER".
MEMLOCK
if ((MEMLOCK_AMNT < 65536)); then
echo ""
echo "## WARNING: memlock limit is less than 64MB"
echo -n "## DPDK with VFIO may not be able to initialize "
echo "if run as user \"$TARGET_USER\"."
fi
fi
fi
fi