Received: by 2002:ac0:8845:0:0:0:0:0 with SMTP id g63csp126293img; Wed, 27 Feb 2019 18:19:52 -0800 (PST) X-Google-Smtp-Source: AHgI3IYTwOGbHIGfc0gdvx3tbVDQT1nAHw6r+5/LgcBCfNgc/ftgpO8qfjUSdEc0ZHmE1yaRocb2 X-Received: by 2002:a62:1c45:: with SMTP id c66mr4978859pfc.90.1551320392349; Wed, 27 Feb 2019 18:19:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1551320392; cv=none; d=google.com; s=arc-20160816; b=vq62BSpl2KULcjtlOSXlmio9IKrfScY3Svz2ChSxpc6xCvX1yeg2ECJhpiyGmnFxFK FWrnZLs3zArk7WMHp4jtW17cd74JomeA1WbKcHbRg11dQ++nh9xMcb6r0BJ+99AV9erQ oPqo1PdiY5sMJGs6O5cTMU61mrJoux2xPMh907+dPmpJK47Y2MMqDuxUCbVNqvy9DMNL F5H965NFi/h2RQNXXgMyFD8EnpZeq5d1X/df4biEOksTK0zefoDK0X4g8PEheiYaPp8D mxkcBaF5HYZn0puQS84rN/PRXvbpZoxqldr5fzgbQvOWPLU+Xi5wO/KtQr4EY5UN4ADi L2HA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from; bh=qImDKhW66AzCuoNyqvyprY/jSnw+rPbm4Fv7bWHuvuA=; b=pLsRnwc2RJTdh2FUqvt1o+OeLCbO2CRoZHz1igBvrMRfCPv/9YPRT7znIVW03JW+f1 +xvogcVQB1/lo+Igfkl4KU2uRRZk5ay6iNOCg0e6jpoGPsyIEfuurSnaAfwW0E9XAGEW Cvxf4/bnKUZwyA5TcU2lz9/F/ZsTDXYtX4F/+ZvKrMxyF1nKLeGTS/G/kI7tR4NkQ2I/ oT7F+e1yQwvksDfkzSnXb7NQ3dEvi+5Rq5kIg2wtb9gi6WWTongEeZHb7J5Pjmce1A1G f+PCpotlZ0KRLV7EVixJHPJ1cMWujeEIjCapL/2mmATAZElT0ZFvOp8zQippplQ7P772 mblQ== 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 h18si16290937pgj.479.2019.02.27.18.19.37; Wed, 27 Feb 2019 18:19:52 -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 S1730831AbfB1CTF (ORCPT + 99 others); Wed, 27 Feb 2019 21:19:05 -0500 Received: from mail-qk1-f194.google.com ([209.85.222.194]:34375 "EHLO mail-qk1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730798AbfB1CTC (ORCPT ); Wed, 27 Feb 2019 21:19:02 -0500 Received: by mail-qk1-f194.google.com with SMTP id a15so11200413qkc.1 for ; Wed, 27 Feb 2019 18:19:02 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=qImDKhW66AzCuoNyqvyprY/jSnw+rPbm4Fv7bWHuvuA=; b=ZlMwHzYbDIXKFXiKIjruT7eCivHuOvi1pTejcsA+9wHaHz4HDdznQ641/CUvtWzE1U gHaC9rVl2MOv4TLzMQSbXw7OPHvf0i4ZchwUUO1ti2Lp757bPgqLbgrxwBZJ1qrl7wYM Vf0bIIuyeraMsBV/45t+P2qM98WLxKKnNMu0y6wmXWKRX5qaWYHb/8xDTz/DnnCmqXBP F7NzPNyk8lGdgNIJ4J022fowerVbbG7ajU6WoVlZ9Tb9M2WrmRw75TpNYDHa8BLxMrFf c0yR62c58BCfu8Jl0SaFAxZkcYSYo782graN4lbzEm0uf6cIIQd4E5JnrK8UQiIQor7A FItg== X-Gm-Message-State: AHQUAubupjEJa8CYgRI2g1QR+beOjLbKEx0YfN8wDsdAHxRSoeMv75ye HAPTiAAk2XOayUTN5lRi1qg= X-Received: by 2002:a37:4e97:: with SMTP id c145mr4659307qkb.85.1551320341809; Wed, 27 Feb 2019 18:19:01 -0800 (PST) Received: from localhost.localdomain (cpe-98-13-254-243.nyc.res.rr.com. [98.13.254.243]) by smtp.gmail.com with ESMTPSA id y21sm12048357qth.90.2019.02.27.18.19.00 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 27 Feb 2019 18:19:00 -0800 (PST) From: Dennis Zhou 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 12/12] percpu: use chunk scan_hint to skip some scanning Date: Wed, 27 Feb 2019 21:18:39 -0500 Message-Id: <20190228021839.55779-13-dennis@kernel.org> X-Mailer: git-send-email 2.13.5 In-Reply-To: <20190228021839.55779-1-dennis@kernel.org> References: <20190228021839.55779-1-dennis@kernel.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Just like blocks, chunks now maintain a scan_hint. This can be used to skip some scanning by promoting the scan_hint to be the contig_hint. The chunk's scan_hint is primarily updated on the backside and relies on full scanning when a block becomes free or the free region spans across blocks. Signed-off-by: Dennis Zhou --- mm/percpu.c | 36 +++++++++++++++++++++++++++--------- 1 file changed, 27 insertions(+), 9 deletions(-) diff --git a/mm/percpu.c b/mm/percpu.c index 197479f2c489..40d49d7fb286 100644 --- a/mm/percpu.c +++ b/mm/percpu.c @@ -711,20 +711,31 @@ static void pcpu_block_update_scan(struct pcpu_chunk *chunk, int bit_off, /** * pcpu_chunk_refresh_hint - updates metadata about a chunk * @chunk: chunk of interest + * @full_scan: if we should scan from the beginning * * Iterates over the metadata blocks to find the largest contig area. - * It also counts the populated pages and uses the delta to update the - * global count. + * A full scan can be avoided on the allocation path as this is triggered + * if we broke the contig_hint. In doing so, the scan_hint will be before + * the contig_hint or after if the scan_hint == contig_hint. This cannot + * be prevented on freeing as we want to find the largest area possibly + * spanning blocks. */ -static void pcpu_chunk_refresh_hint(struct pcpu_chunk *chunk) +static void pcpu_chunk_refresh_hint(struct pcpu_chunk *chunk, bool full_scan) { struct pcpu_block_md *chunk_md = &chunk->chunk_md; int bit_off, bits; - /* clear metadata */ - chunk_md->contig_hint = 0; + /* promote scan_hint to contig_hint */ + if (!full_scan && chunk_md->scan_hint) { + bit_off = chunk_md->scan_hint_start + chunk_md->scan_hint; + chunk_md->contig_hint_start = chunk_md->scan_hint_start; + chunk_md->contig_hint = chunk_md->scan_hint; + chunk_md->scan_hint = 0; + } else { + bit_off = chunk_md->first_free; + chunk_md->contig_hint = 0; + } - bit_off = chunk_md->first_free; bits = 0; pcpu_for_each_md_free_region(chunk, bit_off, bits) { pcpu_block_update(chunk_md, bit_off, bit_off + bits); @@ -884,6 +895,13 @@ static void pcpu_block_update_hint_alloc(struct pcpu_chunk *chunk, int bit_off, if (nr_empty_pages) pcpu_update_empty_pages(chunk, -1 * nr_empty_pages); + if (pcpu_region_overlap(chunk_md->scan_hint_start, + chunk_md->scan_hint_start + + chunk_md->scan_hint, + bit_off, + bit_off + bits)) + chunk_md->scan_hint = 0; + /* * The only time a full chunk scan is required is if the chunk * contig hint is broken. Otherwise, it means a smaller space @@ -894,7 +912,7 @@ static void pcpu_block_update_hint_alloc(struct pcpu_chunk *chunk, int bit_off, chunk_md->contig_hint, bit_off, bit_off + bits)) - pcpu_chunk_refresh_hint(chunk); + pcpu_chunk_refresh_hint(chunk, false); } /** @@ -1005,7 +1023,7 @@ static void pcpu_block_update_hint_free(struct pcpu_chunk *chunk, int bit_off, * the else condition below. */ if (((end - start) >= PCPU_BITMAP_BLOCK_BITS) || s_index != e_index) - pcpu_chunk_refresh_hint(chunk); + pcpu_chunk_refresh_hint(chunk, true); else pcpu_block_update(&chunk->chunk_md, pcpu_block_off_to_off(s_index, start), @@ -1078,7 +1096,7 @@ static int pcpu_find_block_fit(struct pcpu_chunk *chunk, int alloc_bits, if (bit_off + alloc_bits > chunk_md->contig_hint) return -1; - bit_off = chunk_md->first_free; + bit_off = pcpu_next_hint(chunk_md, alloc_bits); bits = 0; pcpu_for_each_fit_region(chunk, alloc_bits, align, bit_off, bits) { if (!pop_only || pcpu_is_populated(chunk, bit_off, bits, -- 2.17.1