linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Michal Hocko <mhocko@suse.com>
To: Uladzislau Rezki <urezki@gmail.com>
Cc: Andrew Morton <akpm@linux-foundation.org>,
	Dave Chinner <david@fromorbit.com>, Neil Brown <neilb@suse.de>,
	Christoph Hellwig <hch@lst.de>,
	linux-fsdevel@vger.kernel.org, linux-mm@kvack.org,
	LKML <linux-kernel@vger.kernel.org>,
	Ilya Dryomov <idryomov@gmail.com>,
	Jeff Layton <jlayton@kernel.org>
Subject: Re: [PATCH v2 2/4] mm/vmalloc: add support for __GFP_NOFAIL
Date: Thu, 25 Nov 2021 09:46:39 +0100	[thread overview]
Message-ID: <YZ9Nb2XA/OGWL1zz@dhcp22.suse.cz> (raw)
In-Reply-To: <YZ6cfoQah8Wo1eSZ@pc638.lan>

On Wed 24-11-21 21:11:42, Uladzislau Rezki wrote:
> On Tue, Nov 23, 2021 at 05:02:38PM -0800, Andrew Morton wrote:
> > On Tue, 23 Nov 2021 20:01:50 +0100 Uladzislau Rezki <urezki@gmail.com> wrote:
> > 
> > > On Mon, Nov 22, 2021 at 04:32:31PM +0100, Michal Hocko wrote:
> > > > From: Michal Hocko <mhocko@suse.com>
> > > > 
> > > > Dave Chinner has mentioned that some of the xfs code would benefit from
> > > > kvmalloc support for __GFP_NOFAIL because they have allocations that
> > > > cannot fail and they do not fit into a single page.
> > 
> > Perhaps we should tell xfs "no, do it internally".  Because this is a
> > rather nasty-looking thing - do we want to encourage other callsites to
> > start using it?
> > 
> > > > The large part of the vmalloc implementation already complies with the
> > > > given gfp flags so there is no work for those to be done. The area
> > > > and page table allocations are an exception to that. Implement a retry
> > > > loop for those.
> > > > 
> > > > Add a short sleep before retrying. 1 jiffy is a completely random
> > > > timeout. Ideally the retry would wait for an explicit event - e.g.
> > > > a change to the vmalloc space change if the failure was caused by
> > > > the space fragmentation or depletion. But there are multiple different
> > > > reasons to retry and this could become much more complex. Keep the retry
> > > > simple for now and just sleep to prevent from hogging CPUs.
> > > > 
> > 
> > Yes, the horse has already bolted.  But we didn't want that horse anyway ;)
> > 
> > I added GFP_NOFAIL back in the mesozoic era because quite a lot of
> > sites were doing open-coded try-forever loops.  I thought "hey, they
> > shouldn't be doing that in the first place, but let's at least
> > centralize the concept to reduce code size, code duplication and so
> > it's something we can now grep for".  But longer term, all GFP_NOFAIL
> > sites should be reworked to no longer need to do the retry-forever
> > thing.  In retrospect, this bright idea of mine seems to have added
> > license for more sites to use retry-forever.  Sigh.
> > 
> > > > +		if (nofail) {
> > > > +			schedule_timeout_uninterruptible(1);
> > > > +			goto again;
> > > > +		}
> > 
> > The idea behind congestion_wait() is to prevent us from having to
> > hard-wire delays like this.  congestion_wait(1) would sleep for up to
> > one millisecond, but will return earlier if reclaim events happened
> > which make it likely that the caller can now proceed with the
> > allocation event, successfully.
> > 
> > However it turns out that congestion_wait() was quietly broken at the
> > block level some time ago.  We could perhaps resurrect the concept at
> > another level - say by releasing congestion_wait() callers if an amount
> > of memory newly becomes allocatable.  This obviously asks for inclusion
> > of zone/node/etc info from the congestion_wait() caller.  But that's
> > just an optimization - if the newly-available memory isn't useful to
> > the congestion_wait() caller, they just fail the allocation attempts
> > and wait again.
> > 
> > > well that is sad...
> > > I have raised two concerns in our previous discussion about this change,
> > 
> > Can you please reiterate those concerns here?
> >
> 1. I proposed to repeat(if fails) in one solid place, i.e. get rid of
> duplication and spreading the logic across several places. This is about
> simplification.

I am all for simplifications. But the presented simplification lead to 2) and ...

