From: Kirill Tkhai <ktkhai@virtuozzo.com>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: "kirill@shutemov.name" <kirill@shutemov.name>,
"hughd@google.com" <hughd@google.com>,
"aarcange@redhat.com" <aarcange@redhat.com>,
"christian.koenig@amd.com" <christian.koenig@amd.com>,
"imbrenda@linux.vnet.ibm.com" <imbrenda@linux.vnet.ibm.com>,
"yang.shi@linux.alibaba.com" <yang.shi@linux.alibaba.com>,
"riel@surriel.com" <riel@surriel.com>,
"ying.huang@intel.com" <ying.huang@intel.com>,
"minchan@kernel.org" <minchan@kernel.org>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
"linux-mm@kvack.org" <linux-mm@kvack.org>
Subject: Re: [PATCH] mm: Reuse only-pte-mapped KSM page in do_wp_page()
Date: Sun, 30 Dec 2018 09:47:51 +0000 [thread overview]
Message-ID: <cfb2180d-8da8-6d99-44b8-ffc052869182@virtuozzo.com> (raw)
In-Reply-To: <20181229134017.0264b5cab7e3ebb483b49f65@linux-foundation.org>
On 30.12.2018 00:40, Andrew Morton wrote:
> On Thu, 13 Dec 2018 18:29:08 +0300 Kirill Tkhai <ktkhai@virtuozzo.com> wrote:
>
>> This patch adds an optimization for KSM pages almost
>> in the same way, that we have for ordinary anonymous
>> pages. If there is a write fault in a page, which is
>> mapped to an only pte, and it is not related to swap
>> cache; the page may be reused without copying its
>> content.
>>
>> [Note, that we do not consider PageSwapCache() pages
>> at least for now, since we don't want to complicate
>> __get_ksm_page(), which has nice optimization based
>> on this (for the migration case). Currenly it is
>> spinning on PageSwapCache() pages, waiting for when
>> they have unfreezed counters (i.e., for the migration
>> finish). But we don't want to make it also spinning
>> on swap cache pages, which we try to reuse, since
>> there is not a very high probability to reuse them.
>> So, for now we do not consider PageSwapCache() pages
>> at all.]
>>
>> So, in reuse_ksm_page() we check for 1)PageSwapCache()
>> and 2)page_stable_node(), to skip a page, which KSM
>> is currently trying to link to stable tree. Then we
>> do page_ref_freeze() to prohibit KSM to merge one more
>> page into the page, we are reusing. After that, nobody
>> can refer to the reusing page: KSM skips !PageSwapCache()
>> pages with zero refcount; and the protection against
>> of all other participants is the same as for reused
>> ordinary anon pages pte lock, page lock and mmap_sem.
>>
>> ...
>>
>> +bool reuse_ksm_page(struct page *page,
>> + struct vm_area_struct *vma,
>> + unsigned long address)
>> +{
>> + VM_BUG_ON_PAGE(is_zero_pfn(page_to_pfn(page)), page);
>> + VM_BUG_ON_PAGE(!page_mapped(page), page);
>> + VM_BUG_ON_PAGE(!PageLocked(page), page);
>> +
>> + if (PageSwapCache(page) || !page_stable_node(page))
>> + return false;
>> + /* Prohibit parallel get_ksm_page() */
>> + if (!page_ref_freeze(page, 1))
>> + return false;
>> +
>> + page_move_anon_rmap(page, vma);
>> + page->index = linear_page_index(vma, address);
>> + page_ref_unfreeze(page, 1);
>> +
>> + return true;
>> +}
>
> Can we avoid those BUG_ON()s?
>
> Something like this:
>
> --- a/mm/ksm.c~mm-reuse-only-pte-mapped-ksm-page-in-do_wp_page-fix
> +++ a/mm/ksm.c
> @@ -2649,9 +2649,14 @@ bool reuse_ksm_page(struct page *page,
> struct vm_area_struct *vma,
> unsigned long address)
> {
> - VM_BUG_ON_PAGE(is_zero_pfn(page_to_pfn(page)), page);
> - VM_BUG_ON_PAGE(!page_mapped(page), page);
> - VM_BUG_ON_PAGE(!PageLocked(page), page);
> +#ifdef CONFIG_DEBUG_VM
> + if (WARN_ON(is_zero_pfn(page_to_pfn(page))) ||
> + WARN_ON(!page_mapped(page)) ||
> + WARN_ON(!PageLocked(page))) {
> + dump_page(page, "reuse_ksm_page");
> + return false;
> + }
> +#endif
Looks good!
> if (PageSwapCache(page) || !page_stable_node(page))
> return false;
>
> We don't have a VM_WARN_ON_PAGE() and we can't provide one because the
> VM_foo() macros don't return a value. It's irritating and I keep
> forgetting why we ended up doing them this way.
Thanks!
prev parent reply other threads:[~2018-12-30 9:48 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-12-13 15:29 Kirill Tkhai
2018-12-13 19:15 ` Yang Shi
2018-12-14 9:26 ` Kirill Tkhai
2018-12-14 18:06 ` Yang Shi
2018-12-15 9:18 ` Kirill Tkhai
2018-12-29 9:34 ` Kirill Tkhai
2018-12-29 21:40 ` Andrew Morton
2018-12-30 9:47 ` Kirill Tkhai [this message]
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=cfb2180d-8da8-6d99-44b8-ffc052869182@virtuozzo.com \
--to=ktkhai@virtuozzo.com \
--cc=aarcange@redhat.com \
--cc=akpm@linux-foundation.org \
--cc=christian.koenig@amd.com \
--cc=hughd@google.com \
--cc=imbrenda@linux.vnet.ibm.com \
--cc=kirill@shutemov.name \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=minchan@kernel.org \
--cc=riel@surriel.com \
--cc=yang.shi@linux.alibaba.com \
--cc=ying.huang@intel.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