Changeset 102

Show
Ignore:
Timestamp:
07/14/05 08:28:54 (3 years ago)
Author:
jtv
Message:

Allow building with most configuration features disabled; better debug output

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • README

    r92 r102  
    3333 
    3434Robustness and user-friendliness are the first priorities of development.  For 
    35 example, all alternatives we have found will unnecessarily allocate several 
    36 chunks of memory in dealing with low-memory situations.  Allocation failure will 
    37 typically crash these programs, whereas swapspace categorically avoids all 
    38 reliance on dynamically allocated memory. 
     35example, all alternatives we looked at perversely needed to allocate multiple 
     36chunks of memory in dealing with low-memory situations; allocation failure would 
     37typically crash these programs.  It turned out that none of these allocations 
     38were really necessary, and swapspace avoids them categorically.  This kills two 
     39birds with one stone when it comes to reliability: (i) the program doesn't ask 
     40for memory just when the least memory is available and (ii) it eliminates one of 
     41the most important causes of programming bugs as a risk factor. 
    3942 
    4043User-friendliness primarily means that no silly questions are asked of the user. 
    4144The daemon tries to be sensible and figure out what is needed at runtime, by 
    42 itself, and without user intervention. 
     45itself, and without user intervention.  You should not have any need to learn 
     46about the configuration parameters, or tweak them.  They exist mostly for 
     47development purposes. 
    4348 
    4449The swapspace daemon has been in production use for several months on various 
     
    5762state. 
    5863 
     64Swapspace itself is a small program: about 40 kilobytes on my system--or even 
     65less in a special version that doesn't accept most options and ignores its 
     66configuration file.  On top of that it allocates no memory at runtime (although 
     67the system will allocate some, of course) and does not use much stack space. 
     68 
    5969 
    6070When not to use it 
     
    6373need to remain responsive at all times; depending on the system and the 
    6474cicrumstances, the creation a large new swapfile can take as long as half a 
    65 minute and occupy quite a lot of the system's attention.  The program attempt
    66 to minimize the frequency of allocations, but cannot avoid them altogether while 
    67 still being useful. 
     75minute and occupy quite a lot of the system's attention.  The program minimize
     76the number of times swapfiles are created, but it wouldn't be very useful if it 
     77never created any swapfiles at all! 
    6878 
    69 We are hoping to address this shortcoming in the future.  Since the problem 
     79We are hoping to bring further improvements in the future.  Since the problem 
    7080appears to be caused mostly by system code, however, it's hard to be sure that 
    71 this is really possible. 
     81this is really possible.  It may turn out to be possible for the kernel, with 
     82some modifications, to extend an existing swapfile while it is already in use. 
     83That would probably help a great deal, but we don't know at the moment how much 
     84work it would take. 
    7285 
    7386 
  • debian/changelog

    r96 r102  
    66  * New -v|--verbose option logs state transitions and other debug info 
    77  * Updated documentation 
     8  * Makefile installs binary as world-executable (and strips it first) 
     9  * Can be built with most configuration features disabled 
     10  * Much more extensive dumps of internal state on signal receipt 
     11  * Add own C/cpp options to those set in environment 
    812 
    9  -- Jeroen T. Vermeulen <jtv@sipa.or.th>  Sat, 02 July 2005 15:30:00 +0700 
     13 -- Jeroen T. Vermeulen <jtv@sipa.or.th>  Thu, 14 July 2005 19:30:00 +0700 
    1014 
    1115swapspace (1.4) unstable; urgency=low 
  • doc/swapspace.8

    r91 r102  
    1111This program aims to reduce or do away with the need for swapfiles. 
    1212.PP 
    13 The following options are accepted. 
     13.B swapspace 
     14can be built in two configurations: the full-featured one (which is 
     15now the default) or the unconfigurable version.  The latter only accepts a few 
     16options, disabling all features that are probably only relevant to developers. 
     17At some point in the feature, when enough confidence exists that the various 
     18configuration parameters are either good enough for everyone or have been made 
     19unnecessary, the unconfigurable build may become the default. 
     20.PP 
     21The following options are accepted in the unconfigurable version.  All of these 
     22have more extensive equivalents in the full-featured version. 
     23.TP 
     24\fB\-d\fR 
     25Quietly ignored; always enabled in unconfigurable version. 
     26.TP 
     27\fB\-h\fR 
     28Display usage information and exit. 
     29.TP 
     30\fB\-p\fR 
     31Write process identifier to \fI/var/lib/swapspace.pid\fR when starting (and 
     32delete it when shutting down).  The file's name and location cannot be changed 
     33in the unconfigurable version. 
     34.TP 
     35\fB\-q\fR 
     36Quietly ignored; always enabled in unconfigurable version. 
     37.TP 
     38\fB\-v\fR 
     39Quietly ignored; always enabled in unconfigurable version. 
     40.TP 
     41\fB\-V\fR 
     42Print program version information and exit. 
     43.PP 
     44In most cases, these should be the only options of any interest for normal use 
     45of the program.  All files are kept in their default locations, which were 
     46chosen in accordance with the Linux Filesystem Hierarchy Standard, and 
     47algorithmic parameters are left at defaults that have been tested to work well 
     48for a wide range of uses. 
     49.PP 
     50The full-featured configuration accepts more options, as listed below. 
    1451The long-format options may also be specified, without the leading "\-\-", in a 
    1552configuration file.  By default, \fI/etc/swapspace.conf\fR is read on startup. 
  • src/Makefile

    r85 r102  
    44# swapspace is written in C99, but with at least one extension that isn't 
    55# supported in gcc's C99 mode: sigaction() (though it is part of POSIX). 
    6 CFLAGS=--std=gnu99 -Wall --pedantic -Wshadow -O2 -g 
    7 CPPFLAGS=-DSUPPORT_LARGE_FILES -DVERSION="\"$(VERSION)\"" -DDATE="\"$(DATE)\"" 
     6CFLAGS += --std=gnu99 -Wall --pedantic -Wshadow -O2 -g 
     7CPPFLAGS += -DSUPPORT_LARGE_FILES -DVERSION="\"$(VERSION)\"" -DDATE="\"$(DATE)\"" 
    88RM=rm -f 
     9 
     10# Uncomment this to build a special ultra-lightweight unconfigurable version of 
     11# swapspace.  This saves perhaps 20 kilobytes of binary size and breaks all but 
     12# a few of the command line options.  You probably don't want this; it's mostly 
     13# here as a proof-of-concept and testing ground for the future elimination of 
     14# configuration items. 
     15#CPPFLAGS += -DNO_CONFIG 
     16 
     17# Uncomment this to disable assertions and internal consistency checking that 
     18# you probably don't need after release. 
     19# CPPFLAGS += -DNDEBUG 
    920 
    1021all : swapspace hog 
  • src/log.c

    r93 r102  
    135135 
    136136 
     137#ifndef NO_CONFIG 
    137138void log_discrep(int priority, 
    138139    const char msg[], 
     
    157158        found); 
    158159} 
     160#endif 
    159161 
  • src/log.h

    r93 r102  
    4848void log_perrno_str(int priority, const char msg[], const char arg[], int err); 
    4949 
    50 /// Log message, but appending an integer argument 
     50/// Log message, but appending a quoted integer argument 
    5151void log_int(int priority, const char msg[], int arg); 
    5252 
     53/// Log message, but appending an (unquoted) long long argument 
     54void log_longlong(int priority, const char msg[], long long arg); 
     55 
     56#ifndef NO_CONFIG 
    5357/// Log logfile size discrepancy 
    5458void log_discrep(int priority, 
     
    5761    memsize_t expected, 
    5862    memsize_t found); 
     63#endif 
    5964 
    6065#endif 
  • src/main.c

    r94 r102  
    4343#include "swaps.h" 
    4444 
    45  
    46  
    47 static bool godaemon = false; 
    48  
    49 char *set_daemon(long long dummy) 
    50 { 
    51   godaemon = true; 
    52   return NULL; 
    53 } 
    54  
    55  
    56 bool quiet = false; 
    57 bool verbose = false; 
    58  
    5945char localbuf[8192]; 
    60  
    6146time_t clock = 0; 
     47 
    6248 
    6349static char pidfile[PATH_MAX] = "/var/run/swapspace.pid"; 
     
    7157} 
    7258 
     59#ifndef NO_CONFIG 
     60static bool godaemon = false; 
     61 
     62char *set_daemon(long long dummy) 
     63{ 
     64  godaemon = true; 
     65  return NULL; 
     66} 
     67 
     68bool quiet = false; 
     69bool verbose = false; 
     70 
    7371char *set_quiet(long long dummy) 
    7472{ 
     
    7674  return NULL; 
    7775} 
    78  
    7976char *set_verbose(long long dummy) 
    8077{ 
     
    8380} 
    8481 
    85  
    8682bool main_check_config(void) 
    8783{ 
     
    8985  return true; 
    9086} 
    91  
    92  
    93  
    94 /// Was a dump of statistics requested? 
    95 static volatile bool print_status=false; 
    96  
    97 /// Was an immediate adjustment requested? 
    98 static volatile bool adjust_swap=false; 
     87#else 
     88#define godaemon true 
     89#endif 
    9990 
    10091 
     
    10394  unlink(pidfile); 
    10495} 
    105  
    10696 
    10797/// Write our process identifier to pid file.  Clobbers localbuf. 
     
    117107  return true; 
    118108} 
    119  
    120109 
    121110/// Create pidfile, if requested 
     
    143132} 
    144133 
    145  
    146134/// Signal handler that causes program to abort, but cleans up pidfile first  
    147135static void sighand_die(int sig) 
     
    151139  exit(EXIT_FAILURE); 
    152140} 
    153  
    154  
    155141 
    156142/// Write process id to pidfile if requested, and close it.  Clobbers localbuf. 
     
    172158} 
    173159 
    174  
    175160static pid_t daemonize(void) 
    176161{ 
     
    182167 
    183168 
     169/// Was a dump of statistics requested? 
     170static volatile bool print_status=false; 
     171 
     172/// Was an immediate adjustment requested? 
     173static volatile bool adjust_swap=false; 
     174 
    184175 
    185176/// Signal handler that requests generation of a status report to stdout 
     
    237228  if (unlikely(!read_proc_swaps()) || 
    238229      unlikely(!activate_old_swaps()) || 
    239       unlikely(!check_memory_status()) || 
    240       unlikely(!startpidfile())) 
     230      unlikely(!check_memory_status())) 
    241231    return EXIT_FAILURE; 
     232 
     233  if (unlikely(!startpidfile())) return EXIT_FAILURE; 
    242234 
    243235  /* Do a first iteration here so we can report any startup errors, and if we're 
     
    252244  { 
    253245    if (!read_proc_swaps()) return EXIT_FAILURE; 
     246#ifndef NO_CONFIG 
    254247    if (!quiet && !proc_swaps_parsed()) 
    255248      fputs("[/proc/swaps is empty, so cannot check its format]\n", stderr); 
     249#endif 
    256250  } 
    257251 
    258252  if (godaemon) 
    259253  { 
     254#ifndef NO_CONFIG 
    260255    if (verbose) log_msg(LOG_DEBUG, "daemonizing..."); 
     256#endif 
    261257    const pid_t pid = daemonize(); 
    262258    if (unlikely(pid < 0)) 
     
    272268       */ 
    273269      lseek(pidfd, 0, SEEK_SET); 
     270#ifndef NO_CONFIG 
    274271      if (verbose) log_int(LOG_DEBUG, "got process id", pid); 
     272#endif 
    275273      return writepid(pid) ? EXIT_SUCCESS : EXIT_FAILURE; 
    276274    } 
  • src/main.h

    r89 r102  
    4545extern time_t clock; 
    4646 
     47#ifndef NO_CONFIG 
    4748/// Suppress informational output and warnings? 
    4849extern bool quiet; 
     
    5051extern bool verbose; 
    5152 
    52 char *set_daemon(long long dummy); 
    53 char *set_pidfile(long long dummy); 
    5453char *set_quiet(long long dummy); 
    5554char *set_verbose(long long dummy); 
    5655 
    5756bool main_check_config(void); 
     57#endif 
     58 
     59char *set_daemon(long long dummy); 
     60char *set_pidfile(long long dummy); 
    5861 
    5962#endif 
  • src/memory.c

    r86 r102  
    4747static int cache_meekness=80; 
    4848 
     49#ifndef NO_CONFIG 
    4950char *set_freetarget(long long pct) 
    5051{ 
     
    5253  return NULL; 
    5354} 
    54  
    5555char *set_lower_freelimit(long long pct) 
    5656{ 
     
    5858  return NULL; 
    5959} 
    60  
    6160char *set_upper_freelimit(long long pct) 
    6261{ 
     
    6463  return NULL; 
    6564} 
    66  
    6765char *set_buffer_meekness(long long pct) 
    6866{ 
     
    7068  return NULL; 
    7169} 
    72  
    7370char *set_cache_meekness(long long pct) 
    7471{ 
     
    7673  return NULL; 
    7774} 
    78  
    7975 
    8076bool memory_check_config(void) 
     
    8581  return true; 
    8682} 
     83#endif 
    8784 
    8885 
     
    280277{ 
    281278  const memsize_t init_req = memory_target(); 
    282   if (init_req == MEMSIZE_ERROR) return false; 
     279  if (unlikely(init_req == MEMSIZE_ERROR)) return false; 
     280#ifndef NO_CONFIG 
    283281  if (init_req && !quiet) 
    284282  { 
    285283    printf("Initial memory status: "); 
    286     if (init_req > 0) printf("would prefer %lld extra bytes\n", init_req); 
    287     else if (init_req < 0) printf("%lld bytes to spare\n", -init_req); 
    288   } 
     284    if (init_req > 0) 
     285      sprintf(localbuf, "would prefer %lld extra bytes", init_req); 
     286    else 
     287      sprintf(localbuf, "%lld bytes to spare", -init_req); 
     288    log_msg(LOG_INFO, localbuf); 
     289  } 
     290#endif 
    289291  return true; 
    290292} 
     
    379381  return request; 
    380382} 
     383 
     384 
     385static void dump_memline(const char category[], 
     386    long long total, 
     387    long long free, 
     388    long long cached) 
     389{ 
     390  sprintf(localbuf, 
     391      "%s: %lld total, %lld free (%lld used); %lld cached", 
     392      category, 
     393      total, 
     394      free, 
     395      (total - free), 
     396      cached); 
     397  log_msg(LOG_INFO, localbuf); 
     398} 
     399 
     400void dump_memory(void) 
     401{ 
     402  struct memstate st = { 0, 0, 0, 0, 0, 0, 0, 0 }; 
     403  if (unlikely(!read_proc_meminfo(&st))) return; 
     404  check_memory_status(); 
     405 
     406  dump_memline("core", st.MemTotal, st.MemFree, st.Cached); 
     407  dump_memline("swap", st.SwapTotal, st.SwapFree, st.SwapCached); 
     408  dump_memline("total", 
     409      space_total(&st), 
     410      st.MemFree + st.SwapFree, 
     411      st.Cached + st.SwapCached); 
     412 
     413  sprintf(localbuf, 
     414      "bufs: %lld, dirty: %lld, writeback: %lld", 
     415      st.Buffers, 
     416      st.Dirty, 
     417      st.Writeback); 
     418  log_msg(LOG_INFO, localbuf); 
     419 
     420  const int pf = pct_free(&st); 
     421  sprintf(localbuf, 
     422      "estimate free: %lld cache, %lld bufs, %lld total (%d%%)", 
     423      cache_free(&st), 
     424      buffers_free(&st), 
     425      space_free(&st), 
     426      pf); 
     427  log_msg(LOG_INFO, localbuf); 
     428  sprintf(localbuf, 
     429      "thresholds: %d%% < %d%% < %d%%", 
     430      lower_freelimit, 
     431      pf, 
     432      upper_freelimit); 
     433  log_msg(LOG_INFO, localbuf); 
     434} 
     435 
     436 
  • src/memory.h

    r78 r102  
    4141memsize_t memory_target(void); 
    4242 
     43void dump_memory(void); 
     44 
     45#ifndef NO_CONFIG 
    4346char *set_lower_freelimit(long long pct); 
    4447char *set_upper_freelimit(long long pct); 
     
    4851 
    4952bool memory_check_config(void); 
     53#endif 
    5054 
    5155#endif 
     56 
  • src/opts.c

    r95 r102  
    3131#include "opts.h" 
    3232#include "support.h" 
     33#include "state.h" 
    3334#include "swaps.h" 
    3435 
     36 
     37static const char copyright[] = "\n" 
     38      "Copyright (c) 2004-2005 Software Industry Promotion Agency of Thailand\n" 
     39      "Written by Jeroen T. Vermeulen <jtv@sipa.or.th>\n" 
     40      "This program is free software, and is available for use under the GNU\n" 
     41      "General Public License (GPL).\n"; 
     42 
     43 
     44#ifndef NO_CONFIG 
    3545static char configfile[PATH_MAX] = "/etc/swapspace.conf"; 
    3646 
     
    4252static char *set_help(long long dummy); 
    4353static char *set_version(long long dummy); 
    44  
    4554 
    4655enum argtype { at_none, at_num, at_str }; 
     
    5766  const char *desc; 
    5867}; 
    59  
    6068 
    6169/// Available options, sorted alphabetically by long option name 
     
    97105 
    98106 
     107static int optcmp(const void *o1, const void *o2) 
     108{ 
     109  return strcmp(((const struct option *)o1)->name, 
     110                ((const struct option *)o2)->name); 
     111} 
     112 
     113 
    99114#ifndef NDEBUG 
    100115static bool options_okay(void) 
     
    141156  return true; 
    142157} 
    143 #endif 
     158#endif // NDEBUG 
    144159 
    145160static const char *argproto(int opt, bool shortopt) 
     
    154169  return result; 
    155170} 
    156  
    157 const char copyright[] = "\n" 
    158       "Copyright (c) 2004-2005 Software Industry Promotion Agency of Thailand\n" 
    159       "Written by Jeroen T. Vermeulen <jtv@sipa.or.th>\n" 
    160       "This program is free software, and is available for use under the GNU\n" 
    161       "General Public License (GPL).\n"; 
    162171 
    163172static char *set_help(long long dummy) 
     
    197206  exit(EXIT_SUCCESS); 
    198207} 
     208#else 
     209 
     210static void short_usage(void) 
     211{ 
     212  puts("This is the unconfigurable version of swapspace.\n" 
     213      "\n" 
     214      "Usage: swapspace [-d] [-h] [-p] [-V]\n" 
     215      "\t-d run as daemon" 
     216      "\t-h display this overview and exit\n" 
     217      "\t-p create pidfile\n" 
     218      "\t-q (ignored)\n" 
     219      "\t-v (ignored)\n" 
     220      "\t-V display version information and exit\n" 
     221      "\n" 
     222      "Use zero-argument version for normal operation."); 
     223  puts(copyright); 
     224  exit(EXIT_SUCCESS); 
     225} 
     226 
     227#endif  // NO_CONFIG 
    199228 
    200229 
     
    207236 
    208237 
    209 static int optcmp(const void *o1, const void *o2) 
    210 
    211   return strcmp(((const struct option *)o1)->name, 
    212                 ((const struct option *)o2)->name); 
    213 
    214  
    215  
    216  
     238#ifndef NO_CONFIG 
    217239/// Emit error message about configuration.  Returns false. 
    218240static bool config_error(const char msg[]) 
     
    292314  return true; 
    293315} 
    294  
    295316 
    296317 
     
    411432  return true; 
    412433} 
    413  
     434#endif  // NO_CONFIG 
    414435 
    415436 
    416437bool configure(int argc, char *argv[]) 
    417438{ 
     439#ifndef NO_CONFIG 
     440 
    418441  assert(options_okay()); 
    419442 
     
    427450   
    428451  return main_check_config() && swaps_check_config() && memory_check_config(); 
    429 
    430  
     452 
     453#else 
     454 
     455  // Unconfigurable build; we only do a minimal options loop. 
     456  for (int a=1; argv[a]; ++a) 
     457  { 
     458    if (argv[a][0] != '-') 
     459    { 
     460      fprintf(stderr, "Invalid argument: '%s'.  Try the -h option.\n", argv[a]); 
     461      return false; 
     462    } 
     463    switch (argv[a][1]) 
     464    { 
     465    case 'd':                   break;  // Quietly ignored 
     466    case 'h': short_usage();    break;  // Does not return 
     467    case 'p': set_pidfile(0);   break; 
     468    case 'q':                   break;  // Quietly ignored 
     469    case 'v':                   break;  // Quietly ignored 
     470    case 'V': set_version(0);   break;  // Does not return 
     471    default: 
     472      fprintf(stderr,"Invalid option: '%s'. Try -h instead.\n",argv[a]); 
     473      return false; 
     474    } 
     475  } 
     476  return swaps_check_config(); 
     477 
     478#endif 
     479
     480 
     481 
  • src/state.c

    r96 r102  
    5151static inline bool timer_timeout(void) { return timer <= 0; } 
    5252 
     53#ifndef NO_CONFIG 
    5354char *set_cooldown(long long duration) 
    5455{ 
     
    5758  return NULL; 
    5859} 
     60#endif 
    5961 
    6062 
     
    8486static void state_to(enum State s) 
    8587{ 
     88#ifndef NO_CONFIG 
    8689  if (verbose) 
    8790  { 
     
    8992    log_msg(LOG_DEBUG, localbuf); 
    9093  } 
     94#endif 
    9195  the_state = s; 
    9296  timer_reset(); 
  • src/state.h

    r96 r102  
    2828void request_diet(void); 
    2929 
     30#ifndef NO_CONFIG 
     31char *set_cooldown(long long duration); 
    3032#endif 
    3133 
     34#endif 
     35 
  • src/swaps.c

    r98 r102  
    5656static size_t swappath_len; 
    5757 
    58 char *set_swappath(long long dummy) 
    59 { 
    60   return swappath; 
    61 } 
    6258 
    6359/// Smallest allowed swapfile size 
     
    7066 
    7167 
     68#ifndef NO_CONFIG 
     69char *set_swappath(long long dummy) 
     70{ 
     71  return swappath; 
     72} 
    7273char *set_min_swapsize(long long size) 
    7374{ 
     
    7576  return NULL; 
    7677} 
    77  
    7878char *set_max_swapsize(long long size) 
    7979{ 
     
    8181  return NULL; 
    8282} 
     83#endif 
    8384 
    8485 
    8586bool swaps_check_config(void) 
    8687{ 
     88#ifndef NO_CONFIG 
    8789  CHECK_CONFIG_ERR(min_swapsize > max_swapsize); 
    8890  CHECK_CONFIG_ERR(min_swapsize < 10*PAGE_SIZE); 
     91#endif 
    8992 
    9093  if (chdir(swappath) == -1) 
     
    9396    return false; 
    9497  } 
     98 
     99  swappath_len = strlen(swappath); 
     100 
     101#ifndef NO_CONFIG 
    95102  if (!getcwd(swappath, sizeof(swappath))) 
    96103  { 
     
    98105    return false; 
    99106  } 
    100   swappath_len = strlen(swappath); 
    101107  // Remove trailing slash, if any 
    102108  if (swappath_len && swappath[swappath_len-1] == '/') 
     
    110116    return false; 
    111117  } 
     118#endif 
    112119 
    113120  return true; 
     
    150157 
    151158  dump_state(); 
    152  
    153   // TODO: Print memory overview, and include percentages 
    154  
    155   log_msg(LOG_INFO, "swapfiles in use:"); 
    156   log_msg(LOG_INFO, "file          size          used"); 
    157   for (int i=0; i<MAX_SWAPFILES; ++i) if (swapfiles[i].size) 
    158   { 
    159     sprintf(localbuf,"%4d%16lld%16lld",i,swapfiles[i].size,swapfiles[i].used); 
    160     log_msg(LOG_INFO, localbuf); 
     159  dump_memory(); 
     160 
     161  // Count active swapfiles.  Note that we don't remember this anywhere; it's 
     162  // rarely needed (only when requested), it's not very costly to derive, and 
     163  // keeping a redundant counter is just asking for minor bugs. 
     164  int activeswaps = 0; 
     165  for (int i=0; i<MAX_SWAPFILES; ++i) if (swapfiles[i].size) ++activeswaps; 
     166  sprintf(localbuf, "swapfiles in use: %d", activeswaps); 
     167  log_msg(LOG_INFO, localbuf); 
     168  if (activeswaps) 
     169  { 
     170    log_msg(LOG_INFO, "file          size          used"); 
     171    for (int i=0; i<MAX_SWAPFILES; ++i) if (swapfiles[i].size) 
     172    { 
     173      sprintf(localbuf,"%4d%16lld%16lld",i,swapfiles[i].size,swapfiles[i].used); 
     174      log_msg(LOG_INFO, localbuf); 
     175    } 
    161176  } 
    162177} 
     
    220235      { 
    221236        max_swapsize = TRUNC_TO_PAGE(bytes); 
     237#ifndef NO_CONFIG 
    222238        if (verbose) 
    223239        { 
     
    225241          log_msg(LOG_INFO, localbuf); 
    226242        } 
     243#endif 
    227244      } 
    228245      break; 
     
    332349    if (valid_swapfile(d->d_name, &seqno) && !swapfiles[seqno].size) 
    333350    { 
     351#ifndef NO_CONFIG 
    334352      if (!quiet) log_int(LOG_INFO, "Found old swapfile", seqno); 
     353#endif 
    335354      const memsize_t size = filesize(d->d_name);  
    336355      if (likely(size > min_swapsize && enable_swapfile(d->d_name))) 
     
    340359      else 
    341360      { 
     361#ifndef NO_CONFIG 
    342362        if (!quiet) log_int(LOG_NOTICE, "Deleting unusable swapfile", seqno); 
     363#endif 
    343364        unlink(d->d_name); 
    344365      } 
     
    430451      { 
    431452        // We didn't know about this swapfile yet.  Adopt it. 
     453#ifndef NO_CONFIG 
    432454        if (!quiet) log_int(LOG_NOTICE, "Detected swapfile", result->seqno); 
     455#endif 
    433456        swapfiles[result->seqno].created = clock; 
    434457      } 
     458#ifndef NO_CONFIG 
    435459      else if (unlikely(swapfiles[result->seqno].size != result->size)) 
    436460      { 
     
    461485            result->used, 
    462486            result->size); 
     487#endif 
    463488 
    464489      swapfiles[result->seqno].size = result->size; 
     
    510535  char namebuf[30]; 
    511536  snprintf(namebuf, sizeof(namebuf), "%d", file); 
     537#ifndef NO_CONFIG 
    512538  if (!quiet) log_int(LOG_NOTICE, "Retiring swapfile", file); 
     539#endif 
    513540  if (unlikely(swapoff(namebuf) == -1)) return false; 
    514541  swapfiles[file].size = 0; 
     
    565592 
    566593  // We can allocate another swapfile.  Great. 
     594#ifndef NO_CONFIG 
    567595  if (!quiet) log_int(LOG_NOTICE, "Allocating swapfile", newswap); 
     596#endif 
    568597  char file[30]; 
    569598  snprintf(file, sizeof(file), "%d", newswap); 
  • src/swaps.h

    r82 r102  
    6464void free_swapfile(memsize_t maxsize); 
    6565 
     66#ifndef NO_CONFIG 
    6667char *set_min_swapsize(long long size); 
    6768char *set_max_swapsize(long long size); 
    68 char *set_cooldown(long long duration); 
    6969char *set_swappath(long long dummy); 
     70#endif 
    7071 
    7172/// Verify configuration for swaps module; cd into swappath