cacheflush(2)
π cacheflush(2) β bestie edition π
okay so this is a page from the System Calls Manual, and it's all about cacheflush(2). if you're on a MIPS-core girlie's machine or honestly anywhere with a split instruction/data cache, this one's for you. strap in, we're flushing caches and we're doing it cutely π§Ήβ¨
πΈ NAME πΈ
cacheflush β flush contents of instruction and/or data cache
π LIBRARY π
Standard C library (libc, -lc)
β¨ SYNOPSIS β¨
#include <sys/cachectl.h>
int cacheflush(int nbytes;
void addr[nbytes], int nbytes, int cache);
bestie heads up: on some architectures there is literally no glibc wrapper for this system call. go read VERSIONS before you start typing, i'm begging π
π DESCRIPTION π
cacheflush() flushes the contents of the indicated cache(s) for the user addresses in the range addr to (addr+nbytes-1). yes, inclusive, yes, that's the vibe.
and cache can be one of these three icons:
ICACHEβ flush the instruction cache. slay, the CPU knows what to do next π₯DCACHEβ write back to memory and invalidate the affected valid cache lines. two things at once, main character energy, no notes πBCACHEβ same as(ICACHE|DCACHE). it's both, it's a combo, it ate π
π«Ά RETURN VALUE π«Ά
cacheflush() returns 0 on success. iconic. flawless. no cap.
on error it returns -1 and sets errno to indicate the error. not the vibe, but we move π
π¨ ERRORS π¨
EFAULTβ some or all of the address rangeaddrto(addr+nbytes-1)is not accessible. like, you pointed at something that isn't yours. rude but fair πEINVALβcacheis not one ofICACHE,DCACHE, orBCACHE(but see BUGS π the call is lying to you a little bit)
π¦ VERSIONS π¦
lowkey important: cacheflush() should not be used in programs intended to be portable. it's giving "works on my machine" and it means it.
on Linux, this call first appeared on the MIPS architecture. but nowadays Linux provides a cacheflush() system call on some other architectures too β except with different arguments. same name, different girl. π
π Architecture-specific variants π
glibc provides a wrapper for this system call, with the prototype shown up in SYNOPSIS, for the following architectures:
ARC, CSKY, MIPS, and NIOS2. (yes, those exact four, no extras, write them down βοΈ)
on some other architectures, Linux provides this system call with different arguments:
M68K:
int cacheflush(unsigned long addr, int scope, int cache,
unsigned long size);
SH:
int cacheflush(unsigned long addr, unsigned long size, int op);
NDS32:
int cacheflush(unsigned int start, unsigned int end, int cache);
on the architectures above, glibc does not provide a wrapper for this system call β you have to call it yourself using syscall(2). yes, manually. it's giving DIY β¨
π GCC alternative π
unless you need the finer grained control that this system call provides, you probably want to use the GCC built-in function __builtin___clear_cache(), which provides a portable interface across platforms supported by GCC and compatible compilers:
void __builtin___clear_cache(void *begin, void *end);
on platforms that don't require instruction cache flushes, __builtin___clear_cache() has no effect. it's just out here existing, doing nothing, and honestly? same π«Ά
note: on some GCC-compatible compilers, the prototype for this built-in function useschar *instead ofvoid *for the parameters. tiny little difference, big little consequences π
π STANDARDS π
historically, this system call was available on all MIPS UNIX variants β including RISC/os, IRIX, Ultrix, NetBSD, OpenBSD, and FreeBSD β and also on some non-UNIX MIPS operating systems. so the existence of this call in MIPS operating systems is a de-facto standard. she's been everywhere, she's a legend, periodt π
π BUGS π
okay this is the messy part, listen up:
- Linux kernels older than Linux 2.6.11 ignore the
addrandnbytesarguments, making this function fairly expensive. therefore, the whole cache is always flushed. not "sometimes", not "partially" β the whole thing. every time. π - this function always behaves as if
BCACHEhas been passed for thecacheargument, and does not do any error checking on thecacheargument. so thatEINVALabove? yeah. see? told you. the flag isn't even being read bestie. it's fake. it's decorative. it's a vibe. π
and that's the whole page!! go flush something, love you, bye!! πΈππ
this page is from Linux man-pages 6.20, dated 2026-02-08 β mwah, kisses to the maintainers, thank you for your service πβ¨
π¦ where this page comes from
- arch rolling: man-pages 6.20-1 Β· BSD-2-Clause AND BSD-3-Clause AND BSD-4.3TAHOE AND BSD-4-Clause-UC AND GPL-1.0-or-later AND GPL-2.0-only AND GPL-2.0-or-later AND GPL-3.0-or-later AND LGPL-3.0-linking-exception AND LGPL-3.0-or-later AND LicenseRef-Public-Domain AND LicenseRef-UltraPermissive AND Linux-man-pages-1-para AND Linux-man-pages-copyleft AND Linux-man-pages-copyleft-2-para AND Linux-man-pages-copyleft-var AND MIT AND Spencer-94
- nixpkgs unstable: man-pages 6.20
- π the page's license: GPL-2.0-or-later
- Copyright 1994-1995, Waldorf GMBH
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms