Received: by 2002:ac0:8845:0:0:0:0:0 with SMTP id g63csp126606img; Wed, 27 Feb 2019 18:20:23 -0800 (PST) X-Google-Smtp-Source: AHgI3Ib89QNhd48TAuKsqnM+KUV2hybMnYD448YxejQ2KKGenGye6grayS7uyEQZH2xF1SDKyQPM X-Received: by 2002:a17:902:380c:: with SMTP id l12mr5390467plc.326.1551320423296; Wed, 27 Feb 2019 18:20:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1551320423; cv=none; d=google.com; s=arc-20160816; b=KsAN2SkpPjTBxgAce37VDOJvxOIEzon83N9Z7LvFXmSj4ZFt4mfmK0AD23TA9tw6BO sKXMOKzIY/UWqunisr3SMG5A/CcOtBevsbPrzaPP7V1I6635/IJ9Av5a7NFFySqCWtM2 v5axkJ4MQhO9Q4fPGIC05DgAPeqb8CB74M+RoLYjj3PZAPliL/UMlaWBxwbYwY7VAqju hBp0tChNblc8kaM7WSZhkD2RAOYyqCqAjOS7GA/ZeBxhv89IoTc8P9hpX+yAqCXPYp0C 4Qvh0OWGplaSLRfQnolIVQgOdB0tz6ir7Dnjw18/ULNWOrlggzhLvH8pDmJaUPoXm3vh iHTw== 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=O/uMqMX1RLXk35wATf5Bntd/FX1DZTwSKmJPgUmEjAI=; b=vfHyHo+i0IXddJRTrQ5nuG2/ciFDwiT3uwHLKO3KqF9uUI5J3LIexmqPgnuDYVthja vpTIAlYwiEsluRHnbnyGJSQCAPIgttHTKK4d5DRdKPy4IoTyflIzp7G0i5HDKiVpFh0V f9qJRNjMRwsNM3oS8IWxCPuXjBkIgJLQf9dhDUbiShhpX1T5zUxNOk8sq7bIyOwu40y5 Oc9HZE0DCHOQBF79q3hOXwta2Cp+u0fEg0A683wjtlodHC9JJa/OvgHXQOBhVWivAIaQ C6YxsoNI9qjE/UFFAhr4uvPxMeWHiv/fG+QHHqbJpmmtWR0EsNaH7hXS1TWtzD1f/6VX J9/g== 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 31si16937410plg.291.2019.02.27.18.20.08; Wed, 27 Feb 2019 18:20:23 -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 S1730753AbfB1CS5 (ORCPT + 99 others); Wed, 27 Feb 2019 21:18:57 -0500 Received: from mail-qk1-f195.google.com ([209.85.222.195]:35849 "EHLO mail-qk1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730706AbfB1CSw (ORCPT ); Wed, 27 Feb 2019 21:18:52 -0500 Received: by mail-qk1-f195.google.com with SMTP id c2so10482096qkb.3 for ; Wed, 27 Feb 2019 18:18:51 -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=O/uMqMX1RLXk35wATf5Bntd/FX1DZTwSKmJPgUmEjAI=; b=MCCbKf9KlYbc8pDJ3g8WUZyh0a1kzcM75kR6ogClbXQbKJbmoJzQLAUtNzfWFM6xgx GX4VxbcsfV/Unrd+OThj17x8turPAn4ug2vBHfdvtFytzOcpS7i23C6N6XgPgbpAj4zT 4LZfXEA7kZ96aPC55IPjR/0RGcFqGg3VoS2PcxP59znCwWDO/kOgAZThncDBmUS2OeU4 6nhzuDKVtTBwAy8ec2rXkMs6c0vhV/p4qsbTLX5Xjg9CP7YOZh6ghT3WgjYKc4zrm4JA HGfAfNX9hV7TzaKB5OoIW9/Pm/OCVH8vMYUH0t5XfOz/xISNyYUQ9Hq6IMtovecgNSQQ bykQ== X-Gm-Message-State: AHQUAuZvsq6wPziEvcajc4EhQUtzUQGzY3jAKYu5ivPh6+tJUXVlmCL8 dU4iaTdOSKpe33Ob3d0ciS0= X-Received: by 2002:a37:d6c6:: with SMTP id p67mr4570900qkl.329.1551320331211; Wed, 27 Feb 2019 18:18:51 -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.18.49 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 27 Feb 2019 18:18:50 -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 05/12] percpu: relegate chunks unusable when failing small allocations Date: Wed, 27 Feb 2019 21:18:32 -0500 Message-Id: <20190228021839.55779-6-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 In certain cases, requestors of percpu memory may want specific alignments. However, it is possible to end up in situations where the contig_hint matches, but the alignment does not. This causes excess scanning of chunks that will fail. To prevent this, if a small allocation fails (< 32B), the chunk is moved to the empty list. Once an allocation is freed from that chunk, it is placed back into rotation. Signed-off-by: Dennis Zhou --- mm/percpu.c | 35 ++++++++++++++++++++++++++--------- 1 file changed, 26 insertions(+), 9 deletions(-) diff --git a/mm/percpu.c b/mm/percpu.c index c996bcffbb2a..3d7deece9556 100644 --- a/mm/percpu.c +++ b/mm/percpu.c @@ -94,6 +94,8 @@ /* the slots are sorted by free bytes left, 1-31 bytes share the same slot */ #define PCPU_SLOT_BASE_SHIFT 5 +/* chunks in slots below this are subject to being sidelined on failed alloc */ +#define PCPU_SLOT_FAIL_THRESHOLD 3 #define PCPU_EMPTY_POP_PAGES_LOW 2 #define PCPU_EMPTY_POP_PAGES_HIGH 4 @@ -488,6 +490,22 @@ static void pcpu_mem_free(void *ptr) kvfree(ptr); } +static void __pcpu_chunk_move(struct pcpu_chunk *chunk, int slot, + bool move_front) +{ + if (chunk != pcpu_reserved_chunk) { + if (move_front) + list_move(&chunk->list, &pcpu_slot[slot]); + else + list_move_tail(&chunk->list, &pcpu_slot[slot]); + } +} + +static void pcpu_chunk_move(struct pcpu_chunk *chunk, int slot) +{ + __pcpu_chunk_move(chunk, slot, true); +} + /** * pcpu_chunk_relocate - put chunk in the appropriate chunk slot * @chunk: chunk of interest @@ -505,12 +523,8 @@ static void pcpu_chunk_relocate(struct pcpu_chunk *chunk, int oslot) { int nslot = pcpu_chunk_slot(chunk); - if (chunk != pcpu_reserved_chunk && oslot != nslot) { - if (oslot < nslot) - list_move(&chunk->list, &pcpu_slot[nslot]); - else - list_move_tail(&chunk->list, &pcpu_slot[nslot]); - } + if (oslot != nslot) + __pcpu_chunk_move(chunk, nslot, oslot < nslot); } /** @@ -1381,7 +1395,7 @@ static void __percpu *pcpu_alloc(size_t size, size_t align, bool reserved, bool is_atomic = (gfp & GFP_KERNEL) != GFP_KERNEL; bool do_warn = !(gfp & __GFP_NOWARN); static int warn_limit = 10; - struct pcpu_chunk *chunk; + struct pcpu_chunk *chunk, *next; const char *err; int slot, off, cpu, ret; unsigned long flags; @@ -1443,11 +1457,14 @@ static void __percpu *pcpu_alloc(size_t size, size_t align, bool reserved, restart: /* search through normal chunks */ for (slot = pcpu_size_to_slot(size); slot < pcpu_nr_slots; slot++) { - list_for_each_entry(chunk, &pcpu_slot[slot], list) { + list_for_each_entry_safe(chunk, next, &pcpu_slot[slot], list) { off = pcpu_find_block_fit(chunk, bits, bit_align, is_atomic); - if (off < 0) + if (off < 0) { + if (slot < PCPU_SLOT_FAIL_THRESHOLD) + pcpu_chunk_move(chunk, 0); continue; + } off = pcpu_alloc_area(chunk, bits, bit_align, off); if (off >= 0) -- 2.17.1