From: Andrew Morton <akpm@linux-foundation.org>
To: Bob Liu <lliubbo@gmail.com>
Cc: linux-mm@kvack.org, kosaki.motohiro@jp.fujitsu.com
Subject: Re: [RESEND][PATCH] __isolate_lru_page:skip unneeded "not"
Date: Fri, 2 Apr 2010 16:01:25 -0700 [thread overview]
Message-ID: <20100402160125.87ebb3ba.akpm@linux-foundation.org> (raw)
In-Reply-To: <y2tcf18f8341004021525wa44a76ev8f4372a7191e0240@mail.gmail.com>
On Sat, 3 Apr 2010 06:25:08 +0800
Bob Liu <lliubbo@gmail.com> wrote:
> >> - /*
> >> - * When checking the active state, we need to be sure we are
> >> - * dealing with comparible boolean values. Take the logical not
> >> - * of each.
> >> - */
> >
> > You deleted a spelling mistake too!
> >
> >> - if (mode != ISOLATE_BOTH && (!PageActive(page) != !mode))
> >> - return ret;
> >> -
> >> - if (mode != ISOLATE_BOTH && page_is_file_cache(page) != file)
> >> - return ret;
> >> + if (mode != ISOLATE_BOTH) {
> >> + if ((PageActive(page) != mode) ||
> >> + (page_is_file_cache(page) != file))
> >> + return ret;
> >> + }
> >
> > The compiler should be able to avoid testing for ISOLATE_BOTH twice,
>
> Thanks for your kindly reply.
> then is the two "not" able to avoid by the compiler ?
> if yes, this patch is meanless and should be ignore.
I very much doubt if the compiler knows that these two variables can
only ever have values 0 or 1, so I expect that removing the !'s will
reduce text size.
That being said, it wouldn't be a good and maintainable change -
one point in using enumerations such as ISOLATE_* is to hide their real
values. Adding code which implicitly "knows" that a particular
enumerated identifier has a particular underlying value is rather
grubby and fragile.
But the code's already doing that.
It's also a bit fragile to assume that a true/false-returning C
function (PageActive) will always return 0 or 1. It's a common C idiom
for such functions to return 0 or non-zero (not necessarily 1).
So a clean and maintainable implementation of
if (mode != ISOLATE_BOTH && (!PageActive(page) != !mode))
return ret;
would be
if (mode != ISOLATE_BOTH &&
((PageActive(page) && mode == ISOLATE_ACTIVE) ||
(!PageActive(page) && mode == ISOLATE_INACTIVE)))
return ret;
which is just dying for an optimisation trick such as the one which is
already there ;)
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
prev parent reply other threads:[~2010-04-04 15:08 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-04-01 13:37 [RESEND][PATCH] __isolate_lru_page:skip unneeded "not" Bob Liu
2010-04-02 22:05 ` Andrew Morton
2010-04-02 22:25 ` Bob Liu
2010-04-02 23:01 ` Andrew Morton [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=20100402160125.87ebb3ba.akpm@linux-foundation.org \
--to=akpm@linux-foundation.org \
--cc=kosaki.motohiro@jp.fujitsu.com \
--cc=linux-mm@kvack.org \
--cc=lliubbo@gmail.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;
as well as URLs for NNTP newsgroup(s).