From: "Michał Mirosław" <emmir@google.com>
To: Muhammad Usama Anjum <usama.anjum@collabora.com>
Cc: Peter Xu <peterx@redhat.com>,
David Hildenbrand <david@redhat.com>,
Andrew Morton <akpm@linux-foundation.org>,
Andrei Vagin <avagin@gmail.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
Subject: Re: [PATCH v18 2/5] fs/proc/task_mmu: Implement IOCTL to get and optionally clear info about PTEs
Date: Wed, 21 Jun 2023 00:05:05 +0200 [thread overview]
Message-ID: <CABb0KFEqJasf9nM3wL1oaK9ObcYzwzjtrRBcWRc3wGqdZRUpXg@mail.gmail.com> (raw)
In-Reply-To: <444ed144-a2ee-cb16-880a-128383c83a08@collabora.com>
On Tue, 20 Jun 2023 at 13:16, Muhammad Usama Anjum
<usama.anjum@collabora.com> wrote:
> On 6/19/23 1:16 PM, Michał Mirosław wrote:
> > On Fri, 16 Jun 2023 at 08:57, Muhammad Usama Anjum
> > <usama.anjum@collabora.com> wrote:
> >>
> >> On 6/16/23 1:07 AM, Michał Mirosław wrote:
> >>> On Thu, 15 Jun 2023 at 17:11, Muhammad Usama Anjum
> >>> <usama.anjum@collabora.com> wrote:
> >>>> On 6/15/23 7:52 PM, Michał Mirosław wrote:
> >>>>> On Thu, 15 Jun 2023 at 15:58, Muhammad Usama Anjum
> >>>>> <usama.anjum@collabora.com> wrote:
> >>>>>> I'll send next revision now.
> >>>>>> On 6/14/23 11:00 PM, Michał Mirosław wrote:
> >>>>>>> (A quick reply to answer open questions in case they help the next version.)
> > [...]
> >>>>>>> I guess this will be reworked anyway, but I'd prefer this didn't need
> >>>>>>> custom errors etc. If we agree to decoupling the selection and GET
> >>>>>>> output, it could be:
> >>>>>>>
> >>>>>>> bool is_interesting_page(p, flags); // this one does the
> >>>>>>> required/anyof/excluded match
> >>>>>>> size_t output_range(p, start, len, flags); // this one fills the
> >>>>>>> output vector and returns how many pages were fit
> >>>>>>>
> >>>>>>> In this setup, `is_interesting_page() && (n_out = output_range()) <
> >>>>>>> n_pages` means this is the final range, no more will fit. And if
> >>>>>>> `n_out == 0` then no pages fit and no WP is needed (no other special
> >>>>>>> cases).
> >>>>>> Right now, pagemap_scan_output() performs the work of both of these two
> >>>>>> functions. The part can be broken into is_interesting_pages() and we can
> >>>>>> leave the remaining part as it is.
> >>>>>>
> >>>>>> Saying that n_out < n_pages tells us the buffer is full covers one case.
> >>>>>> But there is case of maximum pages have been found and walk needs to be
> >>>>>> aborted.
> >>>>>
> >>>>> This case is exactly what `n_out < n_pages` will cover (if scan_output
> >>>>> uses max_pages properly to limit n_out).
> >>>>> Isn't it that when the buffer is full we want to abort the scan always
> >>>>> (with WP if `n_out > 0`)?
> >>>> Wouldn't it be duplication of condition if buffer is full inside
> >>>> pagemap_scan_output() and just outside it. Inside pagemap_scan_output() we
> >>>> check if we have space before putting data inside it. I'm using this same
> >>>> condition to indicate that buffer is full.
> >>>
> >>> I'm not sure what do you mean? The buffer-full conditions would be
> >>> checked in ..scan_output() and communicated to the caller by returning
> >>> N less than `n_pages` passed in. This is exactly how e.g. read()
> >>> works: if you get less than requested you've hit the end of the file.
> >>> If the file happens to have size that is equal to the provided buffer
> >>> length, the next read() will return 0.
> >> Right now we have:
> >>
> >> pagemap_scan_output():
> >> if (p->vec_buf_index >= p->vec_buf_len)
> >> return PM_SCAN_BUFFER_FULL;
> >> if (p->found_pages == p->max_pages)
> >> return PM_SCAN_FOUND_MAX_PAGES;
> >
> > Why do you need to differentiate between those cases?
> >
> >> pagemap_scan_pmd_entry():
> >> ret = pagemap_scan_output(bitmap, p, start, n_pages);
> >> if (ret >= 0) // success
> >> make_UFFD_WP and flush
> >> else
> >> buffer_error
> >>
> >> You are asking me to do:
> >>
> >> pagemap_scan_output():
> >> if (p->vec_buf_index >= p->vec_buf_len)
> >> return 0;
> >
> >> if (p->found_pages == p->max_pages)
> >> return PM_SCAN_FOUND_MAX_PAGES;
> >
> > This should be instead:
> >
> > n_pages = min(p->max_pags - p_found_pages, n_pages)
> > ...
> > return n_pages;
> You are missing the optimization here that we check for full buffer every
> time adding to user buffer. This was added to remove extra iteration of
> page walk if buffer is full already. The way you are suggesting will remove it.
>
> So you are returning remaining pages to be found now. This doesn't seem
> right. If max_pages is 520, found_pages is 0 and n_pages is 512 before
> calling pagemap_scan_output(). found_pages would become 512 after adding
> 512 pages to output buffer. But n_pages would return 8 instead of 512. You
> were saying we should return the number of pages added to the output buffer.
Ok, if we want this optimization, then i'd rework it so that we have:
bool pagemap_scan_output(..., int *n_pages)
{
limit n_pages;
...
return have_more_room_in_output;
}
The compiler should remove the pointer and memory storage for
`n_pages` when inlining the function.
Best Regards
Michał Mirosław
next prev parent reply other threads:[~2023-06-20 22:05 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-06-13 10:29 [PATCH v18 0/5] " Muhammad Usama Anjum
2023-06-13 10:29 ` [PATCH v18 1/5] userfaultfd: UFFD_FEATURE_WP_ASYNC Muhammad Usama Anjum
2023-06-13 10:29 ` [PATCH v18 2/5] fs/proc/task_mmu: Implement IOCTL to get and optionally clear info about PTEs Muhammad Usama Anjum
2023-06-13 16:11 ` kernel test robot
2023-06-13 22:36 ` Michał Mirosław
2023-06-14 13:46 ` Muhammad Usama Anjum
2023-06-14 15:14 ` Michał Mirosław
2023-06-14 17:09 ` Muhammad Usama Anjum
2023-06-14 18:00 ` Michał Mirosław
2023-06-15 13:58 ` Muhammad Usama Anjum
2023-06-15 14:52 ` Michał Mirosław
2023-06-15 14:58 ` Michał Mirosław
2023-06-15 15:16 ` Muhammad Usama Anjum
2023-06-15 20:00 ` Michał Mirosław
2023-06-16 6:37 ` Muhammad Usama Anjum
2023-06-15 15:11 ` Muhammad Usama Anjum
2023-06-15 20:07 ` Michał Mirosław
2023-06-16 6:57 ` Muhammad Usama Anjum
2023-06-19 8:16 ` Michał Mirosław
2023-06-20 11:15 ` Muhammad Usama Anjum
2023-06-20 22:05 ` Michał Mirosław [this message]
2023-06-21 4:44 ` Muhammad Usama Anjum
2023-06-21 13:24 ` Michał Mirosław
2023-06-14 4:09 ` Randy Dunlap
2023-06-14 11:36 ` Muhammad Usama Anjum
2023-06-13 10:29 ` [PATCH v18 3/5] tools headers UAPI: Update linux/fs.h with the kernel sources Muhammad Usama Anjum
2023-06-13 10:29 ` [PATCH v18 4/5] mm/pagemap: add documentation of PAGEMAP_SCAN IOCTL Muhammad Usama Anjum
2023-06-14 4:20 ` Randy Dunlap
2023-06-14 11:27 ` Muhammad Usama Anjum
2023-06-13 10:29 ` [PATCH v18 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=CABb0KFEqJasf9nM3wL1oaK9ObcYzwzjtrRBcWRc3wGqdZRUpXg@mail.gmail.com \
--to=emmir@google.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=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=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=usama.anjum@collabora.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox