From: George Dunlap <george.dunlap@citrix.com>
To: Jan Beulich <JBeulich@suse.com>,
xen-devel <xen-devel@lists.xenproject.org>
Cc: George Dunlap <George.Dunlap@eu.citrix.com>,
Andrew Cooper <andrew.cooper3@citrix.com>,
Keir Fraser <keir@xen.org>
Subject: Re: [PATCH 4/4] x86/PoD: shorten certain operations on higher order ranges
Date: Wed, 23 Sep 2015 18:10:55 +0100 [thread overview]
Message-ID: <5602DD1F.4070802@citrix.com> (raw)
In-Reply-To: <55F7E6BC02000078000A2BDD@prv-mh.provo.novell.com>
On 09/15/2015 08:37 AM, Jan Beulich wrote:
> @@ -574,41 +576,46 @@ recount:
> * + There are PoD entries to handle, or
> * + There is ram left, and we want to steal it
> */
> - for ( i=0;
> - i<(1<<order) && (pod>0 || (steal_for_cache && ram > 0));
> - i++)
> + for ( i = 0;
> + i < (1UL << order) && (pod > 0 || (steal_for_cache && ram > 0));
> + i += n )
> {
> mfn_t mfn;
> p2m_type_t t;
> p2m_access_t a;
> + unsigned int cur_order;
>
> - mfn = p2m->get_entry(p2m, gpfn + i, &t, &a, 0, NULL, NULL);
> + mfn = p2m->get_entry(p2m, gpfn + i, &t, &a, 0, &cur_order, NULL);
> + if ( order < cur_order )
> + cur_order = order;
> + n = 1UL << cur_order;
> if ( t == p2m_populate_on_demand )
> {
> - p2m_set_entry(p2m, gpfn + i, _mfn(INVALID_MFN), 0, p2m_invalid,
> - p2m->default_access);
> - p2m->pod.entry_count--;
> + p2m_set_entry(p2m, gpfn + i, _mfn(INVALID_MFN), cur_order,
> + p2m_invalid, p2m->default_access);
> + p2m->pod.entry_count -= n;
> BUG_ON(p2m->pod.entry_count < 0);
> - pod--;
> + pod -= n;
> }
> else if ( steal_for_cache && p2m_is_ram(t) )
> {
> struct page_info *page;
> + unsigned int j;
>
> ASSERT(mfn_valid(mfn));
>
> page = mfn_to_page(mfn);
>
> - p2m_set_entry(p2m, gpfn + i, _mfn(INVALID_MFN), 0, p2m_invalid,
> - p2m->default_access);
> - set_gpfn_from_mfn(mfn_x(mfn), INVALID_M2P_ENTRY);
> -
> - p2m_pod_cache_add(p2m, page, 0);
> + p2m_set_entry(p2m, gpfn + i, _mfn(INVALID_MFN), cur_order,
> + p2m_invalid, p2m->default_access);
> + for ( j = 0; j < n; ++j )
> + set_gpfn_from_mfn(mfn_x(mfn), INVALID_M2P_ENTRY);
> + p2m_pod_cache_add(p2m, page, cur_order);
>
> steal_for_cache = ( p2m->pod.entry_count > p2m->pod.count );
This code will now steal an entire 2MiB page even if we only need a few
individual pages, then free it below (calling p2m_pod_set_cache_target()).
Upon reflection, this is actually a feature -- if we have singleton
pages in the cache, we can free those first, hopefully keeping the 2MiB
page together.
It would be good to have a comment here to that effect, though; perhaps:
"If we need less than 1<<order, may end up stealing more memory here
than we actually need. This will be rectified below, however; and
stealing too much and then freeing what we need may allow us to free
smaller pages from the cache, and avoid breaking up superpages."
It occurs to me that the steal_for_cache calculations are also wrong
here --it should be (p2m->pod.entry_count - pod > p2m->pod.count) --
i.e., we should steal if liabilities would be greater than assets
*after* this function completed, not before.
Otherwise, everything else looks good, thanks.
I assume you'll resubmit this when the patch it depends on leaves RFC?
In which case I'll wait until I see that version to Ack it.
-George
next prev parent reply other threads:[~2015-09-23 17:11 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <55F70C9A02000078000A2A58@prv-mh.provo.novell.com>
2015-09-15 7:13 ` [PATCH 0/4] x86/p2m: use large pages for MMIO mappings Jan Beulich
2015-09-15 7:30 ` [PATCH 1/4] x86/EPT: always return proper order value from ept_get_entry() Jan Beulich
2015-09-16 7:15 ` Tian, Kevin
2015-09-17 16:13 ` Andrew Cooper
2015-09-15 7:31 ` [PATCH 2/4] x86/NPT: always return proper order value from p2m_pt_get_entry() Jan Beulich
2015-09-15 7:35 ` Jan Beulich
2015-09-15 7:32 ` Jan Beulich
2015-09-17 16:14 ` Andrew Cooper
2015-09-15 7:34 ` [PATCH 3/4 RFC] x86/p2m: use large pages for MMIO mappings Jan Beulich
2015-09-16 10:02 ` Julien Grall
2015-09-17 16:37 ` Andrew Cooper
2015-09-17 17:59 ` Jan Beulich
2015-09-22 8:32 ` Jan Beulich
2015-09-29 11:33 ` Julien Grall
2015-09-29 11:44 ` Jan Beulich
2015-09-29 12:16 ` Julien Grall
2015-09-29 12:46 ` Jan Beulich
2015-09-29 12:52 ` Julien Grall
2015-09-29 13:00 ` Jan Beulich
2015-09-29 13:06 ` Julien Grall
2015-09-29 13:27 ` Jan Beulich
2015-09-30 10:15 ` Julien Grall
2015-09-15 7:37 ` [PATCH 4/4] x86/PoD: shorten certain operations on higher order ranges Jan Beulich
2015-09-23 17:10 ` George Dunlap [this message]
2015-09-23 17:16 ` George Dunlap
2015-09-24 8:42 ` Jan Beulich
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=5602DD1F.4070802@citrix.com \
--to=george.dunlap@citrix.com \
--cc=George.Dunlap@eu.citrix.com \
--cc=JBeulich@suse.com \
--cc=andrew.cooper3@citrix.com \
--cc=keir@xen.org \
--cc=xen-devel@lists.xenproject.org \
/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;
as well as URLs for NNTP newsgroup(s).