Commit Graph

98 Commits

Author SHA1 Message Date
Jack Drogon 93238575f7 Fix typo 2018-07-03 18:19:46 +02:00
Fuxin Hao a4f658b2b5 Fix update_zmalloc_stat_alloc in zrealloc 2018-06-14 16:44:19 +08:00
Salvatore Sanfilippo e2a9ea0405
Merge pull request #4901 from KFilipek/zmalloc_typo_fix
HW_PHYSMEM typo in preprocessor condition
2018-06-11 16:32:40 +02:00
Remi Collet 9561fec496 include stdint.h for unit64_t definition 2018-05-30 15:33:06 +02:00
Oran Agra ad133e1023 Active defrag fixes for 32bit builds
problems fixed:
* failing to read fragmentation information from jemalloc
* overflow in jemalloc fragmentation hint to the defragger
* test suite not triggering eviction after population
2018-05-17 09:52:00 +03:00
Krzysztof Filipek fd9177dd33 Typo in preprocessor condition 2018-05-06 20:18:48 +02:00
Oran Agra 806736cdf9 Adding real allocator fragmentation to INFO and MEMORY command + active defrag test
other fixes / improvements:
- LUA script memory isn't taken from zmalloc (taken from libc malloc)
  so it can cause high fragmentation ratio to be displayed (which is false)
- there was a problem with "fragmentation" info being calculated from
  RSS and used_memory sampled at different times (now sampling them together)

other details:
- adding a few more allocator info fields to INFO and MEMORY commands
- improve defrag test to measure defrag latency of big keys
- increasing the accuracy of the defrag test (by looking at real grag info)
  this way we can use an even lower threshold and still avoid false positives
