| 1 |
.\" Copyright 1994-1995, Waldorf GMBH |
| 2 |
.\" Copyright, the authors of the Linux man-pages project |
| 3 |
.\" |
| 4 |
.\" SPDX-License-Identifier: GPL-2.0-or-later |
| 5 |
.\" |
| 6 |
.TH cacheflush 2 2026-02-08 "Linux man-pages 6.18" |
| 7 |
.SH NAME |
| 8 |
cacheflush \- flush contents of instruction and/or data cache |
| 9 |
.SH LIBRARY |
| 10 |
Standard C library |
| 11 |
.RI ( libc ,\~ \-lc ) |
| 12 |
.SH SYNOPSIS |
| 13 |
.nf |
| 14 |
.B #include <sys/cachectl.h> |
| 15 |
.P |
| 16 |
.BR "int cacheflush(" "int nbytes;" |
| 17 |
.BI " void " addr [ nbytes "], int "nbytes ", int "cache ); |
| 18 |
.fi |
| 19 |
.P |
| 20 |
.IR Note : |
| 21 |
On some architectures, |
| 22 |
there is no glibc wrapper for this system call; |
| 23 |
see VERSIONS. |
| 24 |
.SH DESCRIPTION |
| 25 |
.BR cacheflush () |
| 26 |
flushes the contents of the indicated cache(s) for the |
| 27 |
user addresses in the range |
| 28 |
.I addr |
| 29 |
to |
| 30 |
.IR (addr+nbytes\-1) . |
| 31 |
.I cache |
| 32 |
may be one of: |
| 33 |
.TP |
| 34 |
.B ICACHE |
| 35 |
Flush the instruction cache. |
| 36 |
.TP |
| 37 |
.B DCACHE |
| 38 |
Write back to memory and invalidate the affected valid cache lines. |
| 39 |
.TP |
| 40 |
.B BCACHE |
| 41 |
Same as |
| 42 |
.BR (ICACHE|DCACHE) . |
| 43 |
.SH RETURN VALUE |
| 44 |
.BR cacheflush () |
| 45 |
returns 0 on success. |
| 46 |
On error, it returns \-1 and sets |
| 47 |
.I errno |
| 48 |
to indicate the error. |
| 49 |
.SH ERRORS |
| 50 |
.TP |
| 51 |
.B EFAULT |
| 52 |
Some or all of the address range |
| 53 |
.I addr |
| 54 |
to |
| 55 |
.I (addr+nbytes\-1) |
| 56 |
is not accessible. |
| 57 |
.TP |
| 58 |
.B EINVAL |
| 59 |
.I cache |
| 60 |
is not one of |
| 61 |
.BR ICACHE , |
| 62 |
.BR DCACHE , |
| 63 |
or |
| 64 |
.B BCACHE |
| 65 |
(but see BUGS). |
| 66 |
.SH VERSIONS |
| 67 |
.BR cacheflush () |
| 68 |
should not be used in programs intended to be portable. |
| 69 |
On Linux, this call first appeared on the MIPS architecture, |
| 70 |
but nowadays, Linux provides a |
| 71 |
.BR cacheflush () |
| 72 |
system call on some other architectures, but with different arguments. |
| 73 |
.SS Architecture-specific variants |
| 74 |
glibc provides a wrapper for this system call, |
| 75 |
with the prototype shown in SYNOPSIS, |
| 76 |
for the following architectures: |
| 77 |
ARC, CSKY, MIPS, and NIOS2. |
| 78 |
.P |
| 79 |
On some other architectures, |
| 80 |
Linux provides this system call, with different arguments: |
| 81 |
.TP |
| 82 |
M68K: |
| 83 |
.nf |
| 84 |
.BI "int cacheflush(unsigned long " addr ", int " scope ", int " cache , |
| 85 |
.BI " unsigned long " size ); |
| 86 |
.fi |
| 87 |
.TP |
| 88 |
SH: |
| 89 |
.nf |
| 90 |
.BI "int cacheflush(unsigned long " addr ", unsigned long " size ", int " op ); |
| 91 |
.fi |
| 92 |
.TP |
| 93 |
NDS32: |
| 94 |
.nf |
| 95 |
.BI "int cacheflush(unsigned int " start ", unsigned int " end ", int " cache ); |
| 96 |
.fi |
| 97 |
.P |
| 98 |
On the above architectures, |
| 99 |
glibc does not provide a wrapper for this system call; |
| 100 |
call it using |
| 101 |
.BR syscall (2). |
| 102 |
.SS GCC alternative |
| 103 |
Unless you need the finer grained control that this system call provides, |
| 104 |
you probably want to use the GCC built-in function |
| 105 |
.BR __builtin___clear_cache (), |
| 106 |
which provides a portable interface |
| 107 |
across platforms supported by GCC and compatible compilers: |
| 108 |
.P |
| 109 |
.in +4n |
| 110 |
.EX |
| 111 |
.BI "void __builtin___clear_cache(void *" begin ", void *" end ); |
| 112 |
.EE |
| 113 |
.in |
| 114 |
.P |
| 115 |
On platforms that don't require instruction cache flushes, |
| 116 |
.BR __builtin___clear_cache () |
| 117 |
has no effect. |
| 118 |
.P |
| 119 |
.IR Note : |
| 120 |
On some GCC-compatible compilers, |
| 121 |
the prototype for this built-in function uses |
| 122 |
.I char * |
| 123 |
instead of |
| 124 |
.I void * |
| 125 |
for the parameters. |
| 126 |
.SH STANDARDS |
| 127 |
Historically, this system call was available on all MIPS UNIX variants |
| 128 |
including RISC/os, IRIX, Ultrix, NetBSD, OpenBSD, and FreeBSD |
| 129 |
(and also on some non-UNIX MIPS operating systems), so that |
| 130 |
the existence of this call in MIPS operating systems is a de-facto |
| 131 |
standard. |
| 132 |
.SH BUGS |
| 133 |
Linux kernels older than Linux 2.6.11 ignore the |
| 134 |
.I addr |
| 135 |
and |
| 136 |
.I nbytes |
| 137 |
arguments, making this function fairly expensive. |
| 138 |
Therefore, the whole cache is always flushed. |
| 139 |
.P |
| 140 |
This function always behaves as if |
| 141 |
.B BCACHE |
| 142 |
has been passed for the |
| 143 |
.I cache |
| 144 |
argument and does not do any error checking on the |
| 145 |
.I cache |
| 146 |
argument. |