Re: [RFC 2/2] mm: additional checks to page flag set/clear
From: Kirill A. Shutemov
Date: Mon Dec 30 2013 - 07:12:34 EST
On Sat, Dec 28, 2013 at 08:45:04PM -0500, Sasha Levin wrote:
> Check if the flag is already set before setting it, and vice versa
> for clearing.
>
> Obviously setting or clearing a flag twice isn't a problem on it's
> own, but it implies that there's an issue where some piece of code
> assumed an opposite state of the flag.
BUG() is overkill. WARN_ONCE is more then enough.
And I don't think this kind of checks make sense for all flags.
Have you seen any obviously broken case which these checks could catch?
> Signed-off-by: Sasha Levin <sasha.levin@xxxxxxxxxx>
> ---
> include/linux/page-flags.h | 12 ++++++++++--
> 1 file changed, 10 insertions(+), 2 deletions(-)
>
> diff --git a/include/linux/page-flags.h b/include/linux/page-flags.h
> index d1fe1a7..36b0bef 100644
> --- a/include/linux/page-flags.h
> +++ b/include/linux/page-flags.h
> @@ -130,6 +130,12 @@ enum pageflags {
>
> #ifndef __GENERATING_BOUNDS_H
>
> +#ifdef CONFIG_DEBUG_VM_PAGE_FLAGS
> +#define VM_ASSERT_FLAG(assert, page) VM_BUG_ON_PAGE(assert, page)
> +#else
> +#define VM_ASSERT_FLAG(assert, page) do { } while (0)
> +#endif
> +
> /*
> * Macros to create function definitions for page flags
> */
> @@ -139,11 +145,13 @@ static inline int Page##uname(const struct page *page) \
>
> #define SETPAGEFLAG(uname, lname) \
> static inline void SetPage##uname(struct page *page) \
> - { set_bit(PG_##lname, &page->flags); }
> + { VM_ASSERT_FLAG(Page##uname(page), page); \
> + set_bit(PG_##lname, &page->flags); }
>
> #define CLEARPAGEFLAG(uname, lname) \
> static inline void ClearPage##uname(struct page *page) \
> - { clear_bit(PG_##lname, &page->flags); }
> + { VM_ASSERT_FLAG(!Page##uname(page), page); \
> + clear_bit(PG_##lname, &page->flags); }
>
> #define __SETPAGEFLAG(uname, lname) \
> static inline void __SetPage##uname(struct page *page) \
> --
> 1.8.3.2
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to majordomo@xxxxxxxxxxxxxxx
> More majordomo info at http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at http://www.tux.org/lkml/
--
Kirill A. Shutemov
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/