Subject: Re: [PATCH 10/17] netvm: Allow skb allocation to use PFMEMALLOC reserves

From: Peter Zijlstra <[email-masked]>
Date: Fri, 11 May 2012 16:42:30 +0200

On Fri, 2012-05-11 at 15:32 +0100, Mel Gorman wrote:
> > > +extern atomic_t memalloc_socks;
> > > +static inline int sk_memalloc_socks(void)
> > > +{
> > > +   return atomic_read(&memalloc_socks);
> > > +}
> > 
> > Please change this to be a static branch.
> > 
> 
> Will do. I renamed memalloc_socks to sk_memalloc_socks, made it a int as
> atomics are unnecessary and I check it directly in a branch instead of a
> static inline. It should be relatively easy for the branch predictor. 

David means you to use include/linux/jump_label.h.

static struct static_key sk_memalloc_socks = STATIC_KEY_INIT_FALSE;

and have your function read:

static inline bool sk_memalloc_socks(void)
{
	return static_key_false(&sk_memalloc_socks);
}

which can be modified using:

  static_key_slow_inc(&sk_memalloc_socks);

or

  static_key_slow_dec(&sk_memalloc_socks);

This magic goo turns the branch into self-modifying code such that the
branch is an unconditional jump at runtime.

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email-masked].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email-masked]"> [email-masked] </a>