Skip to content
项目
群组
代码片段
帮助
正在加载...
登录
切换导航
F
freeswitch
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
张华
freeswitch
Commits
e195d5a2
提交
e195d5a2
authored
3月 27, 2017
作者:
Anthony Minessale
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
FS-10167 WIP getting rid of mmap
上级
020f80b8
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
9 行增加
和
46 行删除
+9
-46
ks_types.h
libs/libks/src/include/ks_types.h
+1
-2
ks.c
libs/libks/src/ks.c
+1
-1
ks_pool.c
libs/libks/src/ks_pool.c
+7
-43
没有找到文件。
libs/libks/src/include/ks_types.h
浏览文件 @
e195d5a2
...
...
@@ -99,7 +99,6 @@ KS_BEGIN_EXTERN_C
KS_STATUS_PAGE_SIZE
,
/* could not get system page-size */
KS_STATUS_OPEN_ZERO
,
/* could not open /dev/zero */
KS_STATUS_NO_MEM
,
/* no memory available */
KS_STATUS_MMAP
,
/* problems with mmap */
KS_STATUS_SIZE
,
/* error processing requested size */
KS_STATUS_TOO_BIG
,
/* allocation exceeded max size */
KS_STATUS_MEM
,
/* invalid memory address */
...
...
@@ -125,6 +124,7 @@ KS_BEGIN_EXTERN_C
"GENERR",\
"INACTIVE",\
"TIMEOUT",\
"DUPLICATE_OPERATION",\
"ARG_NULL",\
"ARG_INVALID",\
"PNT",\
...
...
@@ -132,7 +132,6 @@ KS_BEGIN_EXTERN_C
"PAGE_SIZE",\
"OPEN_ZERO",\
"NO_MEM",\
"MMAP",\
"SIZE",\
"TOO_BIG",\
"MEM",\
...
...
libs/libks/src/ks.c
浏览文件 @
e195d5a2
...
...
@@ -186,7 +186,7 @@ KS_DECLARE(int) ks_cpu_count(void)
cpu_count
=
sysinfo
.
dwNumberOfProcessors
;
}
#endif
return
cpu_count
;
}
...
...
libs/libks/src/ks_pool.c
浏览文件 @
e195d5a2
...
...
@@ -26,14 +26,9 @@
* library which was close to what we needed but did not exactly do
* what I wanted.
*
* The following uses mmap from /dev/zero. It allows a number of
* allocations to be made inside of a memory pool then with a clear or
* close the pool can be reset without any memory fragmentation and
* growth problems.
*/
#include "ks.h"
#include <sys/mman.h>
#define KS_POOL_MAGIC 0xABACABA
/* magic for struct */
#define BLOCK_MAGIC 0xB1B1007
/* magic for blocks */
...
...
@@ -113,7 +108,6 @@ struct ks_pool_s {
unsigned
int
mp_page_size
;
/* page-size of our system */
off_t
mp_top
;
/* top of our allocations in fd */
ks_pool_log_func_t
mp_log_func
;
/* log callback function */
void
*
mp_addr
;
/* current address for mmaping */
void
*
mp_min_p
;
/* min address in pool for checks */
void
*
mp_bounds_p
;
/* max address in pool for checks */
struct
ks_pool_block_st
*
mp_first_p
;
/* first memory block we are using */
...
...
@@ -453,7 +447,6 @@ static void *alloc_pages(ks_pool_t *mp_p, const unsigned int page_n, ks_status_t
{
void
*
mem
;
unsigned
long
size
;
int
state
;
/* are we over our max-pages? */
if
(
mp_p
->
mp_max_pages
>
0
&&
mp_p
->
mp_page_c
>=
mp_p
->
mp_max_pages
)
{
...
...
@@ -468,34 +461,10 @@ static void *alloc_pages(ks_pool_t *mp_p, const unsigned int page_n, ks_status_t
#endif
state
=
MAP_PRIVATE
|
MAP_ANON
;
#if defined(MAP_FILE)
state
|=
MAP_FILE
;
#endif
#if defined(MAP_VARIABLE)
state
|=
MAP_VARIABLE
;
#endif
/* mmap from /dev/zero */
mem
=
mmap
(
mp_p
->
mp_addr
,
size
,
PROT_READ
|
PROT_WRITE
,
state
,
-
1
,
mp_p
->
mp_top
);
if
(
mem
==
(
void
*
)
MAP_FAILED
)
{
if
(
errno
==
ENOMEM
)
{
SET_POINTER
(
error_p
,
KS_STATUS_NO_MEM
);
}
else
{
SET_POINTER
(
error_p
,
KS_STATUS_MMAP
);
}
return
NULL
;
}
mem
=
malloc
(
size
);
ks_assert
(
mem
);
mp_p
->
mp_top
+=
size
;
if
(
mp_p
->
mp_addr
!=
NULL
)
{
mp_p
->
mp_addr
=
(
char
*
)
mp_p
->
mp_addr
+
size
;
}
mp_p
->
mp_page_c
+=
page_n
;
SET_POINTER
(
error_p
,
KS_STATUS_SUCCESS
);
...
...
@@ -521,11 +490,10 @@ static void *alloc_pages(ks_pool_t *mp_p, const unsigned int page_n, ks_status_t
*
* size -> Size of the block that we are freeing.
*
* sbrk_b -> Set to one if the pages were allocated with sbrk else mmap.
*/
static
int
free_pages
(
void
*
pages
,
const
unsigned
long
size
)
{
(
void
)
munmap
(
pages
,
size
);
free
(
pages
);
return
KS_STATUS_SUCCESS
;
}
...
...
@@ -1123,7 +1091,6 @@ static ks_pool_t *ks_pool_raw_open(const unsigned int flags, const unsigned int
/* mp.mp_page_size set below */
/* mp.mp_blocks_bit_n set below */
/* mp.mp_top set below */
/* mp.mp_addr set below */
mp
.
mp_log_func
=
NULL
;
mp
.
mp_min_p
=
NULL
;
mp
.
mp_bounds_p
=
NULL
;
...
...
@@ -1146,7 +1113,6 @@ static ks_pool_t *ks_pool_raw_open(const unsigned int flags, const unsigned int
}
}
mp
.
mp_addr
=
start_addr
;
/* we start at the front of the file */
mp
.
mp_top
=
0
;
...
...
@@ -1276,7 +1242,7 @@ static ks_status_t ks_pool_raw_close(ks_pool_t *mp_p)
{
ks_pool_block_t
*
block_p
,
*
next_p
;
void
*
addr
;
unsigned
long
size
;
//
unsigned long size;
int
ret
,
final
=
KS_STATUS_SUCCESS
;
/* special case, just return no-error */
...
...
@@ -1336,9 +1302,10 @@ static ks_status_t ks_pool_raw_close(ks_pool_t *mp_p)
}
else
{
addr
=
mp_p
;
}
size
=
SIZE_OF_PAGES
(
mp_p
,
PAGES_IN_SIZE
(
mp_p
,
sizeof
(
ks_pool_t
)));
//size = SIZE_OF_PAGES(mp_p, PAGES_IN_SIZE(mp_p, sizeof(ks_pool_t)));
(
void
)
munmap
(
addr
,
size
);
free
(
addr
);
ks_mutex_unlock
(
mutex
);
ks_mutex_destroy
(
&
mutex
);
...
...
@@ -2190,9 +2157,6 @@ KS_DECLARE(const char *) ks_pool_strerror(const ks_status_t error)
case
KS_STATUS_NO_MEM
:
return
"no memory available"
;
break
;
case
KS_STATUS_MMAP
:
return
"problems with mmap"
;
break
;
case
KS_STATUS_SIZE
:
return
"error processing requested size"
;
break
;
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论