>_ IzzyLab

Hands-on task

This task is step 1 of the course “Server: first steps”

How much memory the server has

easy~4 min

The developers want to run a new app on the server and ask how much RAM it has.

Find out how much memory the server has in total, and write a single whole number to /root/mem.txt — the amount in megabytes, without units. For example, if there are 2 gigabytes of memory, the file should contain 2048.

What you'll practise:
  • free
  • RAM
  • swap
  • available

Topic breakdown

RAM is where programs run. When there isn't enough of it, the system starts moving data out to swap — a paging area on disk. A disk is many times slower than memory, so a server that's busy swapping slows down noticeably. And if swap runs out too, the kernel kills the hungriest process.

free shows how much memory there is and how it's used. Sample output of free -h:

               total        used        free      shared  buff/cache   available
Mem:            15Gi       4.2Gi       1.1Gi       210Mi        10Gi        11Gi
Swap:          2.0Gi          0B       2.0Gi
  • total — how much memory there is in total;
  • used — taken by programs;
  • free — not used by anything at all;
  • buff/cache — the file cache: Linux keeps recently read files in spare memory and hands that memory to programs as soon as they need it;
  • available — how much can really be given to new programs.

So a small free is normal: the memory isn't sitting idle, it's working as cache. available is the number to look at.

The -h flag picks readable units by itself, -m prints everything in megabytes (strictly, mebibytes: 1 Mi = 1024 Ki), -g in gigabytes.

What's checked

  1. /root/mem.txt created
  2. The file holds the total memory in megabytes

What it looks like