Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
B
brpc
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
brpc
Commits
c40418cb
Commit
c40418cb
authored
Oct 13, 2017
by
gejun
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
r35379: Add -free_memory_to_system_interval
parent
4e992920
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
30 additions
and
7 deletions
+30
-7
global.cpp
src/brpc/global.cpp
+30
-7
No files found.
src/brpc/global.cpp
View file @
c40418cb
...
...
@@ -62,15 +62,25 @@
#include "brpc/socket_map.h" // SocketMapList
#include "brpc/server.h"
#include "brpc/trackme.h" // TrackMe
#include <malloc.h> // malloc_trim
#include "brpc/details/usercode_backup_pool.h"
#include <malloc.h> // malloc_trim
#include "butil/fd_guard.h"
#include "butil/files/file_watcher.h"
extern
"C"
{
// defined in gperftools/malloc_extension_c.h
void
BAIDU_WEAK
MallocExtension_ReleaseFreeMemory
(
void
);
}
namespace
brpc
{
DECLARE_bool
(
usercode_in_pthread
);
DEFINE_int32
(
free_memory_to_system_interval
,
0
,
"Try to return free memory to system every so many seconds, "
"values <= 0 disables this feature"
);
BRPC_VALIDATE_GFLAG
(
free_memory_to_system_interval
,
PassValidate
);
namespace
policy
{
// Defined in http_rpc_protocol.cpp
void
InitCommonStrings
();
...
...
@@ -177,7 +187,7 @@ static void* GlobalUpdate(void*) {
const
int
WARN_NOSLEEP_THRESHOLD
=
2
;
int64_t
last_time_us
=
start_time_us
;
int
consecutive_nosleep
=
0
;
//int64_t last_malloc_trim
_time = start_time_us;
int64_t
last_return_free_memory
_time
=
start_time_us
;
while
(
1
)
{
const
int64_t
sleep_us
=
1000000L
+
last_time_us
-
butil
::
gettimeofday_us
();
if
(
sleep_us
>
0
)
{
...
...
@@ -214,11 +224,24 @@ static void* GlobalUpdate(void*) {
}
}
// TODO: Add branch for tcmalloc.
// if (last_time_us > last_malloc_trim_time + 10*1000000L) {
// last_malloc_trim_time = last_time_us;
// malloc_trim(10*1024*1024/*leave 10M pad*/);
// }
const
int
return_mem_interval
=
FLAGS_free_memory_to_system_interval
/*reloadable*/
;
if
(
return_mem_interval
>
0
&&
last_time_us
>=
last_return_free_memory_time
+
return_mem_interval
*
1000000L
)
{
last_return_free_memory_time
=
last_time_us
;
// TODO: Calling MallocExtension::instance()->ReleaseFreeMemory may
// crash the program in later calls to malloc, verified on tcmalloc
// 1.7 and 2.5, which means making the static member function weak
// in details/tcmalloc_extension.cpp is probably not correct, however
// it does work for heap profilers.
if
(
MallocExtension_ReleaseFreeMemory
!=
NULL
)
{
MallocExtension_ReleaseFreeMemory
();
}
else
{
// GNU specific.
malloc_trim
(
10
*
1024
*
1024
/*leave 10M pad*/
);
}
}
}
return
NULL
;
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment