mm: Do not use double negation for testing page flags
Subsystems (2)
PATCH 1/1 mm: Do not use double negation for testing page flags
With the discussion[1], I found it seems there are every PageFlags functions return bool at this moment so we don't need double negation any more.
Although it's not a problem to keep it, it makes future users confused to use dobule negation for them, too.
Remove such possibility.
[1] https://marc.info/?l=linux-kernel&m=148881578820434
Frankly sepaking, I like every PageFlags return bool instead of int. It will make it clear. AFAIR, Chen Gang had tried it but don't know why it was not merged at that time.
http://lkml.kernel.org/r/[email protected]
--- mm/khugepaged.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
mm/khugepaged.c +2 -2
@@ -548,7 +548,7 @@ static int __collapse_huge_page_isolate(struct vm_area_struct *vma,* The page must only be referenced by the scanned process * and page swap cache. */ -if (page_count (page) !=1 + !!PageSwapCache (page)) { +if (page_count (page) !=1 +PageSwapCache (page)) {unlock_page (page); result =SCAN_PAGE_COUNT ; goto out;
@@ -1181,7 +1181,7 @@ static int khugepaged_scan_pmd(struct mm_struct *mm,* The page must only be referenced by the scanned process * and page swap cache. */ -if (page_count (page) !=1 + !!PageSwapCache (page)) { +if (page_count (page) !=1 +PageSwapCache (page)) { result =SCAN_PAGE_COUNT ; goto out_unmap; }
Signature · 1 line
2.7.4
Quoted 7 lines · Minchan Kim
With the discussion[1], I found it seems there are every PageFlags functions return bool at this moment so we don't need double negation any more.
Although it's not a problem to keep it, it makes future users confused to use dobule negation for them, too.Remove such possibility.
A quick search of '!!Page' in the source tree does not show any other place having this double negation. So I guess this is all which need to be fixed.
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Hi Anshuman,
Quoted 7 lines · Anshuman Khandual
Quoted 6 lines · Minchan Kim
With the discussion[1], I found it seems there are every PageFlags functions return bool at this moment so we don't need double negation any more.
Although it's not a problem to keep it, it makes future users confused to use dobule negation for them, too.
Quoted 5 lines
Quoted 1 line
Remove such possibility.
A quick search of '!!Page' in the source tree does not show any other place having this double negation. So I guess this is all which need to be fixed.
Yeb. That's the why my patch includes only khugepagd part but my concern is PageFlags returns int type not boolean so user might be confused easily and tempted to use dobule negation.
Other side is they who create new custom PageXXX(e.g., PageMovable) should keep it in mind that they should return 0 or 1 although fucntion prototype's return value is int type. It shouldn't be documented nowhere. Although we can add a little description somewhere in page-flags.h, I believe changing to boolean is more clear/not-error-prone so Chen's work is enough worth, I think.
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Vlastimil Babka
Acked-byQuoted 20 lines · Minchan Kim
Hi Anshuman,
Quoted 7 lines · Anshuman Khandual
Quoted 6 lines · Minchan Kim
With the discussion[1], I found it seems there are every PageFlags functions return bool at this moment so we don't need double negation any more.
Although it's not a problem to keep it, it makes future users confused to use dobule negation for them, too.Quoted 5 lines
Quoted 1 line
Remove such possibility.
A quick search of '!!Page' in the source tree does not show any other place having this double negation. So I guess this is all which need to be fixed.
Yeb. That's the why my patch includes only khugepagd part but my concern is PageFlags returns int type not boolean so user might be confused easily and tempted to use dobule negation.
Quoted 6 lines
Other side is they who create new custom
PageXXX(e.g., PageMovable)should keep it in mind that they should return 0 or 1 although fucntion prototype's return value is int type.It shouldn't be
documented nowhere.
Was this double negation intentional? :P
Quoted 3 lines
Although we can add a little description
somewhere inpage-flags.h, I believe changing to boolean is more clear/not-error-prone so Chen's work is enough worth, I think.
Agree, unless some arches benefit from the int by performance for some reason (no idea if it's possible).
Anyway, to your original patch:
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Michal Hocko
Acked-byQuoted 1 line · Vlastimil Babka
On 03/08/2017 06:25 AM, Minchan Kim wrote:
[...]
Quoted 6 lines
Quoted 3 lines
Although we can add a little description
somewhere inpage-flags.h, I believe changing to boolean is more clear/not-error-prone so Chen's work is enough worth, I think.Agree, unless some arches benefit from the int by performance for some reason (no idea if it's possible).
I have a vague recollection somebody tried to change this to bool and the resulting code was larger on some architecture. Do not remember any details though
Btw. feel free to add
Signature · 8 lines
Michal Hocko SUSE Labs -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Hi Vlastimil,
Quoted 21 lines · Vlastimil Babka
Quoted 20 lines · Minchan Kim
Hi Anshuman,
Quoted 7 lines · Anshuman Khandual
Quoted 6 lines · Minchan Kim
With the discussion[1], I found it seems there are every PageFlags functions return bool at this moment so we don't need double negation any more.
Although it's not a problem to keep it, it makes future users confused to use dobule negation for them, too.Quoted 5 lines
Quoted 1 line
Remove such possibility.
A quick search of '!!Page' in the source tree does not show any other place having this double negation. So I guess this is all which need to be fixed.
Yeb. That's the why my patch includes only khugepagd part but my concern is PageFlags returns int type not boolean so user might be confused easily and tempted to use dobule negation.
Quoted 8 lines
Quoted 6 lines
Other side is they who create new custom
PageXXX(e.g., PageMovable)should keep it in mind that they should return 0 or 1 although fucntion prototype's return value is int type.It shouldn't be
documented nowhere.Was this double negation intentional? :P
Nice catch!
It seems you have a crystal ball. ;-)
Quoted 11 lines
Quoted 4 lines
Although we can add a little description
somewhere inpage-flags.h, I believe changing to boolean is more clear/not-error-prone so Chen's work is enough worth, I think.Agree, unless some arches benefit from the int by performance for some reason (no idea if it's possible).
Anyway, to your original patch:
Acked-by Vlastimil Babka <[email protected]>
Thanks!
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 14 lines · Minchan Kim
With the discussion[1], I found it seems there are every PageFlags functions return bool at this moment so we don't need double negation any more.
Although it's not a problem to keep it, it makes future users confused to use dobule negation for them, too.Remove such possibility.
[1] https://marc.info/?l=linux-kernel&m=148881578820434
Frankly sepaking, I like every PageFlags return bool instead of int. It will make it clear. AFAIR, Chen Gang had tried it but don't know why it was not merged at that time.
Quoted 8 lines
http://lkml.kernel.org/r/[email protected]
Cc Vlastimil Vlastimil Babka <[email protected]>Cc Michal Hocko <[email protected]>Cc Kirill A. Shutemov <[email protected]>Cc Johannes Weiner <[email protected]>Cc Chen Gang <[email protected]>Signed-off-by Minchan Kim <[email protected]>
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>