From: Matthew Wilcox <willy@infradead.org>
To: Liang Zhang <zhangliang5@huawei.com>
Cc: akpm@linux-foundation.org, linux-mm@kvack.org,
linux-kernel@vger.kernel.org, wangzhigang17@huawei.com,
Linus Torvalds <torvalds@linux-foundation.org>,
David Hildenbrand <david@redhat.com>
Subject: Re: [PATCH] mm: reuse the unshared swapcache page in do_wp_page
Date: Thu, 13 Jan 2022 14:39:28 +0000 [thread overview]
Message-ID: <YeA5oP/iaxtVPHb3@casper.infradead.org> (raw)
In-Reply-To: <20220113140318.11117-1-zhangliang5@huawei.com>
On Thu, Jan 13, 2022 at 10:03:18PM +0800, Liang Zhang wrote:
> In current implementation, process's read requestions will fault in pages
> with WP flags in PTEs. Next, if process emit a write requestion will go
> into do_wp_page() and copy data to a new allocated page from the old one
> due to refcount > 1 (page table mapped and swapcache), which could be
> result in performance degradation. In fact, this page is exclusively owned
> by this process and the duplication from old to a new allocated page is
> really unnecessary.
>
> So In this situation, these unshared pages can be reused by its process.
Let's bring Linus in on this, but I think this reintroduces all of the
mapcount problems that we've been discussing recently.
How about this as an alternative?
+++ b/mm/memory.c
@@ -3291,11 +3291,11 @@ static vm_fault_t do_wp_page(struct vm_fault *vmf)
struct page *page = vmf->page;
/* PageKsm() doesn't necessarily raise the page refcount */
- if (PageKsm(page) || page_count(page) != 1)
+ if (PageKsm(page) || page_count(page) != 1 + PageSwapCache(page))
goto copy;
if (!trylock_page(page))
goto copy;
- if (PageKsm(page) || page_mapcount(page) != 1 || page_count(page) != 1) {
+ if (PageKsm(page) || page_mapcount(page) != 1 || page_count(page) != 1 + PageSwapCache(page)) {
unlock_page(page);
goto copy;
}
> Signed-off-by: Liang Zhang <zhangliang5@huawei.com>
> ---
> This patch has been tested with redis benchmark. Here is the test
> result.
>
> Hardware
> ========
> Memory (GB): 512G
> CPU (total #): 88
> NVMe SSD (GB): 1024
>
> OS
> ==
> kernel 5.10.0
>
> Testcase
> ========
> step 1:
> Run 16 VMs (4U8G), each running with redis-server, in a cgroup
> limiting memory.limit_in_bytes to 100G.
> step 2:
> Run memtier_bemchmark in host with params "--threads=1 --clients=1 \
> --pipeline=256 --data-size=2048 --requests=allkeys --key-minimum=1 \
> --key-maximum=30000000 --key-prefix=memtier-benchmark-prefix-redistests"
> to test every VM concurrently.
>
> Workset size
> ============
> cat memory.memsw.usage_in_bytes
> 125403303936
>
> Result
> ======
> Comparing with Baseline, this patch can achieved 41% more Ops/sec,
> 41% more Hits/sec, 41% more Misses/sec, 30% less Latency and
> 41% more KB/sec.
>
> Index(average) Baseline kernel Patched kernel
> Ops/sec 109497 155428
> Hits/sec 8653 12283
> Misses/sec 90889 129014
> Latency 2.297 1.603
> KB/sec 44569 63186
>
>
> mm/memory.c | 9 ++++++++-
> 1 file changed, 8 insertions(+), 1 deletion(-)
>
> diff --git a/mm/memory.c b/mm/memory.c
> index 23f2f1300d42..fd4d868b1c2d 100644
> --- a/mm/memory.c
> +++ b/mm/memory.c
> @@ -3291,10 +3291,16 @@ static vm_fault_t do_wp_page(struct vm_fault *vmf)
> struct page *page = vmf->page;
>
> /* PageKsm() doesn't necessarily raise the page refcount */
> - if (PageKsm(page) || page_count(page) != 1)
> + if (PageKsm(page))
> goto copy;
> if (!trylock_page(page))
> goto copy;
> +
> + /* reuse the unshared swapcache page */
> + if (PageSwapCache(page) && reuse_swap_page(page, NULL)) {
> + goto reuse;
> + }
> +
> if (PageKsm(page) || page_mapcount(page) != 1 || page_count(page) != 1) {
> unlock_page(page);
> goto copy;
> @@ -3304,6 +3310,7 @@ static vm_fault_t do_wp_page(struct vm_fault *vmf)
> * page count reference, and the page is locked,
> * it's dark out, and we're wearing sunglasses. Hit it.
> */
> +reuse:
> unlock_page(page);
> wp_page_reuse(vmf);
> return VM_FAULT_WRITE;
> --
> 2.30.0
>
>
next prev parent reply other threads:[~2022-01-13 14:39 UTC|newest]
Thread overview: 45+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-01-13 14:03 Liang Zhang
2022-01-13 14:39 ` Matthew Wilcox [this message]
2022-01-13 14:46 ` David Hildenbrand
2022-01-13 15:02 ` Matthew Wilcox
2022-01-13 15:04 ` David Hildenbrand
2022-01-13 16:37 ` Linus Torvalds
2022-01-13 16:48 ` David Hildenbrand
2022-01-13 17:14 ` Linus Torvalds
2022-01-13 17:25 ` David Hildenbrand
2022-01-13 17:44 ` Linus Torvalds
2022-01-13 17:55 ` David Hildenbrand
2022-01-13 18:55 ` Linus Torvalds
2022-01-13 21:07 ` Matthew Wilcox
2022-01-14 5:00 ` zhangliang (AG)
2022-01-14 11:23 ` David Hildenbrand
2022-01-17 2:11 ` zhangliang (AG)
2022-01-17 12:58 ` David Hildenbrand
2022-01-17 13:31 ` zhangliang (AG)
2022-01-20 14:15 ` David Hildenbrand
2022-01-20 14:39 ` Matthew Wilcox
2022-01-20 15:26 ` David Hildenbrand
2022-01-20 15:36 ` Matthew Wilcox
2022-01-20 15:39 ` David Hildenbrand
2022-01-20 15:45 ` Matthew Wilcox
2022-01-20 15:51 ` David Hildenbrand
2022-01-20 16:09 ` Matthew Wilcox
2022-01-20 16:35 ` David Hildenbrand
2022-01-20 15:37 ` Linus Torvalds
2022-01-20 15:46 ` David Hildenbrand
2022-01-20 17:22 ` Linus Torvalds
2022-01-20 17:49 ` David Hildenbrand
2022-01-20 17:48 ` Nadav Amit
2022-01-20 18:00 ` David Hildenbrand
2022-01-20 18:11 ` Nadav Amit
2022-01-20 18:19 ` David Hildenbrand
2022-01-20 19:55 ` David Hildenbrand
2022-01-20 20:07 ` Matthew Wilcox
2022-01-20 20:09 ` David Hildenbrand
2022-01-20 20:37 ` David Hildenbrand
2022-01-20 20:46 ` Nadav Amit
2022-01-20 20:49 ` David Hildenbrand
2022-01-21 9:01 ` David Hildenbrand
2022-01-21 17:43 ` Nadav Amit
2022-01-20 20:18 ` David Hildenbrand
2022-01-14 3:29 ` zhangliang (AG)
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=YeA5oP/iaxtVPHb3@casper.infradead.org \
--to=willy@infradead.org \
--cc=akpm@linux-foundation.org \
--cc=david@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=torvalds@linux-foundation.org \
--cc=wangzhigang17@huawei.com \
--cc=zhangliang5@huawei.com \
/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
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®