Repository navigation
crimson/os/seastore: introduce 2Q cache replacement algorithm - #64060
Conversation
Config Diff Tool Output+ added: seastore_cachepin_type (crimson.yaml.in)
+ added: seastore_cachepin_2q_out_ratio (crimson.yaml.in)
+ added: seastore_cachepin_2q_in_ratio (crimson.yaml.in)
+ added: seastore_cachepin_size_pershard (crimson.yaml.in)
- removed: seastore_cache_lru_size (crimson.yaml.in)
The above configuration changes are found in the PR. Please update the relevant release documentation if necessary. |
|
The benchmark of LRU vs 2Q is WIP. |
random read/write testseastore_cache_lru_size = 256M rbd image size = 5G LRU rand write IOPS 2997LRU rand read IOPS 13345TwoQ rand write IOPS 3104TwoQ rand read IOPS 13287io replay from https://github.com/alibaba/block-tracesseastore_cache_lru_size = 2G Select random 10 devices, 1.7TiB images size in total, replay the io trace with trace file in fio TwoQ read IOPS 290 write IOPS 2420LRU read IOPS 288 write IOPS 2350mixed io workloadseastore_cache_lru_size = 256M rbd image size = 5G Prepare two RBD images:
LRUimage_0 read IOPS 911 write IOPS 911image_1 read BW 229978 write BW 230390TwoQimage_0 read IOPS 959 write IOPS 961image_1 read BW 208366 write BW 209470 |
|
The case which needs attention is that in 'mixed IO workload,' the throughput of the TwoQ implementation is worse than that of LRU. This decrease appears to be caused by searching for extents in the warm out queue, which is implemented using std::map. |
|
Replace the impl of warm out queue to
image_0image_1LRUimage_0 read IOPS 907 write IOPS 910image_1 read BW 209651 write BW 209524TwoQimage_0 read IOPS 969 write IOPS 967image_1 read BW 216875 write BW 216546 |
There was a problem hiding this comment.
This decrease appears to be caused by searching for extents in the warm out queue, which is implemented using std::map.
LRU/2Q needs to be efficient as part of the critical path.
Do you see any regressions after the optimization from the first 2 workloads?
(Seems 2Q is a generally better algorithm than LRU, worth considering to make it default, but needs some proves)
There are several other points worth considering:
- To make 2Q really effective, I think it is essential to make sure in SeaStore we don't call
touch_extent()multiple times per access. - Do we have metrics in 2Q to understand/prove the above property under a sequential workload?
There was a problem hiding this comment.
Can A1 queue deal with (distinguish) sequential partial reads inside the same large extent?
There was a problem hiding this comment.
I'm not sure, need to rethink it.
There was a problem hiding this comment.
The "mixed io workload" test setup is that first fill the image with bs=1M io_depth=64, then randrw with bs=1M.
The new test setup could be fill image with bs=4M and randrs with bs=1M to test this case.
There was a problem hiding this comment.
TwoQ partial reads inside the same large extent test with bs=4M to fill image sequentially and do randrw with bs=1M:
image_0 read IOPS 967 write IOPS 967
randwrite-4K: (g=0): rw=randrw, bs=(R) 4096B-4096B, (W) 4096B-4096B, (T) 4096B-4096B, ioengine=rbd, iodepth=768
fio-3.28
Starting 1 process
Jobs: 1 (f=1): [m(1)][100.0%][r=276KiB/s,w=368KiB/s][r=69,w=92 IOPS][eta 00m:00s]
randwrite-4K: (groupid=0, jobs=1): err= 0: pid=1537237: Tue Jun 24 13:09:44 2025
read: IOPS=966, BW=3864KiB/s (3957kB/s)(3400MiB/900941msec)
slat (nsec): min=543, max=974912, avg=4601.79, stdev=2810.96
clat (usec): min=437, max=19434k, avg=348234.88, stdev=2120535.79
lat (usec): min=443, max=19434k, avg=348239.48, stdev=2120535.80
clat percentiles (msec):
| 1.00th=[ 3], 5.00th=[ 5], 10.00th=[ 6], 20.00th=[ 8],
| 30.00th=[ 9], 40.00th=[ 11], 50.00th=[ 12], 60.00th=[ 15],
| 70.00th=[ 22], 80.00th=[ 38], 90.00th=[ 83], 95.00th=[ 207],
| 99.00th=[15100], 99.50th=[16174], 99.90th=[17113], 99.95th=[17113],
| 99.99th=[17113]
bw ( KiB/s): min= 1402, max= 7032, per=100.00%, avg=3869.02, stdev=676.19, samples=1800
iops : min= 350, max= 1758, avg=967.16, stdev=169.06, samples=1800
write: IOPS=966, BW=3867KiB/s (3960kB/s)(3402MiB/900941msec); 0 zone resets
slat (nsec): min=1867, max=1606.6k, avg=9801.06, stdev=4622.94
clat (msec): min=3, max=26995, avg=446.40, stdev=2422.64
lat (msec): min=3, max=26995, avg=446.41, stdev=2422.64
clat percentiles (msec):
| 1.00th=[ 12], 5.00th=[ 16], 10.00th=[ 20], 20.00th=[ 27],
| 30.00th=[ 34], 40.00th=[ 40], 50.00th=[ 47], 60.00th=[ 57],
| 70.00th=[ 71], 80.00th=[ 99], 90.00th=[ 178], 95.00th=[ 401],
| 99.00th=[16979], 99.50th=[17113], 99.90th=[17113], 99.95th=[17113],
| 99.99th=[17113]
bw ( KiB/s): min= 1482, max= 5368, per=100.00%, avg=3870.95, stdev=615.69, samples=1800
iops : min= 370, max= 1342, avg=967.65, stdev=153.94, samples=1800
lat (usec) : 500=0.01%, 750=0.01%, 1000=0.01%
lat (msec) : 2=0.12%, 4=1.98%, 10=17.73%, 20=19.90%, 50=29.42%
lat (msec) : 100=16.90%, 250=8.12%, 500=2.04%, 750=0.60%, 1000=0.29%
lat (msec) : 2000=0.40%, >=2000=2.49%
cpu : usr=1.98%, sys=1.18%, ctx=1058456, majf=0, minf=14175
IO depths : 1=0.1%, 2=0.1%, 4=0.1%, 8=0.1%, 16=0.1%, 32=0.1%, >=64=100.0%
submit : 0=0.0%, 4=100.0%, 8=0.0%, 16=0.0%, 32=0.0%, 64=0.0%, >=64=0.0%
complete : 0=0.0%, 4=100.0%, 8=0.0%, 16=0.0%, 32=0.0%, 64=0.0%, >=64=0.1%
issued rwts: total=870420,870954,0,0 short=0,0,0,0 dropped=0,0,0,0
latency : target=0, window=0, percentile=100.00%, depth=768
Run status group 0 (all jobs):
READ: bw=3864KiB/s (3957kB/s), 3864KiB/s-3864KiB/s (3957kB/s-3957kB/s), io=3400MiB (3565MB), run=900941-900941msec
WRITE: bw=3867KiB/s (3960kB/s), 3867KiB/s-3867KiB/s (3960kB/s-3960kB/s), io=3402MiB (3567MB), run=900941-900941msec
Disk stats (read/write):
nvme2n1: ios=0/10623, merge=0/13962, ticks=0/2598, in_queue=2598, util=0.60%
image_0 read BW 214372 write BW 214007
randwrite-4K: (g=0): rw=randrw, bs=(R) 1024KiB-1024KiB, (W) 1024KiB-1024KiB, (T) 1024KiB-1024KiB, ioengine=rbd, iodepth=64
fio-3.28
Starting 1 process
Jobs: 1 (f=1): [m(1)][100.0%][r=340MiB/s,w=340MiB/s][r=340,w=340 IOPS][eta 00m:00s]
randwrite-4K: (groupid=0, jobs=1): err= 0: pid=1537307: Tue Jun 24 13:09:44 2025
read: IOPS=209, BW=209MiB/s (219MB/s)(184GiB/900175msec)
slat (nsec): min=640, max=89951, avg=6270.64, stdev=1926.81
clat (usec): min=1050, max=19207k, avg=124865.27, stdev=1157797.72
lat (usec): min=1056, max=19207k, avg=124871.54, stdev=1157797.72
clat percentiles (msec):
| 1.00th=[ 3], 5.00th=[ 6], 10.00th=[ 7], 20.00th=[ 11],
| 30.00th=[ 17], 40.00th=[ 23], 50.00th=[ 30], 60.00th=[ 36],
| 70.00th=[ 44], 80.00th=[ 52], 90.00th=[ 63], 95.00th=[ 75],
| 99.00th=[ 249], 99.50th=[13489], 99.90th=[16442], 99.95th=[17113],
| 99.99th=[17113]
bw ( KiB/s): min=124928, max=364544, per=100.00%, avg=214372.25, stdev=30183.69, samples=1800
iops : min= 122, max= 356, avg=209.21, stdev=29.46, samples=1800
write: IOPS=208, BW=209MiB/s (219MB/s)(184GiB/900175msec); 0 zone resets
slat (usec): min=149, max=5306, avg=354.52, stdev=85.51
clat (msec): min=7, max=25757, avg=180.99, stdev=1246.29
lat (msec): min=7, max=25758, avg=181.34, stdev=1246.29
clat percentiles (msec):
| 1.00th=[ 23], 5.00th=[ 31], 10.00th=[ 36], 20.00th=[ 44],
| 30.00th=[ 51], 40.00th=[ 58], 50.00th=[ 66], 60.00th=[ 74],
| 70.00th=[ 86], 80.00th=[ 102], 90.00th=[ 136], 95.00th=[ 186],
| 99.00th=[ 667], 99.50th=[14026], 99.90th=[17113], 99.95th=[17113],
| 99.99th=[17113]
bw ( KiB/s): min=86016, max=391168, per=100.00%, avg=214007.60, stdev=24038.86, samples=1800
iops : min= 84, max= 382, avg=208.86, stdev=23.46, samples=1800
lat (msec) : 2=0.17%, 4=0.95%, 10=8.53%, 20=8.52%, 50=36.00%
lat (msec) : 100=34.60%, 250=9.28%, 500=0.94%, 750=0.19%, 1000=0.07%
lat (msec) : 2000=0.08%, >=2000=0.68%
cpu : usr=7.67%, sys=0.45%, ctx=348428, majf=0, minf=646508
IO depths : 1=0.1%, 2=0.1%, 4=0.1%, 8=0.1%, 16=0.1%, 32=0.1%, >=64=100.0%
submit : 0=0.0%, 4=100.0%, 8=0.0%, 16=0.0%, 32=0.0%, 64=0.0%, >=64=0.0%
complete : 0=0.0%, 4=100.0%, 8=0.0%, 16=0.0%, 32=0.0%, 64=0.1%, >=64=0.0%
issued rwts: total=188318,188006,0,0 short=0,0,0,0 dropped=0,0,0,0
latency : target=0, window=0, percentile=100.00%, depth=64
Run status group 0 (all jobs):
READ: bw=209MiB/s (219MB/s), 209MiB/s-209MiB/s (219MB/s-219MB/s), io=184GiB (197GB), run=900175-900175msec
WRITE: bw=209MiB/s (219MB/s), 209MiB/s-209MiB/s (219MB/s-219MB/s), io=184GiB (197GB), run=900175-900175msec
Disk stats (read/write):
nvme2n1: ios=0/10617, merge=0/13943, ticks=0/2598, in_queue=2597, util=0.60%
At least it's not worse than LRU...
There was a problem hiding this comment.
At least it's not worse than LRU...
Yeah, I also agree that 2Q is a generally better algorithm (if implemented properly).
Can A1 queue deal with (distinguish) sequential partial reads inside the same large extent?
I think it's commen that extent granularity isn't align with reads, and IIUC it can cause an extent to be touched multiple times and be promoted to the main buffer inappropriately.
Probably we can add a TODO comment to the class, and deal with it in the next step.
There was a problem hiding this comment.
IIUC it can cause an extent to be touched multiple times and be promoted to the main buffer inappropriately.
Make sence, one naive idea is that maintain a visit bitmap in ObjectDataBlock and the entry in warm out queue or similar structure like LRU/LFU bufferlist in one extent so that we could evict the data in a fine-grained granularity
There was a problem hiding this comment.
Hm, a visit bitmap seems unnecessary until really needed.
Probably good enough to start with simply remembering the last access end-offset of every extent from the A1 queue, encapsulated inside Q2 solution, I suppose?
There was a problem hiding this comment.
This method works well, filtering out nearly half of the accesses to the warm out queue in pure high throughput read cases(rw=randread bw=1M) compared to the previous approach.
Not test yet, I will test and profile it again.
The actual overhead of 2Q compared to LRU is that when an extent isn't found in either the warm_in or hot queue(CachedExtent::primary_ref_list_hook), it needs to search through the warm_out queue (implemented as an laddr-indexed hash table) to check for previous access. However, once extents are added to the warm_in/hot queue, subsequent touches won't trigger warm_out searches because
Probably not, if we had metrics that could filter out the sequential request reliably, we could drop 2Q algorithm completely. However, we could add some metrics to track an extent's queue location during touch operations. We could also do another priori benchmark using static-layout-laddr. Establish mappings from rados object name and clone prefix laddr in seastore and we could examine 2Q's laddrs to determine if extents are from sequential workloads. Previous results showed that the 95% of extents from sequential workload image reside in warm_in queue, with fewer than 5% in the hot queue. |
I meant, see #64060 (comment), if an extent is touched multiple times in a single access, it will be wrongly promoted to the main buffer, which beats the design goal.
I meant to use certain workload (e.g. pure sequential) to understand whether/how-much the design goal is enforced.
Observability is equally important, I think. For example, ideally, under pure sequentail reads, no |
Okay, I get it. |
|
This pull request can no longer be automatically merged: a rebase is needed and changes have to be manually resolved |
992f8be to
99952fc
Compare
|
Other comments will be resolved in next push. |
|
jenkins test api |
cyx1231st
left a comment
There was a problem hiding this comment.
Final comments, LGTM!
Note, 2Q is not included in CI. If wish to prevent regressions, probably good to randomize LRU vs 2Q configurations in the qa tests.
Signed-off-by: Zhang Song <[email protected]>
Signed-off-by: Zhang Song <[email protected]>
…usive hook Signed-off-by: Zhang Song <[email protected]>
Signed-off-by: Zhang Song <[email protected]>
Signed-off-by: Zhang Song <[email protected]>
Signed-off-by: Zhang Song <[email protected]>
…re partially read from the last access end Signed-off-by: Zhang Song <[email protected]>
…ut each queue Signed-off-by: Zhang Song <[email protected]>
Signed-off-by: Zhang Song <[email protected]>
Signed-off-by: Zhang Song <[email protected]>
Signed-off-by: Zhang Song <[email protected]>
|
jenkins test make check |
We can add 2Q as an option to be randomly selected when triggering jobs. We can do this by selecting a new qa branch which would include only 2q: We could use the same build sha1 for both tests. Generally speaking, do we want to consider this as the new default once verified? |
Yeah, IIRC @zhscn won't include random QA part in this PR, not familiar with it yet.
Yeah, this is a better decision, I was thinking about only testing the default option, and validate 2Q after QA is improved in the next PR. (so it can be done in batches)
If there is bandwidth, probably good to double confirm in sepia that there is no regression in our standard perf tests. However, from @zhscn's local evaluation, and also in theory, it has general benefits. |
Let's address this (random qa) after merging this PR. I'll open a tracker.
I'm ok with both, I think it should be nice to test 2q as default just for sanity prior to merging (even if it won't be perfect, we can keep polishing it after merge).
Ack. We can start with adding this as an option and then consider switching default. |
|
rebuilding, previous build failed: |
Contribution Guidelines
To sign and title your commits, please refer to Submitting Patches to Ceph.
If you are submitting a fix for a stable branch (e.g. "quincy"), please refer to Submitting Patches to Ceph - Backports for the proper workflow.
When filling out the below checklist, you may click boxes directly in the GitHub web UI. When entering or editing the entire PR message in the GitHub web UI editor, you may also select a checklist item by adding an
xbetween the brackets:[x]. Spaces and capitalization matter when checking off items this way.Checklist
Show available Jenkins commands
jenkins test classic perfJenkins Job | Jenkins Job Definitionjenkins test crimson perfJenkins Job | Jenkins Job Definitionjenkins test signedJenkins Job | Jenkins Job Definitionjenkins test make checkJenkins Job | Jenkins Job Definitionjenkins test make check arm64Jenkins Job | Jenkins Job Definitionjenkins test submodulesJenkins Job | Jenkins Job Definitionjenkins test dashboardJenkins Job | Jenkins Job Definitionjenkins test dashboard cephadmJenkins Job | Jenkins Job Definitionjenkins test apiJenkins Job | Jenkins Job Definitionjenkins test docsReadTheDocs | Github Workflow Definitionjenkins test ceph-volume allJenkins Jobs | Jenkins Jobs Definitionjenkins test windowsJenkins Job | Jenkins Job Definitionjenkins test rook e2eJenkins Job | Jenkins Job Definition