Bug #78192
closed100% CPU utilization if nosnaptrim osd flag set during snapshot removal
0%
Description
The Problem & Symptoms:
If the OSD flag nosnaptrim is set during snapshot removal, some PGs get stuck in active+clean+snaptrim_wait state.
The primary OSDs servicing those specific PGs enter an endless loop (entering and exiting the trimmer state 1,000 to 2,000 times per second).
Then ceph_osd_op_rw_latency_sum spikes and these OSDs become hammered, unable to serve client ops.
This unthrottled, high-frequency cycle consumes 100% CPU utilization on the specific CPU core handling the primary OSD process.
Resolution:
As soon as the nosnaptrim flag is unset, all symptoms immediately disappear and CPU core utilization returns to normal.
Note:
Restarting an affected OSD clears the snaptrim_wait state flag from the PG, but the underlying queue length (snaptrimq_len) remains intact.
As soon as nosnaptrim is unset, this OSD immediately processes the remaining snapshot queues as expected, and snaptrimq_len drops to 0.
To reproduce the issue:
#create rbd image:
RBD_POOL=rbd_pool; RBD_IMAGE=test_disk
rbd create ${RBD_POOL}/${RBD_IMAGE} --size 100G
RBD_ID=$(rbd info ${RBD_POOL}/${RBD_IMAGE} --format json | jq -r .id)
#map rbd with nbd-rbd:
modprobe -v nbd max_part=8
rbd-nbd map --name client.admin -k /etc/ceph/ceph.client.admin.keyring ${RBD_POOL}/${RBD_IMAGE}
#write data and create a chain of snapshots:
for RBD_SNAP in test-snap{1..10}; do
dd if=/dev/urandom of=/dev/nbd0 bs=8M count=128 conv=fsync,notrunc status=progress
#create rbd image snapshot:
rbd snap create ${RBD_POOL}/${RBD_IMAGE}@${RBD_SNAP}
rbd snap protect ${RBD_POOL}/${RBD_IMAGE}@${RBD_SNAP}
done
#unmap rbd:
rbd-nbd unmap /dev/nbd0
modprobe -v --remove nbd
#delete rbd image:
ceph osd set nosnaptrim
for RBD_SNAP in test-snap{10..1}; do
rbd snap unprotect ${RBD_POOL}/${RBD_IMAGE}@${RBD_SNAP}
rbd snap rm ${RBD_POOL}/${RBD_IMAGE}@${RBD_SNAP}
sleep 4
done
rbd rm ${RBD_POOL}/${RBD_IMAGE}
#in parallel, unset & set nosnaptrim osd flags, until some pgs transitions to snaptrim_wait state:
until ceph pg dump pgs_brief | grep snaptrim; do ceph osd unset nosnaptrim; sleep 1; ceph osd set nosnaptrim; sleep 1; done
#check status:
ceph pg dump pgs_brief | grep snaptrim
ceph pg ls snaptrim snaptrim_wait -fjson | jq -cr '.pg_stats | map(select(.snaptrimq_len > 0) | {pgid, acting_primary, state, snaptrimq_len})[]'
#check osd debug log:
#find primary osd of first pg in snaptrim_wait state:
FSID=$(ceph fsid); declare -p FSID
OSD_ID=$(ceph pg ls snaptrim snaptrim_wait -fjson | jq -r '.pg_stats | map(select(.snaptrimq_len > 0) | .acting_primary)[0]'); declare -p OSD_ID
ceph osd find ${OSD_ID}
ceph tell osd.${OSD_ID} config set debug_osd 20
journalctl -o short-iso-precise -fu ceph-${FSID}@osd.${OSD_ID}.service
2026-06-30T18:27:21.955399+02:00 pg[9.38 active+clean trimq=[df69~25]] exit Trimming
2026-06-30T18:27:21.955399+02:00 pg[9.38 active+clean trimq=[df69~25]] PeeringState::prepare_stats_for_publish reporting purged_snaps []
2026-06-30T18:27:21.955399+02:00 pg[9.38 active+clean trimq=[df69~25]] PeeringState::prepare_stats_for_publish publish_stats_to_osd 731015:1033356179
2026-06-30T18:27:21.955399+02:00 pg[9.38 active+clean trimq=[df69~25]] enter NotTrimming
2026-06-30T18:27:21.955399+02:00 pg[9.38 active+clean trimq=[df69~25]] SnapTrimmer state<NotTrimming>: NotTrimming react KickTrim
2026-06-30T18:27:21.955399+02:00 pg[9.38 active+clean trimq=[df69~25]] exit NotTrimming
2026-06-30T18:27:21.955399+02:00 pg[9.38 active+clean trimq=[df69~25]] enter Trimming
2026-06-30T18:27:21.955399+02:00 pg[9.38 active+clean trimq=[df69~25]] enter Trimming/WaitReservation
2026-06-30T18:27:21.955399+02:00 pg[9.38 active+clean+snaptrim_wait trimq=[df69~25]] PeeringState::prepare_stats_for_publish reporting purged_snaps []
2026-06-30T18:27:21.955399+02:00 pg[9.38 active+clean+snaptrim_wait trimq=[df69~25]] PeeringState::prepare_stats_for_publish publish_stats_to_osd 731015:1033356180
2026-06-30T18:27:21.955399+02:00 pg[9.38 active+clean+snaptrim_wait trimq=[df69~25]] SnapTrimmer state<Trimming/WaitReservation>: WaitReservation react SnapTrimReserved
2026-06-30T18:27:21.955399+02:00 pg[9.38 active+clean+snaptrim_wait trimq=[df69~25]] exit Trimming/WaitReservation
2026-06-30T18:27:21.955909+02:00 pg[9.38 active+clean trimq=[df69~25]] PeeringState::prepare_stats_for_publish reporting purged_snaps []
2026-06-30T18:27:21.955909+02:00 pg[9.38 active+clean trimq=[df69~25]] PeeringState::prepare_stats_for_publish publish_stats_to_osd 731015:1033356181
2026-06-30T18:27:21.955909+02:00 pg[9.38 active+clean trimq=[df69~25]] exit Trimming
2026-06-30T18:27:21.955909+02:00 pg[9.38 active+clean trimq=[df69~25]] PeeringState::prepare_stats_for_publish reporting purged_snaps []
2026-06-30T18:27:21.955909+02:00 pg[9.38 active+clean trimq=[df69~25]] PeeringState::prepare_stats_for_publish publish_stats_to_osd 731015:1033356182
2026-06-30T18:27:21.955909+02:00 pg[9.38 active+clean trimq=[df69~25]] enter NotTrimming
2026-06-30T18:27:21.955909+02:00 pg[9.38 active+clean trimq=[df69~25]] SnapTrimmer state<NotTrimming>: NotTrimming react KickTrim
2026-06-30T18:27:21.955909+02:00 pg[9.38 active+clean trimq=[df69~25]] exit NotTrimming
2026-06-30T18:27:21.955909+02:00 pg[9.38 active+clean trimq=[df69~25]] enter Trimming
2026-06-30T18:27:21.955909+02:00 pg[9.38 active+clean trimq=[df69~25]] enter Trimming/WaitReservation
2026-06-30T18:27:21.955909+02:00 pg[9.38 active+clean+snaptrim_wait trimq=[df69~25]] PeeringState::prepare_stats_for_publish reporting purged_snaps []
2026-06-30T18:27:21.955909+02:00 pg[9.38 active+clean+snaptrim_wait trimq=[df69~25]] PeeringState::prepare_stats_for_publish publish_stats_to_osd 731015:1033356183
2026-06-30T18:27:21.956380+02:00 pg[9.38 active+clean+snaptrim_wait trimq=[df69~25]] SnapTrimmer state<Trimming/WaitReservation>: WaitReservation react SnapTrimReserved
2026-06-30T18:27:21.956380+02:00 pg[9.38 active+clean+snaptrim_wait trimq=[df69~25]] exit Trimming/WaitReservation
2026-06-30T18:27:21.956380+02:00 pg[9.38 active+clean trimq=[df69~25]] PeeringState::prepare_stats_for_publish reporting purged_snaps []
2026-06-30T18:27:21.956380+02:00 pg[9.38 active+clean trimq=[df69~25]] PeeringState::prepare_stats_for_publish publish_stats_to_osd 731015:1033356184
2026-06-30T18:27:21.956380+02:00 pg[9.38 active+clean trimq=[df69~25]] exit Trimming
2026-06-30T18:27:21.956380+02:00 pg[9.38 active+clean trimq=[df69~25]] PeeringState::prepare_stats_for_publish reporting purged_snaps []
2026-06-30T18:27:21.956380+02:00 pg[9.38 active+clean trimq=[df69~25]] PeeringState::prepare_stats_for_publish publish_stats_to_osd 731015:1033356185
2026-06-30T18:27:21.956380+02:00 pg[9.38 active+clean trimq=[df69~25]] enter NotTrimming
2026-06-30T18:27:21.956380+02:00 pg[9.38 active+clean trimq=[df69~25]] SnapTrimmer state<NotTrimming>: NotTrimming react KickTrim
2026-06-30T18:27:21.956380+02:00 pg[9.38 active+clean trimq=[df69~25]] exit NotTrimming
2026-06-30T18:27:21.956380+02:00 pg[9.38 active+clean trimq=[df69~25]] enter Trimming
2026-06-30T18:27:21.956380+02:00 pg[9.38 active+clean trimq=[df69~25]] enter Trimming/WaitReservation
2026-06-30T18:27:21.956856+02:00 pg[9.38 active+clean+snaptrim_wait trimq=[df69~25]] PeeringState::prepare_stats_for_publish reporting purged_snaps []
2026-06-30T18:27:21.956856+02:00 pg[9.38 active+clean+snaptrim_wait trimq=[df69~25]] PeeringState::prepare_stats_for_publish publish_stats_to_osd 731015:1033356186
2026-06-30T18:27:21.956856+02:00 pg[9.38 active+clean+snaptrim_wait trimq=[df69~25]] SnapTrimmer state<Trimming/WaitReservation>: WaitReservation react SnapTrimReserved
2026-06-30T18:27:21.956856+02:00 pg[9.38 active+clean+snaptrim_wait trimq=[df69~25]] exit Trimming/WaitReservation
2026-06-30T18:27:21.956856+02:00 pg[9.38 active+clean trimq=[df69~25]] PeeringState::prepare_stats_for_publish reporting purged_snaps []
journalctl -o short-iso-precise -fu ceph-${FSID}@osd.${OSD_ID}.service | egrep "enter Trimming" | cut -c -19 | uniq -c
962 2026-06-30T20:00:38
530 2026-06-30T20:00:39
1290 2026-06-30T20:00:40
1310 2026-06-30T20:00:41
1328 2026-06-30T20:00:42
1388 2026-06-30T20:00:43
370 2026-06-30T20:00:44
journalctl -o short-iso-precise -fu ceph-${FSID}@osd.${OSD_ID}.service | egrep -i trim | cut -c -19 | uniq -c
10 2026-06-30T20:00:54
4656 2026-06-30T20:00:55
7891 2026-06-30T20:00:56
9982 2026-06-30T20:00:57
9330 2026-06-30T20:00:58
7900 2026-06-30T20:00:59
ceph tell osd.${OSD_ID} config unset debug_osd
ceph osd unset nosnaptrim
FS Updated by Francois Scheurer 5 months ago
- Description updated (diff)
FS Updated by Francois Scheurer 5 months ago
- Description updated (diff)
LF Updated by Laura Flores 5 months ago
- Assignee set to Radoslaw Zarzynski
@Radoslaw Zarzynski can you help triage this?
LF Updated by Laura Flores 4 months ago
Bump up
RZ Updated by Radoslaw Zarzynski 4 months ago
Bump up.
RZ Updated by Radoslaw Zarzynski 4 months ago
- Status changed from New to In Progress
RZ Updated by Radoslaw Zarzynski 4 months ago
It looks OSD is doing a heavy busy-wait by switching between:
boost::statechart::result PrimaryLogPG::WaitReservation::react(const SnapTrimReserved&)
{
PrimaryLogPG *pg = context< SnapTrimmer >().pg;
ldout(pg->cct, 10) << "WaitReservation react SnapTrimReserved" << dendl;
pending = nullptr;
if (!context< SnapTrimmer >().can_trim()) {
post_event(KickTrim());
return transit< NotTrimming >();
}
// ...
boost::statechart::result PrimaryLogPG::NotTrimming::react(const KickTrim&)
{
PrimaryLogPG *pg = context< SnapTrimmer >().pg;
ldout(pg->cct, 10) << "NotTrimming react KickTrim" << dendl;
if (!(pg->is_primary() && pg->is_active())) {
ldout(pg->cct, 10) << "NotTrimming not primary or active" << dendl;
return discard_event();
}
if (!pg->is_clean() ||
pg->snap_trimq.empty()) {
ldout(pg->cct, 10) << "NotTrimming not clean or nothing to trim" << dendl;
return discard_event();
}
if (pg->is_scrub_queued_or_active()) {
ldout(pg->cct, 10) << " scrubbing, will requeue snap_trimmer after" << dendl;
return transit< WaitScrub >();
} else {
return transit< Trimming >();
}
}
RZ Updated by Radoslaw Zarzynski 4 months ago
- Status changed from In Progress to Fix Under Review
- Pull request ID set to 71024
FS Updated by Francois Scheurer 4 months ago
- Affected Versions v19.2.3 added
RZ Updated by Radoslaw Zarzynski 4 months ago
- Backport set to squid, tentacle, umbrella
RZ Updated by Radoslaw Zarzynski 4 months ago
Ronen approved the PR, sent to QA.
RZ Updated by Radoslaw Zarzynski 3 months ago
In QA.
RZ Updated by Radoslaw Zarzynski 3 months ago
Still in QA.
UB Updated by Upkeep Bot 3 months ago
- Status changed from Fix Under Review to Pending Backport
- Merge Commit set to a7047da5bba32ee0390a5d79ca872b4bb6c50096
- Fixed In set to v21.3.0-2903-ga7047da5bb
- Upkeep Timestamp set to 2026-09-04T00:30:11+00:00
UB Updated by Upkeep Bot 3 months ago
- Copied to Backport #80272: squid: 100% CPU utilization if nosnaptrim osd flag set during snapshot removal added
UB Updated by Upkeep Bot 3 months ago
- Copied to Backport #80273: tentacle: 100% CPU utilization if nosnaptrim osd flag set during snapshot removal added
UB Updated by Upkeep Bot 3 months ago
- Copied to Backport #80274: umbrella: 100% CPU utilization if nosnaptrim osd flag set during snapshot removal added
UB Updated by Upkeep Bot 3 months ago
- Status changed from Pending Backport to Backporting
- Upkeep Timestamp changed from 2026-09-04T00:30:11+00:00 to 2026-09-04T00:44:25+00:00