From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1F757C433F5 for ; Wed, 13 Oct 2021 22:45:43 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 8CC2561139 for ; Wed, 13 Oct 2021 22:45:42 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 8CC2561139 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=linux-foundation.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id D92666B006C; Wed, 13 Oct 2021 18:45:41 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D40796B0071; Wed, 13 Oct 2021 18:45:41 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C2E646B0072; Wed, 13 Oct 2021 18:45:41 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0084.hostedemail.com [216.40.44.84]) by kanga.kvack.org (Postfix) with ESMTP id B3FFD6B006C for ; Wed, 13 Oct 2021 18:45:41 -0400 (EDT) Received: from smtpin13.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 6FEB43206C for ; Wed, 13 Oct 2021 22:45:41 +0000 (UTC) X-FDA: 78692897682.13.4188185 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by imf18.hostedemail.com (Postfix) with ESMTP id 6F0E64002085 for ; Wed, 13 Oct 2021 22:45:40 +0000 (UTC) Received: by mail.kernel.org (Postfix) with ESMTPSA id F1CA961130; Wed, 13 Oct 2021 22:45:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux-foundation.org; s=korg; t=1634165138; bh=5WdUyjg12k3PxxjZH9zug2aqg29k94ORIzfCCkILNUA=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=QTDJOYGWkYeUqg04/vVTEWKgQUazJzM95jKx/9HUfi0KxqRwcWRLLh9/xVTLlSyCa AK78Blsabq1a4ClbCl27dVARfFLUEm94hWgJ5GKWTQv0ZZBRfetJO0Z5ESsNsectRW R2uhoPIEepb5r1n5jg1e1036UjRVI1xdD18rYypA= Date: Wed, 13 Oct 2021 15:45:35 -0700 From: Andrew Morton To: SeongJae Park Cc: Jonathan.Cameron@Huawei.com, amit@kernel.org, benh@kernel.crashing.org, corbet@lwn.net, david@redhat.com, dwmw@amazon.com, elver@google.com, foersleo@amazon.de, gthelen@google.com, markubo@amazon.de, rientjes@google.com, shakeelb@google.com, shuah@kernel.org, linux-damon@amazon.com, linux-mm@kvack.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH 1/7] mm/damon/dbgfs: Allow users to set initial monitoring target regions Message-Id: <20211013154535.4aaeaaf9d0182922e405dd1e@linux-foundation.org> In-Reply-To: <20211012205711.29216-2-sj@kernel.org> References: <20211012205711.29216-1-sj@kernel.org> <20211012205711.29216-2-sj@kernel.org> X-Mailer: Sylpheed 3.5.1 (GTK+ 2.24.31; x86_64-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=linux-foundation.org header.s=korg header.b=QTDJOYGW; dmarc=none; spf=pass (imf18.hostedemail.com: domain of akpm@linux-foundation.org designates 198.145.29.99 as permitted sender) smtp.mailfrom=akpm@linux-foundation.org X-Stat-Signature: 9xxq15mxg5g5wayf18ru1xawcegwyri8 X-Rspamd-Queue-Id: 6F0E64002085 X-Rspamd-Server: rspam01 X-HE-Tag: 1634165140-1940 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Tue, 12 Oct 2021 20:57:05 +0000 SeongJae Park wrote: > Some 'damon-dbgfs' users would want to monitor only a part of the entire > virtual memory address space. The program interface users in the kernel > space could use '->before_start()' callback or set the regions inside > the context struct as they want, but 'damon-dbgfs' users cannot. > > For the reason, this commit introduces a new debugfs file called > 'init_region'. 'damon-dbgfs' users can specify which initial monitoring > target address regions they want by writing special input to the file. > The input should describe each region in each line in the below form: > > > > Note that the regions will be updated to cover entire memory mapped > regions after a 'regions update interval' is passed. If you want the > regions to not be updated after the initial setting, you could set the > interval as a very long time, say, a few decades. > > ... > > +static int add_init_region(struct damon_ctx *c, > + unsigned long target_id, struct damon_addr_range *ar) > +{ > + struct damon_target *t; > + struct damon_region *r, *prev; > + unsigned long id; > + int rc = -EINVAL; > + > + if (ar->start >= ar->end) > + return -EINVAL; > + > + damon_for_each_target(t, c) { > + id = t->id; > + if (targetid_is_pid(c)) > + id = (unsigned long)pid_vnr((struct pid *)id); This is a bit ugly. Did you consider making damon_target.id a union of all the possible types it can contain? This will avoid typecasts, has documentation value and reflacts what is actually going on. > + if (id == target_id) { > + r = damon_new_region(ar->start, ar->end); > + if (!r) > + return -ENOMEM; > + damon_add_region(r, t); > + if (damon_nr_regions(t) > 1) { > + prev = damon_prev_region(r); > + if (prev->ar.end > r->ar.start) { > + damon_destroy_region(r, t); > + return -EINVAL; > + } > + } > + rc = 0; > + } > + } > + return rc; > +} > +