Skip to content

Draft: Add POSIX message queue dump/restore support via MQ_IOC_BULK_PEEK (GSoC 2026 PoC)#2990

Draft
DongSunchao wants to merge 4 commits intocheckpoint-restore:criu-devfrom
DongSunchao:criu-dev
Draft

Draft: Add POSIX message queue dump/restore support via MQ_IOC_BULK_PEEK (GSoC 2026 PoC)#2990
DongSunchao wants to merge 4 commits intocheckpoint-restore:criu-devfrom
DongSunchao:criu-dev

Conversation

@DongSunchao
Copy link
Copy Markdown

Description

This Draft PR is a Proof of Concept (PoC) prepared for GSoC 2026: Checkpointing of POSIX message queues.

Currently, CRIU cannot non-destructively dump POSIX message queues because the standard mq_receive() is destructive, and reading the virtual filesystem (/dev/mqueue) does not expose the raw message payloads.

To solve this, I have designed a new Linux kernel ioctl (MQ_IOC_BULK_PEEK) and integrated the corresponding userspace logic into this CRIU branch.

Architectural Highlights of this PoC:

  • Kernel-side Pagination: The kernel implementation safely chunks massive messages (e.g., megabytes) using a hard-capped 8KB internal buffer, start_offset, and the MQ_PEEK_FLAG_HAS_MORE flag to prevent memory spikes and scheduling latency.
  • CRIU Dump: Detects POSIX message queues and incrementally reads metadata (priority, length) and payloads via the new ioctl.
  • CRIU Restore: Re-creates the queues via mq_open() and utilizes mq_send() to perfectly restore the exact priority ordering.

Current Status & ZDTM Test Results

The basic dump and restore logic is fully functional. I have successfully run ZDTM tests (test/zdtm/static/posix-mqueue.c) against my custom kernel. The logs confirm that message priority ordering is perfectly preserved during migration:

09:14:49.996:    66: Sending messages to mqueue...
09:14:50.450:    66: Restored! Receiving and verifying messages...
09:14:50.450:    66: Verified message #0: [Prio 20] 'Message D: Priority 20 (Highest)'
09:14:50.450:    66: Verified message #1: [Prio 10] 'Message C: Priority 10'
09:14:50.450:    66: Verified message #2: [Prio 5]  'Message B: Priority 5 (Chunked into ~7 pieces)'
09:14:50.451:    66: Verified message #3: [Prio 1]  'Message A: Priority 1 (Lowest)'
09:14:50.451:    66: PASS

Dependencies

This branch requires a custom Linux kernel to function.

Kernel Patch Series (RFC): https://github.com/DongSunchao/gsoc-mqueue-bulk-peek

Questions for Mentors

@rst0git @Snorch

Hello Radostin and Pavel! As I am finalizing my GSoC 2026 proposal, I wanted to share this early PoC to prove the technical viability of the MQ_IOC_BULK_PEEK approach.

I would highly appreciate any early feedback on:

  1. The overall architectural approach for the ioctl and chunking mechanism.
  2. The initial Protobuf schema design for storing mqueue states.

I look forward to discussing this further during the application period. Thank you for your time!

Note on Code Style

As this is an early PoC focused on validating the core technical approach, the code formatting and style may not yet fully perfectly align with CRIU's strict coding guidelines. Refining the code style, adding proper error handling, and writing comprehensive comments are my top priorities for the initial phase of the GSoC coding period.

DongSunchao and others added 4 commits March 26, 2026 22:38
Define the image format needed to checkpoint/restore POSIX message queue
file descriptors.

- Add posix-mqueue.proto with ipcns_pmq_data_entry (queue attributes,
  repeated message entries, flags, fown) and posix_mqueue_msg_entry
  (priority, length, payload bytes).
- Extend file_entry in fdinfo.proto with a new fd_types value PQEFD (21)
  and an optional ipcns_pmq_data_entry field pqmfd.
- Register the new image type (IPCNS_PMQ_DATA) throughout the image
  infrastructure: magic number, image-desc template, protobuf descriptor
  enum and include.
Implement dump and restore of open POSIX message queue file descriptors.

Dump side (dump_one_pmq_fd):
- Triggered by MQUEUE_MAGIC fs_type in the fd dispatch table in files.c.
- Uses mq_getattr() to read queue attributes and the custom kernel ioctl
  MQ_IOC_BULK_PEEK to non-destructively snapshot all messages in one or
  more batched calls.  Messages are returned in priority-then-FIFO order,
  which is exactly the order a subsequent mq_receive() would consume them.
- A local fallback definition of the ioctl structures and command is
  included under #ifndef MQ_IOC_BULK_PEEK for kernels that do not yet
  expose the header.
- Serialises the queue name, attributes, flags, fown, and message list
  into a FileEntry / IpcnsPmqDataEntry protobuf written to the files image.

Restore side (pmq_open):
- Unlinks any pre-existing queue with the same name (the process was
  killed after dump but the named queue persists in the kernel).
- Re-creates the queue with the saved attributes, replays messages via
  mq_send() in the saved order to preserve priority ordering, then
  restores fd flags and ownership through rst_file_params().

Adds POSIX_MQUEUE_MAGIC to fs-magic.h and wires the new module into
files.c (dispatch and collection) and the build system.
Add a static ZDTM test for checkpoint/restore of open POSIX message
queue file descriptors.

The test:
- Creates a named queue with mq_maxmsg=10 / mq_msgsize=256.
- Enqueues four messages with distinct priorities (20, 10, 10, 5) to
  exercise both priority ordering and FIFO tie-breaking.
- Records the mqueue inode with fstat() before C/R to detect a false
  pass: if dump fails, zdtm.py sends SIGTERM and the process resumes
  with the original fd intact (same inode); the test fails explicitly
  in that case.
- After restore, verifies that mq_receive() returns messages in the
  expected priority-then-FIFO order with correct payload content.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant