Messages in this thread | | | Date | Mon, 26 Oct 2020 20:59:03 -0300 | From | Jason Gunthorpe <> | Subject | Re: [PATCH 1/2] mm: reorganize internal_get_user_pages_fast() |
| |
On Fri, Oct 23, 2020 at 09:44:17PM -0700, John Hubbard wrote: > > Signed-off-by: Jason Gunthorpe <jgg@nvidia.com> > > mm/gup.c | 88 +++++++++++++++++++++++++++++--------------------------- > > 1 file changed, 46 insertions(+), 42 deletions(-) > > > > diff --git a/mm/gup.c b/mm/gup.c > > index 102877ed77a4b4..ecbe1639ea2af7 100644 > > +++ b/mm/gup.c > > @@ -2671,13 +2671,42 @@ static int __gup_longterm_unlocked(unsigned long start, int nr_pages, > > return ret; > > } > > +static unsigned int lockless_pages_from_mm(unsigned long addr, > > It would be slightly more consistent to use "start" here, too, instead of addr. > > Separately, I'm not joyful about the change to unsigned int for the > return type. I understand why you did it and that's perfectly sound > reasoning: there is no -ERRNO possible here, and nr_pinned will always > be >=0. And it's correct, although it does have a type mismatch in the > return value.
I did it because I had to check that ignoring a negative return or doing some wonky negative arithmetic wasn't some sneaky beahvior. It isn't, the value is really unsigned. So I documented it to save the next person this work.
I think the proper response is to ultimately change the gup_pgd_range() call tree to take the unsigned as well.
> a) change all the nr_pages and nr_pinned throughout, to "long", or > > b) change all the nr_pages and nr_pinned all function args, and use int > return types throughout, as a "O or -ERRNO, only" return value > convention.
The gup_pgd_range() this stuff largely does return
I think gup_pgd_range() works as it does due to
> > + start += (unsigned long)nr_pinned << PAGE_SHIFT; > > + pages += nr_pinned; > > + ret = __gup_longterm_unlocked(start, nr_pages - nr_pinned, gup_flags, > > + pages); > > + if (ret < 0) { > > /* Have to be a bit careful with return values */ > > ...and can we move that comment up one level, so that it reads: > > /* Have to be a bit careful with return values */ > if (ret < 0) { > if (nr_pinned) > return nr_pinned; > return ret; > } > return ret + nr_pinned;
I actually deliberately put it inside the if because there is nothing tricky about ret < 0, that is basically perfectly normal. It is only the logic to drop the error code sometimes that is tricky..
> Thinking about this longer term, it would be nice if the whole gup/pup API > set just stopped pretending that anyone cares about partial success, because > they *don't*. If we had return values of "0 or -ERRNO" throughout, and an > additional set of API wrappers that did some sort of limited retry just like > some of the callers do, that would be a happier story.
It seems like a good idea to me
I'll get the other notes in a v2
Thanks, Jason
| |