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
2
votes
1 answer

What's the "right" way to use GFP_ZERO in latest kernels?

I found that on linux 3.0+ GFP_ZERO is no longer defined in headers. All I found in gfp.h was, /* Plain integer GFP bitmasks. Do not use this directly. */ ... #define ___GFP_ZERO 0x8000u I've checked those "exported" bit masks, on one uses…
daisy
  • 22,498
  • 29
  • 129
  • 265
2
votes
1 answer

Physical address of the address returned by kmalloc

I'm a bit confused about the addresses that kmalloc is returning to me. According to the virtual memory map, the addresses I'm getting are in the ffff880000000000 - ffffc7ffffffffff range, so the "direct mapping of all phys. memory". How does this…
2
votes
0 answers

How can I tell kmalloc to use big (>2M) pages?

I am writing a device driver to allocate a large buffer for DMA. My system is using (or so I believe) 4k pages, and I want it to use larger pages, i.e. at least 2M pages. How can I: enable large pages in the system (or check if they're…
Nathan Fellman
  • 122,701
  • 101
  • 260
  • 319
1
vote
2 answers

kernel crash with kmalloc

I am trying to assign memory using kmalloc in kernel code in fact in a queueing discipline. I want to assign memory to q->agg_queue_hdr of which q is a queueing discipline and agg_queue_hdr is a struct, so if assign memory like this:…
docas
  • 11
  • 4
1
vote
1 answer

vmalloc() allocates from vm_struct list

Kernel document https://www.kernel.org/doc/gorman/html/understand/understand010.html says, that for vmalloc-ing It searches through a linear linked list of vm_structs and returns a new struct describing the allocated region. Does that mean…
Franc
  • 319
  • 9
  • 28
1
vote
1 answer

`aligned_alloc` in Linux Kernel Space when using kmalloc

I am writing a kernel module, porting some functionality from user space that uses the aligned_alloc function from the #include library. I did not find a similar function in the function accessible from kernel modules - is there any…
1
vote
0 answers

use vmalloc memory to do DMA?

I'm writing a driver which need large memory. Let's say it will be 1GB at least. The kernel version >= 3.10. Driver needs run in X86_64 and Arm platform. The hardware may have IOMMU. This large memory will mmap to userspace. Device use those…
randomeval
  • 599
  • 4
  • 13
1
vote
1 answer

What is the relation between the smallest kmalloc() allocation and memory page size?

From this post I realized that: the smallest allocation that kmalloc can handle is as big as 32 or 64 bytes and The actual memory you get back is dependent on the system's architecture But also memory page size is mentioned there and on other…
narotello
  • 419
  • 2
  • 14
1
vote
1 answer

Memory Mapping in Linux Kernel - use of vamlloc() and kmalloc()

Considering a 32bit x86 Linux system with 4 GB of RAM memory, So as described in books as well as on many forums that the Memory mapping would be as follows: Kernel logical address - upto 896 MB - Which is one to one mapped and can be allocated…
Usr1
  • 369
  • 1
  • 6
  • 15
1
vote
1 answer

how can I fix copy_from_user doesn't work?

I'm trying to code an encryption driver in Linux, but when I encrypt the string and copy it into the buffer by using copy_from_user() it doesn't work and the k value is the number of chars in the string If I change the temp in copy_from_user to buf…
1
vote
1 answer

Kmalloc Alignment

Lets say I allocate with kmalloc an array of uint64_t (and lets assume the size of the array is 32kB). I have the following questions : 1) Is the array guaranteed to be page aligned ? 2) Is the array guaranteed to be cache / block aligned ? 3) Is…
XII
  • 420
  • 4
  • 16
1
vote
0 answers

Driver requires large chunks of contiguous physical memory

I need to modify a network adapter driver to increase its performance for my use, and I need a huge physical memory chunk to be contiguous. I will need several of these chunks based on the number of ports. Each chunk should be around…
Kanishka
  • 19
  • 6
1
vote
2 answers

Why physically contiguous memory region is more efficient than virtually contiguous memory.?

It is said that Physically contiguous memory region is more efficient than virtually contiguous memory, for that Robert Love's book says that kernel don't need to set up the page table entries for physically contiguous memory. But doesn't kernel…
Rahul
  • 1,607
  • 3
  • 23
  • 41
1
vote
2 answers

declare memory to struct in c

I have a struct abc in one file struct abc { some variaables and functions } I am using this struct in other file as follows : struct abc *t = kmalloc(sizeof(struct abc)); kmalloc is equivalent to malloc then following errors occur:…
user1079065
  • 2,085
  • 9
  • 30
  • 53
1
vote
0 answers

Disabling oom killer affects the area allocated by kmalloc()?

My Linux Kernel Version is 2.6.34.13 CPU is Powerpc. I would like to make OOM-killer disabled completely in both user process and kernel module. By configuring with fowllowing parameters, I disabled oom killer. vm.overcommit_memory = 2 …
Boblishus
  • 87
  • 1
  • 7