lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <ZqGO7jtUCM2tG_QZ@google.com>
Date: Wed, 24 Jul 2024 23:31:58 +0000
From: Roman Gushchin <roman.gushchin@...ux.dev>
To: Yosry Ahmed <yosryahmed@...gle.com>
Cc: Andrew Morton <akpm@...ux-foundation.org>, linux-mm@...ck.org,
	linux-kernel@...r.kernel.org, Johannes Weiner <hannes@...xchg.org>,
	Michal Hocko <mhocko@...nel.org>,
	Shakeel Butt <shakeel.butt@...ux.dev>,
	Muchun Song <muchun.song@...ux.dev>
Subject: Re: [PATCH v2 1/5] mm: memcg: don't call propagate_protected_usage()
 needlessly

On Wed, Jul 24, 2024 at 04:13:17PM -0700, Yosry Ahmed wrote:
> On Wed, Jul 24, 2024 at 1:21 PM Roman Gushchin <roman.gushchin@...ux.dev> wrote:
> >
> > Memory protection (min/low) requires a constant tracking of
> > protected memory usage. propagate_protected_usage() is called
> > on each page counters update and does a number of operations
> > even in cases when the actual memory protection functionality
> > is not supported (e.g. hugetlb cgroups or memcg swap counters).
> >
> > It's obviously inefficient and leads to a waste of CPU cycles.
> > It can be addressed by calling propagate_protected_usage() only
> > for the counters which do support memory guarantees. As of now
> > it's only memcg->memory - the unified memory memcg counter.
> >
> > Signed-off-by: Roman Gushchin <roman.gushchin@...ux.dev>
> > ---
> >  include/linux/page_counter.h |  8 +++++++-
> >  mm/hugetlb_cgroup.c          |  4 ++--
> >  mm/memcontrol.c              | 16 ++++++++--------
> >  mm/page_counter.c            | 16 +++++++++++++---
> >  4 files changed, 30 insertions(+), 14 deletions(-)
> >
> > diff --git a/include/linux/page_counter.h b/include/linux/page_counter.h
> > index 860f313182e7..b31fd5b208aa 100644
> > --- a/include/linux/page_counter.h
> > +++ b/include/linux/page_counter.h
> > @@ -32,6 +32,7 @@ struct page_counter {
> >         /* Keep all the read most fields in a separete cacheline. */
> >         CACHELINE_PADDING(_pad2_);
> >
> > +       bool protection_support;
> >         unsigned long min;
> >         unsigned long low;
> >         unsigned long high;
> > @@ -45,12 +46,17 @@ struct page_counter {
> >  #define PAGE_COUNTER_MAX (LONG_MAX / PAGE_SIZE)
> >  #endif
> >
> > +/*
> > + * Protection is supported only for the first counter (with id 0).
> > + */
> >  static inline void page_counter_init(struct page_counter *counter,
> > -                                    struct page_counter *parent)
> > +                                    struct page_counter *parent,
> > +                                    bool protection_support)
> 
> Would it be better to make this an internal helper (e.g.
> __page_counter_init()), and add another API function that passes in
> protection_support=true, for example:
> 
> static inline void page_counter_init_protected(..)
> {
>        __page_counter_init(.., true);
> }
> 
> This will get rid of the naked booleans at the callsites of
> page_counter_init(), which are more difficult to interpret. It will
> also reduce the diff as we only need to change the page_counter_init()
> calls of memcg->memory.
> 
> WDYT?

No strong opinion here. There are basically 2 call sites and I don't expect
this number to grow, so not sure if it makes sense to add 2 new helpers.

Another option I thought about is to leave page_counter_init() as it is
and add a separate function to enable the protection tracking.

Thanks!

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