[PATCH v2 0/4] Add new system call for non-destructive peek and inspection to posix ipc mqueue

Mathura_Kumar posted 4 patches 3 weeks, 1 day ago
There is a newer version of this series
Documentation/userspace-api/index.rst         |   1 +
Documentation/userspace-api/ipc.rst           | 222 +++++
arch/alpha/kernel/syscalls/syscall.tbl        |   1 +
arch/arm/tools/syscall.tbl                    |   1 +
arch/arm64/tools/syscall_32.tbl               |   1 +
arch/m68k/kernel/syscalls/syscall.tbl         |   1 +
arch/microblaze/kernel/syscalls/syscall.tbl   |   1 +
arch/mips/kernel/syscalls/syscall_n32.tbl     |   1 +
arch/mips/kernel/syscalls/syscall_n64.tbl     |   1 +
arch/mips/kernel/syscalls/syscall_o32.tbl     |   1 +
arch/parisc/kernel/syscalls/syscall.tbl       |   1 +
arch/powerpc/kernel/syscalls/syscall.tbl      |   1 +
arch/s390/kernel/syscalls/syscall.tbl         |   1 +
arch/sh/kernel/syscalls/syscall.tbl           |   1 +
arch/sparc/kernel/syscalls/syscall.tbl        |   1 +
arch/x86/entry/syscalls/syscall_32.tbl        |   1 +
arch/x86/entry/syscalls/syscall_64.tbl        |   1 +
arch/xtensa/kernel/syscalls/syscall.tbl       |   1 +
include/linux/compat.h                        |   6 +-
include/linux/syscalls.h                      |   6 +
include/uapi/asm-generic/unistd.h             |   7 +-
include/uapi/linux/mqueue.h                   |  14 +-
ipc/mqueue.c                                  | 186 ++++-
ipc/msg.c                                     |   2 +-
ipc/msgutil.c                                 |  48 +-
ipc/util.h                                    |   3 +-
kernel/sys_ni.c                               |   1 +
scripts/syscall.tbl                           |   1 +
.../arch/alpha/entry/syscalls/syscall.tbl     |   1 +
.../perf/arch/arm/entry/syscalls/syscall.tbl  |   1 +
.../arch/arm64/entry/syscalls/syscall_32.tbl  |   1 +
.../arch/mips/entry/syscalls/syscall_n64.tbl  |   1 +
.../arch/parisc/entry/syscalls/syscall.tbl    |   1 +
.../arch/powerpc/entry/syscalls/syscall.tbl   |   1 +
.../perf/arch/s390/entry/syscalls/syscall.tbl |   1 +
tools/perf/arch/sh/entry/syscalls/syscall.tbl |   1 +
.../arch/sparc/entry/syscalls/syscall.tbl     |   1 +
.../arch/x86/entry/syscalls/syscall_32.tbl    |   1 +
.../arch/x86/entry/syscalls/syscall_64.tbl    |   1 +
.../arch/xtensa/entry/syscalls/syscall.tbl    |   1 +
tools/scripts/syscall.tbl                     |   1 +
tools/testing/selftests/ipc/.gitignore        |   1 +
tools/testing/selftests/ipc/Makefile          |   9 +-
tools/testing/selftests/ipc/mq_peek.c         | 785 ++++++++++++++++++
44 files changed, 1278 insertions(+), 43 deletions(-)
create mode 100644 Documentation/userspace-api/ipc.rst
create mode 100644 tools/testing/selftests/ipc/mq_peek.c
[PATCH v2 0/4] Add new system call for non-destructive peek and inspection to posix ipc mqueue
Posted by Mathura_Kumar 3 weeks, 1 day ago

Patch series overview:

  1. Add New system call do_mq_timedreceive2() and handler implementation
  2. Add system call number in all  most common arch.
  3. Prepared Documentation and test
  4. Add entry in performance tools all most common file


Short Description:

    POSIX message queues currently lack a mechanism to read
    a message without removing it from the queue. This is a
    long-standing limitation,when we require inspection of queue state
    without altering it.


    Design considerations:
    Two approaches for copying message data to userspace
    were evaluated:

    1) Refcount-based message lifecycle handling
       - This can help us  Avoids intermediate temp kernel copy
       - Extends message lifetime
       -But this may increase writer starvation under heavy load and
        add unnecessary complication on priority  management and
        delay more time to free space in inode due refcount may prevent

    2) Temporary kernel buffer copy
       - Copies message into a bounded kernel buffer
       - Reduces time message remains locked
       - Improves fairness under write-heavy workloads
       - Simpler lifetime management

    My implementation adopts the temporary buffer approach
    to minimize starvation and reduce locking complexity.
    The design allows future transition if refcounting is
    deemed preferable.

    Testing:
      - 17 functional test cases
      - Multi-threaded producer/consumer scenarios
      - concurrent pop and peek
      - Edge cases: empty queue, FIFO
        invalid flags, signal interruption etc.

Use Case:

1) Observability in distributed systems
 e.g Monitoring tools can inspect queue contents without interfering with
    normal processing

2) Check pointing system like CRIU can have a look into queue without consuming and can store messages

