Swap performance testing

2

I understand the general concept of swap memory, but I need to somehow build a program that forces the use of swap memory for performance testing and I don't know where to even begin.

Basically, I am going to install a flash memory card that will be used as swap space, and I want to test how the performance improves by doing so. I thought it would be easiest to make a simple program that uses multiple threads to test how well it handles multiple processes running simultaneously. Problem is, I just don't know enough about swap (or gathered enough insight from what i've read) to know how I can "force" these threads to use swap space.

Anyone have some solid suggestions on how I can approach this? I would be running this on a 64-bit linux OS, most likely Fedora 18.

cHam

Posted 2013-12-06T16:16:58.913

Reputation: 165

>

  • Flash memory will be killed very quickly if you use it for swap. Flash has limited number of writes. 2. As long as OS operates normally, programs won't run in swap. Data that's being used is loaded into RAM and data that doesn't have to be accessed at the moment is swapped. When it's needed, it's being loaded back to RAM. It's OS that decides what should be swapped, not programs.
  • < – gronostaj – 2013-12-06T16:21:25.823

    I'm not worried about the life of the flash device. This is work related and I need to test a flash device that is setup specifically for swap use. It's a new feature of the product and need to get some data about performance. – cHam – 2013-12-06T17:15:04.580

    Answers

    0

    I don't know if this is better way to archive what you want to do, but i used a C code like this

    #include <stdio.h>
    #include <stdlib.h>
    
    
    #define MB(size) ( (size) * 1024 * 1024 )
    
    int main(){
        char *p;
        if((p = (char *)malloc(MB(256))) != NULL){
                memset(p, "A", MB(256));
                sleep(300);
        }
    }
    
    gcc -o mhog mhog.c
    echo 1 > /proc/sys/vm/overcommit_memory
    

    and run ./mhog many times in this way

    ./mhog &
    

    When your server or computer will be in out of memory situation, you will see the begin used

    c4f4t0r

    Posted 2013-12-06T16:16:58.913

    Reputation: 281

    Could you explain in more detail (an edit would probably be easier to follow than a comment) how this would work in terms of using swap space? If I understand your code correctly, you are allocating 256MB to char p, then not sure what memset does. Why sleep for 300 if not in a while loop? And lastly, I know what echo does, but what is the significance of overcommit_memory? Just trying to really understand what's going on & not just getting something that may work. I appreciate the response either way. – cHam – 2013-12-06T17:37:12.143

    The memset() function fills the first n bytes of the memory area pointed to by s with the constant byte c, the sleep is used like that, the problem ins't exit and memory remain in use, i did a test on kvm virtual guest with 512 MB of memory, an 1G di swap, i cannot give you many info, but talking about overcommit_memory you can check the linux kernel doc, is writen and explained very well – c4f4t0r – 2013-12-06T17:51:54.683