Questions tagged [linux-kernel]

This tag is for questions about the internals of the Linux kernel itself - particularly about writing code that runs within the context of the kernel (like kernel modules or drivers). Questions about writing userspace code in Linux should generally be tagged [linux] instead. Since the internals of the Linux kernel are constantly changing, it is helpful to include the precise kernel version(s) that you are interested in.

This tag is for questions about the internals of the Linux kernel itself - particularly about writing code that runs within the context of the kernel (like kernel modules or drivers).

Questions about writing userspace code in Linux should generally be tagged instead. Since the internals of the Linux kernel are constantly changing, it is helpful to include the precise kernel version(s) that you are interested in.

The kernel is a UNIX-like kernel initially created by Linus Torvalds in 1991 and now is maintained by developers around the world.

Frequently Asked Questions

Online resources

Books

Kernel source code and source code browsers

Further reading

Mailing lists

17371 questions
446
votes
10 answers

How do the likely/unlikely macros in the Linux kernel work and what is their benefit?

I've been digging through some parts of the Linux kernel, and found calls like this: if (unlikely(fd < 0)) { /* Do something */ } or if (likely(!err)) { /* Do something */ } I've found the definition of them: #define likely(x) …
terminus
  • 13,745
  • 8
  • 34
  • 37
301
votes
12 answers

Is bool a native C type?

I've noticed that the Linux kernel code uses bool, but I thought that bool was a C++ type. Is bool a standard C extension (e.g., ISO C90) or a GCC extension?
asussex
  • 3,051
  • 2
  • 16
  • 6
300
votes
13 answers

How is the Linux kernel tested?

How do the Linux kernel developers test their code locally and after they have it committed? Do they use some kind of unit testing and build automation? Test plans?
Ashkan Kh. Nazary
  • 21,844
  • 13
  • 44
  • 68
292
votes
3 answers

What is the theoretical maximum number of open TCP connections that a modern Linux box can have

Assuming infinite performance from hardware, can a Linux box support >65536 open TCP connections? I understand that the number of ephemeral ports (<65536) limits the number of connections from one local IP to one port on one remote IP. The tuple…
fadedbee
  • 42,671
  • 44
  • 178
  • 308
261
votes
5 answers

Increasing the maximum number of TCP/IP connections in Linux

I am programming a server and it seems like my number of connections is being limited since my bandwidth isn't being saturated even when I've set the number of connections to "unlimited". How can I increase or eliminate a maximum number of…
jbu
241
votes
6 answers

Why is Linux called a monolithic kernel?

I read that Linux is a monolithic kernel. Does monolithic kernel mean compiling and linking the complete kernel code into an executable? If Linux is able to support modules, why not break all the subsystems into modules and load them when necessary?…
Boolean
  • 14,266
  • 30
  • 88
  • 129
175
votes
2 answers

Measure time in Linux - time vs clock vs getrusage vs clock_gettime vs gettimeofday vs timespec_get?

Among the timing functions, time, clock getrusage, clock_gettime, gettimeofday and timespec_get, I want to understand clearly how they are implemented and what are their return values in order to know in which situation I have to use them. First we…
Manuel Selva
  • 18,554
  • 22
  • 89
  • 134
174
votes
2 answers

What is ?= in Makefile

KDIR ?= $(shell uname -r) What is the meaning of ?=? I have understood the difference between :=, += and = from another thread available in Stack Overflow, but unable to find the explanation for ?=.
codedoc
  • 2,079
  • 2
  • 11
  • 15
163
votes
16 answers

What is the difference between the kernel space and the user space?

What is the difference between the kernel space and the user space? Do kernel space, kernel threads, kernel processes and kernel stack mean the same thing? Also, why do we need this differentiation?
kc3
  • 4,281
  • 7
  • 20
  • 16
150
votes
2 answers

IOCTL Linux device driver

Can anyone explain me, What is IOCTL? What is it used for? How can I use it? Why can't I define new function that does the same work as IOCTL?
flashdisk
  • 3,652
  • 3
  • 16
  • 22
146
votes
5 answers

Writing programs to cope with I/O errors causing lost writes on Linux

TL;DR: If the Linux kernel loses a buffered I/O write, is there any way for the application to find out? I know you have to fsync() the file (and its parent directory) for durability. The question is if the kernel loses dirty buffers that are…
Craig Ringer
  • 307,061
  • 76
  • 688
  • 778
142
votes
2 answers

What's the use of do while(0) when we define a macro?

Possible Duplicates: Do-While and if-else statements in C/C++ macros do { … } while (0) — what is it good for? I'm reading the linux kernel and I found many macros like this: #define INIT_LIST_HEAD(ptr) do { \ (ptr)->next = (ptr); (ptr)->prev…
amazingjxq
  • 4,487
  • 7
  • 33
  • 35
135
votes
3 answers

kernel stack and user space stack

What's the difference between kernel stack and user stack? Why kernel stack is used? If a local variable is declared in an ISR, where it will be stored? Does each process has its own kernel stack? Then how the process coordinates between both these…
jkv
  • 1,627
  • 4
  • 12
  • 14
134
votes
7 answers

What happens to an open file handle on Linux if the pointed file gets moved or deleted

What happens to an open file handle on Linux if the pointed file meanwhile gets: Moved away -> Does the file handle stay valid? Deleted -> Does this lead to an EBADF, indicating an invalid file handle? Replaced by a new file -> Does the file handle…
Maus
  • 2,724
  • 5
  • 32
  • 37
130
votes
8 answers

What is the difference between vmalloc and kmalloc?

I've googled around and found most people advocating the use of kmalloc, as you're guaranteed to get contiguous physical blocks of memory. However, it also seems as though kmalloc can fail if a contiguous physical block that you want can't be…
FreeMemory
  • 8,444
  • 7
  • 37
  • 49
1
2 3
99 100