Linux内核中的内存分配 [英] Memory Allocation in Linux Kernel

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

问题描述

我今天接受了采访,并被问到这个问题.如果要求您分配大小为2KB的内存,并且分配的内存应该按页对齐,那么您将使用哪种内核内存分配策略.

I had an interview today and was asked this question. What Kernel Memory allocation strategy would you use, if you were asked to allocate memory of size 2KB and that allocated memory should be page aligned.

KMALLOC处理较小的内存分配策略,但是它支持的最低单位是4KB,这是物理页面的大小.我问他,他是否期望平板分配器?他没有积极回应.

KMALLOC handles smaller memory allocation strategies but the lowest unit that it supports is 4KB, which is the size of the physical page. I asked him, if he was expecting slab allocators? He didn't reply positively.

推荐答案

我阅读了以下内容: http://www.makelinux.net/books/lkd2/ch11lev1sec4

I read in: http://www.makelinux.net/books/lkd2/ch11lev1sec4

该函数返回一个指向至少为字节大小的内存区域的指针

The function returns a pointer to a region of memory that is at least size bytes in length

我知道系统操作x86(32位)-RAM 4GB中的最大大小映射,但是它包括参考和信息蛮干.

I know the system Operation x86 ( 32 bits ) - the max size mapping in RAM 4GB, but it include Reference and information brute.

因此4GB是可用的所有空间,转换为'KB'= 4194304 KB,内存Ram等于网格4194304空间(索引和进位信息),或者正方形的边(在拉丁语Radix Quadratum中)SQRT(4194304) =所有尺寸仅索引信息,以及"int标志"下方的信息)

so 4GB is the all space available, convert for 'KB' = 4194304 KB, The Memory Ram iqual the Grid 4194304 spaces( index and bory information ), or the side of square( in latin Radix Quadratum ) SQRT(4194304)= all size only index the information, as well as below "int flags")

无效* kmalloc (size_t大小,整数标志)

void * kmalloc(size_t size, int flags)

您可能希望使用该功能,以用于不同的KB 2或4.

you might want to you use the function, for use KB diferent 2 or 4.

att

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

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