Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

There is Solaris 10 OS on our server, and I would like to make test on this server. For this test memory usage should be high.

So I wonder if there is an easy way to increase memory usage manually ?

share|improve this question
By "usage" you mean just allocated, or memory in use (like during a stress test)? – Nils Sep 20 '12 at 20:09
I mean emory in usage as you said like a stress test. – mibzer Sep 21 '12 at 5:51
Why did you unaccept my answer ? Anything wrong with it ? – jlliagre Sep 21 '12 at 6:04
@jlliagre I think your answer is good for memory allocation. It will not help for stress test. Thanks – mibzer Sep 21 '12 at 6:53
A small correction, tmpfs is not strictly a ramdisk but a "virtual memory" disk. i.e. it will use RAM first but leave it for swap space in case of RAM demand. – jlliagre Sep 22 '12 at 15:47
up vote 4 down vote accepted

The simplest way is to fill /tmp, assuming it is using tmpfs which is the default. Run df -k /tmp to make sure it is.

To increase your (virtual) memory usage by 1 GB, run

mkfile 1g /tmp/1g

release it with

rm /tmp/1g
share|improve this answer
The command mkfile seems to be Solaris specific, other systems may provide fallocate which is similar. – Stéphane Gimenez Sep 21 '12 at 20:57
@Stéphane Gimenez: I believe freebsd and OS/X have mkfile too. The question is Solaris specific anyway. – jlliagre Sep 21 '12 at 22:17
@StéphaneGimenez: This question is specifically about Solaris, but if you need to do this on Linux use dd if=/dev/zero of=/dev/shm/1g bs=1m count=1024 – bahamat Sep 21 '12 at 23:28
if your /tmp/ is size restricted in /etc/vfstab, you can create your file in /var/run and be able to consume more memory. – Tim Kennedy Sep 26 '12 at 13:47

This page should help you. Just small program in c:

#include <stdlib.h>
#include <stdio.h>
#include <string.h>

int main(int argc, char** argv) {
    int max = -1;
    int sleep_interval = 2;
    int mb = 0;
    char* buffer;

    if(argc > 1)
        max = atoi(argv[1]);
    if(argc > 2)
        sleep_interval = atoi(argv[2]);

    while((buffer=malloc(1024*1024)) != NULL && mb != max) {
        memset(buffer, 0, 1024*1024);
        printf("Allocated %d MB\n", mb);
    printf("sleeping for %d\n",sleep_interval);
    return 0;

Keep in mind that without giving the program a maximum amount of memory it'll allocate until it exhausts the amount it can (may be limited by ulimit, amount of memory, or size of address space).

share|improve this answer

The easiest way I know to fill memory is to make a program that allocates an array of strings (or arrays of any other type), if you need to keep the data in memory and not paged, you should scan the allocated memory periodically.

I would add a long (perhaps controlled by a command line argument) sleep interval after the allocation.

I would run several instances of the above program until I fill the desired amount of memory.

share|improve this answer

I have no idea if this works with Solaris, too - but since it is designed to run on Posix compliant systems you could give it a try: stress is a very "simple" stress-test generator, that can do all sorts of stress - creating memory hogs is part of it.

I compiled/tested it so far on some Linux distributions (CentOS, SLES) without problems.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.