public inbox for ltp@lists.linux.it
 help / color / mirror / Atom feed
* [LTP] Testcase to validate the memory usage limit imposed by the topmost memory cgroup
@ 2009-12-25  9:22 Mohamed Naufal
  2010-01-06 16:45 ` Mohamed Naufal
                   ` (2 more replies)
  0 siblings, 3 replies; 20+ messages in thread
From: Mohamed Naufal @ 2009-12-25  9:22 UTC (permalink / raw)
  To: ltp-list


[-- Attachment #1.1: Type: text/plain, Size: 245 bytes --]

Hi

I am a student who attended the FOSS.IN LTP workout (Bangalore, India). I
have attached one of the testcases we were working on. Thought I would get
it reviewed before making a patch. More testcases to follow.

Comments appreciated.

Naufal

[-- Attachment #1.2: Type: text/html, Size: 297 bytes --]

[-- Attachment #2: mem_process.c --]
[-- Type: text/x-csrc, Size: 1458 bytes --]

#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
#include <unistd.h>
#include <sys/mman.h>

int flag_exit;
int flag_allocated;
unsigned int memsize;

/*
process_options: process user specified options
*/
void process_options(int argc, char **argv) {
  int c;

  opterr = 0;
  while ((c = getopt(argc, argv, "m:")) != -1) {
    switch(c) {
    case 'm':
      memsize = atoi(optarg) * 1024 * 1024;
      break;
    default:
      errx(1, "Invalid option specifed");
    }
  }

  if(!memsize)
    errx(1, "Memory size not specified");
}

/*
touch_memory: force physical memory allocation
*/
void touch_memory(char *p, int size) {
  int i;
  int pagesize = getpagesize();

  for (i = 0; i < size; i += pagesize) {
    p[i] = 0xef;
  }
}

void mem_map() {
  static char *p;

  if (!flag_allocated) {
    if ((p = mmap(NULL, memsize, PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANONYMOUS, 0, 0)) == MAP_FAILED)
      errx(1, "mmap failed");
    touch_memory(p, memsize);
  }
  else {;
    if (munmap(p, memsize) == -1)
      errx(1, "munmap failed");
  }
}

/*
sigint: set the exit flag on receiving SIGINT
*/
void sigint(int num) {
  flag_exit = 1;
}

/*
sigusr1: allocate/free memory on receving SIGUSR1
*/
void sigusr1(int num) {
  mem_map();
  flag_allocated = !flag_allocated;
}


int main(int argc, char **argv) {
  signal(SIGINT, sigint);
  signal(SIGUSR1, sigusr1);

  process_options(argc, argv);

  while(!flag_exit)
    sleep(1);

  return 0;
}

[-- Attachment #3: test_mem_fun.sh --]
[-- Type: application/x-sh, Size: 2581 bytes --]

[-- Attachment #4: Type: text/plain, Size: 390 bytes --]

------------------------------------------------------------------------------
This SF.Net email is sponsored by the Verizon Developer Community
Take advantage of Verizon's best-in-class app development support
A streamlined, 14 day to market process makes app distribution fast and easy
Join now and get one step closer to millions of Verizon customers
http://p.sf.net/sfu/verizon-dev2dev 

[-- Attachment #5: Type: text/plain, Size: 155 bytes --]

_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

^ permalink raw reply	[flat|nested] 20+ messages in thread

end of thread, other threads:[~2010-03-06 12:15 UTC | newest]

Thread overview: 20+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-12-25  9:22 [LTP] Testcase to validate the memory usage limit imposed by the topmost memory cgroup Mohamed Naufal
2010-01-06 16:45 ` Mohamed Naufal
2010-01-07  8:50 ` Subrata Modak
2010-01-11 16:22 ` Cyril Hrubis
     [not found]   ` <20100128041619.GB16209@malik-laptop.in.ibm.com>
2010-02-21  7:53     ` Mohamed Naufal
2010-02-21  8:05       ` Mohamed Naufal
2010-02-26 19:05         ` Mohamed Naufal
2010-02-26 20:13       ` Garrett Cooper
2010-02-27 13:05         ` Mohamed Naufal
2010-02-27 14:06           ` Mohamed Naufal
2010-02-27 20:24             ` Garrett Cooper
2010-02-28 18:14               ` Rishikesh K Rajak
2010-03-01  2:37                 ` Mohamed Naufal
2010-03-01  4:29                   ` Rishikesh K Rajak
2010-03-01  5:21                   ` Rishikesh K Rajak
2010-03-01  6:28                     ` Rishikesh K Rajak
2010-03-01  7:40                       ` Mohamed Naufal
2010-03-01  8:58                         ` Rishikesh K Rajak
     [not found]                         ` <20100302120239.GA2845@malik-laptop.in.ibm.com>
2010-03-04 13:18                           ` Rishikesh K Rajak
2010-03-06 12:14                             ` Mohamed Naufal

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox