Enhancement #73868
openCephFS: please stop accepting writes when the journal grows too big
100%
Description
Another title for this bug could have been "unbounded memory use during journal replay".
We had a support case where the customer's OSDs for the cephfs metadata pool became full, then there was a delay in adding more of them, and then there was a client not advancing its latest TID, and then the MDS was severely behind on trimming (1000000/256). Lastly, an attempt to restart the MDS has led to the MDS stuck in the "up:replay" state. It consumed all the RAM and 2 TB of swap and crashed, and started over.
I am currently trying to replay the CephFS journal (recover_dentries) using cephfs-journal-tool, but it also consumed all the RAM and swap, but at least the --range option helps. The issue is that it is insanely slow - more than 12 hours per pass.
If CephFS stopped accepting any operations that led to the insanely big untrimmed journal, then I would not have to wrestle with cephfs-journal-tool wanting to go OOM.
I.e., this is a feature request to provide a hard limit on the untrimmed journal size, in addition to the current "MDS behind on trimming" soft warning. When this limit is hit, all non-read-only client operations should freeze. This is to protect against the journal getting so big that it can't be realistically replayed at all.
VS Updated by Venky Shankar about 1 year ago
- Target version set to v21.0.0
JC Updated by Jos Collin about 1 year ago
- Status changed from New to In Progress
- Assignee set to Jos Collin
As per the discussion with @Venky Shankar,
When the OSD is full, we should block all the client write operations and report a warning in 'ceph -s'. Consequently, this would prevent the journal from getting bigger.
But as I checked, this seems already implemented (atleast the OSD part of it): https://docs.ceph.com/en/latest/rados/troubleshooting/troubleshooting-osd/#no-free-drive-space.
Quoting The mon_osd_full_ratio threshold defaults to 0.95 (or 95% of capacity): this is the point above which clients are prevented from writing data. from the documentation.
AP Updated by Alexander Patrakov about 1 year ago
Hello Jos,
I think there is a misunderstanding.
The "full OSD" situation is a red herring here. I am talking about suspending writes in any situation when the journal gets too big to be replayed, even if it is not related to full OSDs.
The current situation in the customer's cluster is that they added more space, but attempts to get the journal replayed result in the consumption of all the RAM and 2 TB of swap. The workaround that we are currently performing involves using the --range argument for recover_dentries, i.e., replaying the journal piece-by-piece. But the very fact that the journal got so big to require an estimated week of replay activity is something that should be prevented no matter what causes it.
AP Updated by Alexander Patrakov about 1 year ago
Upon reflection, I realized that the original issue was worded confusingly.
Probably, the initial issue, not reported to us, was that journal trimming somehow broke and made the journal too big to be replayed. And then the OSDs became full and everything stopped, thus aggravating the problem. Right now, with some storage added, the metadata OSDs are not full, but the journal is still too big to be replayed by the MDS or by cephfs-journal-tool recover_dentries in one piece, i.e., without the --range argument.
JC Updated by Jos Collin about 1 year ago
Alexander Patrakov wrote in #note-3:
Hello Jos,
I think there is a misunderstanding.
The "full OSD" situation is a red herring here. I am talking about suspending writes in any situation when the journal gets too big to be replayed, even if it is not related to full OSDs.
I don't think it's a good idea to separate "full OSD" situation from hard limiting journal size. Both are related and treating limiting journal size separately would make it unusable for replay.
@Venky Shankar Any thoughts on this?
The current situation in the customer's cluster is that they added more space, but attempts to get the journal replayed result in the consumption of all the RAM and 2 TB of swap. The workaround that we are currently performing involves using the --range argument for recover_dentries, i.e., replaying the journal piece-by-piece. But the very fact that the journal got so big to require an estimated week of replay activity is something that should be prevented no matter what causes it.
The idea is to check if the OSD is full, we should block all the client write operations and this would prevent the journal from getting bigger.
Looks this feature is already there and I'm checking if it's working properly. Do we have any logs from the customer's cluster?
AP Updated by Alexander Patrakov about 1 year ago
I don't think I can separate the existing MDS logs enough to isolate the root cause of the "unreplayable journal" issue, but I'll see what I can do.
If you provide me today or tomorrow with some flags that I can pass to cephfs-journal-tool to help you determine why it eats so much memory, I would be happy to share the output when I apply them to the next range.
To clear the misunderstanding that I think still exists: What I was saying all the time in the previous comments can be summarized as: the cluster should have failed earlier, with a smaller journal that does not require terabytes of RAM to replay.
AP Updated by Alexander Patrakov about 1 year ago
Unfortunately, the historical logs (in particular, the ones that would show the warnings before the metadata OSDs became full) were not preserved, so I can't give them to you.
JC Updated by Jos Collin about 1 year ago
@patrakov
I don't see the appropriate cephfs-journal-tool flags you've mentioned in the above comment.
Could you please check what are the settings for mon_osd_full_ratio, mon_osd_backfillfull_ratio and mon_osd_nearfull_ratio ?
I've also sent an email to you, please reply to that also.
Thanks.
AP Updated by Alexander Patrakov about 1 year ago
mon_osd_full_ratio, mon_osd_backfillfull_ratio and mon_osd_nearfull_ratio are the defaults: 0.85, 0.9, and 0.95.
JC Updated by Jos Collin about 1 year ago
Alexander Patrakov wrote in #note-9:
mon_osd_full_ratio, mon_osd_backfillfull_ratio and mon_osd_nearfull_ratio are the defaults: 0.85, 0.9, and 0.95.
mon_osd_full_ratio = 0.95
mon_osd_backfillfull_ratio = 0.9
mon_osd_nearfull_ratio = 0.85
Is that correct?
AP Updated by Alexander Patrakov about 1 year ago
Yes, you are right. Sorry for listing the names and values in different orders. There is no "inversion".
JC Updated by Jos Collin about 1 year ago ยท Edited
We also respond ENOSPC to op if the OSD is full: https://github.com/ceph/ceph/blob/main/src/mds/Server.cc#L2816
From Alexander's email:
This customer has Ceph 18.2.4. The clients that write are mostly kernel clients. There is also NFS-Ganesha, which is a userspace client using libcephfs, which comes from v18.2.4.
Still running cephfs-journal-tool recover-dentries, so no MDS is running now.
top - 10:17:02 up 12 days, 17:24, 4 users, load average: 1.84, 2.22, 2.34
Tasks: 513 total, 1 running, 512 sleeping, 0 stopped, 0 zombie
%Cpu(s): 3.0 us, 0.7 sy, 0.0 ni, 95.0 id, 1.1 wa, 0.0 hi, 0.2 si, 0.0 st
MiB Mem : 257586.5+total, 5364.348 free, 252549.5+used, 2512.891 buff/cache
MiB Swap: 1907739.+total, 1256613.+free, 651125.6+used. 5037.027 avail Mem
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
157817 ceph 20 0 12.808g 6.487g 9612 S 36.88 2.579 3383:21 /usr/bin/ceph-osd -f --cluster ceph --id 1011 --setuser ceph --setgroup ceph
171348 ceph 20 0 15.457g 6.275g 9432 S 36.88 2.494 1802:55 /usr/bin/ceph-osd -f --cluster ceph --id 966 --setuser ceph --setgroup ceph
147923 ceph 20 0 12.760g 6.333g 9752 S 29.24 2.518 3643:54 /usr/bin/ceph-osd -f --cluster ceph --id 1012 --setuser ceph --setgroup ceph
1210643 root 20 0 0.734t 0.214t 1696 S 18.27 86.91 235:25.30 cephfs-journal-tool --rank cephfs:all event recover_dentries --range=0x1cc8000000000..0x1ccc000000000 summary
...
Here is the summary from the previous run:
root@ceph-mds05 ~ $ time cephfs-journal-tool --rank cephfs:all event recover_dentries --range=0x1cc4000000000..0x1cc8000000000 summary 2025-11-25T16:54:15.372+0000 7f2f85abf280 1 recover_dentries: frag 1024999dc1b.00000000 is corrupt, overwriting 2025-11-25T17:30:09.812+0000 7f2f85abf280 1 recover_dentries: frag 102499b79ac.00000000 is corrupt, overwriting 2025-11-25T17:41:06.998+0000 7f2f85abf280 1 recover_dentries: frag 102499c8116.00000000 is corrupt, overwriting 2025-11-25T18:02:13.639+0000 7f2f85abf280 1 recover_dentries: frag 102499e8788.00000000 is corrupt, overwriting Events by type: FRAGMENT: 114 OPEN: 27025063 PURGED: 20 SESSION: 1011 SUBTREEMAP: 81559 UPDATE: 17357238 Errors: 0 real 1376m59.797s user 147m44.539s sys 92m17.586s
Here are some journal stats:
{
"magic": "ceph fs volume v011",
"write_pos": 506826424778085,
"expire_pos": 504201578863691,
"trimmed_pos": 504201578807296,
"stream_format": 1,
"layout": {
"stripe_unit": 4194304,
"stripe_count": 1,
"object_size": 4194304,
"pool_id": 7,
"pool_ns": ""
}
}
VS Updated by Venky Shankar 10 months ago
Hi @Jos Collin - status on this?
VS Updated by Venky Shankar 3 months ago
- Target version changed from v21.0.0 to v22.0.0
- Backport set to umbrella,tentacle
JC Updated by Jos Collin 3 months ago
- Status changed from In Progress to Fix Under Review
- % Done changed from 0 to 100
- Pull request ID set to 71802
JC Updated by Jos Collin 3 months ago
Venky Shankar wrote in #note-13:
Hi @Jos Collin - status on this?