kmalloc的大小分配 [英] KMALLOC size allocation

查看:680
本文介绍了kmalloc的大小分配的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

做的kmalloc仅分配的页大小的内存,也可以分配较少?
什么是对的kmalloc可以分配的大小?
我在哪里可以找到它的描述,因为每个人我看它并没有真正说它分配多少内存?
我想知道什么是什么是用kmalloc分配的实际尺寸。
它配备2的幂的大小?
它只是觉得从准备缓存空闲对象?

does KMALLOC allocates only in page size memory or it can allocate less ? what are the sizes that the kmalloc can allocate ? where can i find description of it , since everyone i looked it doesn't really say how much memory it allocates ? what i want to know is what are the actual sizes that KMALLOC allocates. does it allocate size of power of 2 ? does it just find free objects from the cache that is ready ?

推荐答案

我的理解是:在内核是处理系统的物理存储器,其中仅在页面大小的块是可用的;因此,当你调用的kmalloc()你会得到只有某些predefined,固定大小的字节数组。

My understanding is as follows: the kernel is dealing with the physical memory of the system, which is available only in page-sized chunks; thus when you call kmalloc() you are going to get only certain predefined, fixed-size byte arrays.

你得到的实际内存取决于系统的架构,但是kmalloc的可以处理的最小分配是一样大的32或64个字节。你会从一个呼叫切换到的kmalloc() 至少的内存,你要求(通常更多)。通常情况下,你不会得到超过128 KB(再次,建筑相关)

The actual memory you get back is dependent on the system's architecture, but the smallest allocation that kmalloc can handle is as big as 32 or 64 bytes. You will get back from a call to kmalloc() at least as much memory as you asked for (usually more). Typically you will not get more than 128 KB (again, architecture dependent)

要获得你系统的页面大小(以字节为单位),您可以执行以下命令:

To get the page size (in bytes) of your system you can execute the command:

getconf PAGESIZE

getconf PAGE_SIZE

这是最大的页面大小此信息在/usr/src/linux/include/linux/slab.h

This information on max page size is in /usr/src/linux/include/linux/slab.h

是的,页面大小通常是2的幂,但同样,你不会得到正是你问什么,但多一点点。

And yes, the page sizes are generally powers of 2, but again, you're not going to get exactly what you ask for, but a little bit more.

您可以使用一些code是这样的:

You can use some code like this:

void * stuff;
stuff = kmalloc(1,GFP_KERNEL);
printk("I got: %zu bytes of memory\n", ksize(stuff));
kfree(stuff);

要显示的内存分配的实际金额:

To show the actual amount of memory allocated:

[90144.702588] I got: 32 bytes of memory

这篇关于kmalloc的大小分配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