All of lore.kernel.org
 help / color / mirror / Atom feed
From: Muhammad Usama Anjum <usama.anjum@collabora.com>
To: Andrei Vagin <avagin@gmail.com>
Cc: "Muhammad Usama Anjum" <usama.anjum@collabora.com>,
	"Peter Xu" <peterx@redhat.com>,
	"David Hildenbrand" <david@redhat.com>,
	"Andrew Morton" <akpm@linux-foundation.org>,
	"Michał Mirosław" <emmir@google.com>,
	"Danylo Mocherniuk" <mdanylo@google.com>,
	"Paul Gofman" <pgofman@codeweavers.com>,
	"Cyrill Gorcunov" <gorcunov@gmail.com>,
	"Mike Rapoport" <rppt@kernel.org>,
	"Nadav Amit" <namit@vmware.com>,
	"Alexander Viro" <viro@zeniv.linux.org.uk>,
	"Shuah Khan" <shuah@kernel.org>,
	"Christian Brauner" <brauner@kernel.org>,
	"Yang Shi" <shy828301@gmail.com>,
	"Vlastimil Babka" <vbabka@suse.cz>,
	"Liam R . Howlett" <Liam.Howlett@oracle.com>,
	"Yun Zhou" <yun.zhou@windriver.com>,
	"Suren Baghdasaryan" <surenb@google.com>,
	"Alex Sierra" <alex.sierra@amd.com>,
	"Matthew Wilcox" <willy@infradead.org>,
	"Pasha Tatashin" <pasha.tatashin@soleen.com>,
	"Axel Rasmussen" <axelrasmussen@google.com>,
	"Gustavo A . R . Silva" <gustavoars@kernel.org>,
	"Dan Williams" <dan.j.williams@intel.com>,
	linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org,
	linux-mm@kvack.org, linux-kselftest@vger.kernel.org,
	"Greg KH" <gregkh@linuxfoundation.org>,
	kernel@collabora.com, "Michał Mirosław" <mirq-linux@rere.qmqm.pl>
Subject: Re: [PATCH v26 2/5] fs/proc/task_mmu: Implement IOCTL to get and optionally clear info about PTEs
Date: Mon, 7 Aug 2023 09:28:19 +0500	[thread overview]
Message-ID: <10f947a2-3917-a5fe-837d-214d70991bcb@collabora.com> (raw)
In-Reply-To: <CANaxB-zZFq7VD7tBBUmACUJPE9iVuTyQKfg4Jw82-U_1qw6ALg@mail.gmail.com>

