Skip to content

Commit

Permalink
Adds a fragment-size= option to volume.config (#11865)
Browse files Browse the repository at this point in the history
* Adds a fragment-size= option to volume.config

* Fix docstring
  • Loading branch information
zwoop authored Nov 15, 2024
1 parent 5e72ad5 commit 675b9f4
Show file tree
Hide file tree
Showing 10 changed files with 46 additions and 12 deletions.
13 changes: 12 additions & 1 deletion doc/admin-guide/files/volume.config.en.rst
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,17 @@ line. This overrides the global :ts:cv:`proxy.config.cache.min_average_object_si
configuration for this volume. This is useful if you have a volume that is dedicated
for say very small objects, and you need a lot of directory entries to store them.

Optional fragment size setting
------------------------------

You can also add an option ``fragment_size=<size>`` to the volume configuration
line. This overrides the global :ts:cv:`proxy.config.cache.target_fragment_size`
configuration for this volume. This allows for a smaller, or larger, fragment size
for a particular volume. This may be useful together with ``avg_obj_size`` as well,
since a larger fragment size could reduce the number of directory entries needed
for a large object.

Note that this setting has a maximmum value of 4MB.

Exclusive spans and volume sizes
================================
Expand Down Expand Up @@ -116,4 +127,4 @@ ramcache has been disabled.::
volume=2 scheme=http size=20%
volume=3 scheme=http size=20%
volume=4 scheme=http size=20% avg_obj_size=4096
volume=5 scheme=http size=20% ramcache=false
volume=5 scheme=http size=20% ramcache=false fragment_size=524288
2 changes: 1 addition & 1 deletion src/iocore/cache/Cache.cc
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ Cache::open(bool clear, bool /* fix ATS_UNUSED */)
for (; q; q = q->link.next) {
blocks = q->b->len;
CacheDisk *d = cp->disk_stripes[i]->disk;
cp->stripes[vol_no] = new StripeSM(d, blocks, q->b->offset, cp->avg_obj_size);
cp->stripes[vol_no] = new StripeSM(d, blocks, q->b->offset, cp->avg_obj_size, cp->fragment_size);
cp->stripes[vol_no]->cache = this;
cp->stripes[vol_no]->cache_vol = cp;

Expand Down
9 changes: 9 additions & 0 deletions src/iocore/cache/CacheHosting.cc
Original file line number Diff line number Diff line change
Expand Up @@ -655,6 +655,7 @@ ConfigVolumes::BuildListFromString(char *config_file_path, char *file_buf)
int in_percent = 0;
bool ramcache_enabled = true;
int avg_obj_size = -1; // Defaults
int fragment_size = -1;

while (true) {
// skip all blank spaces at beginning of line
Expand Down Expand Up @@ -746,6 +747,13 @@ ConfigVolumes::BuildListFromString(char *config_file_path, char *file_buf)
tmp += 13;
avg_obj_size = atoi(tmp);

while (ParseRules::is_digit(*tmp)) {
tmp++;
}
} else if (strcasecmp(tmp, "fragment_size") == 0) { // match fragment_size
tmp += 14;
fragment_size = atoi(tmp);

while (ParseRules::is_digit(*tmp)) {
tmp++;
}
Expand Down Expand Up @@ -786,6 +794,7 @@ ConfigVolumes::BuildListFromString(char *config_file_path, char *file_buf)
configp->scheme = scheme;
configp->size = size;
configp->avg_obj_size = avg_obj_size;
configp->fragment_size = fragment_size;
configp->cachep = nullptr;
configp->ramcache_enabled = ramcache_enabled;
cp_queue.enqueue(configp);
Expand Down
1 change: 1 addition & 0 deletions src/iocore/cache/CacheProcessor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1178,6 +1178,7 @@ cplist_update()
if (cp->scheme == config_vol->scheme) {
cp->ramcache_enabled = config_vol->ramcache_enabled;
cp->avg_obj_size = config_vol->avg_obj_size;
cp->fragment_size = config_vol->fragment_size;
config_vol->cachep = cp;
} else {
/* delete this volume from all the disks */
Expand Down
13 changes: 8 additions & 5 deletions src/iocore/cache/CacheWrite.cc
Original file line number Diff line number Diff line change
Expand Up @@ -525,9 +525,10 @@ CacheVC::openWriteWriteDone(int event, Event *e)
}

static inline int
target_fragment_size()
target_fragment_size(int target_frag_size)
{
uint64_t value = cache_config_target_fragment_size - sizeof(Doc);
uint64_t value = (target_frag_size > 0 ? target_frag_size : cache_config_target_fragment_size) - sizeof(Doc);

ink_release_assert(value <= MAX_FRAG_SIZE);
return value;
}
Expand Down Expand Up @@ -561,6 +562,8 @@ CacheVC::openWriteMain(int /* event ATS_UNUSED */, Event * /* e ATS_UNUSED */)
int64_t total_avail = vio.get_reader()->read_avail();
int64_t avail = total_avail;
int64_t towrite = avail + length;
int frag_size = target_fragment_size(stripe->frag_size);

if (towrite > ntodo) {
avail -= (towrite - ntodo);
towrite = ntodo;
Expand All @@ -579,12 +582,12 @@ CacheVC::openWriteMain(int /* event ATS_UNUSED */, Event * /* e ATS_UNUSED */)
total_len += avail;
}
length = static_cast<uint64_t>(towrite);
if (length > target_fragment_size() && (length < target_fragment_size() + target_fragment_size() / 4)) {
write_len = target_fragment_size();
if (length > frag_size && (length < frag_size + frag_size / 4)) {
write_len = frag_size;
} else {
write_len = length;
}
bool not_writing = towrite != ntodo && towrite < target_fragment_size();
bool not_writing = towrite != ntodo && towrite < frag_size;
if (!called_user) {
if (not_writing) {
called_user = 1;
Expand Down
1 change: 1 addition & 0 deletions src/iocore/cache/P_CacheHosting.h
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,7 @@ struct ConfigVol {
bool ramcache_enabled;
int percent;
int avg_obj_size;
int fragment_size;
CacheVol *cachep;
LINK(ConfigVol, link);
};
Expand Down
3 changes: 2 additions & 1 deletion src/iocore/cache/Stripe.cc
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,10 @@ struct StripeInitInfo {
// Stripe
//

Stripe::Stripe(CacheDisk *disk, off_t blocks, off_t dir_skip, int avg_obj_size)
Stripe::Stripe(CacheDisk *disk, off_t blocks, off_t dir_skip, int avg_obj_size, int fragment_size)
: path{ats_strdup(disk->path)},
fd{disk->fd},
frag_size{fragment_size},
skip{ROUND_TO_STORE_BLOCK((dir_skip < START_POS ? START_POS : dir_skip))},
start{skip},
len{blocks * STORE_BLOCK_SIZE},
Expand Down
4 changes: 3 additions & 1 deletion src/iocore/cache/Stripe.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ struct CacheVol {
off_t size = 0;
int num_vols = 0;
int avg_obj_size = -1; // Defer to the records.config if not overriden
int fragment_size = -1; // Defer to the records.config if not overriden
bool ramcache_enabled = true;
StripeSM **stripes = nullptr;
DiskStripe **disk_stripes = nullptr;
Expand Down Expand Up @@ -86,6 +87,7 @@ class Stripe
ats_scoped_str hash_text;
char *path = nullptr;
int fd{-1};
int frag_size{-1};

char *raw_dir{nullptr};
Dir *dir{};
Expand Down Expand Up @@ -115,7 +117,7 @@ class Stripe
*
* @see START_POS
*/
Stripe(CacheDisk *disk, off_t blocks, off_t dir_skip, int avg_obj_size = -1);
Stripe(CacheDisk *disk, off_t blocks, off_t dir_skip, int avg_obj_size = -1, int fragment_size = -1);

int dir_check();

Expand Down
6 changes: 4 additions & 2 deletions src/iocore/cache/StripeSM.cc
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,10 @@ struct StripeInitInfo {
// This is weird: the len passed to the constructor for _preserved_dirs is
// initialized in the superclasse's constructor. This is safe because the
// superclass should always be initialized first.
StripeSM::StripeSM(CacheDisk *disk, off_t blocks, off_t dir_skip, int avg_obj_size)
: Continuation(new_ProxyMutex()), Stripe{disk, blocks, dir_skip, avg_obj_size}, _preserved_dirs{static_cast<int>(len)}
StripeSM::StripeSM(CacheDisk *disk, off_t blocks, off_t dir_skip, int avg_obj_size, int fragment_size)
: Continuation(new_ProxyMutex()),
Stripe{disk, blocks, dir_skip, avg_obj_size, fragment_size},
_preserved_dirs{static_cast<int>(len)}
{
open_dir.mutex = this->mutex;
SET_HANDLER(&StripeSM::aggWrite);
Expand Down
6 changes: 5 additions & 1 deletion src/iocore/cache/StripeSM.h
Original file line number Diff line number Diff line change
Expand Up @@ -165,10 +165,14 @@ class StripeSM : public Continuation, public Stripe
* @param blocks: Number of blocks. Must be at least 10.
* @param dir_skip: Offset into the disk at which to start the stripe.
* If this value is less than START_POS, START_POS will be used instead.
* @param avg_obj_size: Optional average object size. If not provided, use default
* from proxy.config.cache.min_average_object_size.
* @param fragment_size: Optional fragment size. If not provided, use default
* from proxy.config.cache.target_fragment_size.
*
* @see START_POS
*/
StripeSM(CacheDisk *disk, off_t blocks, off_t dir_skip, int avg_obj_size = -1);
StripeSM(CacheDisk *disk, off_t blocks, off_t dir_skip, int avg_obj_size = -1, int fragment_size = -1);

Queue<CacheVC, Continuation::Link_link> &get_pending_writers();

Expand Down

0 comments on commit 675b9f4

Please sign in to comment.