]> git.karo-electronics.de Git - karo-tx-linux.git/commit
mm: support madvise(MADV_FREE)
authorMinchan Kim <minchan@kernel.org>
Tue, 7 Apr 2015 23:44:41 +0000 (09:44 +1000)
committerStephen Rothwell <sfr@canb.auug.org.au>
Tue, 7 Apr 2015 23:44:41 +0000 (09:44 +1000)
commit8b22e9419a851ac5e811186ea6c2654013e47287
treee51267fc15afae01acb8bc1c03c01b49819fd455
parent2af58c31e289354a588760494f13d480e332c721
mm: support madvise(MADV_FREE)

Linux doesn't have an ability to free pages lazy while other OS already
have been supported that named by madvise(MADV_FREE).

The gain is clear that kernel can discard freed pages rather than swapping
out or OOM if memory pressure happens.

Without memory pressure, freed pages would be reused by userspace without
another additional overhead(ex, page fault + allocation + zeroing).

How to work is following as.

When madvise syscall is called, VM clears dirty bit of ptes of the range.
If memory pressure happens, VM checks dirty bit of page table and if it
found still "clean", it means it's a "lazyfree pages" so VM could discard
the page instead of swapping out.  Once there was store operation for the
page before VM peek a page to reclaim, dirty bit is set so VM can swap out
the page instead of discarding.

Firstly, heavy users would be general allocators(ex, jemalloc, tcmalloc
and hope glibc supports it) and jemalloc/tcmalloc already have supported
the feature for other OS(ex, FreeBSD)

barrios@blaptop:~/benchmark/ebizzy$ lscpu
Architecture:          x86_64
CPU op-mode(s):        32-bit, 64-bit
Byte Order:            Little Endian
CPU(s):                12
On-line CPU(s) list:   0-11
Thread(s) per core:    1
Core(s) per socket:    1
Socket(s):             12
NUMA node(s):          1
Vendor ID:             GenuineIntel
CPU family:            6
Model:                 2
Stepping:              3
CPU MHz:               3200.185
BogoMIPS:              6400.53
Virtualization:        VT-x
Hypervisor vendor:     KVM
Virtualization type:   full
L1d cache:             32K
L1i cache:             32K
L2 cache:              4096K
NUMA node0 CPU(s):     0-11
ebizzy benchmark(./ebizzy -S 10 -n 512)

Higher avg is better.

 vanilla-jemalloc MADV_free-jemalloc

1 thread
records: 10     records: 10
avg: 2961.90     avg:   12069.70
std:   71.96(2.43%)     std:     186.68(1.55%)
max: 3070.00     max:   12385.00
min: 2796.00     min:   11746.00

2 thread
records: 10     records: 10
avg: 5020.00     avg:   17827.00
std:  264.87(5.28%)     std:     358.52(2.01%)
max: 5244.00     max:   18760.00
min: 4251.00     min:   17382.00

4 thread
records: 10     records: 10
avg: 8988.80     avg:   27930.80
std: 1175.33(13.08%)     std:    3317.33(11.88%)
max: 9508.00     max:   30879.00
min: 5477.00     min:   21024.00

8 thread
records: 10     records: 10
avg:   13036.50     avg:   33739.40
std:  170.67(1.31%)     std:    5146.22(15.25%)
max:   13371.00     max:   40572.00
min:   12785.00     min:   24088.00

16 thread
records: 10     records: 10
avg:   11092.40     avg:   31424.20
std:  710.60(6.41%)     std:    3763.89(11.98%)
max:   12446.00     max:   36635.00
min: 9949.00     min:   25669.00

32 thread
records: 10     records: 10
avg:   11067.00     avg:   34495.80
std:  971.06(8.77%)     std:    2721.36(7.89%)
max:   12010.00     max:   38598.00
min: 9002.00     min:   30636.00

In summary, MADV_FREE is about much faster than MADV_DONTNEED.

Signed-off-by: Minchan Kim <minchan@kernel.org>
Reviewed-by: Michal Hocko <mhocko@suse.cz>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
include/linux/rmap.h
include/linux/vm_event_item.h
include/uapi/asm-generic/mman-common.h
mm/madvise.c
mm/rmap.c
mm/vmscan.c
mm/vmstat.c