📄 store_dir_coss.c
字号:
percent(SD->map->n_files_in_map, SD->map->max_n_files));#endif#if !USE_AUFSOPS storeAppendPrintf(sentry, "Pending operations: %d out of %d\n", cs->aq.aq_numpending, MAX_ASYNCOP);#endif storeAppendPrintf(sentry, "Flags:"); if (SD->flags.selected) storeAppendPrintf(sentry, " SELECTED"); if (SD->flags.read_only) storeAppendPrintf(sentry, " READ-ONLY"); storeAppendPrintf(sentry, "\n"); storeAppendPrintf(sentry, "Pending Relocations: %d\n", cs->pending_reloc_count); membufsDump(cs, sentry);}static voidstoreCossDirParse(SwapDir * sd, int index, char *path){ unsigned int i; unsigned int size; CossInfo *cs; off_t max_offset; i = GetInteger(); size = i << 10; /* Mbytes to Kbytes */ if (size <= 0) fatal("storeCossDirParse: invalid size value"); cs = xcalloc(1, sizeof(CossInfo)); if (cs == NULL) fatal("storeCossDirParse: couldn't xmalloc() CossInfo!\n"); sd->index = index; sd->path = xstrdup(path); sd->max_size = size; sd->fsdata = cs; cs->fd = -1; cs->swaplog_fd = -1; sd->init = storeCossDirInit; sd->newfs = storeCossDirNewfs; sd->dump = storeCossDirDump; sd->freefs = storeCossDirFree; sd->dblcheck = NULL; sd->statfs = storeCossDirStats; sd->maintainfs = NULL; sd->checkobj = storeCossDirCheckObj; sd->checkload = storeCossDirCheckLoadAv; sd->refobj = NULL; /* LRU is done in storeCossRead */ sd->unrefobj = NULL; sd->callback = storeCossDirCallback; sd->sync = storeCossSync; sd->obj.create = storeCossCreate; sd->obj.open = storeCossOpen; sd->obj.close = storeCossClose; sd->obj.read = storeCossRead; sd->obj.write = storeCossWrite; sd->obj.unlink = storeCossUnlink; sd->obj.recycle = storeCossRecycle; sd->log.open = storeCossDirOpenSwapLog; sd->log.close = storeCossDirCloseSwapLog; sd->log.write = storeCossDirSwapLog; sd->log.clean.start = storeCossDirWriteCleanStart; sd->log.clean.write = storeCossDirWriteCleanEntry; sd->log.clean.nextentry = storeCossDirCleanLogNextEntry; sd->log.clean.done = storeCossDirWriteCleanDone; cs->current_offset = 0; cs->fd = -1; cs->swaplog_fd = -1; cs->numcollisions = 0; cs->membufs.head = cs->membufs.tail = NULL; /* set when the rebuild completes */ cs->current_membuf = NULL; cs->blksz_bits = 9; /* default block size = 512 */ cs->blksz_mask = (1 << cs->blksz_bits) - 1; /* By default, only overwrite objects that were written mor ethan 50% of the disk ago * and use a maximum of 10 in-memory stripes */ cs->minumum_overwrite_pct = 0.5; cs->nummemstripes = 10; /* Calculate load in 60 second incremenets */ /* This could be made configurable */ cs->load_interval = 60; parse_cachedir_options(sd, options, 0); cs->sizerange_max = sd->max_objsize; cs->sizerange_min = sd->max_objsize; /* Enforce maxobjsize being set to something */ if (sd->max_objsize == -1) fatal("COSS requires max-size to be set to something other than -1!\n"); if (sd->max_objsize > COSS_MEMBUF_SZ) fatalf("COSS max-size option must be less than COSS_MEMBUF_SZ (%d)\n", COSS_MEMBUF_SZ); /* * check that we won't overflow sfileno later. 0xFFFFFF is the * largest possible sfileno, assuming sfileno is a 25-bit * signed integer, as defined in structs.h. */ max_offset = (off_t) 0xFFFFFF << cs->blksz_bits; if ((sd->max_size + (cs->nummemstripes * (COSS_MEMBUF_SZ >> 10))) > (unsigned long) (max_offset >> 10)) { debug(47, 1) ("COSS block-size = %d bytes\n", 1 << cs->blksz_bits); debug(47, 1) ("COSS largest file offset = %lu KB\n", (unsigned long) max_offset >> 10); debug(47, 1) ("COSS cache_dir size = %d KB\n", sd->max_size); fatal("COSS cache_dir size exceeds largest offset\n"); } cs->max_disk_nf = ((off_t) sd->max_size << 10) >> cs->blksz_bits; debug(47, 2) ("COSS: max disk fileno is %d\n", cs->max_disk_nf); /* XXX todo checks */ /* Ensure that off_t range can cover the max_size */ /* Ensure that the max size IS a multiple of the membuf size, or things * will get very fruity near the end of the disk. */ cs->numstripes = (off_t) (((off_t) sd->max_size) << 10) / COSS_MEMBUF_SZ; debug(47, 2) ("COSS: number of stripes: %d of %d bytes each\n", cs->numstripes, COSS_MEMBUF_SZ); cs->stripes = xcalloc(cs->numstripes, sizeof(struct _cossstripe)); for (i = 0; i < cs->numstripes; i++) { cs->stripes[i].id = i; cs->stripes[i].membuf = NULL; cs->stripes[i].numdiskobjs = -1; } cs->minimum_stripe_distance = cs->numstripes * cs->minumum_overwrite_pct; /* Make sure cs->maxfull has a default value */ if (cs->maxfullstripes == 0) cs->maxfullstripes = cs->numstripes; /* We will reject new objects (ie go into hit-only mode) * if there are <= 2 stripes available */ cs->hitonlyfullstripes = cs->maxfullstripes - HITONLY_BUFS; debug(47, 2) ("COSS: number of memory-only stripes %d of %d bytes each\n", cs->nummemstripes, COSS_MEMBUF_SZ); cs->memstripes = xcalloc(cs->nummemstripes, sizeof(struct _cossstripe)); for (i = 0; i < cs->nummemstripes; i++) { cs->memstripes[i].id = i; cs->memstripes[i].membuf = NULL; cs->memstripes[i].numdiskobjs = -1; } /* Update the max size (used for load calculations) */ if (sd->max_size > max_coss_dir_size) max_coss_dir_size = sd->max_size;}static voidstoreCossDirReconfigure(SwapDir * sd, int index, char *path){ unsigned int i; unsigned int size; i = GetInteger(); size = i << 10; /* Mbytes to Kbytes */ if (size <= 0) fatal("storeCossDirParse: invalid size value"); if (size == sd->max_size) debug(3, 1) ("Cache COSS dir '%s' size remains unchanged at %d KB\n", path, size); else { debug(3, 1) ("Cache COSS dir '%s' size changed to %d KB\n", path, size); sd->max_size = size; } parse_cachedir_options(sd, options, 1); /* Enforce maxobjsize being set to something */ if (sd->max_objsize == -1) fatal("COSS requires max-size to be set to something other than -1!\n");}voidstoreCossDirDump(StoreEntry * entry, SwapDir * s){ storeAppendPrintf(entry, " %d", s->max_size >> 10); dump_cachedir_options(entry, options, s);}static voidstoreCossDirParseMaxFullBufs(SwapDir * sd, const char *name, const char *value, int reconfiguring){ CossInfo *cs = sd->fsdata; int maxfull = atoi(value); if (maxfull <= HITONLY_BUFS) fatalf("COSS ERROR: There must be more than %d maxfullbufs\n", HITONLY_BUFS); if (maxfull > 500) fatal("COSS ERROR: Squid will likely use too much memory if it ever used 500MB worth of full buffers\n"); cs->maxfullstripes = maxfull;}static voidstoreCossDirParseMemOnlyBufs(SwapDir * sd, const char *name, const char *value, int reconfiguring){ CossInfo *cs = sd->fsdata; int membufs = atoi(value); if (reconfiguring) { debug(47, 0) ("WARNING: cannot change COSS memory bufs Squid is running\n"); return; } if (membufs < 2) fatal("COSS ERROR: There must be at least 2 membufs\n"); if (membufs > 500) fatal("COSS ERROR: Squid will likely use too much memory if it ever used 500MB worth of buffers\n"); cs->nummemstripes = membufs;}static voidstoreCossDirParseMaxWaste(SwapDir * sd, const char *name, const char *value, int reconfiguring){ CossInfo *cs = sd->fsdata; int waste = atoi(value); if (waste < 8192) fatal("COSS max-stripe-waste must be > 8192\n"); if (waste > sd->max_objsize) debug(47, 1) ("storeCossDirParseMaxWaste: COSS max-stripe-waste can not be bigger than the max object size (%" PRINTF_OFF_T ")\n", sd->max_objsize); cs->sizerange_min = waste;}static voidstoreCossDirParseOverwritePct(SwapDir * sd, const char *name, const char *value, int reconfiguring){ CossInfo *cs = sd->fsdata; int pct = atoi(value); if (pct < 0) fatal("COSS overwrite percent must be > 0\n"); if (pct > 100) fatal("COSS overwrite percent must be < 100\n"); cs->minumum_overwrite_pct = (float) pct / 100; cs->minimum_stripe_distance = cs->numstripes * cs->minumum_overwrite_pct;}static voidstoreCossDirParseBlkSize(SwapDir * sd, const char *name, const char *value, int reconfiguring){ CossInfo *cs = sd->fsdata; int blksz = atoi(value); int check; int nbits; if (blksz == (1 << cs->blksz_bits)) /* no change */ return; if (reconfiguring) { debug(47, 0) ("WARNING: cannot change COSS block-size while Squid is running\n"); return; } nbits = 0; check = blksz; while (check > 1) { nbits++; check >>= 1; } check = 1 << nbits; if (check != blksz) fatal("COSS block-size must be a power of 2\n"); if (nbits > 13) fatal("COSS block-size must be 8192 or smaller\n"); cs->blksz_bits = nbits; cs->blksz_mask = (1 << cs->blksz_bits) - 1;}static voidstoreCossDirDumpMaxFullBufs(StoreEntry * e, const char *option, SwapDir * sd){ CossInfo *cs = sd->fsdata; storeAppendPrintf(e, " maxfullbufs=%d MB", cs->maxfullstripes);}static voidstoreCossDirDumpMemOnlyBufs(StoreEntry * e, const char *option, SwapDir * sd){ CossInfo *cs = sd->fsdata; storeAppendPrintf(e, " membufs=%d MB", cs->nummemstripes);}static voidstoreCossDirDumpMaxWaste(StoreEntry * e, const char *option, SwapDir * sd){ CossInfo *cs = sd->fsdata; storeAppendPrintf(e, " max-stripe-waste=%d", cs->sizerange_min);}static voidstoreCossDirDumpOverwritePct(StoreEntry * e, const char *option, SwapDir * sd){ CossInfo *cs = sd->fsdata; storeAppendPrintf(e, " overwrite-percent=%d%%", (int) cs->minumum_overwrite_pct * 100);}static voidstoreCossDirDumpBlkSize(StoreEntry * e, const char *option, SwapDir * sd){ CossInfo *cs = sd->fsdata; storeAppendPrintf(e, " block-size=%d", 1 << cs->blksz_bits);}static SwapDir *storeCossDirPick(void){ int i, choosenext = 0; SwapDir *SD; if (n_coss_dirs == 0) return NULL; for (i = 0; i < Config.cacheSwap.n_configured; i++) { SD = &Config.cacheSwap.swapDirs[i]; if (strcmp(SD->type, SWAPDIR_COSS) == 0) { if ((last_coss_pick_index == -1) || (n_coss_dirs == 1)) { last_coss_pick_index = i; return SD; } else if (choosenext) { last_coss_pick_index = i; return SD; } else if (last_coss_pick_index == i) { choosenext = 1; } } } for (i = 0; i < Config.cacheSwap.n_configured; i++) { SD = &Config.cacheSwap.swapDirs[i]; if (strcmp(SD->type, SWAPDIR_COSS) == 0) { if ((last_coss_pick_index == -1) || (n_coss_dirs == 1)) { last_coss_pick_index = i; return SD; } else if (choosenext) { last_coss_pick_index = i; return SD; } else if (last_coss_pick_index == i) { choosenext = 1; } } } return NULL;}/* * initial setup/done code */static voidstoreCossDirDone(void){ int i, n_dirs = n_coss_dirs; for (i = 0; i < n_dirs; i++) storeCossDirShutdown(storeCossDirPick());/* * TODO : check if others memPoolDestroy() of COSS objects are needed here */ memPoolDestroy(coss_state_pool); coss_initialised = 0;}static voidstoreCossStats(StoreEntry * sentry){ const char *tbl_fmt = "%10s %10d %10d %10d\n"; storeAppendPrintf(sentry, "\n OPS SUCCESS FAIL\n"); storeAppendPrintf(sentry, tbl_fmt, "open", coss_stats.open.ops, coss_stats.open.success, coss_stats.open.fail); storeAppendPrintf(sentry, tbl_fmt, "create", coss_stats.create.ops, coss_stats.create.success, coss_stats.create.fail); storeAppendPrintf(sentry, tbl_fmt, "close", coss_stats.close.ops, coss_stats.close.success, coss_stats.close.fail); storeAppendPrintf(sentry, tbl_fmt, "unlink", coss_stats.unlink.ops, coss_stats.unlink.success, coss_stats.unlink.fail); storeAppendPrintf(sentry, tbl_fmt, "read", coss_stats.read.ops, coss_stats.read.success, coss_stats.read.fail); storeAppendPrintf(sentry, tbl_fmt, "write", coss_stats.write.ops, coss_stats.write.success, coss_stats.write.fail); storeAppendPrintf(sentry, tbl_fmt, "s_write", coss_stats.stripe_write.ops, coss_stats.stripe_write.success, coss_stats.stripe_write.fail); storeAppendPrintf(sentry, "\n"); storeAppendPrintf(sentry, "stripes: %d\n", coss_stats.stripes);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -