Re: [PATCH 07/12] percpu: add block level scan_hint

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Sun, Mar 03, 2019 at 06:01:42AM +0000, Peng Fan wrote:
> Hi Dennis
> 
> > -----Original Message-----
> > From: owner-linux-mm@xxxxxxxxx [mailto:owner-linux-mm@xxxxxxxxx] On
> > Behalf Of Dennis Zhou
> > Sent: 2019年2月28日 10:19
> > To: Dennis Zhou <dennis@xxxxxxxxxx>; Tejun Heo <tj@xxxxxxxxxx>; Christoph
> > Lameter <cl@xxxxxxxxx>
> > Cc: Vlad Buslov <vladbu@xxxxxxxxxxxx>; kernel-team@xxxxxx;
> > linux-mm@xxxxxxxxx; linux-kernel@xxxxxxxxxxxxxxx
> > Subject: [PATCH 07/12] percpu: add block level scan_hint
> > 
> > Fragmentation can cause both blocks and chunks to have an early first_firee
> > bit available, but only able to satisfy allocations much later on. This patch
> > introduces a scan_hint to help mitigate some unnecessary scanning.
> > 
> > The scan_hint remembers the largest area prior to the contig_hint. If the
> > contig_hint == scan_hint, then scan_hint_start > contig_hint_start.
> > This is necessary for scan_hint discovery when refreshing a block.
> > 
> > Signed-off-by: Dennis Zhou <dennis@xxxxxxxxxx>
> > ---
> >  mm/percpu-internal.h |   9 ++++
> >  mm/percpu.c          | 101
> > ++++++++++++++++++++++++++++++++++++++++---
> >  2 files changed, 103 insertions(+), 7 deletions(-)
> > 
> > diff --git a/mm/percpu-internal.h b/mm/percpu-internal.h index
> > b1739dc06b73..ec58b244545d 100644
> > --- a/mm/percpu-internal.h
> > +++ b/mm/percpu-internal.h
> > @@ -9,8 +9,17 @@
> >   * pcpu_block_md is the metadata block struct.
> >   * Each chunk's bitmap is split into a number of full blocks.
> >   * All units are in terms of bits.
> > + *
> > + * The scan hint is the largest known contiguous area before the contig hint.
> > + * It is not necessarily the actual largest contig hint though.  There
> > + is an
> > + * invariant that the scan_hint_start > contig_hint_start iff
> > + * scan_hint == contig_hint.  This is necessary because when scanning
> > + forward,
> > + * we don't know if a new contig hint would be better than the current one.
> >   */
> >  struct pcpu_block_md {
> > +	int			scan_hint;	/* scan hint for block */
> > +	int			scan_hint_start; /* block relative starting
> > +						    position of the scan hint */
> >  	int                     contig_hint;    /* contig hint for block */
> >  	int                     contig_hint_start; /* block relative starting
> >  						      position of the contig hint */ diff --git
> > a/mm/percpu.c b/mm/percpu.c index 967c9cc3a928..df1aacf58ac8 100644
> > --- a/mm/percpu.c
> > +++ b/mm/percpu.c
> > @@ -320,6 +320,34 @@ static unsigned long pcpu_block_off_to_off(int index,
> > int off)
> >  	return index * PCPU_BITMAP_BLOCK_BITS + off;  }
> > 
> > +/*
> > + * pcpu_next_hint - determine which hint to use
> > + * @block: block of interest
> > + * @alloc_bits: size of allocation
> > + *
> > + * This determines if we should scan based on the scan_hint or first_free.
> > + * In general, we want to scan from first_free to fulfill allocations
> > +by
> > + * first fit.  However, if we know a scan_hint at position
> > +scan_hint_start
> > + * cannot fulfill an allocation, we can begin scanning from there
> > +knowing
> > + * the contig_hint will be our fallback.
> > + */
> > +static int pcpu_next_hint(struct pcpu_block_md *block, int alloc_bits)
> > +{
> > +	/*
> > +	 * The three conditions below determine if we can skip past the
> > +	 * scan_hint.  First, does the scan hint exist.  Second, is the
> > +	 * contig_hint after the scan_hint (possibly not true iff
> > +	 * contig_hint == scan_hint).  Third, is the allocation request
> > +	 * larger than the scan_hint.
> > +	 */
> > +	if (block->scan_hint &&
> > +	    block->contig_hint_start > block->scan_hint_start &&
> > +	    alloc_bits > block->scan_hint)
> > +		return block->scan_hint_start + block->scan_hint;
> > +
> > +	return block->first_free;
> > +}
> > +
> >  /**
> >   * pcpu_next_md_free_region - finds the next hint free area
> >   * @chunk: chunk of interest
> > @@ -415,9 +443,11 @@ static void pcpu_next_fit_region(struct pcpu_chunk
> > *chunk, int alloc_bits,
> >  		if (block->contig_hint &&
> >  		    block->contig_hint_start >= block_off &&
> >  		    block->contig_hint >= *bits + alloc_bits) {
> > +			int start = pcpu_next_hint(block, alloc_bits);
> > +
> >  			*bits += alloc_bits + block->contig_hint_start -
> > -				 block->first_free;
> > -			*bit_off = pcpu_block_off_to_off(i, block->first_free);
> > +				 start;
> 
> This might not relevant to this patch.
> Not sure it is intended or not.
> For `alloc_bits + block->contig_hink_start - [block->first_free or start]`
> If the reason is to let pcpu_is_populated return a proper next_off when pcpu_is_populated
> fail, it makes sense. If not, why not just use *bits += alloc_bits.
> 

This is how the iterator works. Without it, it doesn't.

Thanks,
Dennis




[Index of Archives]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Bugtraq]     [Linux OMAP]     [Linux MIPS]     [eCos]     [Asterisk Internet PBX]     [Linux API]

  Powered by Linux