mirror of
https://github.com/fluencelabs/redis
synced 2025-03-23 19:10:51 +00:00
zmalloc: zmalloc_get_smap_bytes_by_field() modified to work for any PID.
The goal is to get copy-on-write amount of the child from the parent.
This commit is contained in:
parent
b13759e90a
commit
945a2f948e
@ -1328,7 +1328,7 @@ int rewriteAppendOnlyFileBackground(void) {
|
||||
redisSetProcTitle("redis-aof-rewrite");
|
||||
snprintf(tmpfile,256,"temp-rewriteaof-bg-%d.aof", (int) getpid());
|
||||
if (rewriteAppendOnlyFile(tmpfile) == C_OK) {
|
||||
size_t private_dirty = zmalloc_get_private_dirty();
|
||||
size_t private_dirty = zmalloc_get_private_dirty(-1);
|
||||
|
||||
if (private_dirty) {
|
||||
serverLog(LL_NOTICE,
|
||||
|
@ -79,7 +79,7 @@ int THPIsEnabled(void) {
|
||||
* value of the function is non-zero, the process is being targeted by
|
||||
* THP support, and is likely to have memory usage / latency issues. */
|
||||
int THPGetAnonHugePagesSize(void) {
|
||||
return zmalloc_get_smap_bytes_by_field("AnonHugePages:");
|
||||
return zmalloc_get_smap_bytes_by_field("AnonHugePages:",-1);
|
||||
}
|
||||
|
||||
/* ---------------------------- Latency API --------------------------------- */
|
||||
|
@ -1024,7 +1024,7 @@ int rdbSaveBackground(char *filename) {
|
||||
redisSetProcTitle("redis-rdb-bgsave");
|
||||
retval = rdbSave(filename);
|
||||
if (retval == C_OK) {
|
||||
size_t private_dirty = zmalloc_get_private_dirty();
|
||||
size_t private_dirty = zmalloc_get_private_dirty(-1);
|
||||
|
||||
if (private_dirty) {
|
||||
serverLog(LL_NOTICE,
|
||||
@ -1761,7 +1761,7 @@ int rdbSaveToSlavesSockets(void) {
|
||||
retval = C_ERR;
|
||||
|
||||
if (retval == C_OK) {
|
||||
size_t private_dirty = zmalloc_get_private_dirty();
|
||||
size_t private_dirty = zmalloc_get_private_dirty(-1);
|
||||
|
||||
if (private_dirty) {
|
||||
serverLog(LL_NOTICE,
|
||||
|
@ -304,15 +304,26 @@ float zmalloc_get_fragmentation_ratio(size_t rss) {
|
||||
* /proc/self/smaps. The field must be specified with trailing ":" as it
|
||||
* apperas in the smaps output.
|
||||
*
|
||||
* Example: zmalloc_get_smap_bytes_by_field("Rss:");
|
||||
* If a pid is specified, the information is extracted for such a pid,
|
||||
* otherwise if pid is -1 the information is reported is about the
|
||||
* current process.
|
||||
*
|
||||
* Example: zmalloc_get_smap_bytes_by_field("Rss:",-1);
|
||||
*/
|
||||
#if defined(HAVE_PROC_SMAPS)
|
||||
size_t zmalloc_get_smap_bytes_by_field(char *field) {
|
||||
size_t zmalloc_get_smap_bytes_by_field(char *field, long pid) {
|
||||
char line[1024];
|
||||
size_t bytes = 0;
|
||||
FILE *fp = fopen("/proc/self/smaps","r");
|
||||
int flen = strlen(field);
|
||||
|
||||
if (pid == -1) {
|
||||
FILE *fp = fopen("/proc/self/smaps","r");
|
||||
} else {
|
||||
char filename[128];
|
||||
snprintf(filename,sizeof(filename),"/proc/%ld/smaps",pid);
|
||||
FILE *fp = fopen(filename,"r");
|
||||
}
|
||||
|
||||
if (!fp) return 0;
|
||||
while(fgets(line,sizeof(line),fp) != NULL) {
|
||||
if (strncmp(line,field,flen) == 0) {
|
||||
@ -327,14 +338,15 @@ size_t zmalloc_get_smap_bytes_by_field(char *field) {
|
||||
return bytes;
|
||||
}
|
||||
#else
|
||||
size_t zmalloc_get_smap_bytes_by_field(char *field) {
|
||||
size_t zmalloc_get_smap_bytes_by_field(char *field, long pid) {
|
||||
((void) field);
|
||||
((void) pid);
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
size_t zmalloc_get_private_dirty(void) {
|
||||
return zmalloc_get_smap_bytes_by_field("Private_Dirty:");
|
||||
size_t zmalloc_get_private_dirty(long pid) {
|
||||
return zmalloc_get_smap_bytes_by_field("Private_Dirty:",pid);
|
||||
}
|
||||
|
||||
/* Returns the size of physical memory (RAM) in bytes.
|
||||
|
@ -75,8 +75,8 @@ void zmalloc_enable_thread_safeness(void);
|
||||
void zmalloc_set_oom_handler(void (*oom_handler)(size_t));
|
||||
float zmalloc_get_fragmentation_ratio(size_t rss);
|
||||
size_t zmalloc_get_rss(void);
|
||||
size_t zmalloc_get_private_dirty(void);
|
||||
size_t zmalloc_get_smap_bytes_by_field(char *field);
|
||||
size_t zmalloc_get_private_dirty(long pid);
|
||||
size_t zmalloc_get_smap_bytes_by_field(char *field, long pid);
|
||||
size_t zmalloc_get_memory_size(void);
|
||||
void zlibc_free(void *ptr);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user