From: Peng Fan <peng.fan@nxp.com>
To: Dennis Zhou <dennis@kernel.org>
Cc: Tejun Heo <tj@kernel.org>, Christoph Lameter <cl@linux.com>,
Vlad Buslov <vladbu@mellanox.com>,
"kernel-team@fb.com" <kernel-team@fb.com>,
"linux-mm@kvack.org" <linux-mm@kvack.org>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: RE: [PATCH 07/12] percpu: add block level scan_hint
Date: Mon, 4 Mar 2019 09:36:24 +0000 [thread overview]
Message-ID: <AM0PR04MB44812F00CC6FA3DE09D8327688710@AM0PR04MB4481.eurprd04.prod.outlook.com> (raw)
In-Reply-To: <20190303202323.GB4868@dennisz-mbp.dhcp.thefacebook.com>
> -----Original Message-----
> From: Dennis Zhou [mailto:dennis@kernel.org]
> Sent: 2019年3月4日 4:23
> To: Peng Fan <peng.fan@nxp.com>
> Cc: Tejun Heo <tj@kernel.org>; Christoph Lameter <cl@linux.com>; Vlad
> Buslov <vladbu@mellanox.com>; kernel-team@fb.com; linux-mm@kvack.org;
> linux-kernel@vger.kernel.org
> Subject: Re: [PATCH 07/12] percpu: add block level scan_hint
>
> On Sun, Mar 03, 2019 at 06:01:42AM +0000, Peng Fan wrote:
> > Hi Dennis
> >
> > > -----Original Message-----
> > > From: owner-linux-mm@kvack.org [mailto:owner-linux-mm@kvack.org]
> On
> > > Behalf Of Dennis Zhou
> > > Sent: 2019年2月28日 10:19
> > > To: Dennis Zhou <dennis@kernel.org>; Tejun Heo <tj@kernel.org>;
> > > Christoph Lameter <cl@linux.com>
> > > Cc: Vlad Buslov <vladbu@mellanox.com>; kernel-team@fb.com;
> > > linux-mm@kvack.org; linux-kernel@vger.kernel.org
> > > 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@kernel.org>
> > > ---
> > > 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.
Oops,I made a mistake, you are right, the iterator needs such logic.
Thanks,
Peng.
>
> Thanks,
> Dennis
next prev parent reply other threads:[~2019-03-04 9:36 UTC|newest]
Thread overview: 35+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-02-28 2:18 [PATCH 00/12] introduce percpu block scan_hint Dennis Zhou
2019-02-28 2:18 ` [PATCH 01/12] percpu: update free path with correct new free region Dennis Zhou
2019-03-02 12:56 ` Peng Fan
2019-02-28 2:18 ` [PATCH 02/12] percpu: do not search past bitmap when allocating an area Dennis Zhou
2019-03-02 13:32 ` Peng Fan
2019-03-02 22:23 ` Dennis Zhou
2019-03-03 8:41 ` Peng Fan
2019-02-28 2:18 ` [PATCH 03/12] percpu: introduce helper to determine if two regions overlap Dennis Zhou
2019-03-02 13:37 ` Peng Fan
2019-03-02 22:24 ` Dennis Zhou
2019-02-28 2:18 ` [PATCH 04/12] percpu: manage chunks based on contig_bits instead of free_bytes Dennis Zhou
2019-03-02 13:48 ` Peng Fan
2019-03-02 22:32 ` Dennis Zhou
2019-03-03 8:42 ` Peng Fan
2019-02-28 2:18 ` [PATCH 05/12] percpu: relegate chunks unusable when failing small allocations Dennis Zhou
2019-03-02 13:55 ` Peng Fan
2019-03-02 22:34 ` Dennis Zhou
2019-02-28 2:18 ` [PATCH 06/12] percpu: set PCPU_BITMAP_BLOCK_SIZE to PAGE_SIZE Dennis Zhou
2019-03-03 4:56 ` Peng Fan
2019-02-28 2:18 ` [PATCH 07/12] percpu: add block level scan_hint Dennis Zhou
2019-03-03 6:01 ` Peng Fan
2019-03-03 20:23 ` Dennis Zhou
2019-03-04 9:36 ` Peng Fan [this message]
2019-02-28 2:18 ` [PATCH 08/12] percpu: remember largest area skipped during allocation Dennis Zhou
2019-02-28 2:18 ` [PATCH 09/12] percpu: use block scan_hint to only scan forward Dennis Zhou
2019-02-28 2:18 ` [PATCH 10/12] percpu: make pcpu_block_md generic Dennis Zhou
2019-03-03 6:35 ` Peng Fan
2019-02-28 2:18 ` [PATCH 11/12] percpu: convert chunk hints to be based on pcpu_block_md Dennis Zhou
2019-03-03 8:18 ` Peng Fan
2019-03-03 20:22 ` Dennis Zhou
2019-03-04 6:36 ` Peng Fan
2019-02-28 2:18 ` [PATCH 12/12] percpu: use chunk scan_hint to skip some scanning Dennis Zhou
2019-03-03 8:38 ` Peng Fan
2019-02-28 14:47 ` [PATCH 00/12] introduce percpu block scan_hint Vlad Buslov
2019-03-13 20:19 ` Dennis Zhou
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=AM0PR04MB44812F00CC6FA3DE09D8327688710@AM0PR04MB4481.eurprd04.prod.outlook.com \
--to=peng.fan@nxp.com \
--cc=cl@linux.com \
--cc=dennis@kernel.org \
--cc=kernel-team@fb.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=tj@kernel.org \
--cc=vladbu@mellanox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox