Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1760138AbcDEVN5 (ORCPT ); Tue, 5 Apr 2016 17:13:57 -0400 Received: from mail-pa0-f53.google.com ([209.85.220.53]:33486 "EHLO mail-pa0-f53.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1760110AbcDEVN4 (ORCPT ); Tue, 5 Apr 2016 17:13:56 -0400 Date: Tue, 5 Apr 2016 14:13:53 -0700 (PDT) From: Hugh Dickins X-X-Sender: hugh@eggly.anvils To: Andrew Morton cc: "Kirill A. Shutemov" , Andrea Arcangeli , Andres Lagar-Cavilla , Yang Shi , Ning Qu , linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH 02/31] huge tmpfs: include shmem freeholes in available memory In-Reply-To: Message-ID: References: User-Agent: Alpine 2.11 (LSU 23 2013-08-11) MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2252 Lines: 63 ShmemFreeHoles will be freed under memory pressure, but are not included in MemFree: they need to be added into MemAvailable, and wherever the kernel calculates freeable pages, rather than actually free pages. They must not be counted as free when considering whether to go to reclaim. There is certainly room for debate about other places, but I think I've got about the right list - though I'm unfamiliar with and undecided about drivers/staging/android/lowmemorykiller.c and kernel/power/snapshot.c. While NR_SHMEM_FREEHOLES should certainly not be counted in NR_FREE_PAGES, there is a case for including ShmemFreeHoles in the user-visible MemFree after all: I can see both sides of that argument, leaving it out so far. Signed-off-by: Hugh Dickins --- mm/page-writeback.c | 2 ++ mm/page_alloc.c | 6 ++++++ mm/util.c | 1 + 3 files changed, 9 insertions(+) --- a/mm/page-writeback.c +++ b/mm/page-writeback.c @@ -285,6 +285,7 @@ static unsigned long zone_dirtyable_memo */ nr_pages -= min(nr_pages, zone->totalreserve_pages); + nr_pages += zone_page_state(zone, NR_SHMEM_FREEHOLES); nr_pages += zone_page_state(zone, NR_INACTIVE_FILE); nr_pages += zone_page_state(zone, NR_ACTIVE_FILE); @@ -344,6 +345,7 @@ static unsigned long global_dirtyable_me */ x -= min(x, totalreserve_pages); + x += global_page_state(NR_SHMEM_FREEHOLES); x += global_page_state(NR_INACTIVE_FILE); x += global_page_state(NR_ACTIVE_FILE); --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -3760,6 +3760,12 @@ long si_mem_available(void) available += pagecache; /* + * Shmem freeholes help to keep huge pages intact, but contain + * no data, and can be shrunk whenever small pages are needed. + */ + available += global_page_state(NR_SHMEM_FREEHOLES); + + /* * Part of the reclaimable slab consists of items that are in use, * and cannot be freed. Cap this estimate at the low watermark. */ --- a/mm/util.c +++ b/mm/util.c @@ -496,6 +496,7 @@ int __vm_enough_memory(struct mm_struct if (sysctl_overcommit_memory == OVERCOMMIT_GUESS) { free = global_page_state(NR_FREE_PAGES); + free += global_page_state(NR_SHMEM_FREEHOLES); free += global_page_state(NR_FILE_PAGES); /*