Re: Swap priorities with swapon (Is my swap drive working?)

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]




James Bensley wrote:
>> It will kick in, regardless of priority.
>>
>> But probably someone will come up with a small c program which eats all
>> available memory :)
>>
>> Regards,
>>
>> Ralph
> 
> I would be interested  in such a program if anyone has one or a mega
> bash script that can achive the same?
> 

cat /proc/meminfo says it all, but if you really want to test this can 
do the job:

[nthierry@tryo tmp]$ cat totalMem.c
#include <stdlib.h>
#include <stdio.h>

int main(void)
{
   int size = 0 ;
   while(1)
     {
       if (malloc(1024*1024*sizeof(char)))
         size++ ;
       else
         {
           printf("Total available memory: %d Mb\n", size) ;
           exit(0) ;
         }
     }
}

[nthierry@tryo tmp]$ gcc -W -Wall totalMem.c
[nthierry@tryo tmp]$ su -
[root@tryo tmp]# echo 2 > /proc/sys/vm/overcommit_memory
[root@tryo tmp]# echo 100 > /proc/sys/vm/overcommit_ratio
[NOTE: the previous 2 commands must be run as root, and disable the 
memory overcommit mode. See man malloc (under BUGS) and man proc (search 
for overcommit) for details.]
[root@tryo tmp]# swapoff -a
[root@tryo tmp]# ./a.out
Total available memory: 1487 Mb
[root@tryo tmp]# swapon -a
[root@tryo tmp]# ./a.out
Total available memory: 2056 Mb

This system has 600 Mb swap space and 2 Gb of RAM of which ~500 Mb are 
currently used by other processes.
So it works, and shows that the swap is indeed available.

When satisfied restore the vm settings
[root@tryo tmp]# echo 50 > /proc/sys/vm/overcommit_ratio
[root@tryo tmp]# echo 0 > /proc/sys/vm/overcommit_memory


_______________________________________________
CentOS mailing list
CentOS@xxxxxxxxxx
http://lists.centos.org/mailman/listinfo/centos

[Index of Archives]     [CentOS]     [CentOS Announce]     [CentOS Development]     [CentOS ARM Devel]     [CentOS Docs]     [CentOS Virtualization]     [Carrier Grade Linux]     [Linux Media]     [Asterisk]     [DCCP]     [Netdev]     [Xorg]     [Linux USB]
  Powered by Linux