Changeset 85

Show
Ignore:
Timestamp:
07/01/05 00:35:06 (4 years ago)
Author:
jtv
Message:

Reworked custom signal handlers and stats logging

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • debian/changelog

    r82 r85  
    22 
    33  * Redesigned internal state machine, should improve corner-case behaviour 
     4  * Custom signal handlers are now reusable 
     5  * Signal-triggered stats dump now goes to log if appropriate 
    46 
    57 -- Jeroen T. Vermeulen <jtv@sipa.or.th>  Wed, 29 June 2005 14:10:00 +0700 
  • src/Makefile

    r82 r85  
    22 
    33# Assumes we're using gcc 
    4 CFLAGS=--std=c99 -Wall --pedantic -Wshadow -O2 -g 
     4# swapspace is written in C99, but with at least one extension that isn't 
     5# supported in gcc's C99 mode: sigaction() (though it is part of POSIX). 
     6CFLAGS=--std=gnu99 -Wall --pedantic -Wshadow -O2 -g 
    57CPPFLAGS=-DSUPPORT_LARGE_FILES -DVERSION="\"$(VERSION)\"" -DDATE="\"$(DATE)\"" 
    68RM=rm -f 
     
    2426opts.o : opts.c opts.h main.h ../VERSION ../DATE 
    2527 
    26 state.o : state.c state.h main.h memory.h support.h swaps.h 
     28state.o : state.c state.h log.h main.h memory.h support.h swaps.h 
    2729 
    2830support.o : support.c config.h env.h support.h 
  • src/main.c

    r82 r85  
    180180 
    181181 
     182static void install_sighandler(int signum, void (*handler)(int)) 
     183{ 
     184  struct sigaction sa; 
     185  memset(&sa, 0, sizeof(sa)); 
     186  sa.sa_handler = handler; 
     187  sigaction(signum, &sa, NULL); 
     188} 
     189 
     190 
    182191/// Install signal handlers 
    183192static void install_sigs(void) 
     
    188197  signal(SIGXFSZ, SIG_IGN); 
    189198#endif 
    190   // TODO: Looks like these only work once...  Should remain in effect! 
    191   signal(SIGUSR1, sighand_status); 
    192   signal(SIGUSR2, sighand_adjust); 
     199 
     200  install_sighandler(SIGUSR1, sighand_status); 
     201  install_sighandler(SIGUSR2, sighand_adjust); 
    193202} 
    194203 
  • src/state.c

    r83 r85  
    2121#include <stdio.h> 
    2222 
     23#include "log.h" 
    2324#include "main.h" 
    2425#include "memory.h" 
     
    3031 */ 
    3132 
    32 // TODO: Adaptive cooldown_time? 
     33/* TODO: Adaptive cooldown_time? 
     34 * Extend cooldown time if a swapfile is allocated shortly after deallocation in 
     35 * "overfed" state (say, within another timeout period), or if one is 
     36 * deallocated shortly (say, at most two timeout periods) after having been 
     37 * allocated. 
     38 * Reduce cooldown time if "hungry" and/or "overfed" states consistently timeout 
     39 * too soon (say, X times in the first half of the timeout period but never in 
     40 * the second) 
     41 */ 
     42 
    3343/// Minimum cooldown time before returning to "steady state" allocation policy 
    3444static time_t cooldown_time = 600; 
     
    140150void dump_state(void) 
    141151{ 
    142   printf("state:\t%s\n", Statenames[the_state]); 
    143   if (timer > 0) printf("timer:\t%ld\n", (long)timer); 
     152  sprintf(localbuf, "state: %s", Statenames[the_state]); 
     153  log_msg(LOG_INFO, localbuf); 
     154  if (timer > 0) 
     155  { 
     156    sprintf(localbuf, "timer: %ld", (long)timer); 
     157    log_msg(LOG_INFO, localbuf); 
     158  } 
    144159} 
    145160 
  • src/swaps.c

    r82 r85  
    8989  if (chdir(swappath) == -1) 
    9090  { 
    91     log_perr_str(LOG_ERR, "Coult not cd to", swappath); 
     91    log_perr_str(LOG_ERR, "Could not cd to", swappath); 
    9292    return false; 
    9393  } 
     
    145145void dump_stats(void) 
    146146{ 
    147   // TODO: Allow this to go to logfile 
    148   printf("clock: %lld\t", (long long)clock); 
     147  sprintf(localbuf, "clock: %lld", (long long)clock); 
     148  log_msg(LOG_INFO, localbuf); 
     149 
    149150  dump_state(); 
    150151 
    151152  // TODO: Print memory overview, and include percentages 
    152153 
    153   puts("swapfiles in use:\nfile\tsize\tused"); 
    154   for (int i=0; i<MAX_SWAPFILES; ++i) 
    155     if (swapfiles[i].size) 
    156       printf("%d\t%lld\t%lld\n", 
    157           i, 
    158           swapfiles[i].size, 
    159           swapfiles[i].used); 
    160   puts("---"); 
     154  log_msg(LOG_INFO, "swapfiles in use:"); 
     155  log_msg(LOG_INFO, "file          size          used"); 
     156  for (int i=0; i<MAX_SWAPFILES; ++i) if (swapfiles[i].size) 
     157  { 
     158    sprintf(localbuf,"%4d%16lld%16lld",i,swapfiles[i].size,swapfiles[i].used); 
     159    log_msg(LOG_INFO, localbuf); 
     160  } 
    161161} 
    162162