Received: by 2002:ac0:aed5:0:0:0:0:0 with SMTP id t21csp1956535imb; Sun, 3 Mar 2019 12:25:31 -0800 (PST) X-Google-Smtp-Source: APXvYqwtkZkvw+z/oVl4AApy+nbjela/ECV0nPnAgKnxHBSPBRYa4+eX8j0nGyK+iP4UeJLlLKk+ X-Received: by 2002:a62:46cc:: with SMTP id o73mr12207348pfi.182.1551644731400; Sun, 03 Mar 2019 12:25:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1551644731; cv=none; d=google.com; s=arc-20160816; b=igAA8uRjIWYTu4PVsVBBcH78aBPU135Am+l5bsSTL0VBB7QrkL/UclS31FCxuPzpYH Lz3ZbbfinUSHcpyTHAyPDlkuUAE+btytcJcbIyZ6IWH4CSiYS/8yFETM3r+tkPSb059t 4OzzsBM4T5A3epo5rO8hZK5wkifp7+j80mrIcJNzNTTjWm/JXPjbKSJtNGqAMYNMO14B wrJ9Lrm1z5Dax0HLZEnzye5W6/3Hw42Ne903qw2vD8zIYsbGXBjUIi5W1Gx2pZY+Pi4r 5uBoqP/nqYU4MZxMT7btbRA9PJR56N5tCcdRkO4/R9zaQvxG+M2l7k1ZVs8daBwDxkmm wiRw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-transfer-encoding:content-disposition:mime-version :references:message-id:subject:cc:to:from:date; bh=As7imqn3G4dxOZMTUK1PJuwiWK8PE0mTgXX3jRyo/mE=; b=VXu5YXITah2CJAGLJrGYox3Xb5XpfrqlLzNxZgE08/CQUyRzO+EWAequHYaVWwIiq9 6Eg+yLrc1T8kDuCZIA+j3lbajw36TM2A498SnqroX5Ek7v4HM5c7y8pH1zF73ZaMykEC TiBZgKGuvJW779LdQNmmwnazqgezYsyDpbEmnvZmO4wO+LOPnM2X5LGL3RO5865/FR2D jYrFf8ReYJax9I7zPXOKT25318QEY3UOJNw5kTKSQ4GM5rIxZvVheE8PMpzUJ60pcECn /clhmNoS7KxyGwNlUEUnfVnhNQGcU/f0UY6Rm9ZIT7U3Op9CKIlhEvl0P67pze0KoVp/ LMDA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id s14si3579189plq.284.2019.03.03.12.25.16; Sun, 03 Mar 2019 12:25:31 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726705AbfCCUX1 (ORCPT + 99 others); Sun, 3 Mar 2019 15:23:27 -0500 Received: from mail-yw1-f65.google.com ([209.85.161.65]:45708 "EHLO mail-yw1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726512AbfCCUX0 (ORCPT ); Sun, 3 Mar 2019 15:23:26 -0500 Received: by mail-yw1-f65.google.com with SMTP id r188so2507001ywb.12 for ; Sun, 03 Mar 2019 12:23:26 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:content-transfer-encoding :in-reply-to:user-agent; bh=As7imqn3G4dxOZMTUK1PJuwiWK8PE0mTgXX3jRyo/mE=; b=PSER5JQuMcFr+IYCCl6AvZPkH3wNCh/d1kYhRRC2IGZ7rgBi6JQmIsWQumr8Y5Usw7 +TaoBXv5V2ZCxTVrJcVQZWQ/nqGhehfZwFc9RaDcK+PKtS/24b/p+ZQhgEsSA1QQivTy 0nfiRdzl6hyAKGjuZVhlOnbJI+oUiH6gkvF4stmCoLlLF5QUtXPAunnWgdd3nX6nvnOO cp+doxa0+b5Ovm1p1Q509VT49harZPMoxRmWQaQ40zegr6o68FpHmn+f0vF8L7e4jiX+ DPUi09FG8652vgzpKyuFjdbCpQBy+bLgkjIyqOFOjte9uszc0jz9JxA5a/CsrNHdGRgx 7Sqg== X-Gm-Message-State: APjAAAUOKHhPjbLB/W8rLvuKnE/4/+BOB9R8r8ES4SRFJvH0wH2V4wkg OCsOO1pFDB9GD4vtxNl5V0M= X-Received: by 2002:a81:9b05:: with SMTP id s5mr11783129ywg.351.1551644605744; Sun, 03 Mar 2019 12:23:25 -0800 (PST) Received: from dennisz-mbp.dhcp.thefacebook.com ([2620:10d:c091:200::ffe8]) by smtp.gmail.com with ESMTPSA id p13sm1614143ywe.80.2019.03.03.12.23.24 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 03 Mar 2019 12:23:25 -0800 (PST) Date: Sun, 3 Mar 2019 15:23:23 -0500 From: Dennis Zhou To: Peng Fan Cc: Tejun Heo , Christoph Lameter , Vlad Buslov , "kernel-team@fb.com" , "linux-mm@kvack.org" , "linux-kernel@vger.kernel.org" Subject: Re: [PATCH 07/12] percpu: add block level scan_hint Message-ID: <20190303202323.GB4868@dennisz-mbp.dhcp.thefacebook.com> References: <20190228021839.55779-1-dennis@kernel.org> <20190228021839.55779-8-dennis@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 ; Tejun Heo ; Christoph > > Lameter > > Cc: Vlad Buslov ; 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 > > --- > > 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