From: David Hildenbrand <david@redhat.com>
To: Alistair Popple <apopple@nvidia.com>
Cc: linux-mm@kvack.org, akpm@linux-foundation.org,
John Hubbard <jhubbard@nvidia.com>, Peter Xu <peterx@redhat.com>,
Nadav Amit <nadav.amit@gmail.com>,
huang ying <huang.ying.caritas@gmail.com>,
LKML <linux-kernel@vger.kernel.org>,
"Sierra Guiza, Alejandro (Alex)" <alex.sierra@amd.com>,
Felix Kuehling <Felix.Kuehling@amd.com>,
Jason Gunthorpe <jgg@nvidia.com>,
Ralph Campbell <rcampbell@nvidia.com>,
Matthew Wilcox <willy@infradead.org>,
Karol Herbst <kherbst@redhat.com>, Lyude Paul <lyude@redhat.com>,
Ben Skeggs <bskeggs@redhat.com>,
Logan Gunthorpe <logang@deltatee.com>,
paulus@ozlabs.org, linuxppc-dev@lists.ozlabs.org
Subject: Re: [PATCH] hmm-tests: Fix migrate_dirty_page test
Date: Wed, 14 Sep 2022 12:09:10 +0200 [thread overview]
Message-ID: <35003c8f-d777-b2b1-4d48-20f90ba66994@redhat.com> (raw)
In-Reply-To: <878rmnn0jq.fsf@nvdebian.thelocal>
On 13.09.22 10:20, Alistair Popple wrote:
>
> David Hildenbrand <david@redhat.com> writes:
>
>> On 13.09.22 07:22, Alistair Popple wrote:
>>> As noted by John Hubbard the original test relied on side effects of the
>>> implementation of migrate_vma_setup() to detect if pages had been
>>> swapped to disk or not. This is subject to change in future so
>>> explicitly check for swap entries via pagemap instead. Fix a spelling
>>> mistake while we're at it.
>>> Signed-off-by: Alistair Popple <apopple@nvidia.com>
>>> Fixes: 5cc88e844e87 ("selftests/hmm-tests: add test for dirty bits")
>>> ---
>>> tools/testing/selftests/vm/hmm-tests.c | 50 +++++++++++++++++++++++---
>>> 1 file changed, 46 insertions(+), 4 deletions(-)
>>> diff --git a/tools/testing/selftests/vm/hmm-tests.c
>>> b/tools/testing/selftests/vm/hmm-tests.c
>>> index 70fdb49b59ed..b5f6a7dc1f12 100644
>>> --- a/tools/testing/selftests/vm/hmm-tests.c
>>> +++ b/tools/testing/selftests/vm/hmm-tests.c
>>> @@ -1261,9 +1261,47 @@ static int destroy_cgroup(void)
>>> return 0;
>>> }
>>> +static uint64_t get_pfn(int fd, uint64_t ptr)
>>> +{
>>> + uint64_t pfn;
>>> + int ret;
>>> +
>>> + ret = pread(fd, &pfn, sizeof(ptr),
>>> + (uint64_t) ptr / getpagesize() * sizeof(ptr));
>>> + if (ret != sizeof(ptr))
>>> + return 0;
>>> +
>>> + return pfn;
>>> +}
>>> +
>>> +#define PAGEMAP_SWAPPED (1ULL << 62)
>>> +
>>> +/* Returns true if at least one page in the range is on swap */
>>> +static bool pages_swapped(void *ptr, unsigned long pages)
>>> +{
>>> + uint64_t pfn;
>>> + int fd = open("/proc/self/pagemap", O_RDONLY);
>>> + unsigned long i;
>>> +
>>> + if (fd < 0)
>>> + return false;
>>> +
>>> + for (i = 0; i < pages; i++) {
>>> + pfn = get_pfn(fd, (uint64_t) ptr + i * getpagesize());
>>> +
>>> + if (pfn & PAGEMAP_SWAPPED) {
>>> + close(fd);
>>> + return true;
>>> + }
>>
>> We do have pagemap_get_entry() in vm_util.c to query the pagemap entry.
>
> Thanks. I'd missed that, although `grep pagemap
> tools/testing/selftests/vm` suggests I'm not the first to follow a
> tradition of open-coding this :-)
>
> But there's no need to perpetuate that tradition, so will redo this to
> use vm_util.c instead.
Yeah, we just recently factored stuff out into there. I'll be factoring
out more in my upcoming tests from the madv_populate tests.
--
Thanks,
David / dhildenb
prev parent reply other threads:[~2022-09-14 10:09 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-09-13 5:22 Alistair Popple
2022-09-13 7:21 ` Mika Penttilä
2022-09-13 8:06 ` David Hildenbrand
2022-09-13 8:20 ` Alistair Popple
2022-09-14 10:09 ` David Hildenbrand [this message]
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=35003c8f-d777-b2b1-4d48-20f90ba66994@redhat.com \
--to=david@redhat.com \
--cc=Felix.Kuehling@amd.com \
--cc=akpm@linux-foundation.org \
--cc=alex.sierra@amd.com \
--cc=apopple@nvidia.com \
--cc=bskeggs@redhat.com \
--cc=huang.ying.caritas@gmail.com \
--cc=jgg@nvidia.com \
--cc=jhubbard@nvidia.com \
--cc=kherbst@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=linuxppc-dev@lists.ozlabs.org \
--cc=logang@deltatee.com \
--cc=lyude@redhat.com \
--cc=nadav.amit@gmail.com \
--cc=paulus@ozlabs.org \
--cc=peterx@redhat.com \
--cc=rcampbell@nvidia.com \
--cc=willy@infradead.org \
/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