> 2. Second one is about to do an unwinding and release everything what we
> have just accumulated in terms of memory consumption. The failure might
> occur, if so a condition we are in is a low memory one or high memory
> pressure. In this case, since we are about to sleep some milliseconds
> in order to repeat later, IMHO it makes sense to release memory:
> 
> - to prevent killing apps or possible OOM;
> - we can end up looping quite a lot of time or even forever if users do
>   nasty things with vmalloc API and __GFP_NOFAIL flag.

... this is where we disagree and I have tried to explain why. The primary
memory to allocate are pages to back the vmalloc area. Failing to
allocate few page tables - which btw. do not fail as they are order-0 -
and result into the whole and much more expensive work to allocate the
former is really wasteful. You've had a concern about OOM killer
invocation while retrying the page table allocation but you should
realize that page table allocations might already invoke OOM killer so that
is absolutely nothing new.
-- 
Michal Hocko
SUSE Labs

  reply	other threads:[~2021-11-25  8:48 UTC|newest]

Thread overview: 44+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-22 15:32 [PATCH v2 0/4] extend vmalloc support for constrained allocations Michal Hocko
2021-11-22 15:32 ` [PATCH v2 1/4] mm/vmalloc: alloc GFP_NO{FS,IO} for vmalloc Michal Hocko
2021-11-23 19:05   ` Uladzislau Rezki
2021-11-26 15:13   ` Vlastimil Babka
2021-11-22 15:32 ` [PATCH v2 2/4] mm/vmalloc: add support for __GFP_NOFAIL Michal Hocko
2021-11-23 19:01   ` Uladzislau Rezki
2021-11-23 20:09     ` Michal Hocko
2021-11-24 20:46       ` Uladzislau Rezki
2021-11-24  1:02     ` Andrew Morton
2021-11-24  3:16       ` NeilBrown
2021-11-24  3:48         ` Andrew Morton
2021-11-24  5:23           ` NeilBrown
2021-11-25  0:32             ` Theodore Y. Ts'o
2021-11-26 14:50             ` Vlastimil Babka
2021-11-26 15:09               ` Michal Hocko
2021-11-24 23:45         ` Dave Chinner
2021-11-24  8:43       ` Michal Hocko
2021-11-24 20:37         ` Uladzislau Rezki
2021-11-25  8:48           ` Michal Hocko
2021-11-25 18:40             ` Uladzislau Rezki
2021-11-25 19:21               ` Michal Hocko
2021-11-24 20:11       ` Uladzislau Rezki
2021-11-25  8:46         ` Michal Hocko [this message]
2021-11-25 18:02           ` Uladzislau Rezki
2021-11-25 19:24             ` Michal Hocko
2021-11-25 20:03               ` Uladzislau Rezki
2021-11-25 20:13                 ` Michal Hocko
2021-11-25 20:21                   ` Uladzislau Rezki
2021-11-26 10:48   ` Michal Hocko
2021-11-28  0:00     ` Andrew Morton
2021-11-29  8:56       ` Michal Hocko
2021-11-26 15:32   ` Vlastimil Babka
2021-11-22 15:32 ` [PATCH v2 3/4] mm/vmalloc: be more explicit about supported gfp flags Michal Hocko
2021-11-23 18:58   ` Uladzislau Rezki
2021-11-26 15:39   ` Vlastimil Babka
2021-11-22 15:32 ` [PATCH v2 4/4] mm: allow !GFP_KERNEL allocations for kvmalloc Michal Hocko
2021-11-23 18:57   ` Uladzislau Rezki
2021-11-23 19:02   ` Uladzislau Rezki
2021-11-26 15:50   ` Vlastimil Babka
2021-11-24 22:55 ` [PATCH v2 0/4] extend vmalloc support for constrained allocations Dave Chinner
2021-11-25  8:58   ` Michal Hocko
2021-11-25  9:30     ` Michal Hocko
2021-11-25 21:30       ` Dave Chinner
2021-11-26  9:20       ` Vlastimil Babka

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=YZ9Nb2XA/OGWL1zz@dhcp22.suse.cz \
    --to=mhocko@suse.com \
    --cc=akpm@linux-foundation.org \
    --cc=david@fromorbit.com \
    --cc=hch@lst.de \
    --cc=idryomov@gmail.com \
    --cc=jlayton@kernel.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=neilb@suse.de \
    --cc=urezki@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).