linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Kent Overstreet <kent.overstreet@linux.dev>
To: Michal Hocko <mhocko@suse.com>
Cc: linux-mm@kvack.org, Vlastimil Babka <vbabka@suse.cz>,
	 Matthew Wilcox <willy@infradead.org>,
	"Darrick J . Wong" <djwong@kernel.org>
Subject: Re: [PATCH 2/2] mm: introduce PF_MEMALLOC_NOWARN
Date: Sun, 28 Jan 2024 14:43:16 -0500	[thread overview]
Message-ID: <jc7n2mzifvthvav4rryg6liywmk3gqbt5lgggdur2tb3a5yrn7@ebllquxuhnyt> (raw)
In-Reply-To: <ZbZ2nDMkqawqDOEs@tiehlicka>

On Sun, Jan 28, 2024 at 04:45:32PM +0100, Michal Hocko wrote:
> On Fri 26-01-24 17:07:56, Kent Overstreet wrote:
> > If we're using PF_MEMALLOC, we might have a fallback and might not to
> > warn about a failing allocation - thus we need a PF_* equivalent of
> > __GFP_NOWARN.
> 
> Could you be more specific about the user? Is this an allocation from
> the reclaim path or an explicit PF_MEMALLOC one? It would be also really
> helpful to explain why GFP_NOWARN cannot be used directly.

Explicit PF_MEMALLOC.

It's for a call to alloc_inode(), which doesn't take gfp flags, and
plumbing it would require modifying a s_ops callback and would touch
every filesystem - but we want to get away from gfp flags anyways :)

More specifically, the code where I'm using it is doing a "try
GFP_NOWAIT first; if that fails drop locks and do GFP_KERNEL" dance;
it's part of a cleanup for some weird lifetime stuff related to
fs/inode.c.

#define memalloc_flags_do(_flags, _do)						\
({										\
	unsigned _saved_flags = memalloc_flags_save(_flags);			\
	typeof(_do) _ret = _do;							\
	memalloc_noreclaim_restore(_saved_flags);				\
	_ret;									\
})

/*
 * Allocate a new inode, dropping/retaking btree locks if necessary:
 */
static struct bch_inode_info *bch2_new_inode(struct btree_trans *trans)
{
	struct bch_fs *c = trans->c;

	struct bch_inode_info *inode =
		memalloc_flags_do(PF_MEMALLOC|PF_MEMALLOC_NOWARN, to_bch_ei(new_inode(c->vfs_sb)));

	if (unlikely(!inode)) {
		int ret = drop_locks_do(trans, (inode = to_bch_ei(new_inode(c->vfs_sb))) ? 0 : -ENOMEM);
		if (ret && inode)
			discard_new_inode(&inode->v);
		if (ret)
			return ERR_PTR(ret);
	}

	return inode;
}


  reply	other threads:[~2024-01-28 19:43 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-01-26 22:07 [PATCH 1/2] mm: introduce memalloc_flags_{save,restore} Kent Overstreet
2024-01-26 22:07 ` [PATCH 2/2] mm: introduce PF_MEMALLOC_NOWARN Kent Overstreet
2024-01-28 15:45   ` Michal Hocko
2024-01-28 19:43     ` Kent Overstreet [this message]
2024-01-29 10:48       ` Michal Hocko
2024-02-01 11:03         ` Kent Overstreet
2024-02-01 15:59           ` Michal Hocko

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=jc7n2mzifvthvav4rryg6liywmk3gqbt5lgggdur2tb3a5yrn7@ebllquxuhnyt \
    --to=kent.overstreet@linux.dev \
    --cc=djwong@kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=mhocko@suse.com \
    --cc=vbabka@suse.cz \
    --cc=willy@infradead.org \
    /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