diff mbox series

[2/2,-mm] mm: account lazy free pages into available memory

Message ID 1561655524-89276-2-git-send-email-yang.shi@linux.alibaba.com (mailing list archive)
State New, archived
Headers show
Series [1/2,-mm] mm: account lazy free pages separately | expand

Commit Message

Yang Shi June 27, 2019, 5:12 p.m. UTC
Available memory is one of the most important metrics for memory
pressure.  Currently, lazy free pages are not accounted into available
memory, but they are reclaimable actually, like reclaimable slabs.

Accounting lazy free pages into available memory should reflect the real
memory pressure status, and also would help administrators and/or other
high level scheduling tools make better decision.

The /proc/meminfo would show more available memory with test which
creates ~1GB deferred split THP.

Before:
MemAvailable:   43544272 kB
...
AnonHugePages:     10240 kB
ShmemHugePages:        0 kB
ShmemPmdMapped:        0 kB
LazyFreePages:   1046528 kB

After:
MemAvailable:   44415124 kB
...
AnonHugePages:      6144 kB
ShmemHugePages:        0 kB
ShmemPmdMapped:        0 kB
LazyFreePages:   1046528 kB

MADV_FREE pages are not accounted for NR_LAZYFREE since they have been
put on inactive file LRU and accounted into available memory.
Accounting here would double account them.

Signed-off-by: Yang Shi <yang.shi@linux.alibaba.com>
---
 mm/page_alloc.c | 5 +++++
 1 file changed, 5 insertions(+)

Comments

Yang Shi July 8, 2019, 10:53 p.m. UTC | #1
And how about this one?


On 6/27/19 10:12 AM, Yang Shi wrote:
> Available memory is one of the most important metrics for memory
> pressure.  Currently, lazy free pages are not accounted into available
> memory, but they are reclaimable actually, like reclaimable slabs.
>
> Accounting lazy free pages into available memory should reflect the real
> memory pressure status, and also would help administrators and/or other
> high level scheduling tools make better decision.
>
> The /proc/meminfo would show more available memory with test which
> creates ~1GB deferred split THP.
>
> Before:
> MemAvailable:   43544272 kB
> ...
> AnonHugePages:     10240 kB
> ShmemHugePages:        0 kB
> ShmemPmdMapped:        0 kB
> LazyFreePages:   1046528 kB
>
> After:
> MemAvailable:   44415124 kB
> ...
> AnonHugePages:      6144 kB
> ShmemHugePages:        0 kB
> ShmemPmdMapped:        0 kB
> LazyFreePages:   1046528 kB
>
> MADV_FREE pages are not accounted for NR_LAZYFREE since they have been
> put on inactive file LRU and accounted into available memory.
> Accounting here would double account them.
>
> Signed-off-by: Yang Shi <yang.shi@linux.alibaba.com>
> ---
>   mm/page_alloc.c | 5 +++++
>   1 file changed, 5 insertions(+)
>
> diff --git a/mm/page_alloc.c b/mm/page_alloc.c
> index cab50e8..58ceca5 100644
> --- a/mm/page_alloc.c
> +++ b/mm/page_alloc.c
> @@ -5005,6 +5005,7 @@ long si_mem_available(void)
>   	unsigned long wmark_low = 0;
>   	unsigned long pages[NR_LRU_LISTS];
>   	unsigned long reclaimable;
> +	unsigned long lazyfree;
>   	struct zone *zone;
>   	int lru;
>   
> @@ -5038,6 +5039,10 @@ long si_mem_available(void)
>   			global_node_page_state(NR_KERNEL_MISC_RECLAIMABLE);
>   	available += reclaimable - min(reclaimable / 2, wmark_low);
>   
> +	/* Lazyfree pages are reclaimable when memory pressure is hit */
> +	lazyfree = global_node_page_state(NR_LAZYFREE);
> +	available += lazyfree - min(lazyfree / 2, wmark_low);
> +
>   	if (available < 0)
>   		available = 0;
>   	return available;
diff mbox series

Patch

diff --git a/mm/page_alloc.c b/mm/page_alloc.c
index cab50e8..58ceca5 100644
--- a/mm/page_alloc.c
+++ b/mm/page_alloc.c
@@ -5005,6 +5005,7 @@  long si_mem_available(void)
 	unsigned long wmark_low = 0;
 	unsigned long pages[NR_LRU_LISTS];
 	unsigned long reclaimable;
+	unsigned long lazyfree;
 	struct zone *zone;
 	int lru;
 
@@ -5038,6 +5039,10 @@  long si_mem_available(void)
 			global_node_page_state(NR_KERNEL_MISC_RECLAIMABLE);
 	available += reclaimable - min(reclaimable / 2, wmark_low);
 
+	/* Lazyfree pages are reclaimable when memory pressure is hit */
+	lazyfree = global_node_page_state(NR_LAZYFREE);
+	available += lazyfree - min(lazyfree / 2, wmark_low);
+
 	if (available < 0)
 		available = 0;
 	return available;