phongn commented on code in PR #13255: URL: https://github.com/apache/trafficserver/pull/13255#discussion_r3417778502
########## src/iocore/cache/RamCacheS3FIFO.cc: ########## @@ -0,0 +1,418 @@ +/** @file + + A brief file description + + @section license License + + Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + */ + +// S3-FIFO RAM cache replacement policy. +// +// The design follows Yang, Zhang, Qiu, Yue & Rashmi, "FIFO queues are all you need for cache +// eviction" (SOSP 2023) and https://s3fifo.com, mirroring the libCacheSim reference (S3FIFO.c). +// +// EXPERIMENTAL: three FIFO queues -- a small admission queue S (~10% of capacity), a main queue M +// (~90%, a 2-bit CLOCK), and a ghost queue G that remembers the keys of recently evicted objects +// (no data). New objects enter S; on eviction from S an object that was reused (frequency >= 2) is +// promoted to M, otherwise it is demoted to G. A subsequent miss whose key is in G enters M +// directly. The small queue + ghost give S3-FIFO admission control that filters one-hit-wonders -- +// exactly the CDN "quick demotion" property -- at FIFO cost (no per-hit reordering). The ghost +// holds keys, so it costs per-entry metadata at high object cardinality; that metadata is bounded +// and counted against ram_cache.size so total memory stays within the configured budget. Selectable +// as proxy.config.cache.ram_cache.algorithm = 2; see the admin guide (records.yaml.en.rst). + +#include "P_RamCache.h" +#include "P_CacheInternal.h" +#include "StripeSM.h" +#include "iocore/eventsystem/IOBuffer.h" +#include "tscore/CryptoHash.h" +#include "tscore/List.h" + +#define ENTRY_OVERHEAD 128 // per-entry metadata counted against ram_cache.size +#define MAIN_PERCENT 90 // main queue target size, percent of capacity +#define GHOST_SIZE_PERCENT 90 // ghost remembers keys for ~this percent of capacity by object size +#define GHOST_MEM_PERCENT 25 // but never more ghost metadata than this percent of size (OOM-safe) +#define MOVE_TO_MAIN_THRESHOLD 2 // an object in S is promoted to M once reused this many times +#define FREQ_MAX 3 // 2-bit saturating frequency counter Review Comment: libcachesim does expose these directly, it might indeed be good to expose these at tunables: https://github.com/cacheMon/libCacheSim-python/blob/main/README.md -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
