io_uring_prep_cmd_discard(3)
β¨ io_uring_prep_cmd_discard β¨
okay bestie, so this one lives in the liburing manual, and it's literally the glow-up for preparing a discard command. discard = telling your storage "hey, this chunk? don't need it, throw it out π ". let's get into it π«Ά
πΈ SYNOPSIS πΈ
#include <liburing.h>
void io_uring_prep_cmd_discard(struct io_uring_sqe *sqe,
int fd,
uint64_t offset,
uint64_t nbytes);
π¦ DESCRIPTION π¦
so the way that io_uring_prep_cmd_discard(3) works is: it preps a discard command request, no cap. the submission queue entry sqe gets set up to use the file descriptor fd to start discarding nbytes at the specified offset. that's it, that's the whole vibe β¨
now here's the tea β β this command is an asynchronous equivalent of the BLOCK_URING_CMD_DISCARD ioctl, but with a few differences:
- it lets you do multiple parallel discards π₯
- and it does not exclude concurrent writes and reads
and that last one is highkey the important part, so listen up bestie:
it may lead to races for the data on the disk, if the application has IO inflight for the same ranges that the discard operates on. it's the user's responsibility to account for that. π
also, only best efforts are done to invalidate page caches. the user has to make sure that no other inflight requests are modifying or reading the range(s). if that is the case, it might result in stale page cache and data inconsistencies. π so like, be careful fr fr.
available since 6.12. π
β RETURN VALUE β
None. that's it. nothing. zero. the void. π
π ERRORS π
the CQE res field will contain the result of the operation, periodt.
- on success, this field will be set to
0 - on error, a negative error value is returned
and ngl here's the quirky part β where synchronous system calls will return -1 on failure and set errno to the actual error value, io_uring never uses errno. instead it returns the negated errno directly in the CQE res field. iconic behavior, honestly π
π SEE ALSO π
and that's the whole page, bestie! this one came from liburing-2.8, dated Oct 13, 2024, and it's all about io_uring_prep_cmd_discard(3). go forth and discard responsibly, mwah π
ππ¦
π¦ where this page comes from
- alpine 3.22: liburing-doc 2.9-r0 Β· LGPL-2.1-or-later OR MIT
- alpine 3.23: liburing-doc 2.12-r0 Β· LGPL-2.1-or-later OR MIT
- alpine 3.24: liburing-doc 2.14-r0 Β· LGPL-2.1-or-later OR MIT
- arch rolling: liburing 2.15-1 Β· GPL-2.0-only WITH Linux-syscall-note OR MIT AND LGPL-2.0-or-later AND MIT
- centos-stream 10: liburing-devel 2.12-1.el10 Β· (GPLv2 with exceptions and LGPLv2+) or MIT
- centos-stream 9: liburing-devel 2.12-1.el9 Β· (GPLv2 with exceptions and LGPLv2+) or MIT
- centos-stream 9: liburing-devel 2.12-1.el9 Β· (GPLv2 with exceptions and LGPLv2+) or MIT
- debian trixie: liburing-dev 2.9-1
- fedora 43: liburing-devel 2.9-2.fc43 Β· (GPL-2.0-only WITH Linux-syscall-note OR MIT) AND (LGPL-2.0-or-later OR MIT)
- fedora 43: liburing-devel 2.9-2.fc43 Β· (GPL-2.0-only WITH Linux-syscall-note OR MIT) AND (LGPL-2.0-or-later OR MIT)
- fedora 44: liburing-devel 2.13-2.fc44 Β· (GPL-2.0-only WITH Linux-syscall-note OR MIT) AND (LGPL-2.0-or-later OR MIT)
- fedora 44: liburing-devel 2.13-2.fc44 Β· (GPL-2.0-only WITH Linux-syscall-note OR MIT) AND (LGPL-2.0-or-later OR MIT)
- nixpkgs unstable: liburing 2.14
- opensuse-leap 16.0: liburing-devel 2.8-160000.3.1 Β· (GPL-2.0-only AND LGPL-2.1-or-later) OR MIT
- opensuse-leap 16.0: liburing-devel 2.8-160000.3.1 Β· (GPL-2.0-only AND LGPL-2.1-or-later) OR MIT
- opensuse-leap 16.0: liburing-devel 2.8-160000.3.1 Β· (GPL-2.0-only AND LGPL-2.1-or-later) OR MIT
- opensuse-leap 16.0: liburing-devel 2.8-160000.3.1 Β· (GPL-2.0-only AND LGPL-2.1-or-later) OR MIT
- ubuntu questing: liburing-dev 2.11-1
- ubuntu resolute: liburing-dev 2.14-1
- ubuntu stonking: liburing-dev 2.15-1
- π the page's license: LGPL-2.0-or-later
- Copyright (C) 2024 Pavel Begunkov <asml.silence@gmail.com>
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms