From: Jan Beulich <jbeulich@suse.com>
To: David Woodhouse <dwmw2@infradead.org>
Cc: Stefano Stabellini <sstabellini@kernel.org>,
Julien Grall <julien@xen.org>, Wei Liu <wl@xen.org>,
Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>,
George Dunlap <george.dunlap@eu.citrix.com>,
Andrew Cooper <andrew.cooper3@citrix.com>,
Ian Jackson <ian.jackson@eu.citrix.com>,
George Dunlap <george.dunlap@citrix.com>,
Jeff Kubascik <jeff.kubascik@dornerworks.com>,
Stewart Hildebrand <stewart.hildebrand@dornerworks.com>,
xen-devel@lists.xenproject.org
Subject: Re: [Xen-devel] [PATCH 1/2] xen/mm: fold PGC_broken into PGC_state bits
Date: Wed, 18 Mar 2020 10:56:55 +0100 [thread overview]
Message-ID: <9b0d191e-2553-6368-84d6-8425abe23c39@suse.com> (raw)
In-Reply-To: <641040a4aebc62e1e0e3874f513e3a308ec3ace0.camel@infradead.org>
On 17.03.2020 22:52, David Woodhouse wrote:
> On Thu, 2020-02-20 at 12:10 +0100, Jan Beulich wrote:
>> On 07.02.2020 16:57, David Woodhouse wrote:
>>> @@ -1145,16 +1145,19 @@ static int reserve_offlined_page(struct
>>> page_info *head)
>>>
>>> for ( cur_head = head; cur_head < head + ( 1UL << head_order);
>>> cur_head++ )
>>> {
>>> - if ( !page_state_is(cur_head, offlined) )
>>> + struct page_list_head *list;
>>> + if ( page_state_is(cur_head, offlined) )
>>> + list = &page_offlined_list;
>>> + else if (page_state_is(cur_head, broken) )
>>> + list = &page_broken_list;
>>> + else
>>> continue;
>>>
>>> avail[node][zone]--;
>>> total_avail_pages--;
>>> ASSERT(total_avail_pages >= 0);
>>>
>>> - page_list_add_tail(cur_head,
>>> - test_bit(_PGC_broken, &cur_head->count_info) ?
>>> - &page_broken_list : &page_offlined_list);
>>> + page_list_add_tail(cur_head, list);
>>
>> While I realize it's fewer comparisons this way, I still wonder
>> whether for the reader's sake it wouldn't better be
>> page_is_offlined() first and then page_is_broken() down here.
>
> Nah, that would be worse. This way there are two cases which are
> explicitly handled and the list to use for each of them is explicitly
> set. The 'if (a||b) … some_function(a ? thing_for_a : thing_for_b)'
> construct is much less comprehensible.
It's a matter of taste, I agree, and in such a case I generally advise
to see about limiting code churn. For code you then still introduce
anew, yes, taste decisions may typically be to the authors judgement
(there are exceptions, though).
>>> @@ -1699,14 +1714,14 @@ unsigned int online_page(mfn_t mfn,
>>> uint32_t *status)
>>> do {
>>> ret = *status = 0;
>>>
>>> - if ( y & PGC_broken )
>>> + if ( (y & PGC_state) == PGC_state_broken ||
>>> + (y & PGC_state) == PGC_state_broken_offlining )
>>> {
>>> ret = -EINVAL;
>>> *status = PG_ONLINE_FAILED |PG_ONLINE_BROKEN;
>>> break;
>>> }
>>> -
>>> - if ( (y & PGC_state) == PGC_state_offlined )
>>> + else if ( (y & PGC_state) == PGC_state_offlined )
>>
>> I don't see a need for adding "else" here.
>
> They are mutually exclusive cases. It makes things a whole lot clearer
> to the reader to put the 'else' there, and sometimes helps a naïve
> compiler along the way too.
Well, I'm afraid I'm going to be pretty strict about this: It's again
a matter of taste, yes, but we generally try to avoid pointless else.
What you consider "a whole lot clearer to the reader" is the opposite
from my pov.
>>> --- a/xen/include/asm-x86/mm.h
>>> +++ b/xen/include/asm-x86/mm.h
>>> @@ -67,18 +67,27 @@
>>> /* 3-bit PAT/PCD/PWT cache-attribute hint. */
>>> #define PGC_cacheattr_base PG_shift(6)
>>> #define PGC_cacheattr_mask PG_mask(7, 6)
>>> - /* Page is broken? */
>>> -#define _PGC_broken PG_shift(7)
>>> -#define PGC_broken PG_mask(1, 7)
>>> - /* Mutually-exclusive page states: { inuse, offlining, offlined,
>>> free }. */
>>> -#define PGC_state PG_mask(3, 9)
>>> -#define PGC_state_inuse PG_mask(0, 9)
>>> -#define PGC_state_offlining PG_mask(1, 9)
>>> -#define PGC_state_offlined PG_mask(2, 9)
>>> -#define PGC_state_free PG_mask(3, 9)
>>> -#define page_state_is(pg, st) (((pg)->count_info&PGC_state) ==
>>> PGC_state_##st)
>>> -
>>> - /* Count of references to this frame. */
>>> + /*
>>> + * Mutually-exclusive page states:
>>> + * { inuse, offlining, offlined, free, broken_offlining, broken }
>>> + */
>>> +#define PGC_state PG_mask(7, 9)
>>> +#define PGC_state_inuse PG_mask(0, 9)
>>> +#define PGC_state_offlining PG_mask(1, 9)
>>> +#define PGC_state_offlined PG_mask(2, 9)
>>> +#define PGC_state_free PG_mask(3, 9)
>>> +#define PGC_state_broken_offlining PG_mask(4, 9)
>>
>> TBH I'd prefer PGC_state_offlining_broken, as it's not the
>> offlining which is broken, but a broken page is being
>> offlined.
>
> It is the page which is both broken and offlining.
> Or indeed it is the page which is both offlining and broken.
I.e. you agree with flipping the two parts around?
>>> +#define page_is_offlining(pg) (page_state_is((pg), broken_offlining) || \
>>> + page_state_is((pg), offlining))
>>
>> Overall I wonder whether the PGC_state_* ordering couldn't be
>> adjusted such that at least some of these three won't need
>> two comparisons (by masking off a bit before comparing).
>
> The whole point in this exercise is that there isn't a whole bit for
> these; they are each *two* states out of the possible 8.
Sure. But just consider the more general case: Instead of writing
if ( i == 6 || i == 7 )
you can as well write
if ( (i | 1) == 7 )
Similar for multiple == vs a single <= or >=.
Jan
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel
next prev parent reply other threads:[~2020-03-18 10:06 UTC|newest]
Thread overview: 50+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-02-04 15:14 [Xen-devel] [XEN PATCH v2 1/2] Check zone before merging adjacent blocks in heap Stewart Hildebrand
2020-02-04 15:14 ` [Xen-devel] [DO NOT APPLY XEN PATCH v2 2/2] Test case for buddy allocator merging issue Stewart Hildebrand
2020-02-04 15:22 ` [Xen-devel] [XEN PATCH v2 1/2] Check zone before merging adjacent blocks in heap Jan Beulich
2020-02-04 15:37 ` George Dunlap
2020-02-05 9:50 ` David Woodhouse
2020-02-05 10:02 ` Jan Beulich
2020-02-05 10:24 ` David Woodhouse
2020-02-05 10:49 ` Jan Beulich
2020-02-05 11:23 ` David Woodhouse
2020-02-05 13:37 ` Jan Beulich
2020-02-05 14:12 ` David Woodhouse
2020-02-07 15:49 ` David Woodhouse
2020-02-07 15:57 ` [Xen-devel] [PATCH 1/2] xen/mm: fold PGC_broken into PGC_state bits David Woodhouse
2020-02-07 20:27 ` Julien Grall
2020-02-09 13:22 ` David Woodhouse
2020-02-09 17:59 ` Julien Grall
2020-03-17 21:39 ` David Woodhouse
2020-02-20 11:10 ` Jan Beulich
2020-03-17 21:52 ` David Woodhouse
2020-03-18 9:56 ` Jan Beulich [this message]
2020-03-18 12:31 ` Julien Grall
2020-03-18 13:23 ` Jan Beulich
2020-03-18 17:13 ` David Woodhouse
2020-03-19 8:49 ` Jan Beulich
2020-03-19 10:26 ` David Woodhouse
2020-03-19 11:59 ` Jan Beulich
2020-03-19 13:54 ` David Woodhouse
2020-03-19 14:46 ` Jan Beulich
2020-02-07 15:57 ` [Xen-devel] [PATCH 2/2] xen/mm: Introduce PG_state_uninitialised David Woodhouse
2020-02-07 16:30 ` Xia, Hongyan
2020-02-07 16:32 ` David Woodhouse
2020-02-07 16:40 ` Xia, Hongyan
2020-02-07 17:06 ` David Woodhouse
2020-02-07 18:04 ` David Woodhouse
2020-02-20 11:59 ` Jan Beulich
2020-02-20 13:27 ` Julien Grall
2020-03-17 22:15 ` David Woodhouse
2020-03-18 8:53 ` Paul Durrant
2020-03-18 10:10 ` Jan Beulich
2020-03-18 10:41 ` Paul Durrant
2020-03-18 11:12 ` Jan Beulich
2020-03-18 10:03 ` Jan Beulich
2020-03-18 12:11 ` David Woodhouse
2020-03-18 13:27 ` Jan Beulich
2020-02-05 10:22 ` [Xen-devel] [XEN PATCH v2 1/2] Check zone before merging adjacent blocks in heap Julien Grall
2020-02-05 10:32 ` David Woodhouse
2020-02-05 11:36 ` David Woodhouse
2020-02-04 15:37 ` Stewart Hildebrand
2020-03-19 21:17 [Xen-devel] [PATCH 0/2] Handle David Woodhouse
2020-03-19 21:21 ` [Xen-devel] [PATCH 1/2] xen/mm: fold PGC_broken into PGC_state bits David Woodhouse
2020-03-20 13:17 ` Paul Durrant
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=9b0d191e-2553-6368-84d6-8425abe23c39@suse.com \
--to=jbeulich@suse.com \
--cc=andrew.cooper3@citrix.com \
--cc=dwmw2@infradead.org \
--cc=george.dunlap@citrix.com \
--cc=george.dunlap@eu.citrix.com \
--cc=ian.jackson@eu.citrix.com \
--cc=jeff.kubascik@dornerworks.com \
--cc=julien@xen.org \
--cc=konrad.wilk@oracle.com \
--cc=sstabellini@kernel.org \
--cc=stewart.hildebrand@dornerworks.com \
--cc=wl@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.