提交 28f1d924 编写于 作者: 鸿蒙内核源码分析's avatar 鸿蒙内核源码分析

完善虚拟内存模块注解

搜索 @note_pic 可以查看全部字符图
搜索 @note_why 是注者尚未看明白的地方,如果您看明白了,请告诉注者完善
搜索 @note_thinking 是注者的思考和吐槽的地方
上级 8c1e006c
此差异已折叠。
......@@ -78,7 +78,7 @@ struct page_mapping {
typedef struct VmMapRange {
VADDR_T base; /**< vm region base addr */ //线性区基地址
UINT32 size; /**< vm region size */ //线性区大小
UINT32 size; /**< vm region size */ //线性区大小
} LosVmMapRange;
struct VmMapRegion;
......@@ -104,25 +104,25 @@ struct VmFileOps {// 文件操作
void (*remove)(struct VmMapRegion *region, LosArchMmu *archMmu, VM_OFFSET_T offset);//删除
};
struct VmMapRegion {
LosRbNode rbNode; /**< region red-black tree node */ //红黑树节点,主要是挂在VmSpace.regionRbTree
LosVmSpace *space; //所属虚拟空间
LOS_DL_LIST node; /**< region dl list */ //链表节点,主要是挂在VmSpace.regions上
struct VmMapRegion {//线性区描述符,内核通过线性区管理虚拟地址,而线性地址就是虚拟地址
LosRbNode rbNode; /**< region red-black tree node */ //红黑树节点,通过它将本线性区挂在VmSpace.regionRbTree
LosVmSpace *space; //所属虚拟空间,虚拟空间由多个线性区组成
LOS_DL_LIST node; /**< region dl list */ //链表节点,通过它将本线性区挂在VmSpace.regions上
LosVmMapRange range; /**< region address range */ //记录线性区的范围
VM_OFFSET_T pgOff; /**< region page offset to file */ //区域页面到文件的偏移量
UINT32 regionFlags; /**< region flags: cow, user_wired */
UINT32 regionFlags; /**< region flags: cow, user_wired *///线性区标签
UINT32 shmid; /**< shmid about shared region */ //shmid为共享线性区id
UINT8 protectFlags; /**< vm region protect flags: PROT_READ, PROT_WRITE, *///线性区中页框的访问许可权
UINT8 forkFlags; /**< vm space fork flags: COPY, ZERO, */ //fork的方式
UINT8 regionType; /**< vm region type: ANON, FILE, DEV */ //映射类型是匿名,文件,还是设备,所谓匿名可理解为内存映射
union {
struct VmRegionFile {
struct VmRegionFile {//
unsigned int fileMagic;//具有特殊文件格式的文件,魔法数字.例如 stack top 的魔法数字为 0xCCCCCCCC
struct file *file; //文件指针
const LosVmFileOps *vmFOps;//文件处理各操作接口
} rf;
struct VmRegionAnon {
LOS_DL_LIST node; /**< region LosVmPage list */ //线性区虚拟页链表
struct VmRegionAnon {//匿名映射可理解为就是物理内存
LOS_DL_LIST node; /**< region LosVmPage list */ //线性区虚拟页链表
} ra;
struct VmRegionDev {
LOS_DL_LIST node; /**< region LosVmPage list */ //线性区虚拟页链表
......@@ -132,15 +132,15 @@ struct VmMapRegion {
};
typedef struct VmSpace {
LOS_DL_LIST node; /**< vm space dl list */ //节点,主要用于通过它挂到全局虚拟空间链表上
LOS_DL_LIST regions; /**< region dl list */ //双循环链表方式管理虚拟空间的各个线性区
LosRbTree regionRbTree; /**< region red-black tree root */ //采用红黑树方式管理虚拟空间的各个线性区
LOS_DL_LIST node; /**< vm space dl list */ //节点,通过它挂到全局虚拟空间链表上
LOS_DL_LIST regions; /**< region dl list */ //双循环链表方式管理本空间各个线性区
LosRbTree regionRbTree; /**< region red-black tree root */ //采用红黑树方式管理本空间各个线性区
LosMux regionMux; /**< region list mutex lock */ //虚拟空间的互斥锁
VADDR_T base; /**< vm space base addr */ //虚拟空间的基地址
UINT32 size; /**< vm space size */ //虚拟空间大小
VADDR_T base; /**< vm space base addr */ //虚拟空间的基地址
UINT32 size; /**< vm space size */ //虚拟空间大小
VADDR_T heapBase; /**< vm space heap base address */ //虚拟空间堆区基地址
VADDR_T heapNow; /**< vm space heap base now */ //记录虚拟空间分配到哪了
LosVmMapRegion *heap; /**< heap region */ //堆区
VADDR_T heapNow; /**< vm space heap base now */ //虚拟空间堆区分配到哪了
LosVmMapRegion *heap; /**< heap region */ //堆区
VADDR_T mapBase; /**< vm space mapping area base */ //虚拟空间映射区基地址
UINT32 mapSize; /**< vm space mapping area size */ //虚拟空间映射区大小
LosArchMmu archMmu; /**< vm mapping physical memory */ //MMU记录和物理地址的映射情况
......@@ -177,7 +177,7 @@ typedef struct VmSpace {
#define VM_MAP_REGION_FLAG_TEXT (1<<12) //代码区
#define VM_MAP_REGION_FLAG_BSS (1<<13) //bbs数据区 由运行时动态分配
#define VM_MAP_REGION_FLAG_VDSO (1<<14) //VDSO(Virtual Dynamically-lined Shared Object)由内核提供的虚拟.so文件,它不在磁盘上,而在内核里,内核将其映射到一个地址空间中,被所有程序共享,正文段大小为一个页面。
#define VM_MAP_REGION_FLAG_MMAP (1<<15) //映射区
#define VM_MAP_REGION_FLAG_MMAP (1<<15) //映射区,虚拟空间内有专门用来存储<虚拟地址-物理地址>映射的区域
#define VM_MAP_REGION_FLAG_SHM (1<<16) //共享内存区,和代码区同级概念,意思是整个线性区被贴上共享标签
#define VM_MAP_REGION_FLAG_INVALID (1<<17) /* indicates that flags are not specified */
......
/*
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef __LOS_VM_PAGE_H__
#define __LOS_VM_PAGE_H__
#include "los_typedef.h"
#include "los_bitmap.h"
#include "los_list.h"
#include "los_atomic.h"
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */
//注意: vmPage 中并没有虚拟地址,只有物理地址
typedef struct VmPage {
LOS_DL_LIST node; /**< vm object dl list */
UINT32 index; /**< vm page index to vm object */
PADDR_T physAddr; /**< vm page physical addr */
Atomic refCounts; /**< vm page ref count */
UINT32 flags; /**< vm page flags */
UINT8 order; /**< vm page in which order list */
UINT8 segID; /**< the segment id of vm page */
UINT16 nPages; /**< the vm page is used for kernel heap */
} LosVmPage;
extern LosVmPage *g_vmPageArray;//物理内存所有页框(page frame)记录数组
extern size_t g_vmPageArraySize;//物理内存总页框(page frame)数
LosVmPage *LOS_VmPageGet(PADDR_T paddr);
VOID OsVmPageStartup(VOID);
#ifdef __cplusplus
#if __cplusplus
}
#endif /* __cplusplus */
#endif /* __cplusplus */
#endif /* __LOS_VM_PAGE_H__ */
/*
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef __LOS_VM_PAGE_H__
#define __LOS_VM_PAGE_H__
#include "los_typedef.h"
#include "los_bitmap.h"
#include "los_list.h"
#include "los_atomic.h"
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */
//注意: vmPage 中并没有虚拟地址,只有物理地址
typedef struct VmPage { //虚拟内存描述符
LOS_DL_LIST node; /**< vm object dl list */ //虚拟内存节点,通过它挂到全局虚拟页上
UINT32 index; /**< vm page index to vm object */ //索引位置
PADDR_T physAddr; /**< vm page physical addr */ //物理地址
Atomic refCounts; /**< vm page ref count */ //被引用次数,共享内存会被多次引用
UINT32 flags; /**< vm page flags */ //页标签
UINT8 order; /**< vm page in which order list */ //被安置在伙伴算法的几号序列( 2^0,2^1,2^2,...,2^order)
UINT8 segID; /**< the segment id of vm page */ //所在段ID
UINT16 nPages; /**< the vm page is used for kernel heap */ //vm页面用于内核堆
} LosVmPage;
extern LosVmPage *g_vmPageArray;//物理内存所有页框(page frame)记录数组
extern size_t g_vmPageArraySize;//物理内存总页框(page frame)数
LosVmPage *LOS_VmPageGet(PADDR_T paddr);
VOID OsVmPageStartup(VOID);
#ifdef __cplusplus
#if __cplusplus
}
#endif /* __cplusplus */
#endif /* __cplusplus */
#endif /* __LOS_VM_PAGE_H__ */
此差异已折叠。
此差异已折叠。
此差异已折叠。
git add -A
git commit -m '1.CPU切换任务汇编注解 2.对内存的部分系统调用接口注解
git commit -m '完善虚拟内存模块注解
搜索 @note_pic 可以查看全部字符图
搜索 @note_why 是注者尚未看明白的地方,如果您看明白了,请告诉注者完善
搜索 @note_thinking 是注者的思考和吐槽的地方
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册