linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Matthew Wilcox <willy@infradead.org>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: Souptick Joarder <jrdr.linux@gmail.com>, linux-mm@kvack.org
Subject: Re: [PATCH] include: mm: Adding new inline function vmf_error
Date: Thu, 5 Apr 2018 13:26:51 -0700	[thread overview]
Message-ID: <20180405202651.GB3666@bombadil.infradead.org> (raw)
In-Reply-To: <20180405125322.2ef3abfc6159a72725095bd0@linux-foundation.org>

On Thu, Apr 05, 2018 at 12:53:22PM -0700, Andrew Morton wrote:
> > +static inline vm_fault_t vmf_error(int err)
> > +{
> > +	vm_fault_t ret;
> > +
> > +	if (err == -ENOMEM)
> > +		ret = VM_FAULT_OOM;
> > +	else
> > +		ret = VM_FAULT_SIGBUS;
> > +
> > +	return ret;
> > +}
> > +
> 
> That's a bit verbose.  Why not simply
> 
> 	return (err == -ENOMEM) ? VM_FAULT_OOM : VM_FAULT_SIGBUS;

That's a little skimpy for my taste (although Souptick's is more verbose
than I like too) ... I suggested this:

> > @@ -8983,9 +8984,9 @@ int btrfs_page_mkwrite(struct vm_fault *vmf)
> >  	}
> >  	if (ret) {
> >  		if (ret == -ENOMEM)
> > -			ret = VM_FAULT_OOM;
> > +			retval = VM_FAULT_OOM;
> >  		else /* -ENOSPC, -EIO, etc */
> > -			ret = VM_FAULT_SIGBUS;
> > +			retval = VM_FAULT_SIGBUS;
> >  		if (reserved)
> >  			goto out;
> >  		goto out_noreserve;
> 
> I'm seeing this pattern _a lot_ in filesystems.  It gets written in a
> few different ways, but
> 
> 	ret = (err == -ENOMEM) ? VM_FAULT_OOM : VM_FAULT_SIGBUS;
> 
> is really common.  I think we should do a helper function as part of
> these cleanups ... maybe:
> 
> static inline vm_fault_t vmf_error(int errno)
> {
> 	if (err == -ENOMEM)
> 		return VM_FAULT_OOM;
> 	return VM_FAULT_SIGBUS;
> }
> 
> -		if (ret == -ENOMEM)
> -			ret = VM_FAULT_OOM;
> -		else /* -ENOSPC, -EIO, etc */
> -			ret = VM_FAULT_SIGBUS;
> +		ret = vmf_error(err);
> 
> I know we've mostly been deleting these errno-to-vm_fault converters,
> but those try to do too much -- they handle an errno of 0 (when there
> are at least three ways to return success -- 0, NOPAGE and LOCKED),
> and often they've encoded some other VM_FAULT code in a different
> errno, eg the way block_page_mkwrite() uses -EFAULT.
> 
> There are a few other error codes to handle under special conditions,
> but the caller can handle them first.  eg I see block_page_mkwrite()
> eventually looking like this:
> 
> 	err = __block_write_begin(page, 0, end, get_block);
> 	if (!err)
> 		err = block_commit_write(page, 0, end);
> 
> 	if (unlikely(err < 0))
> 		goto error;
> 	set_page_dirty(page);
> 	wait_for_stable_page(page);
> 	return 0;
> error:
> 	if (err == -EAGAIN)
> 		ret = VM_FAULT_NOPAGE;
> 	else
> 		ret = vmf_error(err);
> out_unlock:
> 	unlock_page(page);
> 	return ret;

  reply	other threads:[~2018-04-05 20:26 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-04-05 16:22 [PATCH] include: mm: Adding new inline function vmf_error Souptick Joarder
2018-04-05 16:52 ` Matthew Wilcox
2018-04-05 19:53 ` Andrew Morton
2018-04-05 20:26   ` Matthew Wilcox [this message]
2018-05-02  6:17     ` Souptick Joarder
2018-05-02 21:12       ` Andrew Morton

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=20180405202651.GB3666@bombadil.infradead.org \
    --to=willy@infradead.org \
    --cc=akpm@linux-foundation.org \
    --cc=jrdr.linux@gmail.com \
    --cc=linux-mm@kvack.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;
as well as URLs for NNTP newsgroup(s).