- keep the old (total) "fragmentation" field unchanged, but add new ones for spcific things
- add these the MEMORY DOCTOR command
- deduct LUA memory from the rss in case of non jemalloc allocator (one for which we don't "allocator active/used")
- reduce sampling rate of the rss and allocator info
2018-03-12 15:08:52 +02:00
Oran Agra 5def65008f Fix zrealloc to behave similarly to je_realloc when size is 0
According to C11, the behavior of realloc with size 0 is now deprecated.
it can either behave as free(ptr) and return NULL, or return a valid pointer.
but in zmalloc it can lead to zmalloc_oom_handler and panic.
and that can affect modules that use it.

It looks like both glibc allocator and jemalloc behave like so:
  realloc(malloc(32),0) returns NULL
  realloc(NULL,0) returns a valid pointer

This commit changes zmalloc to behave the same
2018-02-21 11:04:13 +02:00
antirez 6eb51bf1ec zmalloc.c: remove thread safe mode, it's the default way. 2017-05-09 16:59:51 +02:00
antirez 2a51bac44e Simplify atomicvar.h usage by having the mutex name implicit. 2017-05-04 17:01:00 +02:00
antirez f47607af02 Fix preprocessor if/else chain broken in order to fix #3927. 2017-04-11 16:54:27 +02:00
antirez aa5b4be02e Fix zmalloc_get_memory_size() ifdefs to actually use the else branch.
Close #3927.
2017-04-11 16:45:11 +02:00
antirez 173d692bc2 Defrag: activate it only if running modified version of Jemalloc.
This commit also includes minor aesthetic changes like removal of
trailing spaces.
2017-01-10 11:25:39 +01:00
oranagra 7aa9e6d2ae active memory defragmentation 2016-12-30 03:37:52 +02:00
antirez e1eccf9a6b zmalloc: Make fp var non local to fix build. 2016-09-19 10:34:39 +02:00
antirez 945a2f948e 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.
2016-09-19 10:28:42 +02:00
root 28e80bf96d fix linux compile bug 2016-01-13 00:49:28 -08:00
antirez c7b46a4719 zmalloc.c converted to use atomicvar.h. 2015-10-01 13:02:25 +02:00
antirez 9a6354316b Add info as requested by the original getMemorySize() license. 2014-12-17 17:15:39 +01:00
antirez 615f6923d5 getMemorySize() moved into zmalloc.c with other low level mem utils.
See issue #2218.
2014-12-17 17:11:20 +01:00
antirez 620906693e Fix non-linux builds error introduced with THP checks. 2014-11-14 17:13:35 +01:00
antirez 3ef0876b95 THP detection / reporting functions added. 2014-11-12 10:43:32 +01:00
Matt Stancliff a953c88381 Allow atomic memory count update with C11 builtins
From mailing list post https://groups.google.com/forum/#!topic/redis-db/QLjiQe4D7LA

In zmalloc.c the following primitives are currently used
to synchronize access to single global variable:
__sync_add_and_fetch
__sync_sub_and_fetch

In some architectures such as powerpc these primitives are overhead
intensive. More efficient C11 __atomic builtins are available with
newer GCC versions, see
http://gcc.gnu.org/onlinedocs/gcc-4.8.2/gcc/_005f_005fatomic-Builtins.html#_005f_005fatomic-Builtins

By substituting the following  __atomic… builtins:
__atomic_add_fetch
__atomic_sub_fetch

the performance improvement on certain architectures such as powerpc can be significant,
around 10% to 15%, over the implementation using __sync builtins while there is only slight uptick on
Intel architectures because it was already enforcing Intel Strongly ordered memory semantics.

The selection of __atomic built-ins can be predicated on the definition of ATOMIC_RELAXED
which Is available on in gcc 4.8.2 and later versions.
2014-06-26 08:52:53 -04:00
Matt Stancliff f9bca13a1a Use predefined macro for used_memory() update 2014-06-26 08:51:13 -04:00
antirez 93253c2762 Sample and cache RSS in serverCron().
Obtaining the RSS (Resident Set Size) info is slow in Linux and OSX.
This slowed down the generation of the INFO 'memory' section.

Since the RSS does not require to be a real-time measurement, we
now sample it with server.hz frequency (10 times per second by default)
and use this value both to show the INFO rss field and to compute the
fragmentation ratio.

Practically this does not make any difference for memory profiling of
Redis but speeds up the INFO call significantly.
2014-03-24 12:00:20 +01:00
antirez 11e81a1e9a Fixed grammar: before H the article is a, not an. 2013-12-05 16:35:32 +01:00
guiquanz 9d09ce3981 Fixed many typos. 2013-01-19 10:59:44 +01:00
antirez 3cb432837c Use more fine grained HAVE macros instead of HAVE_PROCFS. 2012-11-21 13:17:38 +01:00
antirez 3bfeb9c1a7 zmalloc_get_private_dirty() function added (Linux only).
For non Linux systmes it just returns 0.

This function is useful to estimate copy-on-write because of childs
saving stuff on disk.
2012-11-19 11:47:35 +01:00
antirez af0b220756 zmalloc: kill unused __size parameter in update_zmalloc_stat_alloc() macro. 2012-11-14 12:52:38 +01:00
antirez 1caa627e4e Fix a forget zmalloc_oom() -> zmalloc_oom_handler() replacement. 2012-08-24 15:40:22 +02:00
antirez 6fdc635447 Better Out of Memory handling.
The previous implementation of zmalloc.c was not able to handle out of
memory in an application-specific way. It just logged an error on
standard error, and aborted.

The result was that in the case of an actual out of memory in Redis
where malloc returned NULL (In Linux this actually happens under
specific overcommit policy settings and/or with no or little swap
configured) the error was not properly logged in the Redis log.

This commit fixes this problem, fixing issue #509.
Now the out of memory is properly reported in the Redis log and a stack
trace is generated.

The approach used is to provide a configurable out of memory handler
to zmalloc (otherwise the default one logging the event on the
standard output is used).
2012-08-24 12:55:37 +02:00
antirez d174eed5d7 define zlibc_free() in a way that is not shadowed by jemalloc. 2012-03-27 16:54:53 +02:00
antirez 23c0cdd2ad Produce the watchlog warning log in a way that is safer from a signal handler. Fix a memory leak in the backtrace generation function. 2012-03-27 15:24:33 +02:00
Premysl Hruby 80ff1fc6d0 use gcc sync builtins for memory counter when possible 2012-02-26 11:45:52 +01:00
antirez 442246dde2 Precision of getClientOutputBufferMemoryUsage() greatily improved, see issue #327 for more information. 2012-02-07 13:05:36 +01:00
Chris Lamb 5ae979bf57 Fix crash on SPARC due to improper alignment of allocated memory
I believe that you should be able to drop 'defined(__sun)' completely
from this clause, as Solaris on x86 hardware probably does not have
strict alignment requirements, but I don't have a way to test that.

Thanks to Jurij Smakov <jurij@wooyd.org>.

Signed-off-by: Chris Lamb <lamby@debian.org>
2011-11-16 17:21:16 +00:00
antirez 6504634019 no more allocation stats info in INFO, useless now that we have jemalloc. 2011-07-02 10:31:16 +02:00
antirez 29d04257b0 forward-ported changes in zmalloc.c/h to support jemalloc build 2011-06-20 11:34:04 +02:00
antirez c4df22afb6 Fixed compilation on FreeBSD 2011-01-20 10:59:49 +01:00
antirez 5e1d2d30f7 initial fix of the test suite to run both in in-memory and diskstore mode 2011-01-09 16:49:52 +01:00
antirez 67a1810b32 allocation stats in INFO 2011-01-09 15:56:50 +01:00
antirez 92e282288f zmalloc functions to get RSS and fragmentation refactored into two separated functions 2010-11-02 10:51:09 +01:00
Pieter Noordhuis 7cdc98b630 Don't use prefix when malloc_size() can be called
Also, use tcmalloc functions explicitly via macros to prevent symbol
lookups to resolve to native malloc/free on OSX.
2010-10-23 09:59:28 +02:00
antirez 73db2acc37 memory fragmentation reporting in INFO also added for Mac OS X 2010-09-02 10:57:58 +02:00
antirez eddb388ef9 memory fragmentation ratio in INFO output 2010-09-02 10:34:39 +02:00
Benjamin Kramer 399f2f401c Add zcalloc and use it where appropriate
calloc is more effecient than malloc+memset when the system uses mmap to
allocate memory. mmap always returns zeroed memory so the memset can be
avoided.  The threshold to use mmap is 16k in osx libc and 128k in bsd
libc and glibc. The kernel can lazily allocate the pages, this reduces
memory usage when we have a page table or hash table that is mostly
empty.

This change is most visible when you start a new redis instance with vm
enabled.  You'll see no increased memory usage no matter how big your
page table is.
2010-07-25 00:11:20 +02:00
antirez e2641e09cc redis.c split into many different C files.
networking related stuff moved into networking.c

moved more code

more work on layout of source code

SDS instantaneuos memory saving. By Pieter and Salvatore at VMware ;)

cleanly compiling again after the first split, now splitting it in more C files

moving more things around... work in progress

split replication code

splitting more

Sets split

Hash split

replication split

even more splitting

more splitting

minor change
2010-07-01 14:38:51 +02:00