3) Resource-aware processing

4) Selective Consumption for Specialized Workers

change since v1:
 - minor update, header guard was removed from include/uapi/linux/mqueue.h 
 - v1 Link: https://lore.kernel.org/all/20260315040827.156558-1-academic1mathura@gmail.com/T/#t

  Thanks for reviewing.


 Documentation/userspace-api/index.rst         |   1 +
 Documentation/userspace-api/ipc.rst           | 222 +++++
 arch/alpha/kernel/syscalls/syscall.tbl        |   1 +
 arch/arm/tools/syscall.tbl                    |   1 +
 arch/arm64/tools/syscall_32.tbl               |   1 +
 arch/m68k/kernel/syscalls/syscall.tbl         |   1 +
 arch/microblaze/kernel/syscalls/syscall.tbl   |   1 +
 arch/mips/kernel/syscalls/syscall_n32.tbl     |   1 +
 arch/mips/kernel/syscalls/syscall_n64.tbl     |   1 +
 arch/mips/kernel/syscalls/syscall_o32.tbl     |   1 +
 arch/parisc/kernel/syscalls/syscall.tbl       |   1 +
 arch/powerpc/kernel/syscalls/syscall.tbl      |   1 +
 arch/s390/kernel/syscalls/syscall.tbl         |   1 +
 arch/sh/kernel/syscalls/syscall.tbl           |   1 +
 arch/sparc/kernel/syscalls/syscall.tbl        |   1 +
 arch/x86/entry/syscalls/syscall_32.tbl        |   1 +
 arch/x86/entry/syscalls/syscall_64.tbl        |   1 +
 arch/xtensa/kernel/syscalls/syscall.tbl       |   1 +
 include/linux/compat.h                        |   6 +-
 include/linux/syscalls.h                      |   6 +
 include/uapi/asm-generic/unistd.h             |   7 +-
 include/uapi/linux/mqueue.h                   |  14 +-
 ipc/mqueue.c                                  | 186 ++++-
 ipc/msg.c                                     |   2 +-
 ipc/msgutil.c                                 |  48 +-
 ipc/util.h                                    |   3 +-
 kernel/sys_ni.c                               |   1 +
 scripts/syscall.tbl                           |   1 +
 .../arch/alpha/entry/syscalls/syscall.tbl     |   1 +
 .../perf/arch/arm/entry/syscalls/syscall.tbl  |   1 +
 .../arch/arm64/entry/syscalls/syscall_32.tbl  |   1 +
 .../arch/mips/entry/syscalls/syscall_n64.tbl  |   1 +
 .../arch/parisc/entry/syscalls/syscall.tbl    |   1 +
 .../arch/powerpc/entry/syscalls/syscall.tbl   |   1 +
 .../perf/arch/s390/entry/syscalls/syscall.tbl |   1 +
 tools/perf/arch/sh/entry/syscalls/syscall.tbl |   1 +
 .../arch/sparc/entry/syscalls/syscall.tbl     |   1 +
 .../arch/x86/entry/syscalls/syscall_32.tbl    |   1 +
 .../arch/x86/entry/syscalls/syscall_64.tbl    |   1 +
 .../arch/xtensa/entry/syscalls/syscall.tbl    |   1 +
 tools/scripts/syscall.tbl                     |   1 +
 tools/testing/selftests/ipc/.gitignore        |   1 +
 tools/testing/selftests/ipc/Makefile          |   9 +-
 tools/testing/selftests/ipc/mq_peek.c         | 785 ++++++++++++++++++
 44 files changed, 1278 insertions(+), 43 deletions(-)
 create mode 100644 Documentation/userspace-api/ipc.rst
 create mode 100644 tools/testing/selftests/ipc/mq_peek.c

-- 
2.43.0
Re: [PATCH v2 0/4] Add new system call for non-destructive peek and inspection to posix ipc mqueue
Posted by Geert Uytterhoeven 2 weeks, 5 days ago
Hi Mathura,

On Sun, 15 Mar 2026 at 22:47, Mathura_Kumar <academic1mathura@gmail.com> wrote:
> Patch series overview:
>
>   1. Add New system call do_mq_timedreceive2() and handler implementation
>   2. Add system call number in all  most common arch.
>   3. Prepared Documentation and test
>   4. Add entry in performance tools all most common file
>
>
> Short Description:
>
>     POSIX message queues currently lack a mechanism to read
>     a message without removing it from the queue. This is a
>     long-standing limitation,when we require inspection of queue state
>     without altering it.

[...]

Thanks for your series!

> change since v1:
>  - minor update, header guard was removed from include/uapi/linux/mqueue.h
>  - v1 Link: https://lore.kernel.org/all/20260315040827.156558-1-academic1mathura@gmail.com/T/#t

Weren't you at v5 before, so how did you get to v1 and v2 again?
What has changed?

"[PATCH] [PATCH V5] mqueue: introduce new do_mq_timedreceive2() [
mq_peek syscall] for non-destructive receive and inspection,fix minor
issue,prepared doc."
https://lore.kernel.org/20260306075009.83723-1-academic1mathura@gmail.com

Gr{oetje,eeting}s,

                        Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds