Received: by 2002:ac0:aed5:0:0:0:0:0 with SMTP id t21csp1411673imb; Sat, 2 Mar 2019 14:25:37 -0800 (PST) X-Google-Smtp-Source: APXvYqxRKT/P4cft8Eozv4YbVHM9qaei9tLquZA6pdcDi2eQCalO/IRA6oFP/M1CEz/MWz1IN8Sa X-Received: by 2002:a65:568b:: with SMTP id v11mr11813731pgs.23.1551565537264; Sat, 02 Mar 2019 14:25:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1551565537; cv=none; d=google.com; s=arc-20160816; b=hjc9+WOGQhBORNg2YVliL5DoVPAKE0wXIR8idW5+6P7DtDnfQixY3GVYISMDVhJ0Lj EdNDn0IL5Dcj5ywyGMKoQpBWDm4wd/uM9rbiQP72i9yps5kHmCRCClYUiJXgHgjJb/nN fKRRawVhpiT8y5P+if1cw1vASoe+0LcgW3HL4k9Ku8KxlXvbVF0xbvPeHW1x/H6O0Xw8 M3LWR3S6yKsTBwwlG/GBfary8Oqww8HOCyiuWJ2mMlsjEIj1Ej6GlKqz7yFzx+NiIJ17 pjFkMi6zs1LJwNNXpGdqnX/tZmgd1HZ2BavTVC174Ubqwo4Hh+4mFMQ/mb+2fCo1dk+Q 2G1Q== 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=xKjx14ks+fWUvz6Cb9F2qKJQJcDxCcs/XzD8Ta06PU0=; b=WVbinwUzXFywGnxlVVJc5wf+BWFP4OdorH2+9YNaA6Y+lxJi+G852msFEM4Ao1ODUb 1kjh6mzTqXId63otJALLg4Fjj9dxXW11Gofg8tCcStJFh3IW5Wu/B7ftM0OXyK/2oAZ4 x8QnkrxBXm+3LYnKt/xKiyiY53t9jRSybnQji9W01sxcLcP97sQqGcOlLaGZBo6BBKwZ pxHTOzhGBUYxH3MR6cGk4wZtQcLXp3e1iW7ZvXrKldFtIts7QkjQ+BlhwKhEb6j75N3P wImK/QGL68cG8cDbniEK9042SyopJ1oFCmtiksfzzkhTA5wa5r9NYbG/5xHp240ou4kh Q1fg== 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 k63si1512800pgd.26.2019.03.02.14.25.21; Sat, 02 Mar 2019 14:25:37 -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 S1726978AbfCBWZC (ORCPT + 99 others); Sat, 2 Mar 2019 17:25:02 -0500 Received: from mail-qk1-f194.google.com ([209.85.222.194]:40485 "EHLO mail-qk1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726225AbfCBWZB (ORCPT ); Sat, 2 Mar 2019 17:25:01 -0500 Received: by mail-qk1-f194.google.com with SMTP id h28so861004qkk.7 for ; Sat, 02 Mar 2019 14:25:00 -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=xKjx14ks+fWUvz6Cb9F2qKJQJcDxCcs/XzD8Ta06PU0=; b=cCs9uCDnVaOwEWtBVyXIIozGVk3efIfPTYJWh/0fmTEim4gnvv8kJxUrbxhWzJYJ5r ugYUk9SZ7pdhcISv3U66MiId5sYZ/9ejK8Py8EsF4NFPmMayMD/qtreo4aT0oeyyqRNF R694pxNh4V3+SgVWhW5Zwx3w0rHuQRIEI7lJ2P/9oBSbzoczK5I/Bk9puQnb33aqRMT6 HD+WbOQ7XrzNpyONe/mSfPWXSJ3Dm+x3vw37dvX8ODb1oG1jnGCWHzWSN+w9+aBWD2g2 w1pN0r1rNNLWjXBt2SxkDBSU6Knd/jB0a8VQkERdBkrtPz3CCkYPPqKthZb5uAdHIppD rMYQ== X-Gm-Message-State: APjAAAUfetjK8MHVWSs9iRrhRmw6SglLQgRI7EdLk/+Rfp+Lo7oahyHI WSzOwDdv0LY7fC8L7CJ17vk= X-Received: by 2002:a37:a247:: with SMTP id l68mr8593537qke.96.1551565500403; Sat, 02 Mar 2019 14:25:00 -0800 (PST) Received: from dennisz-mbp.home ([2604:2000:1406:13e:1c79:146b:53ab:5b76]) by smtp.gmail.com with ESMTPSA id m88sm1031315qte.68.2019.03.02.14.24.59 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 02 Mar 2019 14:24:59 -0800 (PST) Date: Sat, 2 Mar 2019 17:24:57 -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 03/12] percpu: introduce helper to determine if two regions overlap Message-ID: <20190302222457.GB1196@dennisz-mbp.home> References: <20190228021839.55779-1-dennis@kernel.org> <20190228021839.55779-4-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 Sat, Mar 02, 2019 at 01:37:37PM +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 03/12] percpu: introduce helper to determine if two regions > > overlap > > > > 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)) > > I think this could be simplified: > (a < y) && (x < b) could be used to do overlap check. > I'll change it to be the negative. Thanks, Dennis > > > + 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 >