-
Notifications
You must be signed in to change notification settings - Fork 5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
分离内存分配接口与内存分配算法 #5175
分离内存分配接口与内存分配算法 #5175
Conversation
@BernardXiong 在 |
@Guozhanxin 这个方案能合入不?改动比较大,兼容性上估计没啥问题。 |
c1db306
to
6f09461
Compare
begin = (rt_uint8_t *)&heap[1]; | ||
buf_size = buf + TEST_MEM_SIZE - begin; | ||
rt_memset(buf, 0xAA, TEST_MEM_SIZE); | ||
// small heap init |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
注释不太规范,/* */
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
好的,注释我修改下
最好是先评估下这个方案能不能合并,免得白费功夫....
include/rtdef.h
Outdated
@@ -431,7 +431,9 @@ enum rt_object_class_type | |||
RT_Object_Class_Device = 0x09, /**< The object is a device. */ | |||
RT_Object_Class_Timer = 0x0a, /**< The object is a timer. */ | |||
RT_Object_Class_Module = 0x0b, /**< The object is a module. */ | |||
RT_Object_Class_Unknown = 0x0c, /**< The object is unknown. */ | |||
RT_Object_Class_Mem = 0x0c, /**< The object is a small memory. */ | |||
RT_Object_Class_Slab = 0x0d, /**< The object is a slab memory. */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这样搞的话,是不是每加一个内存算法都要加一个类型?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
是的,类型该加的加嘛,我觉得这个没啥影响吧。
还是说搞一个类型?在通过某种方式区分子类型?
* | ||
* @param end_addr the end address of system page. | ||
*/ | ||
RT_WEAK void rt_system_heap_init(void *begin_addr, void *end_addr) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
看起来这么改,对用户自己实现的内存算法影响不大。可以开下这个软件包试试。http://packages.rt-thread.org/detail.html?package=tlsf
src/kservice.c
Outdated
/* Enter critical zone */ | ||
level = _heap_lock(); | ||
/* Change the size of previously allocated memory block */ | ||
nptr = _MEM_REALLOC(&system_heap, rmem, newsize); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
realloc 没有hook吗
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
realloc 原本也没有 hook
include/rtthread.h
Outdated
const char *name, | ||
void *begin_addr, | ||
rt_size_t size); | ||
rt_err_t rt_mem_detach(struct rt_mem *m); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这些api和结构体定义,一定要加到 rt-thread 头文件里面吗?这群其实用户都用不到的。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
修改成多实例,就需要用到了
修改成多实例的原因:一个项目中,内存会被化成多个块供不同的组件使用,不同的内存块使用不同的管理算法。当前 rtt 不支持一个系统中使用多种内存管理算法,就只能魔改
所以就把内存管理算法做成多实例了
src/kservice.c
Outdated
level = _heap_lock(); | ||
/* allocate memory block from system heap */ | ||
ptr = _MEM_MALLOC(&system_heap, size); | ||
#if defined(RT_USING_MEMHEAP_AS_HEAP) && defined(RT_USING_MEMHEAP_AUTO_BINDING) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这部分的逻辑,应该是某一个具体的内存算法的功能,应该放到具体的内存算法内部吧?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这部分逻辑就很尴尬,在现有的 memheap 中,rt_malloc 是在内部实现的。现在把 rt_malloc 拿出来了。这部分代码就得跟着拿出来。
如沟通,调整方式如下:
|
8edcc80
to
0095153
Compare
…ed memory interfaces
…ion and interface
@Guozhanxin 郭老师看一下吧,合并的时候选择squash一下,commits数量太多了 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
请问一下给rt_memheap添加locked这个flag,这个修改作者是遇到什么问题从而进行的修复吗?我这边遇到了踩内存问题,发现厂商给我的代码和仓库缺少这个补丁 @enkiller
与这个修改没关系 |
拉取/合并请求描述:(PR description)
[
改动的原因
核心改动
影响
测试用例
编写中...
]
以下的内容不应该在提交PR时的message修改,修改下述message,PR会被直接关闭。请在提交PR后,浏览器查看PR并对以下检查项逐项check,没问题后逐条在页面上打钩。
The following content must not be changed in the submitted PR message. Otherwise, the PR will be closed immediately. After submitted PR, please use a web browser to visit PR, and check items one by one, and ticked them if no problem.
当前拉取/合并请求的状态 Intent for your PR
必须选择一项 Choose one (Mandatory):
代码质量 Code Quality:
我在这个拉取/合并请求中已经考虑了 As part of this pull request, I've considered the following:
#if 0
代码,不包含已经被注释了的代码 All redundant code is removed and cleaned up