On Wed, Sep 30, 2020 at 05:27:09PM -0700, Roman Gushchin wrote:
> @@ -448,7 +451,12 @@ static inline void set_page_memcg(struct page *page, 
> struct mem_cgroup *memcg)
>   */
>  static inline struct obj_cgroup **page_objcgs(struct page *page)
>  {
> -     return (struct obj_cgroup **)(READ_ONCE(page->memcg_data) & ~0x1UL);
> +     unsigned long memcg_data = READ_ONCE(page->memcg_data);
> +
> +     VM_BUG_ON_PAGE(memcg_data &&
> +                    !(memcg_data & MEMCG_DATA_OBJCGS), page);

This fits on a single line.

> +     return (struct obj_cgroup **)(memcg_data & ~MEMCG_DATA_FLAGS_MASK);
>  }
>  
>  /*
> @@ -463,8 +471,9 @@ static inline struct obj_cgroup 
> **page_objcgs_check(struct page *page)
>  {
>       unsigned long memcg_data = READ_ONCE(page->memcg_data);
>  
> -     if (memcg_data && (memcg_data & 0x1UL))
> -             return (struct obj_cgroup **)(memcg_data & ~0x1UL);
> +     if (memcg_data && (memcg_data & MEMCG_DATA_OBJCGS))
> +             return (struct obj_cgroup **)
> +                     (memcg_data & ~MEMCG_DATA_FLAGS_MASK);

        if (!memcg_data || (memcg_data & MEMCG_DATA_OBJCGS))
                return NULL;

        return (struct obj_cgroup **)(memcg_data & ~MEMCG_DATA_FLAGS_MASK);

> @@ -479,7 +488,11 @@ static inline struct obj_cgroup 
> **page_objcgs_check(struct page *page)
>  static inline bool set_page_objcgs(struct page *page,
>                                       struct obj_cgroup **objcgs)
>  {
> -     return !cmpxchg(&page->memcg_data, 0, (unsigned long)objcgs | 0x1UL);
> +     unsigned long memcg_data = (unsigned long)objcgs;
> +
> +     memcg_data |= MEMCG_DATA_OBJCGS;
> +
> +     return !cmpxchg(&page->memcg_data, 0, memcg_data);

        return !cmpxchg(&page->memcg_data, 0, memcg_data | MEMCG_DATA_OBJCGS);

Reply via email to