简体   繁体   English

在Linux内核中修改Sysfs的/ sys / devices / system / memory /目录

[英]Modifying the /sys/devices/system/memory/ directory of Sysfs in Linux Kernel

I am working on my course homework for modifying the memory directory of Sysfs in Linux Kernel. 我正在完成我的课程作业,以修改Linux内核中Sysfs的内存目录。 I am seeking help from people here after taking permission from my prof. 在获得我教授的许可后,我正在这里寻求人们的帮助。 Here's what I exactly want to do. 这正是我真正想做的。

Background: If I have a 4 GB RAM I can have 4 X 1 GB DIMMS or 2X 2GB DIMMS on my motherboard. 背景:如果我有4 GB的RAM,则我的主板上可以有4 X 1 GB的DIMM或2X 2GB的DIMM。 NUMA is supported in Linux by dividing this 4GB physical memory into many chunks with specific starting and ending physical address for each chunk. 通过将4GB的物理内存划分为许多块,每个块具有特定的开始和结束物理地址,在Linux中支持NUMA。 The 'devices' directory in Sysfs contains the global device hierarchy. Sysfs中的“设备”目录包含全局设备层次结构。 This contains every physical device that has been discovered by the bus types registered with the kernel. 它包含已通过内核注册的总线类型发现的每个物理设备。 Hence the details regarding the memory chunks are stored in the path '/sys/devices/system/memory/' of Linux Kernel. 因此,有关内存块的详细信息存储在Linux内核的路径“ / sys / devices / system / memory /”中。 In this directory, we have a file called 'block_size_bytes' which decides how many parts my RAM can be split into. 在此目录中,我们有一个名为“ block_size_bytes”的文件,该文件决定了我的RAM可以分成多少部分。 For example in my system it is 8000000 and hence the RAM is split into 32 memory folders from memory0 to memory43. 例如,在我的系统中它是8000000,因此RAM从memory0到memory43分为32个内存文件夹。 Every 'memoryX' directory will have a file called 'state' which represents the online/offline state of the memory chunk. 每个“ memoryX”目录将有一个名为“ state”的文件,该文件代表内存块的在线/离线状态。 I can toggle between online/offline if I want to 'switch off' that particular chunk off memory. 如果要“关闭”特定的内存块,可以在在线/离线之间切换。

So here's what I exactly want to do: 所以这就是我要做的事情:

I want to modify this whole directory structure into 4 directories. 我想将整个目录结构修改为4个目录。 Why 4? 为什么是4? Because, I have 4 X 1GB DIMMS on my motherboard, so I want reduce these 32 memory chunks in to to 4 big chunks so that I can control whichever DIMM I want by toggling it's 'state' online/offline. 因为,我的主板上有4个1GB DIMM,所以我希望将这32个内存块减少到4个大块,这样我就可以通过切换在线/离线状态来控制我想要的任何DIMM。 So Basically I want to change the state of the memory on DIMM level. 因此,基本上我想在DIMM级别上更改内存的状态。

That's pretty much my problem description. 那几乎是我的问题描述。

My approach: I have read through the sysfs file system and tried to look up the kernel modules which are responsible for organizing the 'memory' directory of sysfs. 我的方法:我通读了sysfs文件系统,并试图查找负责组织sysfs的“内存”目录的内核模块。 I want to find the module and edit it as per my requirement and compile that module. 我想根据我的要求查找模块并对其进行编辑,然后编译该模块。 It got increasingly difficult to find the specific documentation regarding this topic which lead me to ask this question. 越来越难以找到有关该主题的特定文档,这使我提出了这个问题。 All I could find was that there this C programming file '/lib/modules/3.8.0-19-generic/source/drivers/base/memory.c' which has methods for setting the 'state' of the memory chunks, showing the starting and ending physical address of each memory section and many other methods. 我所能找到的就是这个C编程文件'/lib/modules/3.8.0-19-generic/source/drivers/base/memory.c',其中包含用于设置内存块“状态”的方法,显示每个内存部分的开始和结束物理地址以及许多其他方法。 But I am not able to figure out where exactly these methods are being called or which module is utilizing this C file to set all the attributes. 但是我无法弄清楚到底在哪里调用这些方法,或者哪个模块正在使用此C文件设置所有属性。

Could you please let me know which exact module I need to look for? 您能否让我知道我需要寻找哪个确切的模块? If you find my approach wrong, could you please point me in the right direction? 如果您发现我的方法有误,请您指出正确的方向吗?

Thanks in advance :) 提前致谢 :)

I just answer to this part of the question : 我只是回答问题的这一部分:

But I am not able to figure out where exactly these methods are being called or which module is utilizing this C file to set all the attributes. 但是我无法弄清楚到底在哪里调用这些方法,或者哪个模块正在使用此C文件设置所有属性。

You can use lxr to search in the kernel tree. 您可以使用lxr在内核树中搜索。 Here an exemple with show_mem_state function. 这里是带有show_mem_state函数的示例

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM