Changeset 4282


Ignore:
Timestamp:
01/19/10 13:44:23 (3 years ago)
Author:
sam
Message:

Fix memory limitation method on OS X (page size was ignored) and other
systems (was using MBs instead of MiBs?).

Location:
zzuf/trunk/src
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • zzuf/trunk/src/libzzuf/lib-mem.c

    r4258 r4282  
    132132/* setrlimit(RLIMIT_AS) is ignored on OS X, we need to check memory usage 
    133133 * from inside the process. Oh, and getrusage() doesn't work either. */ 
     134#if defined HAVE_MACH_TASK_H 
     135vm_size_t mach_page_size; 
     136#endif 
     137 
    134138static int memory_exceeded(void) 
    135139{ 
     
    140144    if (task_info(mach_task_self(), TASK_BASIC_INFO, 
    141145                  (task_info_t)&tbi, &mmtn) == KERN_SUCCESS 
    142          && tbi.resident_size > _zz_memory) 
     146         && (int64_t)tbi.resident_size * mach_page_size / 1048576 
     147                  > (int64_t)_zz_memory) 
    143148        return 1; 
    144149#endif 
     
    152157    LOADSYM(malloc); 
    153158    LOADSYM(realloc); 
     159 
     160#if defined HAVE_MACH_TASK_H 
     161    host_page_size(mach_host_self(), &mach_page_size); 
     162#endif 
    154163} 
    155164 
  • zzuf/trunk/src/libzzuf/libzzuf.c

    r4258 r4282  
    177177    tmp = getenv("ZZUF_MEMORY"); 
    178178    if(tmp) 
    179         _zz_memory = atoll(tmp); 
     179        _zz_memory = atoi(tmp); 
    180180 
    181181    tmp = getenv("ZZUF_NETWORK"); 
  • zzuf/trunk/src/myfork.c

    r4257 r4282  
    179179    { 
    180180        struct rlimit rlim; 
    181         rlim.rlim_cur = opts->maxmem * 1000000; 
    182         rlim.rlim_max = opts->maxmem * 1000000; 
     181        rlim.rlim_cur = opts->maxmem * 1048576; 
     182        rlim.rlim_max = opts->maxmem * 1048576; 
    183183        setrlimit(ZZUF_RLIMIT_MEM, &rlim); 
    184184    } 
  • zzuf/trunk/src/zzuf.c

    r4277 r4282  
    291291#if defined HAVE_SETRLIMIT && defined ZZUF_RLIMIT_MEM 
    292292        case 'M': /* --max-memory */ 
    293             setenv("ZZUF_MEMORY", "1", 1); 
    294293            if(myoptarg[0] == '=') 
    295294                myoptarg++; 
     
    458457    if(opts->refuse) 
    459458        setenv("ZZUF_REFUSE", opts->refuse, 1); 
     459#if defined HAVE_SETRLIMIT && defined ZZUF_RLIMIT_MEM 
     460    if(opts->maxmem >= 0) 
     461    { 
     462        char buf[32]; 
     463        snprintf(buf, 32, "%i", opts->maxmem); 
     464        setenv("ZZUF_MEMORY", buf, 1); 
     465    } 
     466#endif 
    460467 
    461468    /* Allocate memory for children handling */ 
Note: See TracChangeset for help on using the changeset viewer.