Questions tagged [kmalloc]

The kmalloc function performs fast dynamic memory allocation and is part of the Linux Kernel API.

The kmalloc() function performs dynamic memory allocation and is part of the Linux Kernel API. In contrast to malloc, this function allocates memory faster in regions of contiguous physical memory, and it doesn't clear the memory it obtains.

More information can be found here

51 questions
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
18
votes
2 answers

What is the meaning of GFP in kmalloc flags?

What is the meaning of GFP flags in kmalloc? For instance GFP_KERNEL, GFP_ATOMIC?
user1485214
  • 181
  • 1
  • 1
  • 3
9
votes
1 answer

Pool of Memory in Kernel driver for Multiple processes

Suppose we want to maintain a pool of memory in a device driver or module. How can that pool be created and be available to multiple processes lets say 4 processes, accessing this driver/module. Assume 1 MB of memory in the pool. When I was reading…
9
votes
2 answers

is memory allocated by kmalloc() ever automatically freed?

I'm writing a device driver that, among other things, allocates a block of memory with kmalloc. This memory is freed when the user program closes the file. In one of my experiments, the user program crashed without closing the file. Would…
Nathan Fellman
  • 122,701
  • 101
  • 260
  • 319
7
votes
2 answers

Linux kernel NULL-pointer dereference in memset from kzalloc

Quite by chance stumbled upon some code in kernel jungles and was a bit confused. There are two implementations of kzalloc(): in tools/virtio/linux/kernel.h and the main one in linux/slab.h. Obviously, in most cases the second one is used. But…
red0ct
  • 4,840
  • 3
  • 17
  • 44
4
votes
0 answers

How kmalloc() and vmalloc() used in 32bit vs 64bit systems?

Architecture: X86, Linux I have gone through several threads related to kmalloc() and vmalloc() and I know the basic differences between them but still have some doubts. I need your help to understand the fundamentals. So As we know that in 32-bit…
Usr1
  • 369
  • 1
  • 6
  • 15
4
votes
1 answer

How to disable cache memory in kernel modules

I'am currently trying to develop a Linux driver to use a custom module developed in FPGA. For that, I use a Xilinx Zynq SoC with a Linux distribution that runs on the 2 ARM cores and my VHDL modules are implemented on the FPGA part, but this is not…
Damien Cappelle
  • 178
  • 1
  • 8
4
votes
1 answer

What is the use of GFP_USER flag in kmalloc?

As far as I understand, the use in the GFP_USER flag (in the call to kmalloc) is used to allocate memory for user space. Does it means that the allocated page are in kernel space, which are accessible to user? Does these pages required to be…
Cool Goose
  • 870
  • 10
  • 16
3
votes
1 answer

Why am I getting a high address when I use kmalloc with GFP_DMA in Linux?

I am writing a device driver for a DMA device in Linux. In Linux Device Drivers, Chapter 15, it says: For devices with this kind of limitation, memory should be allocated from the DMA zone by adding the GFP_DMA flag to the kmalloc or …
Nathan Fellman
  • 122,701
  • 101
  • 260
  • 319
2
votes
1 answer

which kmalloc flag should be used

I've been searching everywhere finding a documentation that explains when to use each flags of kmalloc. I found this reference which fairly explains when to use some of the flags but I can't find the other flags like GFP_HIGHUSER_PAGECACHE,…
Owen
  • 4,063
  • 17
  • 58
  • 78
2
votes
0 answers

From a kmalloc buffer, get corresponding array of pages and offsets

I am working on a new socket that sits on top of TCP sockets, and for performance reasons, I want to call tcp_sendpage instead of tcp_sendmsg (tcp_sendmsg would copy my data unnecessarily). However, my input is a kmalloc'ed buffer that can be…
Lance Chao
  • 79
  • 2
  • 7
2
votes
1 answer

explain devm_kzalloc parameters and usage

I am new to kernel driver programming and would like to understand few aspects. In the below code from http://lxr.free-electrons.com/source/drivers/i2c/busses/i2c-ocores.c?v=3.19 static int ocores_i2c_probe(struct platform_device *pdev) { struct…
dee
  • 95
  • 1
  • 7
2
votes
1 answer

why recursive filesystem calls would be a bad idea when the GFP_NOFS is masked

From LDD3 page 214: GFP_NOIO GFP_NOFS These flags function like GFP_KERNEL, but they add restrictions on what the kernel can do to satisfy the request. A GFP_NOFS allocation is not allowed to perform any filesystem calls, while GFP_NOIO disallows…
dongdong
  • 25
  • 1
  • 4
2
votes
3 answers

Unable to access struct data

In the header file: typedef struct { char* a; int allowed; struct suit { struct t { char* option; int count; } t; struct inner { char* option; …
2
votes
1 answer

Can kmalloc() return invalid memory?

I am writing a linux kernel module in which I implemented a linked list. I know there is a list API in linux kernel but when I implemented it I didn't know so implemented it handling raw pointer with kmalloc(). After running several hours, kernel is…
taufique
  • 2,701
  • 1
  • 26
  • 40
1
2 3 4