Received: by 2002:ac0:8845:0:0:0:0:0 with SMTP id g63csp126874img; Wed, 27 Feb 2019 18:20:43 -0800 (PST) X-Google-Smtp-Source: AHgI3IZ//eCzv59xNHl64BdX5zAE+FIB+Cu0cnbUiJBXmm1RCm6/qbzZ7RaUkEaUjdNAka6f3kWm X-Received: by 2002:a63:da43:: with SMTP id l3mr6161956pgj.164.1551320443909; Wed, 27 Feb 2019 18:20:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1551320443; cv=none; d=google.com; s=arc-20160816; b=ToCMhAPgfb1wMOnZBEWFfhK2zAwnGj4V3q3coqihf5ZRG9ILddPfznN0Q7lppEfCQI ZzH8xjF5gxyl1GGaYDtj2sVgQtG7MuQF4HeueocoGKW2dIzIrfeQx0ZDJe2+FZTmRlnv H3PlMb00BFd3VsK5rle7o/jaz5U2SMw1tmUS8PRT9VZGnrmfG5EqLcX6+78xFBI79F9H p0V1u7fcUY8vWhcRo8O8kyaGTULlr5O0x+IorC0dKZcG0230eJ3bE4DeS2LWM9Nolygu ubJZ7JYtPBQIILPKUwTwRokXQFmR10UvW0BkWEG1lz95ZndOJ73NeTuFfTKYzS4k9akx 2a1g== 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=Zob00SAWeBYh4oEQ8sirU3S+Sks7fCNmhlxQAAwLhMs=; b=GG7XQAQ4U338krqzBDBn7t8PxNCEiI2A7tWjIMO1fuZ/4O5nSPsdf2eI5A/EMtLeaq lrPKiQZ8D94oeEJz4cxHyQg5wmUhISWlQS4UOrZXDIfpiY1ODy1SBbbOYWS28/h72S2I QNzOtm+gwDsDZq6OOpeDudFPOKM8Lhk6p0QbWwvBdYBtxMl68jlVJQaokqFb70P56b0e bOd01BXaHGmGxnxfxYIC8FA8pG4Ku7CuRh599sLD0r0ajlGWGbKMDjjFOU/vGCsa1ghy G7d1LAxlttIymu28ytgP1Umc6acv5ysdBE229KS+XBKjgKsrwcdmi7JJHLdbAg3Y59tz zFGQ== 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 10si16370158pgn.558.2019.02.27.18.20.28; Wed, 27 Feb 2019 18:20:43 -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 S1730907AbfB1CTi (ORCPT + 99 others); Wed, 27 Feb 2019 21:19:38 -0500 Received: from mail-qk1-f193.google.com ([209.85.222.193]:34858 "EHLO mail-qk1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730240AbfB1CSu (ORCPT ); Wed, 27 Feb 2019 21:18:50 -0500 Received: by mail-qk1-f193.google.com with SMTP id z13so11213489qki.2 for ; Wed, 27 Feb 2019 18:18:49 -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=Zob00SAWeBYh4oEQ8sirU3S+Sks7fCNmhlxQAAwLhMs=; b=IEg4Zwy9ZdTjltUjeRyDaDxQ/uv3ho6jDSiF6s/H7nzCF5qP7t2mu6fanNI7vH2x5o u8fa8fq3W8sEd7oJQNOpfImXucEpYqJ+sav4GcgYqeodkj4LcAdfSpvDi7N1gLHkNaNj LKiLiaT9oZ33gGxe9HWtZRIAA0uotErODCJjxzm+Nj+2zOqp5ZB1TVUSu1rMHUqrdlcm CmC0buna5no/74Xl0YnaSuNK24b/yqIgiAJjPno8jyDmn8ASHmKalOX6t/kvgRWALFC/ LKGuUTW6A1t891kfGtFzhLJt9+vsDkv7PGx1G+00V11AVmLUkiIuWjqau9vejZ7L5Y5q 9Kfg== X-Gm-Message-State: APjAAAWLg5YDv2t2Rl5mEhbs3BDOKDd8stcB0F4T+xyTEWDl+o+mxB7h 3giUAE47Zli1Qi1M28AkVX0= X-Received: by 2002:a37:4701:: with SMTP id u1mr4545594qka.357.1551320328211; Wed, 27 Feb 2019 18:18:48 -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.46 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 27 Feb 2019 18:18:47 -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 03/12] percpu: introduce helper to determine if two regions overlap Date: Wed, 27 Feb 2019 21:18:30 -0500 Message-Id: <20190228021839.55779-4-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 While block hints were always accurate, it's possible when spanning across blocks that we miss updating the chunk's contig_hint. Rather than rely on correctness of the boundaries of hints, do a full overlap comparison. Signed-off-by: Dennis Zhou --- mm/percpu.c | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/mm/percpu.c b/mm/percpu.c index 69ca51d238b5..b40112b2fc59 100644 --- a/mm/percpu.c +++ b/mm/percpu.c @@ -546,6 +546,24 @@ static inline int pcpu_cnt_pop_pages(struct pcpu_chunk *chunk, int bit_off, bitmap_weight(chunk->populated, page_start); } +/* + * pcpu_region_overlap - determines if two regions overlap + * @a: start of first region, inclusive + * @b: end of first region, exclusive + * @x: start of second region, inclusive + * @y: end of second region, exclusive + * + * This is used to determine if the hint region [a, b) overlaps with the + * allocated region [x, y). + */ +static inline bool pcpu_region_overlap(int a, int b, int x, int y) +{ + if ((x >= a && x < b) || (y > a && y <= b) || + (x <= a && y >= b)) + return true; + return false; +} + /** * pcpu_chunk_update - updates the chunk metadata given a free area * @chunk: chunk of interest @@ -710,8 +728,11 @@ static void pcpu_block_update_hint_alloc(struct pcpu_chunk *chunk, int bit_off, PCPU_BITMAP_BLOCK_BITS, s_off + bits); - if (s_off >= s_block->contig_hint_start && - s_off < s_block->contig_hint_start + s_block->contig_hint) { + if (pcpu_region_overlap(s_block->contig_hint_start, + s_block->contig_hint_start + + s_block->contig_hint, + s_off, + s_off + bits)) { /* block contig hint is broken - scan to fix it */ pcpu_block_refresh_hint(chunk, s_index); } else { @@ -764,8 +785,10 @@ static void pcpu_block_update_hint_alloc(struct pcpu_chunk *chunk, int bit_off, * contig hint is broken. Otherwise, it means a smaller space * was used and therefore the chunk contig hint is still correct. */ - if (bit_off >= chunk->contig_bits_start && - bit_off < chunk->contig_bits_start + chunk->contig_bits) + if (pcpu_region_overlap(chunk->contig_bits_start, + chunk->contig_bits_start + chunk->contig_bits, + bit_off, + bit_off + bits)) pcpu_chunk_refresh_hint(chunk); } -- 2.17.1