linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Uladzislau Rezki <urezki@gmail.com>
To: Lorenzo Stoakes <lstoakes@gmail.com>
Cc: "Uladzislau Rezki (Sony)" <urezki@gmail.com>,
	Andrew Morton <akpm@linux-foundation.org>,
	linux-mm@kvack.org, LKML <linux-kernel@vger.kernel.org>,
	Baoquan He <bhe@redhat.com>,
	Christoph Hellwig <hch@infradead.org>,
	Matthew Wilcox <willy@infradead.org>,
	Dave Chinner <david@fromorbit.com>,
	Oleksiy Avramchenko <oleksiy.avramchenko@sony.com>
Subject: Re: [PATCH v3 2/2] lib/test_vmalloc.c: Add vm_map_ram()/vm_unmap_ram() test case
Date: Tue, 28 Mar 2023 14:29:57 +0200	[thread overview]
Message-ID: <ZCLdxSyfBpB+zARG@pc636> (raw)
In-Reply-To: <68791932-5e23-4afd-9b36-6cc9a310fdd5@lucifer.local>

> On Mon, Mar 27, 2023 at 07:01:26PM +0200, Uladzislau Rezki (Sony) wrote:
> > Add vm_map_ram()/vm_unmap_ram() test case to our stress test-suite.
> >
> > Signed-off-by: Uladzislau Rezki (Sony) <urezki@gmail.com>
> > ---
> >  lib/test_vmalloc.c | 41 +++++++++++++++++++++++++++++++++++++++++
> >  1 file changed, 41 insertions(+)
> >
> > diff --git a/lib/test_vmalloc.c b/lib/test_vmalloc.c
> > index cd2bdba6d3ed..6633eda4cd4d 100644
> > --- a/lib/test_vmalloc.c
> > +++ b/lib/test_vmalloc.c
> > @@ -53,6 +53,7 @@ __param(int, run_test_mask, INT_MAX,
> >  		"\t\tid: 128,  name: pcpu_alloc_test\n"
> >  		"\t\tid: 256,  name: kvfree_rcu_1_arg_vmalloc_test\n"
> >  		"\t\tid: 512,  name: kvfree_rcu_2_arg_vmalloc_test\n"
> > +		"\t\tid: 1024, name: vm_map_ram_test\n"
> >  		/* Add a new test case description here. */
> >  );
> >
> > @@ -358,6 +359,45 @@ kvfree_rcu_2_arg_vmalloc_test(void)
> >  	return 0;
> >  }
> >
> > +static int
> > +vm_map_ram_test(void)
> > +{
> > +	unsigned int map_nr_pages;
> > +	unsigned char *v_ptr;
> > +	unsigned char *p_ptr;
> > +	struct page **pages;
> > +	struct page *page;
> > +	int i;
> > +
> > +	map_nr_pages = nr_pages > 0 ? nr_pages:1;
> > +	pages = kmalloc(map_nr_pages * sizeof(*page), GFP_KERNEL);
> > +	if (!pages)
> > +		return -1;
> > +
> > +	for (i = 0; i < map_nr_pages; i++) {
> > +		page = alloc_pages(GFP_KERNEL, 1);
> 
> Pedantry, but given I literally patched this pedantically the other day,
> this could be alloc_page(GFP_KERNEL) :)
> 
> > +		if (!page)
> > +			return -1;
> 
> We're leaking memory here right? Should jump to cleanup below.
> 
> > +
> > +		pages[i] = page;
> > +	}
> 
> 
> You should be able to replace this with something like:-
> 
> unsigned long nr_allocated;
> 
> ...
> 
> nr_allocated = alloc_pages_bulk_array(GFP_KERNEL, map_nr_pages, pages);
> if (nr_allocated != map_nr_pages)
> 	goto cleanup;
> 
> > +
> > +	/* Run the test loop. */
> > +	for (i = 0; i < test_loop_count; i++) {
> > +		v_ptr = vm_map_ram(pages, map_nr_pages, -1);
> 
> NIT: The -1 would be clearer as NUMA_NO_NODE
> 
> > +		*v_ptr = 'a';
> > +		vm_unmap_ram(v_ptr, map_nr_pages);
> > +	}
> > +
> 
> Reference to the above you'd add the cleanup label here:-
> 
> cleanup:
> 
> > +	for (i = 0; i < map_nr_pages; i++) {
> > +		p_ptr = page_address(pages[i]);
> > +		free_pages((unsigned long)p_ptr, 1);
> 
> Nit, can be free_page((unsigned long)p_ptr);
> 
Thank you. Will fix all comments, especially switching to the
alloc_page() new API :)

--
Uladzislau Rezki


  reply	other threads:[~2023-03-28 12:30 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-27 17:01 [PATCH v3 1/2] mm: vmalloc: Remove a global vmap_blocks xarray Uladzislau Rezki (Sony)
2023-03-27 17:01 ` [PATCH v3 2/2] lib/test_vmalloc.c: Add vm_map_ram()/vm_unmap_ram() test case Uladzislau Rezki (Sony)
2023-03-27 20:28   ` Lorenzo Stoakes
2023-03-28 12:29     ` Uladzislau Rezki [this message]
2023-03-27 20:09 ` [PATCH v3 1/2] mm: vmalloc: Remove a global vmap_blocks xarray Lorenzo Stoakes
2023-03-28 12:51   ` Uladzislau Rezki
2023-03-28 16:37   ` Uladzislau Rezki
2023-03-29 15:01   ` Uladzislau Rezki
2023-03-29 16:23     ` Lorenzo Stoakes
2023-03-29 17:50       ` Uladzislau Rezki
2023-03-28  3:25 ` Baoquan He
2023-03-28 12:34   ` Uladzislau Rezki
2023-03-29  4:33     ` Baoquan He
2023-03-29  6:54       ` Uladzislau Rezki

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=ZCLdxSyfBpB+zARG@pc636 \
    --to=urezki@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=bhe@redhat.com \
    --cc=david@fromorbit.com \
    --cc=hch@infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=lstoakes@gmail.com \
    --cc=oleksiy.avramchenko@sony.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