On 8/5/23 2:53 AM, Andrei Vagin wrote:
> On Thu, Jul 27, 2023 at 2:37 AM Muhammad Usama Anjum
> <usama.anjum@collabora.com> wrote:
>>
> 
> <snip>
> 
>> +static long do_pagemap_scan(struct mm_struct *mm, unsigned long uarg)
>> +{
>> +       unsigned long walk_start, walk_end;
>> +       struct mmu_notifier_range range;
>> +       struct pagemap_scan_private p;
>> +       size_t n_ranges_out = 0;
>> +       int ret;
>> +
>> +       memset(&p, 0, sizeof(p));
>> +       ret = pagemap_scan_get_args(&p.arg, uarg);
>> +       if (ret)
>> +               return ret;
>> +
>> +       ret = pagemap_scan_init_bounce_buffer(&p);
>> +       if (ret)
>> +               return ret;
>> +
>> +       /* Protection change for the range is going to happen. */
>> +       if (p.arg.flags & PM_SCAN_WP_MATCHING) {
>> +               mmu_notifier_range_init(&range, MMU_NOTIFY_PROTECTION_VMA, 0,
>> +                                       mm, p.arg.start, p.arg.end);
>> +               mmu_notifier_invalidate_range_start(&range);
>> +       }
>> +
>> +       walk_start = walk_end = p.arg.start;
>> +       for (; walk_end != p.arg.end; walk_start = walk_end) {
>> +               int n_out;
>> +
>> +               walk_end = min_t(unsigned long,
>> +                                (walk_start + PAGEMAP_WALK_SIZE) & PAGEMAP_WALK_MASK,
>> +                                p.arg.end);
> 
> This approach has performance implications. The basic program that scans
> its address space takes around 20-30 seconds, but it has just a few
> small mappings. The first optimization that comes to mind is to remove
> the PAGEMAP_WALK_SIZE limit and instead halt walk_page_range when the
> bounce buffer is full. After draining the buffer, the walk_page_range
> function can be restarted.
Yeah, I've this implemented in WIP and will be posting in next revision.

> 
> The test program and perf data can be found here:
> https://gist.github.com/avagin/c5a22f3c78f8cb34281602dfe9c43d10
> 
>> +
>> +               ret = mmap_read_lock_killable(mm);
>> +               if (ret)
>> +                       break;
>> +               ret = walk_page_range(mm, walk_start, walk_end,
>> +                                     &pagemap_scan_ops, &p);
>> +               mmap_read_unlock(mm);
>> +
>> +               n_out = pagemap_scan_flush_buffer(&p);
>> +               if (n_out < 0)
>> +                       ret = n_out;
>> +               else
>> +                       n_ranges_out += n_out;
>> +
>> +               if (ret)
>> +                       break;
>> +       }
>> +
> 
> Thanks,
> Andrei

-- 
BR,
Muhammad Usama Anjum

  reply	other threads:[~2023-08-07  4:28 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-07-27  9:36 [PATCH v26 0/5] Implement IOCTL to get and optionally clear info about PTEs Muhammad Usama Anjum
2023-07-27  9:36 ` [PATCH v26 1/5] userfaultfd: UFFD_FEATURE_WP_ASYNC Muhammad Usama Anjum
2023-07-27  9:36 ` [PATCH v26 2/5] fs/proc/task_mmu: Implement IOCTL to get and optionally clear info about PTEs Muhammad Usama Anjum
2023-07-27 11:40   ` Michał Mirosław
2023-07-27 11:48     ` Muhammad Usama Anjum
2023-07-28 11:02     ` WIP: Performance improvements Muhammad Usama Anjum
2023-07-28 11:13       ` Greg KH
2023-08-07  3:32       ` Andrei Vagin
2023-07-27 11:46   ` [PATCH v26 2/5] fs/proc/task_mmu: Implement IOCTL to get and optionally clear info about PTEs Michał Mirosław
2023-07-27 11:49     ` Muhammad Usama Anjum
2023-08-03 15:08   ` Andrei Vagin
2023-08-03 15:25     ` Michał Mirosław
2023-08-04 15:59       ` Andrei Vagin
2023-08-04 17:17         ` Michał Mirosław
2023-08-04  6:08     ` Muhammad Usama Anjum
2023-08-04 21:53   ` Andrei Vagin
2023-08-07  4:28     ` Muhammad Usama Anjum [this message]
2023-07-27  9:36 ` [PATCH v26 3/5] tools headers UAPI: Update linux/fs.h with the kernel sources Muhammad Usama Anjum
2023-07-27  9:36 ` [PATCH v26 4/5] mm/pagemap: add documentation of PAGEMAP_SCAN IOCTL Muhammad Usama Anjum
2023-07-27  9:36 ` [PATCH v26 5/5] selftests: mm: add pagemap ioctl tests Muhammad Usama Anjum

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=10f947a2-3917-a5fe-837d-214d70991bcb@collabora.com \
    --to=usama.anjum@collabora.com \
    --cc=Liam.Howlett@oracle.com \
    --cc=akpm@linux-foundation.org \
    --cc=alex.sierra@amd.com \
    --cc=avagin@gmail.com \
    --cc=axelrasmussen@google.com \
    --cc=brauner@kernel.org \
    --cc=dan.j.williams@intel.com \
    --cc=david@redhat.com \
    --cc=emmir@google.com \
    --cc=gorcunov@gmail.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=gustavoars@kernel.org \
    --cc=kernel@collabora.com \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=mdanylo@google.com \
    --cc=mirq-linux@rere.qmqm.pl \
    --cc=namit@vmware.com \
    --cc=pasha.tatashin@soleen.com \
    --cc=peterx@redhat.com \
    --cc=pgofman@codeweavers.com \
    --cc=rppt@kernel.org \
    --cc=shuah@kernel.org \
    --cc=shy828301@gmail.com \
    --cc=surenb@google.com \
    --cc=vbabka@suse.cz \
    --cc=viro@zeniv.linux.org.uk \
    --cc=willy@infradead.org \
    --cc=yun.zhou@windriver.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.