From nobody Tue Nov 26 22:39:37 2024 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5BBC91FAF14; Tue, 15 Oct 2024 17:54:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729014863; cv=none; b=OmJ1vFcXCcRvOwjGiklfNjf5r8q199e3BVReGhp8EccMZ2jHP9eLwQK7Ee7X468Y376e9VFsvl+PfwVLMhqztsglm/6lRAei4SQYzD6JuYdQWvT4nXiTiPZvCjUTnGixm8YnoPwk+bDLWaLSSuWV1ufZ69H2QBaWteVtlZPUf1Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729014863; c=relaxed/simple; bh=CKcT9mDCKGTEuzVadIyy50mQuu1BV9tFkUqyOuuB6ho=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=qW8er2ogXYKS7MfMimizWjNif59cJWP3vmnn/1qiz0MdU72nmpkuh9g02K/zddcssNC6vbMP5WUE3Zm7oFsVFpnoIf+IBilsHRtRDag8wbMwMYwapWuzJy8VkAc47Ccy9rFB+nC9MShun2V2vIEvzs+Q+VSTFI/z32XnJnLpRTI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=s/NCcirn; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="s/NCcirn" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9B779C4CECF; Tue, 15 Oct 2024 17:54:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1729014862; bh=CKcT9mDCKGTEuzVadIyy50mQuu1BV9tFkUqyOuuB6ho=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=s/NCcirnrthjZBo65NC5ZyIo/PFULHy3AJApJ4fo0pvU+IOnNpbXBmPhcapWmn/ez 0fM77vlnUh3lKyh4RuC18EQo+2P9vRNaCsen6+efJLOPb5xivmWyHyztD9yv777Nlq 77NTuZx4JXlpxdfoChorkxo3UH9b8g4qWcBscH4w15elfMP5JxNmmz77Ldr6tVyr/J AwrbvBjKArd9ndQ1KyeYpYJkFkj8asLvwUF73RPLlVdpo9bqj0ab7WhAyIJnaJY3Za cTEbrWV7C9pfTpjnQVLO3m8h9am/O+0RFIMDpylE4Dxl+z5DpUr0mrj+HBd8FdjMrO K3rbCfLb9dBSw== From: SeongJae Park To: Cc: SeongJae Park , Andrew Morton , Jonathan Corbet , damon@lists.linux.dev, linux-mm@kvack.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [RFC PATCH 1/7] Docs/admin-guide/mm/damon/usage: remove DAMON debugfs interface documentation Date: Tue, 15 Oct 2024 10:54:06 -0700 Message-Id: <20241015175412.60563-2-sj@kernel.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20241015175412.60563-1-sj@kernel.org> References: <20241015175412.60563-1-sj@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" It's time to remove DAMON debugfs interface, which has deprecated long before in February 2023. Read the cover letter of this patch series for more details. Remove DAMON debugfs interface usage documentation, to avoid confusing users with documents for an already removed thing. Signed-off-by: SeongJae Park --- Documentation/admin-guide/mm/damon/usage.rst | 309 ------------------- 1 file changed, 309 deletions(-) diff --git a/Documentation/admin-guide/mm/damon/usage.rst b/Documentation/a= dmin-guide/mm/damon/usage.rst index d9be9f7caa7d..c685d87ea078 100644 --- a/Documentation/admin-guide/mm/damon/usage.rst +++ b/Documentation/admin-guide/mm/damon/usage.rst @@ -26,12 +26,6 @@ DAMON provides below interfaces for different users. writing kernel space DAMON application programs for you. You can even e= xtend DAMON for various address spaces. For detail, please refer to the inter= face :doc:`document `. -- *debugfs interface. (DEPRECATED!)* - :ref:`This ` is almost identical to :ref:`sysfs inter= face - `. This is deprecated, so users should move to the - :ref:`sysfs interface `. If you depend on this and can= not - move, please report your usecase to damon@lists.linux.dev and - linux-mm@kvack.org. =20 .. _sysfs_interface: =20 @@ -600,306 +594,3 @@ fields are as usual. It shows the index of the DAMON= context (``ctx_idx=3DX``) of the scheme in the list of the contexts of the context's kdamond, the in= dex of the scheme (``scheme_idx=3DX``) in the list of the schemes of the conte= xt, in addition to the output of ``damon_aggregated`` tracepoint. - - -.. _debugfs_interface: - -debugfs Interface (DEPRECATED!) -=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D - -.. note:: - - THIS IS DEPRECATED! - - DAMON debugfs interface is deprecated, so users should move to the - :ref:`sysfs interface `. If you depend on this and can= not - move, please report your usecase to damon@lists.linux.dev and - linux-mm@kvack.org. - -DAMON exports nine files, ``DEPRECATED``, ``attrs``, ``target_ids``, -``init_regions``, ``schemes``, ``monitor_on_DEPRECATED``, ``kdamond_pid``, -``mk_contexts`` and ``rm_contexts`` under its debugfs directory, -``/damon/``. - - -``DEPRECATED`` is a read-only file for the DAMON debugfs interface depreca= tion -notice. Reading it returns the deprecation notice, as below:: - - # cat DEPRECATED - DAMON debugfs interface is deprecated, so users should move to DAMON_S= YSFS. If you cannot, please report your usecase to damon@lists.linux.dev an= d linux-mm@kvack.org. - - -Attributes ----------- - -Users can get and set the ``sampling interval``, ``aggregation interval``, -``update interval``, and min/max number of monitoring target regions by -reading from and writing to the ``attrs`` file. To know about the monitor= ing -attributes in detail, please refer to the :doc:`/mm/damon/design`. For -example, below commands set those values to 5 ms, 100 ms, 1,000 ms, 10 and -1000, and then 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 exa= mple, -the virtual memory address spaces monitoring can have multiple processes a= s the -monitoring targets. Users can set the targets by writing relevant id valu= es 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, be= low -commands set processes having pids 42 and 4242 as the monitoring targets a= nd -check it again:: - - # cd /damon - # echo 42 4242 > target_ids - # cat target_ids - 42 4242 - -Users can also monitor the physical memory address space of the system by -writing a special keyword, "``paddr\n``" to the file. Because physical ad= dress -space monitoring doesn't support multiple targets, reading the file will s= how a -fake value, ``42``, as below:: - - # cd /damon - # echo paddr > target_ids - # cat target_ids - 42 - -Note that setting the target ids doesn't start the monitoring. - - -Initial Monitoring Target Regions ---------------------------------- - -In case of the virtual address space monitoring, DAMON automatically sets = and -updates the monitoring target regions so that entire memory mappings of ta= rget -processes can be covered. However, users can want to limit the monitoring -region to specific address ranges, such as the heap, the stack, or specific -file-mapped area. Or, some users can know the initial access pattern of t= heir -workloads and therefore want to set optimal initial regions for the 'adapt= ive -regions adjustment'. - -In contrast, DAMON do not automatically sets and updates the monitoring ta= rget -regions in case of physical memory monitoring. Therefore, users should se= t the -monitoring target regions by themselves. - -In such cases, users can explicitly set the initial monitoring target regi= ons -as they want, by writing proper values to the ``init_regions`` file. The = input -should be a sequence of three integers separated by white spaces that repr= esent -one region in below form.:: - - - -The ``target idx`` should be the index of the target in ``target_ids`` fil= e, -starting from ``0``, and the regions should be passed in address order. F= or -example, below commands will set a couple of address ranges, ``1-100`` and -``100-200`` as the initial monitoring target region of pid 42, which is the -first one (index ``0``) in ``target_ids``, and another couple of address -ranges, ``20-40`` and ``50-100`` as that of pid 4242, which is the second = one -(index ``1``) in ``target_ids``.:: - - # cd /damon - # cat target_ids - 42 4242 - # echo "0 1 100 \ - 0 100 200 \ - 1 20 40 \ - 1 50 100" > init_regions - -Note that this sets the initial monitoring target regions only. In case of -virtual memory monitoring, DAMON will automatically updates the boundary o= f the -regions after one ``update interval``. Therefore, users should set the -``update interval`` large enough in this case, if they don't want the -update. - - -Schemes -------- - -Users can get and set the DAMON-based operation :ref:`schemes -` by reading from and writing to ``schemes`` debugfs f= ile. -Reading the file also shows the statistics of each scheme. To the file, e= ach -of the schemes should be represented in each line in below form:: - - - -You can disable schemes by simply writing an empty string to the file. - -Target Access Pattern -~~~~~~~~~~~~~~~~~~~~~ - -The target access :ref:`pattern ` of the -scheme. The ```` is constructed with three ranges = in -below form:: - - min-size max-size min-acc max-acc min-age max-age - -Specifically, bytes for the size of regions (``min-size`` and ``max-size``= ), -number of monitored accesses per aggregate interval for access frequency -(``min-acc`` and ``max-acc``), number of aggregate intervals for the age of -regions (``min-age`` and ``max-age``) are specified. Note that the ranges= are -closed interval. - -Action -~~~~~~ - -The ```` is a predefined integer for memory management :ref:`actio= ns -`. The mapping between the ```` values= and -the memory management actions is as below. For the detailed meaning of the -action and DAMON operations set supporting each action, please refer to the -list on :ref:`design doc `. - - - 0: ``willneed`` - - 1: ``cold`` - - 2: ``pageout`` - - 3: ``hugepage`` - - 4: ``nohugepage`` - - 5: ``stat`` - -Quota -~~~~~ - -Users can set the :ref:`quotas ` of the given s= cheme -via the ```` in below form:: - - - -This makes DAMON to try to use only up to ```` milliseconds for applyi= ng -the action to memory regions of the ``target access pattern`` within the -```` milliseconds, and to apply the action to only up to -```` bytes of memory regions within the ````. Setting= both -```` and ```` zero disables the quota limits. - -For the :ref:`prioritization `, = users -can set the weights for the three properties in ```` in = below -form:: - - - -Watermarks -~~~~~~~~~~ - -Users can specify :ref:`watermarks ` of the -given scheme via ```` in below form:: - - - -```` is a predefined integer for the metric to be checked. The -supported numbers and their meanings are as below. - - - 0: Ignore the watermarks - - 1: System's free memory rate (per thousand) - -The value of the metric is checked every ```` microseconds. - -If the value is higher than ```` or lower than ````, = the -scheme is deactivated. If the value is lower than ````, the sch= eme -is activated. - -.. _damos_stats: - -Statistics -~~~~~~~~~~ - -It also counts the total number and bytes of regions that each scheme is t= ried -to be applied, the two numbers for the regions that each scheme is success= fully -applied, and the total number of the quota limit exceeds. This statistics= can -be used for online analysis or tuning of the schemes. - -The statistics can be shown by reading the ``schemes`` file. Reading the = file -will show each scheme you entered in each line, and the five numbers for t= he -statistics will be added at the end of each line. - -Example -~~~~~~~ - -Below commands applies a scheme saying "If a memory region of size in [4Ki= B, -8KiB] is showing accesses per aggregate interval in [0, 5] for aggregate -interval in [10, 20], page out the region. For the paging out, use only u= p to -10ms per second, and also don't page out more than 1GiB per second. Under= the -limitation, page out memory regions having longer age first. Also, check = the -free memory rate of the system every 5 seconds, start the monitoring and p= aging -out when the free memory rate becomes lower than 50%, but stop it if the f= ree -memory rate becomes larger than 60%, or lower than 30%".:: - - # cd /damon - # scheme=3D"4096 8192 0 5 10 20 2" # target access pattern and= action - # scheme+=3D" 10 $((1024*1024*1024)) 1000" # quotas - # scheme+=3D" 0 0 100" # prioritization weights - # scheme+=3D" 1 5000000 600 500 300" # watermarks - # echo "$scheme" > schemes - - -Turning On/Off --------------- - -Setting the files as described above doesn't incur effect unless you expli= citly -start the monitoring. You can start, stop, and check the current status o= f the -monitoring by writing to and reading from the ``monitor_on_DEPRECATED`` fi= le. -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 target process is terminated. Below example commands turn on, off, = and -check the status of DAMON:: - - # cd /damon - # echo on > monitor_on_DEPRECATED - # echo off > monitor_on_DEPRECATED - # cat monitor_on_DEPRECATED - off - -Please note that you cannot write to the above-mentioned debugfs files whi= le -the monitoring is turned on. If you write to the files while DAMON is run= ning, -an error code such as ``-EBUSY`` will be returned. - - -Monitoring Thread PID ---------------------- - -DAMON does requested monitoring with a kernel thread called ``kdamond``. = You -can get the pid of the thread by reading the ``kdamond_pid`` file. When t= he -monitoring is turned off, reading the file returns ``none``. :: - - # cd /damon - # cat monitor_on_DEPRECATED - off - # cat kdamond_pid - none - # echo on > monitor_on_DEPRECATED - # cat kdamond_pid - 18594 - - -Using Multiple Monitoring Threads ---------------------------------- - -One ``kdamond`` thread is created for each monitoring context. You can cr= eate -and remove monitoring contexts for multiple ``kdamond`` required use case = using -the ``mk_contexts`` and ``rm_contexts`` files. - -Writing the name of the new context to the ``mk_contexts`` file creates a -directory of the name on the DAMON debugfs directory. The directory will = have -DAMON debugfs files for the context. :: - - # cd /damon - # ls foo - # ls: cannot access 'foo': No such file or directory - # echo foo > mk_contexts - # ls foo - # attrs init_regions kdamond_pid schemes target_ids - -If the context is not needed anymore, you can remove it and the correspond= ing -directory by putting the name of the context to the ``rm_contexts`` file. = :: - - # echo foo > rm_contexts - # ls foo - # ls: cannot access 'foo': No such file or directory - -Note that ``mk_contexts``, ``rm_contexts``, and ``monitor_on_DEPRECATED`` = files -are in the root directory only. --=20 2.39.5 From nobody Tue Nov 26 22:39:37 2024 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 590981FC7D2; Tue, 15 Oct 2024 17:54:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729014864; cv=none; b=gmmba/2d6LNUViE1SUhydynZGF13u3UgQgsMQczRm31uWJlRKEumIjEi/pkmAH/K6OO6pvK7tn3kU0YtJsqhCgrUX0icTK4HeA2FBabX9ByndWMiq2oBakZ2OYGhFPPZhDy2eRO7Fbgbb/tzG8I6spf78CNgii0V2hhYKFO5iJk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729014864; c=relaxed/simple; bh=wNqTcFJIxQW0DGiFjvquOYDznG7ET2BviVO3AFzePVw=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=r5kIEL1QTVaLYz//KAb681doEOR+w3d8uM5IME0/lqb0Gc8swZMX5myF/kIG1Un2RD8JzTfzscd8NaDbjhEQ8NW3IGatOFlfKT/mmwM0Pi74TiFlfP36nl/SISsUhFCH8djWW4yfE97mttw+kofJ6D29JEPggKy9dumvbTFe7dc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=IN553IGY; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="IN553IGY" Received: by smtp.kernel.org (Postfix) with ESMTPSA id B8FACC4CEC6; Tue, 15 Oct 2024 17:54:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1729014863; bh=wNqTcFJIxQW0DGiFjvquOYDznG7ET2BviVO3AFzePVw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=IN553IGYCEU2daGjInivP6wG0GqSAzY1UIjJtoUptobp/Mi1e1SbYGZ8c4FCruTm/ qtklAPy3K+bvswTj4bT2cK8UcYo4ZqYGYn38LIzSYHJxpWBj5AEOi3Ijba8AE2PLW4 SKVTgx9GC6L2qKGAsYaYEr6akbFYH74Sgna3lEReGrulejAW95EsdPLDpN2cnkguSs zvldwUqzg77Ayt+TqxcrMl8pXczmm0hwtKydMSW6w56qSBhyPljk6mlEDKADUaBu7T OdMJHJAVLYmvWdrccFdnWpQPnk7As+zzqBH7d8KVPruAmReCP1sgUOA41v8MnjR7eF sdZVR9Jm02dRg== From: SeongJae Park To: Cc: SeongJae Park , Andrew Morton , Jonathan Corbet , damon@lists.linux.dev, linux-mm@kvack.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [RFC PATCH 2/7] Docs/mm/damon/design: update for removal of DAMON debugfs interface Date: Tue, 15 Oct 2024 10:54:07 -0700 Message-Id: <20241015175412.60563-3-sj@kernel.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20241015175412.60563-1-sj@kernel.org> References: <20241015175412.60563-1-sj@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" It's time to remove DAMON debugfs interface, which has deprecated long before in February 2023. Read the cover letter of this patch series for more details. Update DAMON design documentation to stop mentioning about the interface, to avoid unnecessary confuses. Signed-off-by: SeongJae Park --- Documentation/mm/damon/design.rst | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/Documentation/mm/damon/design.rst b/Documentation/mm/damon/des= ign.rst index f9c50525bdbf..1c8a43b07b00 100644 --- a/Documentation/mm/damon/design.rst +++ b/Documentation/mm/damon/design.rst @@ -573,15 +573,11 @@ General Purpose User Interface Modules DAMON modules that provide user space ABIs for general purpose DAMON usage= in runtime. =20 -DAMON user interface modules, namely 'DAMON sysfs interface' and 'DAMON de= bugfs -interface' are DAMON API user kernel modules that provide ABIs to the -user-space. Please note that DAMON debugfs interface is currently depreca= ted. - -Like many other ABIs, the modules create files on sysfs and debugfs, allow -users to specify their requests to and get the answers from DAMON by writi= ng to -and reading from the files. As a response to such I/O, DAMON user interfa= ce -modules control DAMON and retrieve the results as user requested via the D= AMON -API, and return the results to the user-space. +Like many other ABIs, the modules create files on pseudo file systems like +'sysfs', allow users to specify their requests to and get the answers from +DAMON by writing to and reading from the files. As a response to such I/O, +DAMON user interface modules control DAMON and retrieve the results as user +requested via the DAMON API, and return the results to the user-space. =20 The ABIs are designed to be used for user space applications development, rather than human beings' fingers. Human users are recommended to use such @@ -590,8 +586,9 @@ Github (https://github.com/damonitor/damo), Pypi (https://pypistats.org/packages/damo), and Fedora (https://packages.fedoraproject.org/pkgs/python-damo/damo/). =20 -Please refer to the ABI :doc:`document ` for -details of the interfaces. +Currently, one module for this type, namely 'DAMON sysfs interface' is +available. Please refer to the ABI :ref:`doc ` for detai= ls of +the interfaces. =20 =20 Special-Purpose Access-aware Kernel Modules @@ -599,8 +596,8 @@ Special-Purpose Access-aware Kernel Modules =20 DAMON modules that provide user space ABI for specific purpose DAMON usage. =20 -DAMON sysfs/debugfs user interfaces are for full control of all DAMON feat= ures -in runtime. For each special-purpose system-wide data access-aware system +DAMON user interface modules are for full control of all DAMON features in +runtime. For each special-purpose system-wide data access-aware system operations such as proactive reclamation or LRU lists balancing, the inter= faces could be simplified by removing unnecessary knobs for the specific purpose= , and extended for boot-time and even compile time control. Default values of D= AMON --=20 2.39.5 From nobody Tue Nov 26 22:39:37 2024 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7B1DB212D0A; Tue, 15 Oct 2024 17:54:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729014865; cv=none; b=FpR/ZcwauabyBeFPzO9uKd/VEjf+raDZrhka0pvko36ZWzt5ZgQBxx40udaEzpfAlBoGPHTZnC0TlLeC+8FIy8kUemDClMU2o669d1m4THOXW0+/DWhHqQL/TQI1slIkYxB3CY+xC4DrMJLSII2H9pNjyt79QqjrD33jl+mejsY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729014865; c=relaxed/simple; bh=7oF79jn9lmm7ZWBErpi45JOkdTnxIklx6KgFpgZJtWk=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=hhT8xwZKyjFP2k42xK+Ss+Akv5N+LfbzGAvPJhUcHqC4HdaG90JIdiQDqjVGCtJ213f0qxZcWDfL+Ex6Km0Wtdut3f8FmnxwrtIEzEch2CPaWHfPgRGErvNJ3Z/YBKr8HkpPxPWSPGIETzdZqXS561sIbD9gzgWSTjMB2Jqrd74= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=ZRwj6O7a; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="ZRwj6O7a" Received: by smtp.kernel.org (Postfix) with ESMTPSA id E7A90C4CEC6; Tue, 15 Oct 2024 17:54:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1729014865; bh=7oF79jn9lmm7ZWBErpi45JOkdTnxIklx6KgFpgZJtWk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ZRwj6O7az1k0rfe6QUN4UubDGCnxPfRgD/fFV9O7VgOyvZFYeHAmHatrF8iS2c48M HM+HZ3n/9fe5ENK+9k3PjOB51b+jiHU20qYQG04hYhGRJpLLxf4dt/C0KEt9i4vRUK i3Ez5U6z09AFYIGB9vOPBbM8mSMIgGvnpWOoIJnsVzJWeG3RvUAFJlwZ9dGplaiXGS 4hyo7A4iwzGUkeq6Pt1SAVXXvWRH4zKaiI9gLAGimKhGYoxVtYcOCTLry+rbQ8sx/d SFBVntz5401F/cpYK0Qm2uvufvwIZpjWtnXsYrBU9/NrLjYEtNmv3rD/ImYBlmhgE0 azYvLs6q6ND8w== From: SeongJae Park To: Cc: SeongJae Park , Andrew Morton , Shuah Khan , damon@lists.linux.dev, linux-mm@kvack.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [RFC PATCH 3/7] selftests/damon/config: remove configs for DAMON debugfs interface selftests Date: Tue, 15 Oct 2024 10:54:08 -0700 Message-Id: <20241015175412.60563-4-sj@kernel.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20241015175412.60563-1-sj@kernel.org> References: <20241015175412.60563-1-sj@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" It's time to remove DAMON debugfs interface, which has deprecated long before in February 2023. Read the cover letter of this patch series for more details. Remove configs for selftests of it from DAMON selftests config file, to prevent unnecessary noises from the tests. [1] https://lore.kernel.org/20230209192009.7885-1-sj@kernel.org Signed-off-by: SeongJae Park --- tools/testing/selftests/damon/config | 1 - 1 file changed, 1 deletion(-) diff --git a/tools/testing/selftests/damon/config b/tools/testing/selftests= /damon/config index 0daf38974eb0..a68a9fead5dc 100644 --- a/tools/testing/selftests/damon/config +++ b/tools/testing/selftests/damon/config @@ -1,6 +1,5 @@ CONFIG_DAMON=3Dy CONFIG_DAMON_SYSFS=3Dy -CONFIG_DAMON_DBGFS=3Dy CONFIG_DAMON_PADDR=3Dy CONFIG_DAMON_VADDR=3Dy CONFIG_DAMON_RECLAIM=3Dy --=20 2.39.5 From nobody Tue Nov 26 22:39:37 2024 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BCF822281CB; Tue, 15 Oct 2024 17:54:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729014867; cv=none; b=V93wXyquJMpZ7O4mnbdTledfzUT0XKMKdxJvjMdYixg84VuLLwLPIMqQnhUFcv7xLewoD1kQn3phmPxHUoPZiM9pkaVhJbuw4MzpAen/Gchg8BfRb5e75LhPiDgRjYSYZFiTvbomVVIm2rPwFeydY9kBv5nknAnlpvhx0kKeo1E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729014867; c=relaxed/simple; bh=0Hh2QMFBW1aSAnc+4PuGanKNHQGEFuqZ1dsyyv6x/qA=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=B7BYiia93SbFJVqNCWWS00cMJKEmsz/9FZ1gxD7OiGhhlR7/9rgR7j5nJM9rCezK1WCGvNeXlFZvv4EuzFxcpy5fboSxscqmvBeyLmyyeB6XjEByNn6Af8UEmPEF4yZagbDGXZuKJRQbBs0jZgopE/eXePnOV4aeZQ2w5IJxwJk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=bHlwaDVq; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="bHlwaDVq" Received: by smtp.kernel.org (Postfix) with ESMTPSA id F3B78C4CEC7; Tue, 15 Oct 2024 17:54:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1729014866; bh=0Hh2QMFBW1aSAnc+4PuGanKNHQGEFuqZ1dsyyv6x/qA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bHlwaDVqMsH0XSWdMbi7ukCdTnwnWTUbtysf0GmDb8+tO7xXP4p7wnGNR93BTUUGu Xqf/Mh/u5wXUQimx9akVJ1j5V/7ratrbknhc9Ge+zeI23jF6onlF9yAD74eQ8bHfD3 2xSpUppkTbrKkIGJeL1reybI1VZklRaXomolyfedL2Flj0ojBAdBmuLOkjHNshTQXg F4UO1WNw7AXplOE/zy+6qe0SpvntzGeVgv0j67yZAgk665LTq9K2/D2pRHyCnNZrs+ 0xXKJYS3G4CR0UTD5rdGjjx+fWEPKIiVzQqUxXR1vsF8Chc8VYfbomE263vmwKj7HF Rfg3Vul8dw6DQ== From: SeongJae Park To: Cc: SeongJae Park , Andrew Morton , Shuah Khan , damon@lists.linux.dev, linux-mm@kvack.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [RFC PATCH 4/7] selftests/damon: remove tests for DAMON debugfs interface Date: Tue, 15 Oct 2024 10:54:09 -0700 Message-Id: <20241015175412.60563-5-sj@kernel.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20241015175412.60563-1-sj@kernel.org> References: <20241015175412.60563-1-sj@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" It's time to remove DAMON debugfs interface, which has deprecated long before in February 2023. Read the cover letter of this patch series for more details. Remove selftests for the interface, to prevent causing unnecessary test failures. Signed-off-by: SeongJae Park --- tools/testing/selftests/damon/.gitignore | 3 - tools/testing/selftests/damon/Makefile | 11 +-- .../testing/selftests/damon/debugfs_attrs.sh | 17 ---- .../debugfs_duplicate_context_creation.sh | 27 ------- .../selftests/damon/debugfs_empty_targets.sh | 21 ----- .../damon/debugfs_huge_count_read_write.sh | 22 ----- .../damon/debugfs_rm_non_contexts.sh | 19 ----- .../selftests/damon/debugfs_schemes.sh | 19 ----- .../selftests/damon/debugfs_target_ids.sh | 19 ----- .../damon/debugfs_target_ids_pid_leak.c | 68 ---------------- .../damon/debugfs_target_ids_pid_leak.sh | 22 ----- ...fs_target_ids_read_before_terminate_race.c | 80 ------------------- ...s_target_ids_read_before_terminate_race.sh | 14 ---- .../selftests/damon/huge_count_read_write.c | 48 ----------- 14 files changed, 1 insertion(+), 389 deletions(-) delete mode 100755 tools/testing/selftests/damon/debugfs_attrs.sh delete mode 100755 tools/testing/selftests/damon/debugfs_duplicate_context= _creation.sh delete mode 100755 tools/testing/selftests/damon/debugfs_empty_targets.sh delete mode 100755 tools/testing/selftests/damon/debugfs_huge_count_read_w= rite.sh delete mode 100755 tools/testing/selftests/damon/debugfs_rm_non_contexts.sh delete mode 100755 tools/testing/selftests/damon/debugfs_schemes.sh delete mode 100755 tools/testing/selftests/damon/debugfs_target_ids.sh delete mode 100644 tools/testing/selftests/damon/debugfs_target_ids_pid_le= ak.c delete mode 100755 tools/testing/selftests/damon/debugfs_target_ids_pid_le= ak.sh delete mode 100644 tools/testing/selftests/damon/debugfs_target_ids_read_b= efore_terminate_race.c delete mode 100755 tools/testing/selftests/damon/debugfs_target_ids_read_b= efore_terminate_race.sh delete mode 100644 tools/testing/selftests/damon/huge_count_read_write.c diff --git a/tools/testing/selftests/damon/.gitignore b/tools/testing/selft= ests/damon/.gitignore index 2ab675fecb6b..2f0297657c81 100644 --- a/tools/testing/selftests/damon/.gitignore +++ b/tools/testing/selftests/damon/.gitignore @@ -1,6 +1,3 @@ # SPDX-License-Identifier: GPL-2.0-only -huge_count_read_write -debugfs_target_ids_read_before_terminate_race -debugfs_target_ids_pid_leak access_memory access_memory_even diff --git a/tools/testing/selftests/damon/Makefile b/tools/testing/selftes= ts/damon/Makefile index 5b2a6a5dd1af..fa6042998004 100644 --- a/tools/testing/selftests/damon/Makefile +++ b/tools/testing/selftests/damon/Makefile @@ -1,15 +1,11 @@ # SPDX-License-Identifier: GPL-2.0 # Makefile for damon selftests =20 -TEST_GEN_FILES +=3D huge_count_read_write -TEST_GEN_FILES +=3D debugfs_target_ids_read_before_terminate_race -TEST_GEN_FILES +=3D debugfs_target_ids_pid_leak TEST_GEN_FILES +=3D access_memory access_memory_even =20 -TEST_FILES =3D _chk_dependency.sh _debugfs_common.sh +TEST_FILES =3D _chk_dependency.sh =20 # functionality tests -TEST_PROGS =3D debugfs_attrs.sh debugfs_schemes.sh debugfs_target_ids.sh TEST_PROGS +=3D sysfs.sh TEST_PROGS +=3D sysfs_update_schemes_tried_regions_wss_estimation.py TEST_PROGS +=3D damos_quota.py damos_quota_goal.py damos_apply_interval.py @@ -17,11 +13,6 @@ TEST_PROGS +=3D damos_tried_regions.py damon_nr_regions.= py TEST_PROGS +=3D reclaim.sh lru_sort.sh =20 # regression tests (reproducers of previously found bugs) -TEST_PROGS +=3D debugfs_empty_targets.sh debugfs_huge_count_read_write.sh -TEST_PROGS +=3D debugfs_duplicate_context_creation.sh -TEST_PROGS +=3D debugfs_rm_non_contexts.sh -TEST_PROGS +=3D debugfs_target_ids_read_before_terminate_race.sh -TEST_PROGS +=3D debugfs_target_ids_pid_leak.sh TEST_PROGS +=3D sysfs_update_removed_scheme_dir.sh TEST_PROGS +=3D sysfs_update_schemes_tried_regions_hang.py =20 diff --git a/tools/testing/selftests/damon/debugfs_attrs.sh b/tools/testing= /selftests/damon/debugfs_attrs.sh deleted file mode 100755 index 902e312bca89..000000000000 --- a/tools/testing/selftests/damon/debugfs_attrs.sh +++ /dev/null @@ -1,17 +0,0 @@ -#!/bin/bash -# SPDX-License-Identifier: GPL-2.0 - -source _debugfs_common.sh - -# Test attrs file -# =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D - -file=3D"$DBGFS/attrs" -orig_content=3D$(cat "$file") - -test_write_succ "$file" "1 2 3 4 5" "$orig_content" "valid input" -test_write_fail "$file" "1 2 3 4" "$orig_content" "no enough fields" -test_write_fail "$file" "1 2 3 5 4" "$orig_content" \ - "min_nr_regions > max_nr_regions" -test_content "$file" "$orig_content" "1 2 3 4 5" "successfully written" -echo "$orig_content" > "$file" diff --git a/tools/testing/selftests/damon/debugfs_duplicate_context_creati= on.sh b/tools/testing/selftests/damon/debugfs_duplicate_context_creation.sh deleted file mode 100755 index 4a76e37ef16b..000000000000 --- a/tools/testing/selftests/damon/debugfs_duplicate_context_creation.sh +++ /dev/null @@ -1,27 +0,0 @@ -#!/bin/bash -# SPDX-License-Identifier: GPL-2.0 - -source _debugfs_common.sh - -# Test duplicated context creation -# =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D - -if ! echo foo > "$DBGFS/mk_contexts" -then - echo "context creation failed" - exit 1 -fi - -if echo foo > "$DBGFS/mk_contexts" -then - echo "duplicate context creation success" - exit 1 -fi - -if ! echo foo > "$DBGFS/rm_contexts" -then - echo "context deletion failed" - exit 1 -fi - -exit 0 diff --git a/tools/testing/selftests/damon/debugfs_empty_targets.sh b/tools= /testing/selftests/damon/debugfs_empty_targets.sh deleted file mode 100755 index effbea33dc16..000000000000 --- a/tools/testing/selftests/damon/debugfs_empty_targets.sh +++ /dev/null @@ -1,21 +0,0 @@ -#!/bin/bash -# SPDX-License-Identifier: GPL-2.0 - -source _debugfs_common.sh - -# Test empty targets case -# =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D - -orig_target_ids=3D$(cat "$DBGFS/target_ids") -echo "" > "$DBGFS/target_ids" - -if [ -f "$DBGFS/monitor_on_DEPRECATED" ] -then - monitor_on_file=3D"$DBGFS/monitor_on_DEPRECATED" -else - monitor_on_file=3D"$DBGFS/monitor_on" -fi - -orig_monitor_on=3D$(cat "$monitor_on_file") -test_write_fail "$monitor_on_file" "on" "orig_monitor_on" "empty target id= s" -echo "$orig_target_ids" > "$DBGFS/target_ids" diff --git a/tools/testing/selftests/damon/debugfs_huge_count_read_write.sh= b/tools/testing/selftests/damon/debugfs_huge_count_read_write.sh deleted file mode 100755 index 922cadac2950..000000000000 --- a/tools/testing/selftests/damon/debugfs_huge_count_read_write.sh +++ /dev/null @@ -1,22 +0,0 @@ -#!/bin/bash -# SPDX-License-Identifier: GPL-2.0 - -source _debugfs_common.sh - -# Test huge count read write -# =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D - -dmesg -C - -for file in "$DBGFS/"* -do - ./huge_count_read_write "$file" -done - -if dmesg | grep -q WARNING -then - dmesg - exit 1 -else - exit 0 -fi diff --git a/tools/testing/selftests/damon/debugfs_rm_non_contexts.sh b/too= ls/testing/selftests/damon/debugfs_rm_non_contexts.sh deleted file mode 100755 index f3ffeb1343cf..000000000000 --- a/tools/testing/selftests/damon/debugfs_rm_non_contexts.sh +++ /dev/null @@ -1,19 +0,0 @@ -#!/bin/bash -# SPDX-License-Identifier: GPL-2.0 - -source _debugfs_common.sh - -# Test putting non-ctx files/dirs to rm_contexts file -# =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D - -dmesg -C - -for file in "$DBGFS/"* -do - (echo "$(basename "$f")" > "$DBGFS/rm_contexts") &> /dev/null - if dmesg | grep -q BUG - then - dmesg - exit 1 - fi -done diff --git a/tools/testing/selftests/damon/debugfs_schemes.sh b/tools/testi= ng/selftests/damon/debugfs_schemes.sh deleted file mode 100755 index 5b39ab44731c..000000000000 --- a/tools/testing/selftests/damon/debugfs_schemes.sh +++ /dev/null @@ -1,19 +0,0 @@ -#!/bin/bash -# SPDX-License-Identifier: GPL-2.0 - -source _debugfs_common.sh - -# Test schemes file -# =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D - -file=3D"$DBGFS/schemes" -orig_content=3D$(cat "$file") - -test_write_succ "$file" "1 2 3 4 5 6 4 0 0 0 1 2 3 1 100 3 2 1" \ - "$orig_content" "valid input" -test_write_fail "$file" "1 2 -3 4 5 6 3 0 0 0 1 2 3 1 100 3 2 1" "$orig_content" "multi lines" -test_write_succ "$file" "" "$orig_content" "disabling" -test_write_fail "$file" "2 1 2 1 10 1 3 10 1 1 1 1 1 1 1 1 2 3" \ - "$orig_content" "wrong condition ranges" -echo "$orig_content" > "$file" diff --git a/tools/testing/selftests/damon/debugfs_target_ids.sh b/tools/te= sting/selftests/damon/debugfs_target_ids.sh deleted file mode 100755 index 49aeabdb0aae..000000000000 --- a/tools/testing/selftests/damon/debugfs_target_ids.sh +++ /dev/null @@ -1,19 +0,0 @@ -#!/bin/bash -# SPDX-License-Identifier: GPL-2.0 - -source _debugfs_common.sh - -# Test target_ids file -# =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D - -file=3D"$DBGFS/target_ids" -orig_content=3D$(cat "$file") - -test_write_succ "$file" "1 2 3 4" "$orig_content" "valid input" -test_write_succ "$file" "1 2 abc 4" "$orig_content" "still valid input" -test_content "$file" "$orig_content" "1 2" "non-integer was there" -test_write_succ "$file" "abc 2 3" "$orig_content" "the file allows wrong i= nput" -test_content "$file" "$orig_content" "" "wrong input written" -test_write_succ "$file" "" "$orig_content" "empty input" -test_content "$file" "$orig_content" "" "empty input written" -echo "$orig_content" > "$file" diff --git a/tools/testing/selftests/damon/debugfs_target_ids_pid_leak.c b/= tools/testing/selftests/damon/debugfs_target_ids_pid_leak.c deleted file mode 100644 index 0cc2eef7d142..000000000000 --- a/tools/testing/selftests/damon/debugfs_target_ids_pid_leak.c +++ /dev/null @@ -1,68 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 -/* - * Author: SeongJae Park - */ - -#define _GNU_SOURCE - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#define DBGFS_TARGET_IDS "/sys/kernel/debug/damon/target_ids" - -static void write_targetid_exit(void) -{ - int target_ids_fd =3D open(DBGFS_TARGET_IDS, O_RDWR); - char pid_str[128]; - - snprintf(pid_str, sizeof(pid_str), "%d", getpid()); - write(target_ids_fd, pid_str, sizeof(pid_str)); - close(target_ids_fd); - exit(0); -} - -unsigned long msec_timestamp(void) -{ - struct timeval tv; - - gettimeofday(&tv, NULL); - return tv.tv_sec * 1000UL + tv.tv_usec / 1000; -} - -int main(int argc, char *argv[]) -{ - unsigned long start_ms; - int time_to_run, nr_forks =3D 0; - - if (argc !=3D 2) { - fprintf(stderr, "Usage: %s \n", argv[0]); - exit(1); - } - time_to_run =3D atoi(argv[1]); - - start_ms =3D msec_timestamp(); - while (true) { - int pid =3D fork(); - - if (pid < 0) { - fprintf(stderr, "fork() failed\n"); - exit(1); - } - if (pid =3D=3D 0) - write_targetid_exit(); - wait(NULL); - nr_forks++; - - if (msec_timestamp() - start_ms > time_to_run) - break; - } - printf("%d\n", nr_forks); - return 0; -} diff --git a/tools/testing/selftests/damon/debugfs_target_ids_pid_leak.sh b= /tools/testing/selftests/damon/debugfs_target_ids_pid_leak.sh deleted file mode 100755 index 31fe33c2b032..000000000000 --- a/tools/testing/selftests/damon/debugfs_target_ids_pid_leak.sh +++ /dev/null @@ -1,22 +0,0 @@ -#!/bin/bash -# SPDX-License-Identifier: GPL-2.0 - -before=3D$(grep "^pid " /proc/slabinfo | awk '{print $2}') - -nr_leaks=3D$(./debugfs_target_ids_pid_leak 1000) -expected_after_max=3D$((before + nr_leaks / 2)) - -after=3D$(grep "^pid " /proc/slabinfo | awk '{print $2}') - -echo > /sys/kernel/debug/damon/target_ids - -echo "tried $nr_leaks pid leak" -echo "number of active pid slabs: $before -> $after" -echo "(up to $expected_after_max expected)" -if [ $after -gt $expected_after_max ] -then - echo "maybe pids are leaking" - exit 1 -else - exit 0 -fi diff --git a/tools/testing/selftests/damon/debugfs_target_ids_read_before_t= erminate_race.c b/tools/testing/selftests/damon/debugfs_target_ids_read_bef= ore_terminate_race.c deleted file mode 100644 index b06f52a8ce2d..000000000000 --- a/tools/testing/selftests/damon/debugfs_target_ids_read_before_terminat= e_race.c +++ /dev/null @@ -1,80 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 -/* - * Author: SeongJae Park - */ -#define _GNU_SOURCE - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#define DBGFS_MONITOR_ON "/sys/kernel/debug/damon/monitor_on_DEPRECATED" -#define DBGFS_TARGET_IDS "/sys/kernel/debug/damon/target_ids" - -static void turn_damon_on_exit(void) -{ - int target_ids_fd =3D open(DBGFS_TARGET_IDS, O_RDWR); - int monitor_on_fd =3D open(DBGFS_MONITOR_ON, O_RDWR); - char pid_str[128]; - - snprintf(pid_str, sizeof(pid_str), "%d", getpid()); - write(target_ids_fd, pid_str, sizeof(pid_str)); - write(monitor_on_fd, "on\n", 3); - close(target_ids_fd); - close(monitor_on_fd); - usleep(1000); - exit(0); -} - -static void try_race(void) -{ - int target_ids_fd =3D open(DBGFS_TARGET_IDS, O_RDWR); - int pid =3D fork(); - int buf[256]; - - if (pid < 0) { - fprintf(stderr, "fork() failed\n"); - exit(1); - } - if (pid =3D=3D 0) - turn_damon_on_exit(); - while (true) { - int status; - - read(target_ids_fd, buf, sizeof(buf)); - if (waitpid(-1, &status, WNOHANG) =3D=3D pid) - break; - } - close(target_ids_fd); -} - -static inline uint64_t ts_to_ms(struct timespec *ts) -{ - return (uint64_t)ts->tv_sec * 1000 + (uint64_t)ts->tv_nsec / 1000000; -} - -int main(int argc, char *argv[]) -{ - struct timespec start_time, now; - int runtime_ms; - - if (argc !=3D 2) { - fprintf(stderr, "Usage: %s \n", argv[0]); - exit(1); - } - runtime_ms =3D atoi(argv[1]); - clock_gettime(CLOCK_MONOTONIC, &start_time); - while (true) { - try_race(); - clock_gettime(CLOCK_MONOTONIC, &now); - if (ts_to_ms(&now) - ts_to_ms(&start_time) > runtime_ms) - break; - } - return 0; -} diff --git a/tools/testing/selftests/damon/debugfs_target_ids_read_before_t= erminate_race.sh b/tools/testing/selftests/damon/debugfs_target_ids_read_be= fore_terminate_race.sh deleted file mode 100755 index fc793c4c9aea..000000000000 --- a/tools/testing/selftests/damon/debugfs_target_ids_read_before_terminat= e_race.sh +++ /dev/null @@ -1,14 +0,0 @@ -#!/bin/bash -# SPDX-License-Identifier: GPL-2.0 - -dmesg -C - -./debugfs_target_ids_read_before_terminate_race 5000 - -if dmesg | grep -q dbgfs_target_ids_read -then - dmesg - exit 1 -else - exit 0 -fi diff --git a/tools/testing/selftests/damon/huge_count_read_write.c b/tools/= testing/selftests/damon/huge_count_read_write.c deleted file mode 100644 index a6fe0689f88d..000000000000 --- a/tools/testing/selftests/damon/huge_count_read_write.c +++ /dev/null @@ -1,48 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 -/* - * Author: SeongJae Park - */ - -#include -#include -#include -#include - -#pragma GCC diagnostic push -#if __GNUC__ >=3D 11 && __GNUC_MINOR__ >=3D 1 -/* Ignore read(2) overflow and write(2) overread compile warnings */ -#pragma GCC diagnostic ignored "-Wstringop-overread" -#pragma GCC diagnostic ignored "-Wstringop-overflow" -#endif - -void write_read_with_huge_count(char *file) -{ - int filedesc =3D open(file, O_RDWR); - char buf[25]; - int ret; - - printf("%s %s\n", __func__, file); - if (filedesc < 0) { - fprintf(stderr, "failed opening %s\n", file); - exit(1); - } - - write(filedesc, "", 0xfffffffful); - perror("after write: "); - ret =3D read(filedesc, buf, 0xfffffffful); - perror("after read: "); - close(filedesc); -} - -#pragma GCC diagnostic pop - -int main(int argc, char *argv[]) -{ - if (argc !=3D 2) { - fprintf(stderr, "Usage: %s \n", argv[0]); - exit(1); - } - write_read_with_huge_count(argv[1]); - - return 0; -} --=20 2.39.5 From nobody Tue Nov 26 22:39:37 2024 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BCF262281C9; Tue, 15 Oct 2024 17:54:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729014867; cv=none; b=HG5xvZODYx0P5XiiRIEs/RHeOMUJClzADNMB1jz9/p/QQ3l9xWuXGQEDyZZZUvRcfib2PBGqSSr7FEtGLs4VsbO8tYtLkkbo5rvKfve0U62ETTzt1xVE3G+tJ7A5SLoQyiQeWy2oiso6T7sBVu25Y18jFmyGljIb76aRxI6OUbk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729014867; c=relaxed/simple; bh=oYXb5ELfdFSBlBTaf0WAv5hcBOQ7eaf8Vl277fIm8X4=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=gejJF1qUFPE8gQ2wLd+GdFDXwgHgDRTC3qH0YoeuC+NpB9TC/Jv0Ir6TJYipSzfSc7K10gI1gZ5McaqR5CTkyp9mPtLGOMndHpMSWdw6lywMjMIZgU99GP0plbyis+klZAJvf/jGtZBQbQDztuHVe4mNvxcPLxu9BHnT57oSMdU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=jgEoebN5; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="jgEoebN5" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 25B67C4CEDA; Tue, 15 Oct 2024 17:54:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1729014867; bh=oYXb5ELfdFSBlBTaf0WAv5hcBOQ7eaf8Vl277fIm8X4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jgEoebN5ggv7bJIo+tsNgprDtKq52wrOPozQdSYwCVYN+SgZfqUvnrAPLS8D/ibpJ 4tRo5REmWLrJjKyeBovXYKZA5W9qTNPB9fltaGLfZV72T48xutIrBPinTlwTVcTBwf 55J4Li7dQGrXMBg08rbbkW6nYCOggKydEWolHwTj1SDocyvqL+RDJozEtZo8EP562L 8tbIhbmmyQJ0NlLTdXu+URKTqB+H+IsV+Apl84HDOwKXJVFZTFuFkHA4CvE3qv6WOv C1y3HDKtF2X3pvYNbtG5f3Qb0IH1f9yPMPu9t2xKZK659xiYZFUGZeR/yk125lTTvH 9O8PwBMbOubuA== From: SeongJae Park To: Cc: SeongJae Park , Andrew Morton , Brendan Higgins , David Gow , Rae Moar , damon@lists.linux.dev, linux-mm@kvack.org, linux-kselftest@vger.kernel.org, kunit-dev@googlegroups.com, linux-kernel@vger.kernel.org Subject: [RFC PATCH 5/7] kunit: configs: remove configs for DAMON debugfs interface tests Date: Tue, 15 Oct 2024 10:54:10 -0700 Message-Id: <20241015175412.60563-6-sj@kernel.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20241015175412.60563-1-sj@kernel.org> References: <20241015175412.60563-1-sj@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" It's time to remove DAMON debugfs interface, which has deprecated long before in February 2023. Read the cover letter of this patch series for more details. Remove kernel configs for running DAMON debugfs interface kunit tests from the kunit all_tests configuration, to prevent unnecessary noises from tests. Signed-off-by: SeongJae Park --- tools/testing/kunit/configs/all_tests.config | 3 --- 1 file changed, 3 deletions(-) diff --git a/tools/testing/kunit/configs/all_tests.config b/tools/testing/k= unit/configs/all_tests.config index b3b00269a52a..b0049be00c70 100644 --- a/tools/testing/kunit/configs/all_tests.config +++ b/tools/testing/kunit/configs/all_tests.config @@ -38,9 +38,6 @@ CONFIG_IWLWIFI=3Dy CONFIG_DAMON=3Dy CONFIG_DAMON_VADDR=3Dy CONFIG_DAMON_PADDR=3Dy -CONFIG_DEBUG_FS=3Dy -CONFIG_DAMON_DBGFS=3Dy -CONFIG_DAMON_DBGFS_DEPRECATED=3Dy =20 CONFIG_REGMAP_BUILD=3Dy =20 --=20 2.39.5 From nobody Tue Nov 26 22:39:37 2024 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D04C91FAF00; Tue, 15 Oct 2024 17:54:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729014868; cv=none; b=IoSbUYMJF0zOWYxgMMTzApHcmFK9sXsMCx+aY7jQMFZd1tTxkv+jEpnekt/HgAKgvuBpSi1TdWUxYLiD/u5M/j3/7Ztzuj+JOQiOuE55lrP+hQmRTDVT3rwxddL8OfSPVtmKg5VCcsI9T1t+C/VCqB9SmVraipvBmNV5h86FRUA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729014868; c=relaxed/simple; bh=+5y1um4gitXtylrMffYca0ktxuX6uSb/9QDvMPQdSFU=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Ohw5gUgo3tmXyz2Gf0HawovwapVigQM+sKPTvdPT8ai+rEWgkj/76EqG7dWHU5AMvFV7yohHTA+J8ukJv3S8mjIEQphOD+7Bc+b6hqIH0LepT22+jmSC0SjIfHo6NhICss1KLFVKTIm4E3wIORPpXB97JNqliONMEQ++PNgOe7M= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=O4lzcSy6; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="O4lzcSy6" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 35735C4CED5; Tue, 15 Oct 2024 17:54:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1729014868; bh=+5y1um4gitXtylrMffYca0ktxuX6uSb/9QDvMPQdSFU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=O4lzcSy6i79Wom+pv+6s2P2i6bYMcG7Nytm2ZVcIpvbvyj4OzDLielOBUIofnAKNF U7OWoBscoDYa5BrM03l8S593Wc8K+kuK8b5LjpVqNaFq9Dt2CvvQjeazjbhNdPTJ+P e/HoNuKk6YdF6WmHd+YdwGC5BfPk0Opt7HVeq9cakKqLRgx+tY6I1URfS63q73dBIz dDDHU7s6PovCqRo5CK/9wY8VHtWNJiVhGQA3u1/VZW0s31VUMZJY+W1Usz5xBW9Hn2 bW4FAmQ5Vrd7LPLEOyCplGqU4aNnVCG97BRUJE+vfUQNLY6+Krt5viH/WZn6w3nU4+ GnLLUsIxV676Q== From: SeongJae Park To: Cc: SeongJae Park , Andrew Morton , Brendan Higgins , David Gow , damon@lists.linux.dev, linux-mm@kvack.org, kunit-dev@googlegroups.com, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [RFC PATCH 6/7] mm/damon: remove DAMON debugfs interface kunit tests Date: Tue, 15 Oct 2024 10:54:11 -0700 Message-Id: <20241015175412.60563-7-sj@kernel.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20241015175412.60563-1-sj@kernel.org> References: <20241015175412.60563-1-sj@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" It's time to remove DAMON debugfs interface, which has deprecated long before in February 2023. Read the cover letter of this patch series for more details. Remove kunit tests for the interface, to prevent unnecessary test failures. Signed-off-by: SeongJae Park --- mm/damon/Kconfig | 12 --- mm/damon/dbgfs.c | 2 - mm/damon/tests/.kunitconfig | 7 -- mm/damon/tests/dbgfs-kunit.h | 173 ----------------------------------- 4 files changed, 194 deletions(-) delete mode 100644 mm/damon/tests/dbgfs-kunit.h diff --git a/mm/damon/Kconfig b/mm/damon/Kconfig index 35b72f88983a..5ee5e62c0a1e 100644 --- a/mm/damon/Kconfig +++ b/mm/damon/Kconfig @@ -89,18 +89,6 @@ config DAMON_DBGFS default y depends on DAMON_DBGFS_DEPRECATED =20 -config DAMON_DBGFS_KUNIT_TEST - bool "Test for damon debugfs interface" if !KUNIT_ALL_TESTS - depends on DAMON_DBGFS && KUNIT=3Dy - default KUNIT_ALL_TESTS - help - This builds the DAMON debugfs interface Kunit test suite. - - For more information on KUnit and unit tests in general, please refer - to the KUnit documentation. - - If unsure, say N. - config DAMON_RECLAIM bool "Build DAMON-based reclaim (DAMON_RECLAIM)" depends on DAMON_PADDR diff --git a/mm/damon/dbgfs.c b/mm/damon/dbgfs.c index b4213bc47e44..5664c2cb0a5e 100644 --- a/mm/damon/dbgfs.c +++ b/mm/damon/dbgfs.c @@ -1144,5 +1144,3 @@ static int __init damon_dbgfs_init(void) } =20 module_init(damon_dbgfs_init); - -#include "tests/dbgfs-kunit.h" diff --git a/mm/damon/tests/.kunitconfig b/mm/damon/tests/.kunitconfig index a73be044fc9b..36a450f57b58 100644 --- a/mm/damon/tests/.kunitconfig +++ b/mm/damon/tests/.kunitconfig @@ -13,10 +13,3 @@ CONFIG_DAMON_VADDR_KUNIT_TEST=3Dy CONFIG_SYSFS=3Dy CONFIG_DAMON_SYSFS=3Dy CONFIG_DAMON_SYSFS_KUNIT_TEST=3Dy - -# for DAMON debugfs interface -CONFIG_DEBUG_FS=3Dy -CONFIG_DAMON_PADDR=3Dy -CONFIG_DAMON_DBGFS_DEPRECATED=3Dy -CONFIG_DAMON_DBGFS=3Dy -CONFIG_DAMON_DBGFS_KUNIT_TEST=3Dy diff --git a/mm/damon/tests/dbgfs-kunit.h b/mm/damon/tests/dbgfs-kunit.h deleted file mode 100644 index d2ecfcc8db86..000000000000 --- a/mm/damon/tests/dbgfs-kunit.h +++ /dev/null @@ -1,173 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -/* - * DAMON Debugfs Interface Unit Tests - * - * Author: SeongJae Park - */ - -#ifdef CONFIG_DAMON_DBGFS_KUNIT_TEST - -#ifndef _DAMON_DBGFS_TEST_H -#define _DAMON_DBGFS_TEST_H - -#include - -static void damon_dbgfs_test_str_to_ints(struct kunit *test) -{ - char *question; - int *answers; - int expected[] =3D {12, 35, 46}; - ssize_t nr_integers =3D 0, i; - - question =3D "123"; - answers =3D str_to_ints(question, strlen(question), &nr_integers); - KUNIT_EXPECT_EQ(test, (ssize_t)1, nr_integers); - KUNIT_EXPECT_EQ(test, 123, answers[0]); - kfree(answers); - - question =3D "123abc"; - answers =3D str_to_ints(question, strlen(question), &nr_integers); - KUNIT_EXPECT_EQ(test, (ssize_t)1, nr_integers); - KUNIT_EXPECT_EQ(test, 123, answers[0]); - kfree(answers); - - question =3D "a123"; - answers =3D str_to_ints(question, strlen(question), &nr_integers); - KUNIT_EXPECT_EQ(test, (ssize_t)0, nr_integers); - kfree(answers); - - question =3D "12 35"; - answers =3D str_to_ints(question, strlen(question), &nr_integers); - KUNIT_EXPECT_EQ(test, (ssize_t)2, nr_integers); - for (i =3D 0; i < nr_integers; i++) - KUNIT_EXPECT_EQ(test, expected[i], answers[i]); - kfree(answers); - - question =3D "12 35 46"; - answers =3D str_to_ints(question, strlen(question), &nr_integers); - KUNIT_EXPECT_EQ(test, (ssize_t)3, nr_integers); - for (i =3D 0; i < nr_integers; i++) - KUNIT_EXPECT_EQ(test, expected[i], answers[i]); - kfree(answers); - - question =3D "12 35 abc 46"; - answers =3D str_to_ints(question, strlen(question), &nr_integers); - KUNIT_EXPECT_EQ(test, (ssize_t)2, nr_integers); - for (i =3D 0; i < 2; i++) - KUNIT_EXPECT_EQ(test, expected[i], answers[i]); - kfree(answers); - - question =3D ""; - answers =3D str_to_ints(question, strlen(question), &nr_integers); - KUNIT_EXPECT_EQ(test, (ssize_t)0, nr_integers); - kfree(answers); - - question =3D "\n"; - answers =3D str_to_ints(question, strlen(question), &nr_integers); - KUNIT_EXPECT_EQ(test, (ssize_t)0, nr_integers); - kfree(answers); -} - -static void damon_dbgfs_test_set_targets(struct kunit *test) -{ - struct damon_ctx *ctx =3D dbgfs_new_ctx(); - char buf[64]; - - if (!damon_is_registered_ops(DAMON_OPS_PADDR)) { - dbgfs_destroy_ctx(ctx); - kunit_skip(test, "PADDR not registered"); - } - - /* Make DAMON consider target has no pid */ - damon_select_ops(ctx, DAMON_OPS_PADDR); - - dbgfs_set_targets(ctx, 0, NULL); - sprint_target_ids(ctx, buf, 64); - KUNIT_EXPECT_STREQ(test, (char *)buf, "\n"); - - dbgfs_set_targets(ctx, 1, NULL); - sprint_target_ids(ctx, buf, 64); - KUNIT_EXPECT_STREQ(test, (char *)buf, "42\n"); - - dbgfs_set_targets(ctx, 0, NULL); - sprint_target_ids(ctx, buf, 64); - KUNIT_EXPECT_STREQ(test, (char *)buf, "\n"); - - dbgfs_destroy_ctx(ctx); -} - -static void damon_dbgfs_test_set_init_regions(struct kunit *test) -{ - struct damon_ctx *ctx =3D damon_new_ctx(); - /* Each line represents one region in `` `` */ - char * const valid_inputs[] =3D {"1 10 20\n 1 20 30\n1 35 45", - "1 10 20\n", - "1 10 20\n0 39 59\n0 70 134\n 1 20 25\n", - ""}; - /* Reading the file again will show sorted, clean output */ - char * const valid_expects[] =3D {"1 10 20\n1 20 30\n1 35 45\n", - "1 10 20\n", - "0 39 59\n0 70 134\n1 10 20\n1 20 25\n", - ""}; - char * const invalid_inputs[] =3D {"3 10 20\n", /* target not exists */ - "1 10 20\n 1 14 26\n", /* regions overlap */ - "0 10 20\n1 30 40\n 0 5 8"}; /* not sorted by address */ - char *input, *expect; - int i, rc; - char buf[256]; - - if (!damon_is_registered_ops(DAMON_OPS_PADDR)) { - damon_destroy_ctx(ctx); - kunit_skip(test, "PADDR not registered"); - } - - damon_select_ops(ctx, DAMON_OPS_PADDR); - - dbgfs_set_targets(ctx, 3, NULL); - - /* Put valid inputs and check the results */ - for (i =3D 0; i < ARRAY_SIZE(valid_inputs); i++) { - input =3D valid_inputs[i]; - expect =3D valid_expects[i]; - - rc =3D set_init_regions(ctx, input, strnlen(input, 256)); - KUNIT_EXPECT_EQ(test, rc, 0); - - memset(buf, 0, 256); - sprint_init_regions(ctx, buf, 256); - - KUNIT_EXPECT_STREQ(test, (char *)buf, expect); - } - /* Put invalid inputs and check the return error code */ - for (i =3D 0; i < ARRAY_SIZE(invalid_inputs); i++) { - input =3D invalid_inputs[i]; - pr_info("input: %s\n", input); - rc =3D set_init_regions(ctx, input, strnlen(input, 256)); - KUNIT_EXPECT_EQ(test, rc, -EINVAL); - - memset(buf, 0, 256); - sprint_init_regions(ctx, buf, 256); - - KUNIT_EXPECT_STREQ(test, (char *)buf, ""); - } - - dbgfs_set_targets(ctx, 0, NULL); - damon_destroy_ctx(ctx); -} - -static struct kunit_case damon_test_cases[] =3D { - KUNIT_CASE(damon_dbgfs_test_str_to_ints), - KUNIT_CASE(damon_dbgfs_test_set_targets), - KUNIT_CASE(damon_dbgfs_test_set_init_regions), - {}, -}; - -static struct kunit_suite damon_test_suite =3D { - .name =3D "damon-dbgfs", - .test_cases =3D damon_test_cases, -}; -kunit_test_suite(damon_test_suite); - -#endif /* _DAMON_TEST_H */ - -#endif /* CONFIG_DAMON_KUNIT_TEST */ --=20 2.39.5 From nobody Tue Nov 26 22:39:37 2024 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3336522910E; Tue, 15 Oct 2024 17:54:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729014870; cv=none; b=tgzmnqOUvvCmtOyUfglQA/mBQBHJcsj8OqtYm4dH42xauxj5KAMCj5Ao/yMziR70ha6ztfWtBqerzLPNd0N/xVln3HRxMuYZImqkLRtg13Xik1URTgCSF709DnyRd60/oi1J6ULDBPm6OQQ88AsMzKwPzCqcU42cXB0lxJhWZqA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729014870; c=relaxed/simple; bh=DqgLfLKxAdQeHSBwaqJNenexXfcRykZ+0OrFMpJb/qs=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=iElfeJ079CyZKTwh2cZx5nti3g/qNnzhzQ5Pi+kHCRMv+Oe7GTjKAU4DsqZ9/bLrk2aNDkEaAhbypVJOS8UCnV/zCLzqcvXuJD6KXKYxslVAJ5DGgZBUgm1FGjb8DGEL8pDEfY5LPw6vkDwdXk3bCGQOjGg94vgus+TQPIeJdPw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=i2p7ZHBd; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="i2p7ZHBd" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 58577C4CED5; Tue, 15 Oct 2024 17:54:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1729014869; bh=DqgLfLKxAdQeHSBwaqJNenexXfcRykZ+0OrFMpJb/qs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=i2p7ZHBdEXuFZtlTdeCwG9mBEgH+k1BzYLZpIHgvGNEjylv5OS0d9ChU5s0CbX9Sp u2kQ7nAYRfIojiFKCvIHTRtnJw4/aqFCcddWsRWu5yqL7yt4j6ho6hIREWFjHOtMD0 xzvMzK7ynVd6g0+cy4BLGmOyl8twySogco8ENVKb39AEIRPOdpbA9BOvbPP0WnVli2 4OKg0s2QcGVBy7ueqHnWr4xd/7i++hdX8Oseqj+3zGeQS+wJU0y1/cwlkb5gKl5hS2 WEf+nZf1FEqUFGJmevkAgLi9TIQSh0WPVsbeijQBXFx4Lp30OaNg52AjwOpPNcKVNT UCmDeZkNIRIXA== From: SeongJae Park To: Cc: SeongJae Park , Andrew Morton , damon@lists.linux.dev, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [RFC PATCH 7/7] mm/damon: remove DAMON debugfs interface Date: Tue, 15 Oct 2024 10:54:12 -0700 Message-Id: <20241015175412.60563-8-sj@kernel.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20241015175412.60563-1-sj@kernel.org> References: <20241015175412.60563-1-sj@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" It's time to remove DAMON debugfs interface, which has deprecated long before in February 2023. Read the cover letter of this patch series for more details. All documents and related tests are also removed. Finally remove the interface. Signed-off-by: SeongJae Park --- mm/damon/Kconfig | 18 - mm/damon/Makefile | 1 - mm/damon/dbgfs.c | 1146 --------------------------------------------- 3 files changed, 1165 deletions(-) delete mode 100644 mm/damon/dbgfs.c diff --git a/mm/damon/Kconfig b/mm/damon/Kconfig index 5ee5e62c0a1e..1cc1cb5ba66f 100644 --- a/mm/damon/Kconfig +++ b/mm/damon/Kconfig @@ -71,24 +71,6 @@ config DAMON_SYSFS_KUNIT_TEST =20 If unsure, say N. =20 -config DAMON_DBGFS_DEPRECATED - bool "DAMON debugfs interface (DEPRECATED!)" - depends on DAMON_VADDR && DAMON_PADDR && DEBUG_FS - help - This builds the debugfs interface for DAMON. The user space admins - can use the interface for arbitrary data access monitoring. - - If unsure, say N. - - This is deprecated, so users should move to the sysfs interface - (DAMON_SYSFS). If you depend on this and cannot move, please report - your usecase to damon@lists.linux.dev and linux-mm@kvack.org. - -config DAMON_DBGFS - bool - default y - depends on DAMON_DBGFS_DEPRECATED - config DAMON_RECLAIM bool "Build DAMON-based reclaim (DAMON_RECLAIM)" depends on DAMON_PADDR diff --git a/mm/damon/Makefile b/mm/damon/Makefile index f7add3f4aa79..8b49012ba8c3 100644 --- a/mm/damon/Makefile +++ b/mm/damon/Makefile @@ -4,6 +4,5 @@ obj-y :=3D core.o obj-$(CONFIG_DAMON_VADDR) +=3D ops-common.o vaddr.o obj-$(CONFIG_DAMON_PADDR) +=3D ops-common.o paddr.o obj-$(CONFIG_DAMON_SYSFS) +=3D sysfs-common.o sysfs-schemes.o sysfs.o -obj-$(CONFIG_DAMON_DBGFS) +=3D dbgfs.o obj-$(CONFIG_DAMON_RECLAIM) +=3D modules-common.o reclaim.o obj-$(CONFIG_DAMON_LRU_SORT) +=3D modules-common.o lru_sort.o diff --git a/mm/damon/dbgfs.c b/mm/damon/dbgfs.c deleted file mode 100644 index 5664c2cb0a5e..000000000000 --- a/mm/damon/dbgfs.c +++ /dev/null @@ -1,1146 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 -/* - * DAMON Debugfs Interface - * - * Author: SeongJae Park - */ - -#define pr_fmt(fmt) "damon-dbgfs: " fmt - -#include -#include -#include -#include -#include -#include -#include - -#define DAMON_DBGFS_DEPRECATION_NOTICE \ - "DAMON debugfs interface is deprecated, so users should move " \ - "to DAMON_SYSFS. If you cannot, please report your usecase to " \ - "damon@lists.linux.dev and linux-mm@kvack.org.\n" - -static struct damon_ctx **dbgfs_ctxs; -static int dbgfs_nr_ctxs; -static struct dentry **dbgfs_dirs; -static DEFINE_MUTEX(damon_dbgfs_lock); - -static void damon_dbgfs_warn_deprecation(void) -{ - pr_warn_once(DAMON_DBGFS_DEPRECATION_NOTICE); -} - -/* - * Returns non-empty string on success, negative error code otherwise. - */ -static char *user_input_str(const char __user *buf, size_t count, loff_t *= ppos) -{ - char *kbuf; - ssize_t ret; - - /* We do not accept continuous write */ - if (*ppos) - return ERR_PTR(-EINVAL); - - kbuf =3D kmalloc(count + 1, GFP_KERNEL | __GFP_NOWARN); - if (!kbuf) - return ERR_PTR(-ENOMEM); - - ret =3D simple_write_to_buffer(kbuf, count + 1, ppos, buf, count); - if (ret !=3D count) { - kfree(kbuf); - return ERR_PTR(-EIO); - } - kbuf[ret] =3D '\0'; - - return kbuf; -} - -static ssize_t dbgfs_attrs_read(struct file *file, - char __user *buf, size_t count, loff_t *ppos) -{ - struct damon_ctx *ctx =3D file->private_data; - char kbuf[128]; - int ret; - - mutex_lock(&ctx->kdamond_lock); - ret =3D scnprintf(kbuf, ARRAY_SIZE(kbuf), "%lu %lu %lu %lu %lu\n", - ctx->attrs.sample_interval, ctx->attrs.aggr_interval, - ctx->attrs.ops_update_interval, - ctx->attrs.min_nr_regions, ctx->attrs.max_nr_regions); - mutex_unlock(&ctx->kdamond_lock); - - return simple_read_from_buffer(buf, count, ppos, kbuf, ret); -} - -static ssize_t dbgfs_attrs_write(struct file *file, - const char __user *buf, size_t count, loff_t *ppos) -{ - struct damon_ctx *ctx =3D file->private_data; - struct damon_attrs attrs; - char *kbuf; - ssize_t ret; - - kbuf =3D user_input_str(buf, count, ppos); - if (IS_ERR(kbuf)) - return PTR_ERR(kbuf); - - if (sscanf(kbuf, "%lu %lu %lu %lu %lu", - &attrs.sample_interval, &attrs.aggr_interval, - &attrs.ops_update_interval, - &attrs.min_nr_regions, - &attrs.max_nr_regions) !=3D 5) { - ret =3D -EINVAL; - goto out; - } - - mutex_lock(&ctx->kdamond_lock); - if (ctx->kdamond) { - ret =3D -EBUSY; - goto unlock_out; - } - - ret =3D damon_set_attrs(ctx, &attrs); - if (!ret) - ret =3D count; -unlock_out: - mutex_unlock(&ctx->kdamond_lock); -out: - kfree(kbuf); - return ret; -} - -/* - * Return corresponding dbgfs' scheme action value (int) for the given - * damos_action if the given damos_action value is valid and supported by - * dbgfs, negative error code otherwise. - */ -static int damos_action_to_dbgfs_scheme_action(enum damos_action action) -{ - switch (action) { - case DAMOS_WILLNEED: - return 0; - case DAMOS_COLD: - return 1; - case DAMOS_PAGEOUT: - return 2; - case DAMOS_HUGEPAGE: - return 3; - case DAMOS_NOHUGEPAGE: - return 4; - case DAMOS_STAT: - return 5; - default: - return -EINVAL; - } -} - -static ssize_t sprint_schemes(struct damon_ctx *c, char *buf, ssize_t len) -{ - struct damos *s; - int written =3D 0; - int rc; - - damon_for_each_scheme(s, c) { - rc =3D scnprintf(&buf[written], len - written, - "%lu %lu %u %u %u %u %d %lu %lu %lu %u %u %u %d %lu %lu %lu %lu %lu %l= u %lu %lu %lu\n", - s->pattern.min_sz_region, - s->pattern.max_sz_region, - s->pattern.min_nr_accesses, - s->pattern.max_nr_accesses, - s->pattern.min_age_region, - s->pattern.max_age_region, - damos_action_to_dbgfs_scheme_action(s->action), - s->quota.ms, s->quota.sz, - s->quota.reset_interval, - s->quota.weight_sz, - s->quota.weight_nr_accesses, - s->quota.weight_age, - s->wmarks.metric, s->wmarks.interval, - s->wmarks.high, s->wmarks.mid, s->wmarks.low, - s->stat.nr_tried, s->stat.sz_tried, - s->stat.nr_applied, s->stat.sz_applied, - s->stat.qt_exceeds); - if (!rc) - return -ENOMEM; - - written +=3D rc; - } - return written; -} - -static ssize_t dbgfs_schemes_read(struct file *file, char __user *buf, - size_t count, loff_t *ppos) -{ - struct damon_ctx *ctx =3D file->private_data; - char *kbuf; - ssize_t len; - - kbuf =3D kmalloc(count, GFP_KERNEL | __GFP_NOWARN); - if (!kbuf) - return -ENOMEM; - - mutex_lock(&ctx->kdamond_lock); - len =3D sprint_schemes(ctx, kbuf, count); - mutex_unlock(&ctx->kdamond_lock); - if (len < 0) - goto out; - len =3D simple_read_from_buffer(buf, count, ppos, kbuf, len); - -out: - kfree(kbuf); - return len; -} - -static void free_schemes_arr(struct damos **schemes, ssize_t nr_schemes) -{ - ssize_t i; - - for (i =3D 0; i < nr_schemes; i++) - kfree(schemes[i]); - kfree(schemes); -} - -/* - * Return corresponding damos_action for the given dbgfs input for a scheme - * action if the input is valid, negative error code otherwise. - */ -static enum damos_action dbgfs_scheme_action_to_damos_action(int dbgfs_act= ion) -{ - switch (dbgfs_action) { - case 0: - return DAMOS_WILLNEED; - case 1: - return DAMOS_COLD; - case 2: - return DAMOS_PAGEOUT; - case 3: - return DAMOS_HUGEPAGE; - case 4: - return DAMOS_NOHUGEPAGE; - case 5: - return DAMOS_STAT; - default: - return -EINVAL; - } -} - -/* - * Converts a string into an array of struct damos pointers - * - * Returns an array of struct damos pointers that converted if the convers= ion - * success, or NULL otherwise. - */ -static struct damos **str_to_schemes(const char *str, ssize_t len, - ssize_t *nr_schemes) -{ - struct damos *scheme, **schemes; - const int max_nr_schemes =3D 256; - int pos =3D 0, parsed, ret; - unsigned int action_input; - enum damos_action action; - - schemes =3D kmalloc_array(max_nr_schemes, sizeof(scheme), - GFP_KERNEL); - if (!schemes) - return NULL; - - *nr_schemes =3D 0; - while (pos < len && *nr_schemes < max_nr_schemes) { - struct damos_access_pattern pattern =3D {}; - struct damos_quota quota =3D {}; - struct damos_watermarks wmarks; - - ret =3D sscanf(&str[pos], - "%lu %lu %u %u %u %u %u %lu %lu %lu %u %u %u %u %lu %lu %lu %lu%n", - &pattern.min_sz_region, &pattern.max_sz_region, - &pattern.min_nr_accesses, - &pattern.max_nr_accesses, - &pattern.min_age_region, - &pattern.max_age_region, - &action_input, "a.ms, - "a.sz, "a.reset_interval, - "a.weight_sz, "a.weight_nr_accesses, - "a.weight_age, &wmarks.metric, - &wmarks.interval, &wmarks.high, &wmarks.mid, - &wmarks.low, &parsed); - if (ret !=3D 18) - break; - action =3D dbgfs_scheme_action_to_damos_action(action_input); - if ((int)action < 0) - goto fail; - - if (pattern.min_sz_region > pattern.max_sz_region || - pattern.min_nr_accesses > pattern.max_nr_accesses || - pattern.min_age_region > pattern.max_age_region) - goto fail; - - if (wmarks.high < wmarks.mid || wmarks.high < wmarks.low || - wmarks.mid < wmarks.low) - goto fail; - - pos +=3D parsed; - scheme =3D damon_new_scheme(&pattern, action, 0, "a, - &wmarks, NUMA_NO_NODE); - if (!scheme) - goto fail; - - schemes[*nr_schemes] =3D scheme; - *nr_schemes +=3D 1; - } - return schemes; -fail: - free_schemes_arr(schemes, *nr_schemes); - return NULL; -} - -static ssize_t dbgfs_schemes_write(struct file *file, const char __user *b= uf, - size_t count, loff_t *ppos) -{ - struct damon_ctx *ctx =3D file->private_data; - char *kbuf; - struct damos **schemes; - ssize_t nr_schemes =3D 0, ret; - - kbuf =3D user_input_str(buf, count, ppos); - if (IS_ERR(kbuf)) - return PTR_ERR(kbuf); - - schemes =3D str_to_schemes(kbuf, count, &nr_schemes); - if (!schemes) { - ret =3D -EINVAL; - goto out; - } - - mutex_lock(&ctx->kdamond_lock); - if (ctx->kdamond) { - ret =3D -EBUSY; - goto unlock_out; - } - - damon_set_schemes(ctx, schemes, nr_schemes); - ret =3D count; - nr_schemes =3D 0; - -unlock_out: - mutex_unlock(&ctx->kdamond_lock); - free_schemes_arr(schemes, nr_schemes); -out: - kfree(kbuf); - return ret; -} - -static ssize_t sprint_target_ids(struct damon_ctx *ctx, char *buf, ssize_t= len) -{ - struct damon_target *t; - int id; - int written =3D 0; - int rc; - - damon_for_each_target(t, ctx) { - if (damon_target_has_pid(ctx)) - /* Show pid numbers to debugfs users */ - id =3D pid_vnr(t->pid); - else - /* Show 42 for physical address space, just for fun */ - id =3D 42; - - rc =3D scnprintf(&buf[written], len - written, "%d ", id); - if (!rc) - return -ENOMEM; - written +=3D rc; - } - if (written) - written -=3D 1; - written +=3D scnprintf(&buf[written], len - written, "\n"); - return written; -} - -static ssize_t dbgfs_target_ids_read(struct file *file, - char __user *buf, size_t count, loff_t *ppos) -{ - struct damon_ctx *ctx =3D file->private_data; - ssize_t len; - char ids_buf[320]; - - mutex_lock(&ctx->kdamond_lock); - len =3D sprint_target_ids(ctx, ids_buf, 320); - mutex_unlock(&ctx->kdamond_lock); - if (len < 0) - return len; - - return simple_read_from_buffer(buf, count, ppos, ids_buf, len); -} - -/* - * Converts a string into an integers array - * - * Returns an array of integers array if the conversion success, or NULL - * otherwise. - */ -static int *str_to_ints(const char *str, ssize_t len, ssize_t *nr_ints) -{ - int *array; - const int max_nr_ints =3D 32; - int nr; - int pos =3D 0, parsed, ret; - - *nr_ints =3D 0; - array =3D kmalloc_array(max_nr_ints, sizeof(*array), GFP_KERNEL); - if (!array) - return NULL; - while (*nr_ints < max_nr_ints && pos < len) { - ret =3D sscanf(&str[pos], "%d%n", &nr, &parsed); - pos +=3D parsed; - if (ret !=3D 1) - break; - array[*nr_ints] =3D nr; - *nr_ints +=3D 1; - } - - return array; -} - -static void dbgfs_put_pids(struct pid **pids, int nr_pids) -{ - int i; - - for (i =3D 0; i < nr_pids; i++) - put_pid(pids[i]); -} - -/* - * Converts a string into an struct pid pointers array - * - * Returns an array of struct pid pointers if the conversion success, or N= ULL - * otherwise. - */ -static struct pid **str_to_pids(const char *str, ssize_t len, ssize_t *nr_= pids) -{ - int *ints; - ssize_t nr_ints; - struct pid **pids; - - *nr_pids =3D 0; - - ints =3D str_to_ints(str, len, &nr_ints); - if (!ints) - return NULL; - - pids =3D kmalloc_array(nr_ints, sizeof(*pids), GFP_KERNEL); - if (!pids) - goto out; - - for (; *nr_pids < nr_ints; (*nr_pids)++) { - pids[*nr_pids] =3D find_get_pid(ints[*nr_pids]); - if (!pids[*nr_pids]) { - dbgfs_put_pids(pids, *nr_pids); - kfree(ints); - kfree(pids); - return NULL; - } - } - -out: - kfree(ints); - return pids; -} - -/* - * dbgfs_set_targets() - Set monitoring targets. - * @ctx: monitoring context - * @nr_targets: number of targets - * @pids: array of target pids (size is same to @nr_targets) - * - * This function should not be called while the kdamond is running. @pids= is - * ignored if the context is not configured to have pid in each target. On - * failure, reference counts of all pids in @pids are decremented. - * - * Return: 0 on success, negative error code otherwise. - */ -static int dbgfs_set_targets(struct damon_ctx *ctx, ssize_t nr_targets, - struct pid **pids) -{ - ssize_t i; - struct damon_target *t, *next; - - damon_for_each_target_safe(t, next, ctx) { - if (damon_target_has_pid(ctx)) - put_pid(t->pid); - damon_destroy_target(t); - } - - for (i =3D 0; i < nr_targets; i++) { - t =3D damon_new_target(); - if (!t) { - damon_for_each_target_safe(t, next, ctx) - damon_destroy_target(t); - if (damon_target_has_pid(ctx)) - dbgfs_put_pids(pids, nr_targets); - return -ENOMEM; - } - if (damon_target_has_pid(ctx)) - t->pid =3D pids[i]; - damon_add_target(ctx, t); - } - - return 0; -} - -static ssize_t dbgfs_target_ids_write(struct file *file, - const char __user *buf, size_t count, loff_t *ppos) -{ - struct damon_ctx *ctx =3D file->private_data; - bool id_is_pid =3D true; - char *kbuf; - struct pid **target_pids =3D NULL; - ssize_t nr_targets; - ssize_t ret; - - kbuf =3D user_input_str(buf, count, ppos); - if (IS_ERR(kbuf)) - return PTR_ERR(kbuf); - - if (!strncmp(kbuf, "paddr\n", count)) { - id_is_pid =3D false; - nr_targets =3D 1; - } - - if (id_is_pid) { - target_pids =3D str_to_pids(kbuf, count, &nr_targets); - if (!target_pids) { - ret =3D -ENOMEM; - goto out; - } - } - - mutex_lock(&ctx->kdamond_lock); - if (ctx->kdamond) { - if (id_is_pid) - dbgfs_put_pids(target_pids, nr_targets); - ret =3D -EBUSY; - goto unlock_out; - } - - /* remove previously set targets */ - dbgfs_set_targets(ctx, 0, NULL); - if (!nr_targets) { - ret =3D count; - goto unlock_out; - } - - /* Configure the context for the address space type */ - if (id_is_pid) - ret =3D damon_select_ops(ctx, DAMON_OPS_VADDR); - else - ret =3D damon_select_ops(ctx, DAMON_OPS_PADDR); - if (ret) - goto unlock_out; - - ret =3D dbgfs_set_targets(ctx, nr_targets, target_pids); - if (!ret) - ret =3D count; - -unlock_out: - mutex_unlock(&ctx->kdamond_lock); - kfree(target_pids); -out: - kfree(kbuf); - return ret; -} - -static ssize_t sprint_init_regions(struct damon_ctx *c, char *buf, ssize_t= len) -{ - struct damon_target *t; - struct damon_region *r; - int target_idx =3D 0; - int written =3D 0; - int rc; - - damon_for_each_target(t, c) { - damon_for_each_region(r, t) { - rc =3D scnprintf(&buf[written], len - written, - "%d %lu %lu\n", - target_idx, r->ar.start, r->ar.end); - if (!rc) - return -ENOMEM; - written +=3D rc; - } - target_idx++; - } - return written; -} - -static ssize_t dbgfs_init_regions_read(struct file *file, char __user *buf, - size_t count, loff_t *ppos) -{ - struct damon_ctx *ctx =3D file->private_data; - char *kbuf; - ssize_t len; - - kbuf =3D kmalloc(count, GFP_KERNEL | __GFP_NOWARN); - if (!kbuf) - return -ENOMEM; - - mutex_lock(&ctx->kdamond_lock); - if (ctx->kdamond) { - mutex_unlock(&ctx->kdamond_lock); - len =3D -EBUSY; - goto out; - } - - len =3D sprint_init_regions(ctx, kbuf, count); - mutex_unlock(&ctx->kdamond_lock); - if (len < 0) - goto out; - len =3D simple_read_from_buffer(buf, count, ppos, kbuf, len); - -out: - kfree(kbuf); - return len; -} - -static int add_init_region(struct damon_ctx *c, int target_idx, - struct damon_addr_range *ar) -{ - struct damon_target *t; - struct damon_region *r, *prev; - unsigned long idx =3D 0; - int rc =3D -EINVAL; - - if (ar->start >=3D ar->end) - return -EINVAL; - - damon_for_each_target(t, c) { - if (idx++ =3D=3D target_idx) { - r =3D damon_new_region(ar->start, ar->end); - if (!r) - return -ENOMEM; - damon_add_region(r, t); - if (damon_nr_regions(t) > 1) { - prev =3D damon_prev_region(r); - if (prev->ar.end > r->ar.start) { - damon_destroy_region(r, t); - return -EINVAL; - } - } - rc =3D 0; - } - } - return rc; -} - -static int set_init_regions(struct damon_ctx *c, const char *str, ssize_t = len) -{ - struct damon_target *t; - struct damon_region *r, *next; - int pos =3D 0, parsed, ret; - int target_idx; - struct damon_addr_range ar; - int err; - - damon_for_each_target(t, c) { - damon_for_each_region_safe(r, next, t) - damon_destroy_region(r, t); - } - - while (pos < len) { - ret =3D sscanf(&str[pos], "%d %lu %lu%n", - &target_idx, &ar.start, &ar.end, &parsed); - if (ret !=3D 3) - break; - err =3D add_init_region(c, target_idx, &ar); - if (err) - goto fail; - pos +=3D parsed; - } - - return 0; - -fail: - damon_for_each_target(t, c) { - damon_for_each_region_safe(r, next, t) - damon_destroy_region(r, t); - } - return err; -} - -static ssize_t dbgfs_init_regions_write(struct file *file, - const char __user *buf, size_t count, - loff_t *ppos) -{ - struct damon_ctx *ctx =3D file->private_data; - char *kbuf; - ssize_t ret =3D count; - int err; - - kbuf =3D user_input_str(buf, count, ppos); - if (IS_ERR(kbuf)) - return PTR_ERR(kbuf); - - mutex_lock(&ctx->kdamond_lock); - if (ctx->kdamond) { - ret =3D -EBUSY; - goto unlock_out; - } - - err =3D set_init_regions(ctx, kbuf, ret); - if (err) - ret =3D err; - -unlock_out: - mutex_unlock(&ctx->kdamond_lock); - kfree(kbuf); - return ret; -} - -static ssize_t dbgfs_kdamond_pid_read(struct file *file, - char __user *buf, size_t count, loff_t *ppos) -{ - struct damon_ctx *ctx =3D file->private_data; - char *kbuf; - ssize_t len; - - kbuf =3D kmalloc(count, GFP_KERNEL | __GFP_NOWARN); - if (!kbuf) - return -ENOMEM; - - mutex_lock(&ctx->kdamond_lock); - if (ctx->kdamond) - len =3D scnprintf(kbuf, count, "%d\n", ctx->kdamond->pid); - else - len =3D scnprintf(kbuf, count, "none\n"); - mutex_unlock(&ctx->kdamond_lock); - if (!len) - goto out; - len =3D simple_read_from_buffer(buf, count, ppos, kbuf, len); - -out: - kfree(kbuf); - return len; -} - -static int damon_dbgfs_open(struct inode *inode, struct file *file) -{ - damon_dbgfs_warn_deprecation(); - - file->private_data =3D inode->i_private; - - return nonseekable_open(inode, file); -} - -static const struct file_operations attrs_fops =3D { - .open =3D damon_dbgfs_open, - .read =3D dbgfs_attrs_read, - .write =3D dbgfs_attrs_write, -}; - -static const struct file_operations schemes_fops =3D { - .open =3D damon_dbgfs_open, - .read =3D dbgfs_schemes_read, - .write =3D dbgfs_schemes_write, -}; - -static const struct file_operations target_ids_fops =3D { - .open =3D damon_dbgfs_open, - .read =3D dbgfs_target_ids_read, - .write =3D dbgfs_target_ids_write, -}; - -static const struct file_operations init_regions_fops =3D { - .open =3D damon_dbgfs_open, - .read =3D dbgfs_init_regions_read, - .write =3D dbgfs_init_regions_write, -}; - -static const struct file_operations kdamond_pid_fops =3D { - .open =3D damon_dbgfs_open, - .read =3D dbgfs_kdamond_pid_read, -}; - -static void dbgfs_fill_ctx_dir(struct dentry *dir, struct damon_ctx *ctx) -{ - const char * const file_names[] =3D {"attrs", "schemes", "target_ids", - "init_regions", "kdamond_pid"}; - const struct file_operations *fops[] =3D {&attrs_fops, &schemes_fops, - &target_ids_fops, &init_regions_fops, &kdamond_pid_fops}; - int i; - - for (i =3D 0; i < ARRAY_SIZE(file_names); i++) - debugfs_create_file(file_names[i], 0600, dir, ctx, fops[i]); -} - -static void dbgfs_before_terminate(struct damon_ctx *ctx) -{ - struct damon_target *t, *next; - - if (!damon_target_has_pid(ctx)) - return; - - mutex_lock(&ctx->kdamond_lock); - damon_for_each_target_safe(t, next, ctx) { - put_pid(t->pid); - damon_destroy_target(t); - } - mutex_unlock(&ctx->kdamond_lock); -} - -static struct damon_ctx *dbgfs_new_ctx(void) -{ - struct damon_ctx *ctx; - - ctx =3D damon_new_ctx(); - if (!ctx) - return NULL; - - if (damon_select_ops(ctx, DAMON_OPS_VADDR) && - damon_select_ops(ctx, DAMON_OPS_PADDR)) { - damon_destroy_ctx(ctx); - return NULL; - } - ctx->callback.before_terminate =3D dbgfs_before_terminate; - return ctx; -} - -static void dbgfs_destroy_ctx(struct damon_ctx *ctx) -{ - damon_destroy_ctx(ctx); -} - -static ssize_t damon_dbgfs_deprecated_read(struct file *file, - char __user *buf, size_t count, loff_t *ppos) -{ - static const char kbuf[512] =3D DAMON_DBGFS_DEPRECATION_NOTICE; - - return simple_read_from_buffer(buf, count, ppos, kbuf, strlen(kbuf)); -} - -/* - * Make a context of @name and create a debugfs directory for it. - * - * This function should be called while holding damon_dbgfs_lock. - * - * Returns 0 on success, negative error code otherwise. - */ -static int dbgfs_mk_context(char *name) -{ - struct dentry *root, **new_dirs, *new_dir; - struct damon_ctx **new_ctxs, *new_ctx; - - if (damon_nr_running_ctxs()) - return -EBUSY; - - new_ctxs =3D krealloc(dbgfs_ctxs, sizeof(*dbgfs_ctxs) * - (dbgfs_nr_ctxs + 1), GFP_KERNEL); - if (!new_ctxs) - return -ENOMEM; - dbgfs_ctxs =3D new_ctxs; - - new_dirs =3D krealloc(dbgfs_dirs, sizeof(*dbgfs_dirs) * - (dbgfs_nr_ctxs + 1), GFP_KERNEL); - if (!new_dirs) - return -ENOMEM; - dbgfs_dirs =3D new_dirs; - - root =3D dbgfs_dirs[0]; - if (!root) - return -ENOENT; - - new_dir =3D debugfs_create_dir(name, root); - /* Below check is required for a potential duplicated name case */ - if (IS_ERR(new_dir)) - return PTR_ERR(new_dir); - dbgfs_dirs[dbgfs_nr_ctxs] =3D new_dir; - - new_ctx =3D dbgfs_new_ctx(); - if (!new_ctx) { - debugfs_remove(new_dir); - dbgfs_dirs[dbgfs_nr_ctxs] =3D NULL; - return -ENOMEM; - } - - dbgfs_ctxs[dbgfs_nr_ctxs] =3D new_ctx; - dbgfs_fill_ctx_dir(dbgfs_dirs[dbgfs_nr_ctxs], - dbgfs_ctxs[dbgfs_nr_ctxs]); - dbgfs_nr_ctxs++; - - return 0; -} - -static ssize_t dbgfs_mk_context_write(struct file *file, - const char __user *buf, size_t count, loff_t *ppos) -{ - char *kbuf; - char *ctx_name; - ssize_t ret; - - kbuf =3D user_input_str(buf, count, ppos); - if (IS_ERR(kbuf)) - return PTR_ERR(kbuf); - ctx_name =3D kmalloc(count + 1, GFP_KERNEL); - if (!ctx_name) { - kfree(kbuf); - return -ENOMEM; - } - - /* Trim white space */ - if (sscanf(kbuf, "%s", ctx_name) !=3D 1) { - ret =3D -EINVAL; - goto out; - } - - mutex_lock(&damon_dbgfs_lock); - ret =3D dbgfs_mk_context(ctx_name); - if (!ret) - ret =3D count; - mutex_unlock(&damon_dbgfs_lock); - -out: - kfree(kbuf); - kfree(ctx_name); - return ret; -} - -/* - * Remove a context of @name and its debugfs directory. - * - * This function should be called while holding damon_dbgfs_lock. - * - * Return 0 on success, negative error code otherwise. - */ -static int dbgfs_rm_context(char *name) -{ - struct dentry *root, *dir, **new_dirs; - struct inode *inode; - struct damon_ctx **new_ctxs; - int i, j; - int ret =3D 0; - - if (damon_nr_running_ctxs()) - return -EBUSY; - - root =3D dbgfs_dirs[0]; - if (!root) - return -ENOENT; - - dir =3D debugfs_lookup(name, root); - if (!dir) - return -ENOENT; - - inode =3D d_inode(dir); - if (!S_ISDIR(inode->i_mode)) { - ret =3D -EINVAL; - goto out_dput; - } - - new_dirs =3D kmalloc_array(dbgfs_nr_ctxs - 1, sizeof(*dbgfs_dirs), - GFP_KERNEL); - if (!new_dirs) { - ret =3D -ENOMEM; - goto out_dput; - } - - new_ctxs =3D kmalloc_array(dbgfs_nr_ctxs - 1, sizeof(*dbgfs_ctxs), - GFP_KERNEL); - if (!new_ctxs) { - ret =3D -ENOMEM; - goto out_new_dirs; - } - - for (i =3D 0, j =3D 0; i < dbgfs_nr_ctxs; i++) { - if (dbgfs_dirs[i] =3D=3D dir) { - debugfs_remove(dbgfs_dirs[i]); - dbgfs_destroy_ctx(dbgfs_ctxs[i]); - continue; - } - new_dirs[j] =3D dbgfs_dirs[i]; - new_ctxs[j++] =3D dbgfs_ctxs[i]; - } - - kfree(dbgfs_dirs); - kfree(dbgfs_ctxs); - - dbgfs_dirs =3D new_dirs; - dbgfs_ctxs =3D new_ctxs; - dbgfs_nr_ctxs--; - - goto out_dput; - -out_new_dirs: - kfree(new_dirs); -out_dput: - dput(dir); - return ret; -} - -static ssize_t dbgfs_rm_context_write(struct file *file, - const char __user *buf, size_t count, loff_t *ppos) -{ - char *kbuf; - ssize_t ret; - char *ctx_name; - - kbuf =3D user_input_str(buf, count, ppos); - if (IS_ERR(kbuf)) - return PTR_ERR(kbuf); - ctx_name =3D kmalloc(count + 1, GFP_KERNEL); - if (!ctx_name) { - kfree(kbuf); - return -ENOMEM; - } - - /* Trim white space */ - if (sscanf(kbuf, "%s", ctx_name) !=3D 1) { - ret =3D -EINVAL; - goto out; - } - - mutex_lock(&damon_dbgfs_lock); - ret =3D dbgfs_rm_context(ctx_name); - if (!ret) - ret =3D count; - mutex_unlock(&damon_dbgfs_lock); - -out: - kfree(kbuf); - kfree(ctx_name); - return ret; -} - -static ssize_t dbgfs_monitor_on_read(struct file *file, - char __user *buf, size_t count, loff_t *ppos) -{ - char monitor_on_buf[5]; - bool monitor_on =3D damon_nr_running_ctxs() !=3D 0; - int len; - - len =3D scnprintf(monitor_on_buf, 5, monitor_on ? "on\n" : "off\n"); - - return simple_read_from_buffer(buf, count, ppos, monitor_on_buf, len); -} - -static ssize_t dbgfs_monitor_on_write(struct file *file, - const char __user *buf, size_t count, loff_t *ppos) -{ - ssize_t ret; - char *kbuf; - - kbuf =3D user_input_str(buf, count, ppos); - if (IS_ERR(kbuf)) - return PTR_ERR(kbuf); - - /* Remove white space */ - if (sscanf(kbuf, "%s", kbuf) !=3D 1) { - kfree(kbuf); - return -EINVAL; - } - - mutex_lock(&damon_dbgfs_lock); - if (!strncmp(kbuf, "on", count)) { - int i; - - for (i =3D 0; i < dbgfs_nr_ctxs; i++) { - if (damon_targets_empty(dbgfs_ctxs[i])) { - kfree(kbuf); - mutex_unlock(&damon_dbgfs_lock); - return -EINVAL; - } - } - ret =3D damon_start(dbgfs_ctxs, dbgfs_nr_ctxs, true); - } else if (!strncmp(kbuf, "off", count)) { - ret =3D damon_stop(dbgfs_ctxs, dbgfs_nr_ctxs); - } else { - ret =3D -EINVAL; - } - mutex_unlock(&damon_dbgfs_lock); - - if (!ret) - ret =3D count; - kfree(kbuf); - return ret; -} - -static int damon_dbgfs_static_file_open(struct inode *inode, struct file *= file) -{ - damon_dbgfs_warn_deprecation(); - return nonseekable_open(inode, file); -} - -static const struct file_operations deprecated_fops =3D { - .read =3D damon_dbgfs_deprecated_read, -}; - -static const struct file_operations mk_contexts_fops =3D { - .open =3D damon_dbgfs_static_file_open, - .write =3D dbgfs_mk_context_write, -}; - -static const struct file_operations rm_contexts_fops =3D { - .open =3D damon_dbgfs_static_file_open, - .write =3D dbgfs_rm_context_write, -}; - -static const struct file_operations monitor_on_fops =3D { - .open =3D damon_dbgfs_static_file_open, - .read =3D dbgfs_monitor_on_read, - .write =3D dbgfs_monitor_on_write, -}; - -static int __init __damon_dbgfs_init(void) -{ - struct dentry *dbgfs_root; - const char * const file_names[] =3D {"mk_contexts", "rm_contexts", - "monitor_on_DEPRECATED", "DEPRECATED"}; - const struct file_operations *fops[] =3D {&mk_contexts_fops, - &rm_contexts_fops, &monitor_on_fops, &deprecated_fops}; - int i; - - dbgfs_root =3D debugfs_create_dir("damon", NULL); - - for (i =3D 0; i < ARRAY_SIZE(file_names); i++) - debugfs_create_file(file_names[i], 0600, dbgfs_root, NULL, - fops[i]); - dbgfs_fill_ctx_dir(dbgfs_root, dbgfs_ctxs[0]); - - dbgfs_dirs =3D kmalloc(sizeof(dbgfs_root), GFP_KERNEL); - if (!dbgfs_dirs) { - debugfs_remove(dbgfs_root); - return -ENOMEM; - } - dbgfs_dirs[0] =3D dbgfs_root; - - return 0; -} - -/* - * Functions for the initialization - */ - -static int __init damon_dbgfs_init(void) -{ - int rc =3D -ENOMEM; - - mutex_lock(&damon_dbgfs_lock); - dbgfs_ctxs =3D kmalloc(sizeof(*dbgfs_ctxs), GFP_KERNEL); - if (!dbgfs_ctxs) - goto out; - dbgfs_ctxs[0] =3D dbgfs_new_ctx(); - if (!dbgfs_ctxs[0]) { - kfree(dbgfs_ctxs); - goto out; - } - dbgfs_nr_ctxs =3D 1; - - rc =3D __damon_dbgfs_init(); - if (rc) { - kfree(dbgfs_ctxs[0]); - kfree(dbgfs_ctxs); - pr_err("%s: dbgfs init failed\n", __func__); - } - -out: - mutex_unlock(&damon_dbgfs_lock); - return rc; -} - -module_init(damon_dbgfs_init); --=20 2.39.5