lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:	Tue, 26 Apr 2011 22:05:40 +1000
From:	NeilBrown <neilb@...e.de>
To:	Mel Gorman <mgorman@...e.de>
Cc:	Linux-MM <linux-mm@...ck.org>,
	Linux-Netdev <netdev@...r.kernel.org>,
	LKML <linux-kernel@...r.kernel.org>,
	David Miller <davem@...emloft.net>,
	Peter Zijlstra <a.p.zijlstra@...llo.nl>
Subject: Re: [PATCH 02/13] mm: sl[au]b: Add knowledge of PFMEMALLOC reserve
 pages

On Tue, 26 Apr 2011 12:33:48 +0100 Mel Gorman <mgorman@...e.de> wrote:

> On Tue, 2011-04-26 at 21:15 +1000, NeilBrown wrote:
> > On Tue, 26 Apr 2011 08:36:43 +0100 Mel Gorman <mgorman@...e.de> wrote:
> > 
> > > +bool gfp_pfmemalloc_allowed(gfp_t gfp_mask)
> > > +{
> > > +	return gfp_to_alloc_flags(gfp_mask) & ALLOC_PFMEMALLOC;
> > > +}
> > > +
> > >  static inline struct page *
> > >  __alloc_pages_slowpath(gfp_t gfp_mask, unsigned int order,
> > >  	struct zonelist *zonelist, enum zone_type high_zoneidx,
> > > @@ -2202,8 +2211,16 @@ nopage:
> > >  got_pg:
> > >  	if (kmemcheck_enabled)
> > >  		kmemcheck_pagealloc_alloc(page, order, gfp_mask);
> > > -	return page;
> > >  
> > > +	/*
> > > +	 * page->pfmemalloc is set when the caller had PFMEMALLOC set or is
> > > +	 * been OOM killed. The expectation is that the caller is taking
> > > +	 * steps that will free more memory. The caller should avoid the
> > > +	 * page being used for !PFMEMALLOC purposes.
> > > +	 */
> > > +	page->pfmemalloc = (alloc_flags & ALLOC_PFMEMALLOC);
> > > +
> > > +	return page;
> > 
> > Linus doesn't seem to be a fan of this construct:
> >    https://lkml.org/lkml/2011/4/1/255
> > 
> 
> There is confusion around this topic. Andrew prefers bool for true/false
> values and it's self-documenting. I tend to prefer it myself for
> readability and there is a slow conversion in the VM from
> ints-used-as-bools to bools and my understanding of bool is that any
> non-zero value will be treated as true (just as it is for int).
> 
> > pfmemalloc is a bool, and the value on the right is either 0 or 0x1000.
> > 
> > If bool happens to be typedefed to 'char' or even 'short', pfmemalloc would
> > always be set to 0.
> 
> It is typedeffed as _Bool though which I thought was able to handle the
> cast appropriately or is that wrong?

Yes, I too believe that _Bool does the right thing, so this particular usage
does happen to be safe in the kernel.  But there is a long tradition of
'bool' being typedefed to an int type so the usage can look wrong.  So maybe
it is best avoided.

I have no strong feeling either way - I just thought I would highlight it.
In general, I like bool, but I don't like automatic casts (I often use
  if (pointer != NULL) ...
because I think it reads better).

Thanks,
NeilBrown



> 
> > Ditto for the gfp_pfmemalloc_allowed function.
> > 
> > Prefixing with '!!' would make it safe.
> > 
> 
> Will do that to avoid any oddities. Thanks
> 

--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