From: Aaron Lu <aaron.lu@linux.alibaba.com>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: linux-mm@kvack.org, Huang Ying <ying.huang@intel.com>,
Hugh Dickins <hughd@google.com>
Subject: Re: [PATCH] mm, swap: use rbtree for swap_extent
Date: Fri, 24 May 2019 12:06:47 +0800 [thread overview]
Message-ID: <357d963e-2657-4926-bab0-a87096a82230@linux.alibaba.com> (raw)
In-Reply-To: <20190523120035.efb7c3bf4c91e3aef255621c@linux-foundation.org>
On 2019/5/24 3:00, Andrew Morton wrote:
...
> On Thu, 23 May 2019 22:24:15 +0800 Aaron Lu <aaron.lu@linux.alibaba.com> wrote:
>> ...
>>
>> +static struct swap_extent *
>> +offset_to_swap_extent(struct swap_info_struct *sis, unsigned long offset)
>> +{
>> + struct swap_extent *se;
>> + struct rb_node *rb;
>> +
>> + rb = sis->swap_extent_root.rb_node;
>> + while (rb) {
>> + se = rb_entry(rb, struct swap_extent, rb_node);
>> + if (offset < se->start_page)
>> + rb = rb->rb_left;
>> + else if (offset >= se->start_page + se->nr_pages)
>> + rb = rb->rb_right;
>> + else
>> + return se;
>> + }
>> + /* It *must* be present */
>> + BUG_ON(1);
>
> I'm surprised this doesn't generate a warning about the function
Ah right, I'm also surprised after you mentioned.
This BUG_ON(1) here is meant to serve the same purpose as the
original code in map_swap_entry():
static sector_t map_swap_entry(swp_entry_t entry, struct block_device **bdev)
{
...
offset = swp_offset(entry);
start_se = sis->curr_swap_extent;
se = start_se;
for ( ; ; ) {
if (se->start_page <= offset &&
offset < (se->start_page + se->nr_pages)) {
return se->start_block + (offset - se->start_page);
}
se = list_next_entry(se, list);
sis->curr_swap_extent = se;
BUG_ON(se == start_se); /* It *must* be present */
}
}
I just copied the pattern and changed the condition to 1 without
much thought.
> failing to return a value. I guess the compiler figured out that
> BUG_ON(non-zero-constant) is equivalent to BUG(), which is noreturn.
>
> Let's do this?
Yes, it doesn't make much sense to use BUG_ON when the condition
is 1...Thanks for the cleanup.
>
> --- a/mm/swapfile.c~mm-swap-use-rbtree-for-swap_extent-fix
> +++ a/mm/swapfile.c
> @@ -218,7 +218,7 @@ offset_to_swap_extent(struct swap_info_s
> return se;
> }
> /* It *must* be present */
> - BUG_ON(1);
> + BUG();
> }
>
prev parent reply other threads:[~2019-05-24 4:06 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-05-23 14:24 Aaron Lu
2019-05-23 19:00 ` Andrew Morton
2019-05-24 4:06 ` Aaron Lu [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=357d963e-2657-4926-bab0-a87096a82230@linux.alibaba.com \
--to=aaron.lu@linux.alibaba.com \
--cc=akpm@linux-foundation.org \
--cc=hughd@google.com \
--cc=linux-mm@kvack.org \
--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