Linux Exercise: Memory Management

Monitoring Memory

  1. Download the usemem program from https://www.demo.wlid.nl/sources/usemem and store it in /usr/local/sbin. Make it executable.
    • # cd /usr/local/sbin
    • # curl https://www.demo.wlid.nl/sources/usemem -o usemem
    • # chmod +x usemem
  2. Usemem requires perl, and on Red Hat/CentOS 8+, perl may not be installed as it is not part of the base installation. Check if perl is installed. If not, install it.
    • # which perl
    • If perl is not available:
      # yum install perl
  3. In a separate window, start the top program. Change the sort order to memory usage, with the "M" command.
    • # top
      Within top, press "M".
  4. Start the usemem program with about half the amount of memory in the system. Check what happens.
    • # usemem 500
  5. Press Enter to stop the usemem program. Then start it with about 90% memory. Check what happens. Also try 150% and 200% of the available memory.

Adding swap spaces

This part assumes you've done the LVM exercise earlier, and have an ExtraVG volume group available.

  1. In your ExtraVG, create an additional LV of 1 GB. Format this LV as a swap space. Enable this swap space and make sure it is enabled when the system boots.
    • # lvcreate -n SwapLV -L 1G ExtraVG
    • # mkswap /dev/ExtraVG/SwapLV
    • # swapon /dev/ExtraVG/SwapLV
    • # vi /etc/fstab
      Add a line describing this swap space. It will look like this:
      /dev/ExtraVG/SwapLV swap swap defaults 0 0
    • # cat /proc/swaps
      You should see two swap spaces now.
    • # reboot
    • # cat /proc/swaps
      Again, you should see two swap spaces now.
  2. Perform the same usemem invocations again, but see if your system is now able to cope with this.

Working with shared libraries

  1. Look at the configuration files of your shared library loader. Do you see which directories contain shared libraries?
    • # cat /etc/ld.so.conf
    • # cd /etc/ld.so.conf.d
    • # ls -l
      Note that the standard directories, such as /lib and /usr/lib, are included by ldconfig by default.
  2. Look at the current date and time, and the timestamp on the file /etc/ld.so.cache. How old is this file?
    • # date
    • # ls -l /etc/ld.so.cache
  3. Re-create the ld.so cache. Did this work?
    • # ldconfig
    • # ls -l /etc/ld.so.cache
  4. Make a list of all the shared libraries on your system, using the ldconfig command.
    • # ldconfig -p
  5. Make a list of all the shared libraries that are used by the /bin/ls command.
    • # ldd /bin/ls
End of exercise