Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp4938459pxj; Tue, 22 Jun 2021 11:14:26 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxHK+bEkkRXv7rOxQRatxJTmfq7PKyhEdZyzBRfePVSToYUUrNJlvTAdYceym6740kAI8bS X-Received: by 2002:a17:906:7142:: with SMTP id z2mr5283329ejj.427.1624385665868; Tue, 22 Jun 2021 11:14:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1624385665; cv=none; d=google.com; s=arc-20160816; b=wuXW0KWf8z+Bn61TT8JpYLcerVDdKM/6eyUmjcmYEorzcKEee27uUiAO0Hq5jaTTTm oE0ixNJ2trgi6FQxJTE/917sJ5hQTVknftCinSo9qnQHyRsbHoTQRdLsJyqVhHSDf3bZ h90HV53poNHck2BJD5/JUuttNJsx9nv6Uv004VBIVHGX/GqDTPOjdIfnR/OH1VtrjpCP tDS9Zjpf640iARF3Wtur5gjs403XxLLaUi6MtCIkewk3NG+1xHhfcM8Ml0FEC/j3uGOo 9edVLtHAOHg0T2sN+Ew4kNmmcNClscONsVAwzXSPmNROwIsBEiHJ7C7koERm9wl+pg7s z8TQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=CZ8ZYzj6hHuJXsmZpwyIWIWw0nLJtjqqsF2RiG/A2YM=; b=dfkU3pzzJgNd48068QKF8nI95WMvdWyCO5Uv8FARNkQznMdNDiNhEsMXe/oFTucGRO DOxpC0/pYySPnT8n3oZ34G3JqSN8vtMzcRosxGz7uz+7mwu0p6hT5U4QJmtN1Y3+Plku VtSqKNurBRSePEb/LZyasYcbFDK3aSTbRyivvRXbe4XuEfwla+5TDE4vhggV2OxqgcHU dB807zv1IP0uy7RQQ8vGWZ7JwruZ7eP+iQurc0iIUZaGfBX+wDbHnljwO7RHUyYUGYR0 wDUFybLJbCA8jFLf3a6Pg0DKkFIv5tvDsRfJI+4cU04kS3uI8WAshwxZZqmnwI0bpnX/ mBKg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=kMmn25Da; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id d19si7673641ejo.229.2021.06.22.11.14.02; Tue, 22 Jun 2021 11:14:25 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=kMmn25Da; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232386AbhFVSPH (ORCPT + 99 others); Tue, 22 Jun 2021 14:15:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41016 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229612AbhFVSPG (ORCPT ); Tue, 22 Jun 2021 14:15:06 -0400 Received: from mail-lf1-x133.google.com (mail-lf1-x133.google.com [IPv6:2a00:1450:4864:20::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 92470C061574 for ; Tue, 22 Jun 2021 11:12:49 -0700 (PDT) Received: by mail-lf1-x133.google.com with SMTP id i1so10429344lfe.6 for ; Tue, 22 Jun 2021 11:12:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=CZ8ZYzj6hHuJXsmZpwyIWIWw0nLJtjqqsF2RiG/A2YM=; b=kMmn25DaPZRRY3V65IMoK6joZt/2Rx0PQGhQ7nqJRDs7n/4KFlbx4nvlU6vYnDJoJ5 FqN2m2BLT2LbAl24AWIhH15trb47pLTYpEYQab6qIbz/RGNfT4FyfxGWsPWQOqhDhCyy gUkP2NoWypK6UmXFHo9NNR14cgrc7797pp6DGXRw0QLpR3vmDsiTr21+/k7YUckC00D4 WBlruau/FcBMV3DWRffttnXsZ88TxMH9gT1cw6XQbBZ3AQYVFwVqhogptbDcN2YZZzKh ZmEnLURq81Wlqyq69lvsaVJpGrrTp9yXsKZOzRX7ji5zmGd6D9aZyNlzGGmMa6OUrcw8 KLhg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=CZ8ZYzj6hHuJXsmZpwyIWIWw0nLJtjqqsF2RiG/A2YM=; b=RUY1QscyJzjTCXpKTJfM463nQrMAvtfhyBhj9WS25qsJPbftuo6QPJwD+R3GnL5tBS vD0IITLMwuOxatgqXa8e8GtXKYKab+XaomXsNB2DwH57TcBnxDU+E3OthuLelDQOhXQE nMQLeBCVNmq63gsZdaVLZyI0IljXGPYfkten33pWW20QngIeQri1c0m+UUAUUBW495DQ Fpsa29T9W1B+SZlIwCBQdaZ0tSQmVCo506qMA5BwP48LGNxt78fqeKy+22nYzVIuDY7B fKPN08wFEFkJdEty6btjRCjuyj2YX5iWrRFbGMRy8O+JU7Lclm/SpkUC/l+SuFBEL9xE oarg== X-Gm-Message-State: AOAM532jp6NKHO0AglxEN8OI+W9wYCGRMLbHtsFK6botlwBis1FR++hF Qp08p8/Qtpa5u0ehqAyZuZvSBxzQr8uRICA//FNuxg== X-Received: by 2002:a05:6512:1191:: with SMTP id g17mr1605160lfr.347.1624385567602; Tue, 22 Jun 2021 11:12:47 -0700 (PDT) MIME-Version: 1.0 References: <20210621083108.17589-1-sj38.park@gmail.com> <20210621083108.17589-8-sj38.park@gmail.com> In-Reply-To: <20210621083108.17589-8-sj38.park@gmail.com> From: Shakeel Butt Date: Tue, 22 Jun 2021 11:12:36 -0700 Message-ID: Subject: Re: [PATCH v31 07/13] mm/damon: Implement a debugfs-based user space interface To: SeongJae Park Cc: Andrew Morton , SeongJae Park , Jonathan.Cameron@huawei.com, acme@kernel.org, alexander.shishkin@linux.intel.com, amit@kernel.org, benh@kernel.crashing.org, Brendan Higgins , Jonathan Corbet , David Hildenbrand , dwmw@amazon.com, Marco Elver , "Du, Fan" , foersleo@amazon.de, greg@kroah.com, Greg Thelen , guoju.fgj@alibaba-inc.com, jgowans@amazon.com, Mel Gorman , mheyne@amazon.de, Minchan Kim , Ingo Molnar , namhyung@kernel.org, "Peter Zijlstra (Intel)" , Rik van Riel , David Rientjes , Steven Rostedt , Mike Rapoport , Shuah Khan , sieberf@amazon.com, snu@zelle79.org, Vlastimil Babka , Vladimir Davydov , zgf574564920@gmail.com, linux-damon@amazon.com, Linux MM , linux-doc@vger.kernel.org, LKML Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Jun 21, 2021 at 1:31 AM SeongJae Park wrote: > > From: SeongJae Park > > DAMON is designed to be used by kernel space code such as the memory > management subsystems, and therefore it provides only kernel space API. > That said, letting the user space control DAMON could provide some > benefits to them. For example, it will allow user space to analyze > their specific workloads and make their own special optimizations. > > For such cases, this commit implements a simple DAMON application kernel > module, namely 'damon-dbgfs', which merely wraps the DAMON api and > exports those to the user space via the debugfs. > > 'damon-dbgfs' exports three files, ``attrs``, ``target_ids``, and > ``monitor_on`` under its debugfs directory, ``/damon/``. > > Attributes > ---------- > > Users can read and write the ``sampling interval``, ``aggregation > interval``, ``regions update interval``, and min/max number of > monitoring target regions by reading from and writing to the ``attrs`` > file. For example, below commands set those values to 5 ms, 100 ms, > 1,000 ms, 10, 1000 and check it again:: > > # cd /damon > # echo 5000 100000 1000000 10 1000 > attrs > # cat attrs > 5000 100000 1000000 10 1000 > > Target IDs > ---------- > > Some types of address spaces supports multiple monitoring target. For > example, the virtual memory address spaces monitoring can have multiple > processes as the monitoring targets. Users can set the targets by > writing relevant id values of the targets to, and get the ids of the > current targets by reading from the ``target_ids`` file. In case of the > virtual address spaces monitoring, the values should be pids of the > monitoring target processes. For example, below commands set processes > having pids 42 and 4242 as the monitoring targets and check it again:: > > # cd /damon > # echo 42 4242 > target_ids > # cat target_ids > 42 4242 > > Note that setting the target ids doesn't start the monitoring. > > Turning On/Off > -------------- > > Setting the files as described above doesn't incur effect unless you > explicitly start the monitoring. You can start, stop, and check the > current status of the monitoring by writing to and reading from the > ``monitor_on`` file. Writing ``on`` to the file starts the monitoring > of the targets with the attributes. Writing ``off`` to the file stops > those. DAMON also stops if every targets are invalidated (in case of > the virtual memory monitoring, target processes are invalidated when > terminated). Below example commands turn on, off, and check the status > of DAMON:: > > # cd /damon > # echo on > monitor_on > # echo off > monitor_on > # cat monitor_on > off > > Please note that you cannot write to the above-mentioned debugfs files > while the monitoring is turned on. If you write to the files while > DAMON is running, an error code such as ``-EBUSY`` will be returned. > > Signed-off-by: SeongJae Park > Reviewed-by: Leonard Foerster > Reviewed-by: Fernand Sieber The high level comment I have for this patch is the layering of pid reference counting. The dbgfs should treat the targets as abstract objects and vaddr should handle the reference counting of pids. More specifically move find_get_pid from dbgfs to vaddr and to add an interface to the primitive for set_targets. At the moment, the pid reference is taken in dbgfs and put in vaddr. This will be the source of bugs in future.