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, 6 May 2014 23:24:08 +0100
From:	Mel Gorman <mgorman@...e.de>
To:	Peter Zijlstra <peterz@...radead.org>
Cc:	Linux-MM <linux-mm@...ck.org>,
	Linux-FSDevel <linux-fsdevel@...r.kernel.org>,
	Johannes Weiner <hannes@...xchg.org>,
	Vlastimil Babka <vbabka@...e.cz>, Jan Kara <jack@...e.cz>,
	Michal Hocko <mhocko@...e.cz>, Hugh Dickins <hughd@...gle.com>,
	Linux Kernel <linux-kernel@...r.kernel.org>
Subject: Re: [PATCH 08/17] mm: page_alloc: Use word-based accesses for
 get/set pageblock bitmaps

On Tue, May 06, 2014 at 10:34:49PM +0200, Peter Zijlstra wrote:
> On Thu, May 01, 2014 at 09:44:39AM +0100, Mel Gorman wrote:
> > +void set_pfnblock_flags_group(struct page *page, unsigned long flags,
> > +					unsigned long end_bitidx,
> > +					unsigned long nr_flag_bits,
> > +					unsigned long mask)
> >  {
> >  	struct zone *zone;
> >  	unsigned long *bitmap;
> > +	unsigned long pfn, bitidx, word_bitidx;
> > +	unsigned long old_word, new_word;
> > +
> > +	BUILD_BUG_ON(NR_PAGEBLOCK_BITS != 4);
> >  
> >  	zone = page_zone(page);
> >  	pfn = page_to_pfn(page);
> >  	bitmap = get_pageblock_bitmap(zone, pfn);
> >  	bitidx = pfn_to_bitidx(zone, pfn);
> > +	word_bitidx = bitidx / BITS_PER_LONG;
> > +	bitidx &= (BITS_PER_LONG-1);
> > +
> >  	VM_BUG_ON_PAGE(!zone_spans_pfn(zone, pfn), page);
> >  
> > +	bitidx += end_bitidx;
> > +	mask <<= (BITS_PER_LONG - bitidx - 1);
> > +	flags <<= (BITS_PER_LONG - bitidx - 1);
> > +
> > +	do {
> > +		old_word = ACCESS_ONCE(bitmap[word_bitidx]);
> > +		new_word = (old_word & ~mask) | flags;
> > +	} while (cmpxchg(&bitmap[word_bitidx], old_word, new_word) != old_word);
> >  }
> 
> You could write it like:
> 
> 	word = ACCESS_ONCE(bitmap[word_bitidx]);
> 	for (;;) {
> 		old_word = cmpxchg(&bitmap[word_bitidx], word, (word & ~mask) | flags);
> 		if (word == old_word);
> 			break;
> 		word = old_word;
> 	}
> 
> It has a slightly tighter loop by avoiding the read being included.

Thanks, I'll use that.

-- 
Mel Gorman
SUSE Labs
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