From: Andrew Morton <akpm@linux-foundation.org>
To: Kirill Tkhai <ktkhai@virtuozzo.com>
Cc: hughd@google.com, aarcange@redhat.com,
kirill.shutemov@linux.intel.com,
andriy.shevchenko@linux.intel.com, mhocko@suse.com,
rppt@linux.vnet.ibm.com, imbrenda@linux.vnet.ibm.com,
corbet@lwn.net, ndesaulniers@google.com, dave.jiang@intel.com,
jglisse@redhat.com, jia.he@hxt-semitech.com,
paulmck@linux.vnet.ibm.com, colin.king@canonical.com,
jiang.biao2@zte.com.cn, linux-mm@kvack.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH v3] ksm: Assist buddy allocator to assemble 1-order pages
Date: Fri, 9 Nov 2018 13:08:57 -0800 [thread overview]
Message-ID: <20181109130857.54a1f383629e771b4f3888c4@linux-foundation.org> (raw)
In-Reply-To: <153995241537.4096.15189862239521235797.stgit@localhost.localdomain>
On Fri, 19 Oct 2018 15:33:39 +0300 Kirill Tkhai <ktkhai@virtuozzo.com> wrote:
> v3: Comment improvements.
> v2: Style improvements.
>
> try_to_merge_two_pages() merges two pages, one of them
> is a page of currently scanned mm, the second is a page
> with identical hash from unstable tree. Currently, we
> merge the page from unstable tree into the first one,
> and then free it.
>
> The idea of this patch is to prefer freeing that page
> of them, which has a free neighbour (i.e., neighbour
> with zero page_count()). This allows buddy allocator
> to assemble at least 1-order set from the freed page
> and its neighbour; this is a kind of cheep passive
> compaction.
>
> AFAIK, 1-order pages set consists of pages with PFNs
> [2n, 2n+1] (odd, even), so the neighbour's pfn is
> calculated via XOR with 1. We check the result pfn
> is valid and its page_count(), and prefer merging
> into @tree_page if neighbour's usage count is zero.
>
> There a is small difference with current behavior
> in case of error path. In case of the second
> try_to_merge_with_ksm_page() is failed, we return
> from try_to_merge_two_pages() with @tree_page
> removed from unstable tree. It does not seem to matter,
> but if we do not want a change at all, it's not
> a problem to move remove_rmap_item_from_tree() from
> try_to_merge_with_ksm_page() to its callers.
>
Seems sensible.
>
> ...
>
> --- a/mm/ksm.c
> +++ b/mm/ksm.c
> @@ -1321,6 +1321,23 @@ static struct page *try_to_merge_two_pages(struct rmap_item *rmap_item,
> {
> int err;
>
> + if (IS_ENABLED(CONFIG_COMPACTION)) {
> + unsigned long pfn;
> +
> + /*
> + * Find neighbour of @page containing 1-order pair in buddy
> + * allocator and check whether its count is 0. If so, we
> + * consider the neighbour as a free page (this is more
> + * probable than it's freezed via page_ref_freeze()), and
> + * we try to use @tree_page as ksm page and to free @page.
> + */
> + pfn = page_to_pfn(page) ^ 1;
> + if (pfn_valid(pfn) && page_count(pfn_to_page(pfn)) == 0) {
> + swap(rmap_item, tree_rmap_item);
> + swap(page, tree_page);
> + }
> + }
> +
A few thoughts
- if tree_page's neighbor is unused, there was no point in doing this
swapping?
- if both *page and *tree_page have unused neighbors we could go
further and look for an opportunity to create an order-2 page.
etcetera. This may b excessive ;)
- are we really sure that this optimization causes desirable results?
If we always merge from one tree into the other, we maximise the
opportunities for page coalescing in the long term. But if we
sometimes merge one way and sometimes merge the other way, we might
end up with less higher-order page coalescing? Or am I confusing
myself?
next prev parent reply other threads:[~2018-11-09 21:09 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-10-19 12:33 Kirill Tkhai
2018-11-09 21:08 ` Andrew Morton [this message]
2018-11-15 14:12 ` Kirill Tkhai
2018-12-10 15:22 ` Kirill Tkhai
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=20181109130857.54a1f383629e771b4f3888c4@linux-foundation.org \
--to=akpm@linux-foundation.org \
--cc=aarcange@redhat.com \
--cc=andriy.shevchenko@linux.intel.com \
--cc=colin.king@canonical.com \
--cc=corbet@lwn.net \
--cc=dave.jiang@intel.com \
--cc=hughd@google.com \
--cc=imbrenda@linux.vnet.ibm.com \
--cc=jglisse@redhat.com \
--cc=jia.he@hxt-semitech.com \
--cc=jiang.biao2@zte.com.cn \
--cc=kirill.shutemov@linux.intel.com \
--cc=ktkhai@virtuozzo.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=mhocko@suse.com \
--cc=ndesaulniers@google.com \
--cc=paulmck@linux.vnet.ibm.com \
--cc=rppt@linux.vnet.ibm.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