mirror of
https://github.com/fluencelabs/redis
synced 2025-03-25 20:01:04 +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");
|
redisSetProcTitle("redis-aof-rewrite");
|
||||||
snprintf(tmpfile,256,"temp-rewriteaof-bg-%d.aof", (int) getpid());
|
snprintf(tmpfile,256,"temp-rewriteaof-bg-%d.aof", (int) getpid());
|
||||||
if (rewriteAppendOnlyFile(tmpfile) == C_OK) {
|
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) {
|
if (private_dirty) {
|
||||||
serverLog(LL_NOTICE,
|
serverLog(LL_NOTICE,
|
||||||
|
@ -79,7 +79,7 @@ int THPIsEnabled(void) {
|
|||||||
* value of the function is non-zero, the process is being targeted by
|
* value of the function is non-zero, the process is being targeted by
|
||||||
* THP support, and is likely to have memory usage / latency issues. */
|
* THP support, and is likely to have memory usage / latency issues. */
|
||||||
int THPGetAnonHugePagesSize(void) {
|
int THPGetAnonHugePagesSize(void) {
|
||||||
return zmalloc_get_smap_bytes_by_field("AnonHugePages:");
|
return zmalloc_get_smap_bytes_by_field("AnonHugePages:",-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ---------------------------- Latency API --------------------------------- */
|
/* ---------------------------- Latency API --------------------------------- */
|
||||||
|
@ -1024,7 +1024,7 @@ int rdbSaveBackground(char *filename) {
|
|||||||
redisSetProcTitle("redis-rdb-bgsave");
|
redisSetProcTitle("redis-rdb-bgsave");
|
||||||
retval = rdbSave(filename);
|
retval = rdbSave(filename);
|
||||||
if (retval == C_OK) {
|
if (retval == C_OK) {
|
||||||
size_t private_dirty = zmalloc_get_private_dirty();
|
size_t private_dirty = zmalloc_get_private_dirty(-1);
|
||||||
|
|
||||||
if (private_dirty) {
|
if (private_dirty) {
|
||||||
serverLog(LL_NOTICE,
|
serverLog(LL_NOTICE,
|
||||||
@ -1761,7 +1761,7 @@ int rdbSaveToSlavesSockets(void) {
|
|||||||
retval = C_ERR;
|
retval = C_ERR;
|
||||||
|
|
||||||
if (retval == C_OK) {
|
if (retval == C_OK) {
|
||||||
size_t private_dirty = zmalloc_get_private_dirty();
|
size_t private_dirty = zmalloc_get_private_dirty(-1);
|
||||||
|
|
||||||
if (private_dirty) {
|
if (private_dirty) {
|
||||||
serverLog(LL_NOTICE,
|
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
|
* /proc/self/smaps. The field must be specified with trailing ":" as it
|
||||||
* apperas in the smaps output.
|
* 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)
|
#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];
|
char line[1024];
|
||||||
size_t bytes = 0;
|
size_t bytes = 0;
|
||||||
FILE *fp = fopen("/proc/self/smaps","r");
|
|
||||||
int flen = strlen(field);
|
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;
|
if (!fp) return 0;
|
||||||
while(fgets(line,sizeof(line),fp) != NULL) {
|
while(fgets(line,sizeof(line),fp) != NULL) {
|
||||||
if (strncmp(line,field,flen) == 0) {
|
if (strncmp(line,field,flen) == 0) {
|
||||||
@ -327,14 +338,15 @@ size_t zmalloc_get_smap_bytes_by_field(char *field) {
|
|||||||
return bytes;
|
return bytes;
|
||||||
}
|
}
|
||||||
#else
|
#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) field);
|
||||||
|
((void) pid);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
size_t zmalloc_get_private_dirty(void) {
|
size_t zmalloc_get_private_dirty(long pid) {
|
||||||
return zmalloc_get_smap_bytes_by_field("Private_Dirty:");
|
return zmalloc_get_smap_bytes_by_field("Private_Dirty:",pid);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Returns the size of physical memory (RAM) in bytes.
|
/* 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));
|
void zmalloc_set_oom_handler(void (*oom_handler)(size_t));
|
||||||
float zmalloc_get_fragmentation_ratio(size_t rss);
|
float zmalloc_get_fragmentation_ratio(size_t rss);
|
||||||
size_t zmalloc_get_rss(void);
|
size_t zmalloc_get_rss(void);
|
||||||
size_t zmalloc_get_private_dirty(void);
|
size_t zmalloc_get_private_dirty(long pid);
|
||||||
size_t zmalloc_get_smap_bytes_by_field(char *field);
|
size_t zmalloc_get_smap_bytes_by_field(char *field, long pid);
|
||||||
size_t zmalloc_get_memory_size(void);
|
size_t zmalloc_get_memory_size(void);
|
||||||
void zlibc_free(void *ptr);
|
void zlibc_free(void *ptr);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user