linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Joshua Hahn <joshua.hahnjy@gmail.com>
To: Suresh K C <suresh.k.chandrappa@gmail.com>
Cc: nphamcs@gmail.com, hannes@cmpxchg.org, shuah@kernel.org,
	linux-mm@kvack.org, linux-kselftest@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] selftests: cachestat: add tests for mmap
Date: Mon, 30 Jun 2025 13:47:43 -0700	[thread overview]
Message-ID: <20250630204744.1581380-1-joshua.hahnjy@gmail.com> (raw)
In-Reply-To: <20250630180803.12866-1-suresh.k.chandrappa@gmail.com>

On Mon, 30 Jun 2025 23:38:03 +0530 Suresh K C <suresh.k.chandrappa@gmail.com> wrote:

> From: Suresh K C <suresh.k.chandrappa@gmail.com>
> 
> Add a test case to verify cachestat behavior with memory-mapped files
> using mmap(). This ensures that pages accessed via mmap are correctly
> accounted for in the page cache.
> 
> Tested on x86_64 with default kernel config

Hi Suresh,

Thank you for writing this patch! I'll let Nhat or Johannes comment more on the
patch, but just had a few thoughts. Before going into the code, I wanted to
note that it would be helpful in the future to note where this patch comes
from. I saw there were a few iterations of this before, so it would help
reviewers track what changed between the versions and what the motivation
for new versions are. 

[...snip...]

> -		ksft_print_msg("Unable to create shmem file.\n");
> +		ksft_print_msg("Unable to create file.\n");
>  		ret = false;
>  		goto out;

Maybe we don't want to lose information about this -- it would be helpful
to see why the test failed. It doesn't seem like there are any other
indicators that would let users know if it was shmem or mmap that failed, so
users would basically be guessing as to which of these two test failed.
(And the same feedback aplies to the next two print statements)

>  	}
>  
>  	if (ftruncate(fd, filesize)) {
> -		ksft_print_msg("Unable to truncate shmem file.\n");
> +		ksft_print_msg("Unable to truncate file.\n");
>  		ret = false;
>  		goto close_fd;
>  	}
>  
>  	if (!write_exactly(fd, filesize)) {
> -		ksft_print_msg("Unable to write to shmem file.\n");
> +		ksft_print_msg("Unable to write to file.\n");
>  		ret = false;
>  		goto close_fd;
>  	}

I'm curious if we need this part down below. It seems like we already call
write_exactly above, which should fill the file descriptor with random
things up to filesize. Maybe it makes more sense to have these two options
(write_exactly vs. directly modifying the contents) in a switch statement?
It seems a bit redundant to do both for FILE_MMAP.

> +	if (type == FILE_MMAP){
> +		char *map = mmap(NULL, filesize, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
> +		if (map == MAP_FAILED) {
> +			ksft_print_msg("mmap failed.\n");
> +			ret = false;
> +			goto close_fd;
> +		}
> +		for (int i = 0; i < filesize; i++) {
> +			map[i] = 'A';
> +		}
> +		map[filesize - 1] = 'X';

I'm also curious what the point of having the last character be different
here. It doesn't seem like there is any validation code to check the contents
of the file, so it seems a bit redundant to me as well. 

Have a great day!
Joshua

Sent using hkml (https://github.com/sjp38/hackermail)


  reply	other threads:[~2025-06-30 20:47 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-06-30 18:08 Suresh K C
2025-06-30 20:47 ` Joshua Hahn [this message]
2025-06-30 22:30 ` Nhat Pham

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=20250630204744.1581380-1-joshua.hahnjy@gmail.com \
    --to=joshua.hahnjy@gmail.com \
    --cc=hannes@cmpxchg.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=nphamcs@gmail.com \
    --cc=shuah@kernel.org \
    --cc=suresh.k.chandrappa@gmail.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