Received: by 2002:a05:6358:489b:b0:bb:da1:e618 with SMTP id x27csp2423129rwn; Fri, 9 Sep 2022 13:33:28 -0700 (PDT) X-Google-Smtp-Source: AA6agR4uXcuR3rpE4f2FtKUcc9o8RI6JUScBggc+omJGweY3eeSIzq/n2amM7LfL9LT+My18Tefs X-Received: by 2002:a05:6402:2b98:b0:43e:107:183d with SMTP id fj24-20020a0564022b9800b0043e0107183dmr12946683edb.366.1662755608543; Fri, 09 Sep 2022 13:33:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662755608; cv=none; d=google.com; s=arc-20160816; b=ZEe+WvZiQcMTb/O54R1V0LbbQB94KEgBo/9clU1id0lfP1WEzxwU5M8TkVrNGTR8zI NWZYCcbOOBb0oT3+V3kg3g7MsW5awxSn6PtWYQ3HPfThxzACSqrq4qbjd1pP1GJ5O2+O VW3YLTnYwwWqbP06rfsUiAk7QBun8OKRATENZRAnl7BRS0mocdUSAKovd1ohzgFBVDmY MUUntEwhnoqLlHOvQWEcWSh3Q7RN/2FU9q9C2BqBkSFKFBRUEqdsSdKIuaz4M54urW52 xCRaN0czqpnwuFiN8nCaB11nSRg8KCu1h+yqWp2cWWTyPnXg6VxPw4MAmuEGNTqX2lYN BKIw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=PHG3tseMODOqgX44qZm0G5El+SJLZ2NP77K3XscEj4I=; b=cs38fHOFFXdudB109d4zaH2MA0MhtMkMrdg7Bmjia4SDSkHCJgyp6DseD/u0YMr2RM N1rtfpprFF/3GKqlBsKzmhgfrQdX1QKswGaXlWDuxvx5Sn+EhrtaWmEes3Ep3DZorwE8 IyE3WZ/kj1yFE1OMiaR5WUdFxZRLahV0UGrGyxyiAGvW1WMU6KUrxbahzyp2LWC7AtYM DVAvZeg40w0ILt4bAY7X2vDwQHxVjCf4dcWZGpsJD8eHNsbCs2YLJxUZK4SzreUm2QHu PnLv+mH9AMoxW7GucbpQ/3UqQyx3v8PWRjukhLgm0PqMf8PjEZwa7i04dcV+Q/RQQrAF 87UA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=ip+V2dwR; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id di14-20020a170906730e00b00773fb36fcb1si1315897ejc.213.2022.09.09.13.33.02; Fri, 09 Sep 2022 13:33:28 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=ip+V2dwR; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232316AbiIIUaq (ORCPT + 99 others); Fri, 9 Sep 2022 16:30:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54512 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230351AbiIIU35 (ORCPT ); Fri, 9 Sep 2022 16:29:57 -0400 Received: from sin.source.kernel.org (sin.source.kernel.org [IPv6:2604:1380:40e1:4800::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CEFBF1449D8 for ; Fri, 9 Sep 2022 13:29:09 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sin.source.kernel.org (Postfix) with ESMTPS id D1E08CE24A2 for ; Fri, 9 Sep 2022 20:29:07 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 369FEC43470; Fri, 9 Sep 2022 20:29:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1662755345; bh=OVGs4WGaZlHSNw1bV9aTKJG9y36ZzMQPGlZGZcjins0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ip+V2dwR7+a6tDS2JAnQCwO5rJFAyowrX5+FfGIBNIsTYot/Veb/nwDlEqmeNtUQs nEMBGWe6pqrJyEb8Hs+MdAFA+I5oFdJNB36NlBpZC0nkTMOd21lG8iO2Ra4ypuPpjQ 4W5dX/F5GI0AkFryiAkYJKkQO8JIV3lB45w4lT7jL47LAAaPIRzynMz6uwU45Bh+XZ E5o5BI4Lyarzt66Xj/yFuiQb9R8RZ3h4J+c8G2gc9WN4gZbF7NICi52SH5OVqMv0in TH9MrIoz+J6fNJe93GTJ17U6HxX04QkESr522tdExGQL28caqt3vzzSA3ojYrHEmu/ K2etw9lz6iwkg== From: SeongJae Park To: SeongJae Park , Andrew Morton Cc: damon@lists.linux.dev, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Yun Levi Subject: [PATCH 2/7] mm/damon/core: avoid holes in newly set monitoring target ranges Date: Fri, 9 Sep 2022 20:28:56 +0000 Message-Id: <20220909202901.57977-3-sj@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220909202901.57977-1-sj@kernel.org> References: <20220909202901.57977-1-sj@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org When there are two or more non-contiguous regions intersecting with given new ranges, 'damon_set_regions()' does not fill the holes. This commit makes the function to fill the holes with newly created regions. Fixes: 3f49584b262c ("mm/damon: implement primitives for the virtual memory address spaces") Reported-by: Yun Levi Signed-off-by: SeongJae Park --- mm/damon/core.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/mm/damon/core.c b/mm/damon/core.c index bae41990f422..6f6c9c9aca9d 100644 --- a/mm/damon/core.c +++ b/mm/damon/core.c @@ -168,6 +168,27 @@ static bool damon_intersect(struct damon_region *r, return !(r->ar.end <= re->start || re->end <= r->ar.start); } +/* + * Fill holes in regions with new regions. + */ +static void damon_fill_regions_holes(struct damon_region *first, + struct damon_region *last, struct damon_target *t) +{ + struct damon_region *r = first; + + damon_for_each_region_from(r, t) { + struct damon_region *next, *newr; + + if (r == last) + break; + next = damon_next_region(r); + if (r->ar.end != next->ar.start) { + newr = damon_new_region(r->ar.end, next->ar.start); + damon_insert_region(newr, r, next, t); + } + } +} + /* * damon_set_regions() - Set regions of a target for given address ranges. * @t: the given target. @@ -226,6 +247,9 @@ int damon_set_regions(struct damon_target *t, struct damon_addr_range *ranges, first->ar.start = ALIGN_DOWN(range->start, DAMON_MIN_REGION); last->ar.end = ALIGN(range->end, DAMON_MIN_REGION); + + /* fill possible holes in the range */ + damon_fill_regions_holes(first, last, t); } } return 0; -- 2.25.1