From: Huang Ying <ying.huang@intel.com> To: Andrew Morton <akpm@linux-foundation.org> Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Huang Ying <ying.huang@intel.com>, Linus Torvalds <torvalds@linux-foundation.org>, Peter Xu <peterx@redhat.com>, Hugh Dickins <hughd@google.com>, Johannes Weiner <hannes@cmpxchg.org>, Mel Gorman <mgorman@suse.de>, Rik van Riel <riel@surriel.com>, Andrea Arcangeli <aarcange@redhat.com>, Michal Hocko <mhocko@kernel.org>, Dave Hansen <dave.hansen@intel.com>, Tim Chen <tim.c.chen@intel.com> Subject: [PATCH] mm: Free unused swap cache page in write protection fault handler Date: Wed, 13 Jan 2021 10:42:41 +0800 [thread overview] Message-ID: <20210113024241.179113-1-ying.huang@intel.com> (raw) Commit 09854ba94c6a ("mm: do_wp_page() simplification") introduces an issue as follows. On a system with free memory as follow before test, total used free shared buff/cache available Mem: 1697300 160156 1459220 8648 77924 1419724 Swap: 1048572 0 0 The AnonPages filed of /proc/meminfo is 11712 kB. After running a memory eater which will trigger many swapins and write protection faults, the free memory becomes, total used free shared buff/cache available Mem: 1697300 352620 1309004 624 35676 1252380 Swap: 1048572 216924 831648 While the /proc/meminfo shows, SwapCached: 198908 kB AnonPages: 1956 kB Then, with `swapoff -a`, the free memory becomes, total used free shared buff/cache available Mem: 1697300 161972 1488184 8648 47144 1433172 Swap: 0 0 0 That is, after swapins and write protection faults, many unused swap cache pages will be left unfreed in system. Although the following page reclaiming or swapoff will free these pages, it's still better to free these pages at the first place. So in this patch, at the end of wp_page_copy(), the old unused swap cache page will be tried to be freed. With that, after running the memory eater which will trigger many swapins and write protection faults, the free memory is, total used free shared buff/cache available Mem: 1697300 154020 1509400 1212 33880 1451524 Swap: 1048572 18432 1030140 While the /proc/meminfo shows, SwapCached: 1240 kB AnonPages: 1904 kB BTW: I think this should be in stable after v5.9. Fixes: 09854ba94c6a ("mm: do_wp_page() simplification") Signed-off-by: "Huang, Ying" <ying.huang@intel.com> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Peter Xu <peterx@redhat.com> Cc: Hugh Dickins <hughd@google.com> Cc: Johannes Weiner <hannes@cmpxchg.org> Cc: Mel Gorman <mgorman@suse.de> Cc: Rik van Riel <riel@surriel.com> Cc: Andrea Arcangeli <aarcange@redhat.com> Cc: Michal Hocko <mhocko@kernel.org> Cc: Dave Hansen <dave.hansen@intel.com> Cc: Tim Chen <tim.c.chen@intel.com> --- mm/memory.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/mm/memory.c b/mm/memory.c index feff48e1465a..2abaff1befcb 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -2963,6 +2963,11 @@ static vm_fault_t wp_page_copy(struct vm_fault *vmf) munlock_vma_page(old_page); unlock_page(old_page); } + if (page_copied && PageSwapCache(old_page) && + !page_mapped(old_page) && trylock_page(old_page)) { + try_to_free_swap(old_page); + unlock_page(old_page); + } put_page(old_page); } return page_copied ? VM_FAULT_WRITE : 0; -- 2.29.2
next reply other threads:[~2021-01-13 2:44 UTC|newest] Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top 2021-01-13 2:42 Huang Ying [this message] 2021-01-13 2:47 ` Linus Torvalds 2021-01-13 3:08 ` huang ying 2021-01-13 3:11 ` Matthew Wilcox 2021-01-13 5:24 ` huang ying 2021-01-13 21:09 ` Linus Torvalds 2021-01-15 8:47 ` Huang, Ying
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20210113024241.179113-1-ying.huang@intel.com \ --to=ying.huang@intel.com \ --cc=aarcange@redhat.com \ --cc=akpm@linux-foundation.org \ --cc=dave.hansen@intel.com \ --cc=hannes@cmpxchg.org \ --cc=hughd@google.com \ --cc=linux-kernel@vger.kernel.org \ --cc=linux-mm@kvack.org \ --cc=mgorman@suse.de \ --cc=mhocko@kernel.org \ --cc=peterx@redhat.com \ --cc=riel@surriel.com \ --cc=tim.c.chen@intel.com \ --cc=torvalds@linux-foundation.org \ --subject='Re: [PATCH] mm: Free unused swap cache page in write protection fault handler' \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).