linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Mike Rapoport <rppt@kernel.org>
To: kirill@shutemov.name
Cc: Andrew Morton <akpm@linux-foundation.org>,
	David Hildenbrand <david@redhat.com>,
	Lorenzo Stoakes <lorenzo.stoakes@oracle.com>,
	"Liam R . Howlett" <Liam.Howlett@oracle.com>,
	Vlastimil Babka <vbabka@suse.cz>,
	Suren Baghdasaryan <surenb@google.com>,
	Michal Hocko <mhocko@suse.com>,
	linux-mm@kvack.org, Usama Arif <usamaarif642@gmail.com>,
	Kiryl Shutsemau <kas@kernel.org>
Subject: Re: [PATCH] tools/mm: Add madvise tool
Date: Fri, 5 Sep 2025 13:59:10 +0300	[thread overview]
Message-ID: <aLrCfvlhWRCEmwXc@kernel.org> (raw)
In-Reply-To: <20250904175729.1029735-1-kirill@shutemov.name>

On Thu, Sep 04, 2025 at 06:57:29PM +0100, kirill@shutemov.name wrote:
> From: Kiryl Shutsemau <kas@kernel.org>
> 
> Add a simple tool that allows to issue an advice on a process or a file.
> 
> It can be useful to experiment with effects of an advice on a workload
> without modifying the workload itself.
> 
> Only supports advices available for process_madvise().
> 
> Signed-off-by: Kiryl Shutsemau <kas@kernel.org>
> ---
>  tools/mm/.gitignore |   4 +-
>  tools/mm/Makefile   |   2 +-
>  tools/mm/madvise.c  | 170 ++++++++++++++++++++++++++++++++++++++++++++
>  3 files changed, 174 insertions(+), 2 deletions(-)
>  create mode 100644 tools/mm/madvise.c
> 

...

> +		unsigned long addr, hpage_pmd_size;
> +		void *p;
> +		int ret;
> +
> +		hpage_pmd_size = read_pmd_pagesize();
> +		if (!hpage_pmd_size) {
> +			printf("Reading PMD pagesize failed");
> +			exit(-1);

Shouldn't it fail only for collapse? Other advices don't depend on THP.

> +		}
> +
> +		// Allocate virtual address space to align the target mmap to PMD size
> +		// Some advices require this.
> +		p = mmap(NULL, end - start + hpage_pmd_size, PROT_NONE,
> +			 MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);
> +		if (p == MAP_FAILED)
> +			perror("mmap0"), exit(-1);
> +		addr = (unsigned long)p;
> +		addr += hpage_pmd_size - 1;
> +		addr &= ~(hpage_pmd_size - 1);
> +
> +		p = mmap((void *)addr, end - start,
> +			 PROT_READ | PROT_WRITE, MAP_SHARED | MAP_FIXED | MAP_POPULATE, fd, start);
> +		if (p == MAP_FAILED)
> +			perror("mmap"), exit(-1);
> +
> +		ret = madvise(p, end - start, advice);
> +		if (ret)
> +			perror("madvise"), exit(-1);
> +	}
> +
> +	return 0;
> +}
> -- 
> 2.50.1
> 

-- 
Sincerely yours,
Mike.


  parent reply	other threads:[~2025-09-05 10:59 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-09-04 17:57 kirill
2025-09-04 19:07 ` Liam R. Howlett
2025-09-05  3:26 ` wang lian
2025-09-05 10:28   ` Kiryl Shutsemau
2025-09-08  1:09     ` wang lian
2025-09-05  9:17 ` Michal Hocko
2025-09-05 10:16   ` Lorenzo Stoakes
2025-09-05 10:56     ` Michal Hocko
2025-09-05 11:02       ` Lorenzo Stoakes
2025-09-05 10:21   ` Kiryl Shutsemau
2025-09-05 11:02     ` Michal Hocko
2025-09-05 10:19 ` David Hildenbrand
2025-09-05 10:24   ` Kiryl Shutsemau
2025-09-05 10:33     ` David Hildenbrand
2025-09-05 10:35       ` Kiryl Shutsemau
2025-09-05 10:37 ` Lorenzo Stoakes
2025-09-05 13:35   ` Kiryl Shutsemau
2025-09-05 16:30   ` Kiryl Shutsemau
2025-09-05 10:45 ` Usama Arif
2025-09-05 10:59 ` Mike Rapoport [this message]
2025-09-05 13:36   ` Kiryl Shutsemau
2025-09-06  8:00     ` Mike Rapoport
2025-09-08 10:04       ` Kiryl Shutsemau
2025-09-10 11:34 ` [ANNOUNCE] mm-tools: Random tools MM-related tools Kiryl Shutsemau

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=aLrCfvlhWRCEmwXc@kernel.org \
    --to=rppt@kernel.org \
    --cc=Liam.Howlett@oracle.com \
    --cc=akpm@linux-foundation.org \
    --cc=david@redhat.com \
    --cc=kas@kernel.org \
    --cc=kirill@shutemov.name \
    --cc=linux-mm@kvack.org \
    --cc=lorenzo.stoakes@oracle.com \
    --cc=mhocko@suse.com \
    --cc=surenb@google.com \
    --cc=usamaarif642@gmail.com \
    --cc=vbabka@suse.cz \
    /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