Thread (30 messages) flat view 30 messages, 5 authors, 2021-04-12

Re: [PATCH 4/9] mm/page_alloc: optimize code layout for __alloc_pages_bulk

From: Mel Gorman <hidden>
Date: 2021-03-25 12:41:29
Also in: linux-mm, linux-nfs, lkml

On Thu, Mar 25, 2021 at 12:12:17PM +0000, Matthew Wilcox wrote:
On Thu, Mar 25, 2021 at 11:42:23AM +0000, Mel Gorman wrote:
quoted
 
-	if (WARN_ON_ONCE(nr_pages <= 0))
+	if (unlikely(nr_pages <= 0))
 		return 0;
If we made nr_pages unsigned, we wouldn't need this check at all (ok,
we'd still need to figure out what to do with 0).  But then, if a user
inadvertently passes in -ENOMEM, we'll try to allocate 4 billion pages.
This is exactly why nr_pages is signed. An error in accounting by the
caller potentially puts the system under severe memory pressure. This
*should* only be a problem when a new caller of the API is being
implemented. The warning goes away in a later patch for reasons explained
in the changelog.
So maybe we should check it.  Gah, API design is hard.
Yep.

-- 
Mel Gorman
SUSE Labs
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help