12

We have some tests we need to run in a server with 32Gb RAM.

All the servers we have access to have 64GB and we can't physically change this.

Is there some way of telling RHEL to use only some fixed amount of RAM, less than what is installed?

5
  • 5
    Is this a licencing thing? This feels like it might be a XY problem.
    – Criggie
    Oct 5, 2023 at 3:52
  • 5
    @Criggie, No, it's not. We're exploring a memory leak, the production servers have 32Gb, and we need to ensure in the lab that we've made things work within that. Oct 5, 2023 at 8:04
  • 4
    If it’s truly a memory leak, then you technically should be testing that memory usage does not grow in an unbounded manner, not that everything seems to work with exactly 32 GB of RAM. Of course, doing that efficiently presupposes you have a way to reproduce it (which should be the case if you’ve figured out a prospective fix), but even if you don’t, it’s still possible to check for this type of thing without needing to see if the system falls over because it ran out of memory. Oct 5, 2023 at 15:18
  • The title might be clearer if it was 'RAM available to' rather than 'RAM used by'?
    – rrauenza
    Oct 5, 2023 at 17:38
  • 1
    @AustinHemmelgarn Thanks, I was summarizing. It's a bit more complex than my summary suggests, and I think we know what we're doing, Oct 6, 2023 at 10:26

2 Answers 2

29

Boot with the kernel parameter mem=32G:

mem=nn[KMG] [KNL,BOOT] Force usage of a specific amount of memory

Amount of memory to be used when the kernel is not able to see the whole system memory or for test. [X86] Work as limiting max address. Use together with memmap= to avoid physical address space collisions. Without memmap= PCI devices could be placed at addresses belonging to unused RAM.

5

Yes, you can allocate a fixed amount of RAM for testing purposes on a server with more physical RAM than you need. To do this, you can use control groups (cgroups) in Red Hat Enterprise Linux (RHEL) to limit the amount of memory that a specific process or group of processes can use.

Here's a step-by-step guide on how to limit the RAM usage for a specific process or group of processes:

  1. Install and Enable cgroup-tools:

    If you haven't already, you may need to install the cgroup-tools package:

    sudo yum install libcgroup-tools
    
  2. Create a Memory Cgroup:

    Create a new cgroup for your test processes:

    sudo cgcreate -g memory:/mytestgroup
    

    Replace /mytestgroup with the desired cgroup name.

  3. Limit Memory Usage:

    Set memory limits for the cgroup. For example, to limit it to 16GB of RAM:

    sudo cgset -r memory.limit_in_bytes=16G mytestgroup
    

    Adjust the limit to the amount of RAM you want to allocate for your tests.

  4. Move Your Process(es) to the Cgroup:

    You'll need to move the processes you want to limit to the cgroup. You can do this by specifying the cgroup for the process or by using the cgexec command. For example, to run a command in the mytestgroup cgroup:

    sudo cgexec -g memory:mytestgroup your_test_command
    

    Replace your_test_command with the actual command you want to run as part of your tests.

  5. Monitor Memory Usage:

    You can monitor the memory usage of the cgroup and its processes using the cgget command:

    sudo cgget -g memory:mytestgroup
    

    This will display information about memory usage, including the memory limit and current usage.

  6. Cleanup:

    When your tests are complete, you can remove the cgroup:

    sudo cgdelete memory:mytestgroup
    

    This will remove the cgroup and release the memory limits.

By following these steps, you can effectively limit the amount of RAM that specific processes or groups of processes can use on a server with more physical RAM than you need for your testing purposes. This allows you to isolate and control the resources allocated to your test processes without the need to physically change the server's hardware configuration.

1
  • Thanks. Not exactly what we needed (we really do want to limit the physical RAM used for everything, not just some processes) but it may be useful in future Oct 9, 2023 at 17:20

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .