All of lore.kernel.org
 help / color / mirror / Atom feed
From: Glenn Washburn <development@efficientek.com>
To: Diego Domingos <diegodo@linux.vnet.ibm.com>
Cc: The development of GNU GRUB <grub-devel@gnu.org>,
	stefanb@linux.ibm.com, dja@axtens.net
Subject: Re: [PATCH 4/6] Add memtool module with memory allocation stress-test
Date: Thu, 11 Aug 2022 12:57:29 -0500	[thread overview]
Message-ID: <20220811125729.6289c29b@crass-HP-ZBook-15-G2> (raw)
In-Reply-To: <20220811174104.1148447-5-diegodo@linux.vnet.ibm.com>

On Thu, 11 Aug 2022 14:41:02 -0300
Diego Domingos <diegodo@linux.vnet.ibm.com> wrote:

> From: Daniel Axtens <dja@axtens.net>
> 
> When working on memory, it's nice to be able to test your work.
> 
> Add a memtest module. When compiled with --enable-mm-debug, it exposes
> 3 commands:

Does this build without giving --enable-mm-debug to configure? Last
time I checked it did not. It would be nice to include this patch if it
allows building without --enable-mm-debug.

Glenn

> 
>  * lsmem - print all allocations and free space in all regions
>  * lsfreemem - print free space in all regions
> 
>  * stress_big_allocs - stress test large allocations:
>   - how much memory can we allocate in one chunk?
>   - how many 1MB chunks can we allocate?
>   - check that gap-filling works with a 1MB aligned 900kB alloc + a
>      100kB alloc.
> 
> Signed-off-by: Daniel Axtens <dja@axtens.net>
> ---
>  grub-core/Makefile.core.def   |   5 ++
>  grub-core/commands/memtools.c | 155 ++++++++++++++++++++++++++++++++++
>  grub-core/kern/mm.c           |   4 +
>  3 files changed, 164 insertions(+)
>  create mode 100644 grub-core/commands/memtools.c
> 
> diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def
> index 5212dfab1..485169d53 100644
> --- a/grub-core/Makefile.core.def
> +++ b/grub-core/Makefile.core.def
> @@ -2538,3 +2538,8 @@ module = {
>    common = commands/i386/wrmsr.c;
>    enable = x86;
>  };
> +
> +module = {
> +  name = memtools;
> +  common = commands/memtools.c;
> +};
> diff --git a/grub-core/commands/memtools.c b/grub-core/commands/memtools.c
> new file mode 100644
> index 000000000..bb4ad359e
> --- /dev/null
> +++ b/grub-core/commands/memtools.c
> @@ -0,0 +1,155 @@
> +/*
> + *  GRUB  --  GRand Unified Bootloader
> + *  Copyright (C) 2021 Free Software Foundation, Inc.
> + *  Copyright (C) 2021 IBM Corporation
> + *
> + *  GRUB is free software: you can redistribute it and/or modify
> + *  it under the terms of the GNU General Public License as published by
> + *  the Free Software Foundation, either version 3 of the License, or
> + *  (at your option) any later version.
> + *
> + *  GRUB is distributed in the hope that it will be useful,
> + *  but WITHOUT ANY WARRANTY; without even the implied warranty of
> + *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> + *  GNU General Public License for more details.
> + *
> + *  You should have received a copy of the GNU General Public License
> + *  along with GRUB.  If not, see <http://www.gnu.org/licenses/>.
> + */
> +
> +#include <config.h>
> +#include <grub/dl.h>
> +#include <grub/misc.h>
> +#include <grub/command.h>
> +#include <grub/i18n.h>
> +#include <grub/memory.h>
> +#include <grub/mm.h>
> +
> +GRUB_MOD_LICENSE ("GPLv3+");
> +
> +#ifdef MM_DEBUG
> +
> +static grub_err_t
> +grub_cmd_lsmem (grub_command_t cmd __attribute__ ((unused)),
> +		 int argc __attribute__ ((unused)),
> +		 char **args __attribute__ ((unused)))
> +
> +{
> +#ifndef GRUB_MACHINE_EMU
> +  grub_mm_dump(0);
> +#endif
> +
> +  return 0;
> +}
> +
> +static grub_err_t
> +grub_cmd_lsfreemem (grub_command_t cmd __attribute__ ((unused)),
> +		    int argc __attribute__ ((unused)),
> +		    char **args __attribute__ ((unused)))
> +
> +{
> +#ifndef GRUB_MACHINE_EMU
> +  grub_mm_dump_free();
> +#endif
> +
> +  return 0;
> +}
> +
> +
> +static grub_err_t
> +grub_cmd_stress_big_allocs (grub_command_t cmd __attribute__ ((unused)),
> +			    int argc __attribute__ ((unused)),
> +			    char **args __attribute__ ((unused)))
> +{
> +  int i, max_mb, blocks_alloced;
> +  void *mem;
> +  void **blocklist;
> +
> +  grub_printf ("Test 1: increasingly sized allocs to 1GB block\n");
> +  for (i = 1; i < 1024; i++) {
> +    grub_printf ("%d MB . ", i);
> +    mem = grub_malloc (i * 1024 * 1024);
> +    if (mem == NULL)
> +      {
> +	grub_printf ("failed\n");
> +	break;
> +      }
> +    else
> +      grub_free (mem);
> +
> +    if (i % 10 == 0)
> +      grub_printf ("\n");
> +  }
> +
> +  max_mb = i - 1;
> +  grub_printf ("Max sized allocation we did was %d MB\n", max_mb);
> +  
> +  grub_printf ("Test 2: 1MB at a time, max 4GB\n");
> +  blocklist = grub_calloc (4096, sizeof (void *));
> +  for (i = 0; i < 4096; i++)
> +    {
> +      blocklist[i] = grub_malloc (1024 * 1024);
> +      if (!blocklist[i])
> +	{
> +	  grub_printf ("Ran out of memory at iteration %d\n", i);
> +	  break;
> +	}
> +    }
> +  blocks_alloced = i;
> +  for (i = 0; i < blocks_alloced; i++)
> +    grub_free (blocklist[i]);
> +
> +  grub_printf ("\nTest 3: 1MB aligned 900kB + 100kB\n");
> +  //grub_mm_debug=1;
> +  for (i = 0; i < 4096; i += 2)
> +    {
> +      blocklist[i] = grub_memalign (1024 * 1024, 900 * 1024);
> +      if (!blocklist[i])
> +	{
> +	  grub_printf ("Failed big allocation, iteration %d\n", i);
> +	  blocks_alloced = i;
> +	  break;
> +	}
> +
> +      blocklist[i + 1] = grub_malloc (100 * 1024);
> +      if (!blocklist[i + 1])
> +	{
> +	  grub_printf ("Failed small allocation, iteration %d\n", i);
> +	  blocks_alloced = i + 1;
> +	  break;
> +	}
> +      grub_printf (".");
> +    }
> +  for (i = 0; i < blocks_alloced; i++)
> +    grub_free (blocklist[i]);
> +
> +  grub_free (blocklist);
> +
> +  grub_errno = GRUB_ERR_NONE;
> +  return GRUB_ERR_NONE;
> +}
> +
> +static grub_command_t cmd_lsmem, cmd_lsfreemem, cmd_sba;
> +
> +#endif /* MM_DEBUG */
> +
> +GRUB_MOD_INIT(memtools)
> +{
> +#ifdef MM_DEBUG
> +  cmd_lsmem = grub_register_command ("lsmem", grub_cmd_lsmem,
> +				     0, N_("List free and allocated memory blocks."));
> +  cmd_lsfreemem = grub_register_command ("lsfreemem", grub_cmd_lsfreemem,
> +					 0, N_("List free memory blocks."));
> +  cmd_sba = grub_register_command ("stress_big_allocs", grub_cmd_stress_big_allocs,
> +  				   0, N_("Stress test large allocations."));
> +#endif
> +}
> +
> +GRUB_MOD_FINI(memtools)
> +{
> +#ifdef MM_DEBUG
> +  grub_unregister_command (cmd_lsmem);
> +  grub_unregister_command (cmd_lsfreemem);
> +  grub_unregister_command (cmd_sba);
> +#endif
> +}
> diff --git a/grub-core/kern/mm.c b/grub-core/kern/mm.c
> index 75f6eacbe..c341d4f60 100644
> --- a/grub-core/kern/mm.c
> +++ b/grub-core/kern/mm.c
> @@ -664,6 +664,8 @@ grub_mm_dump_free (void)
>      {
>        grub_mm_header_t p;
>  
> +      grub_printf ("Region %p (size %" PRIuGRUB_SIZE ")\n\n", r, r->size);
> +
>        /* Follow the free list.  */
>        p = r->first;
>        do
> @@ -691,6 +693,8 @@ grub_mm_dump (unsigned lineno)
>      {
>        grub_mm_header_t p;
>  
> +      grub_printf ("Region %p (size %" PRIuGRUB_SIZE ")\n\n", r, r->size);
> +
>        for (p = (grub_mm_header_t) ALIGN_UP ((grub_addr_t) (r + 1),
>  					    GRUB_MM_ALIGN);
>  	   (grub_addr_t) p < (grub_addr_t) (r+1) + r->size;


  reply	other threads:[~2022-08-11 17:57 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-08-11 17:40 [PATCH 0/6] Dynamic allocation of memory regions and IBM vTPM v2 Diego Domingos
2022-08-11 17:40 ` [PATCH 1/6] ieee1275: request memory with ibm, client-architecture-support Diego Domingos
2022-08-11 17:41 ` [PATCH 2/6] ieee1275: drop len -= 1 quirk in heap_init Diego Domingos
2022-08-11 17:41 ` [PATCH 3/6] ieee1275: support runtime memory claiming Diego Domingos
2022-08-11 17:41 ` [PATCH 4/6] Add memtool module with memory allocation stress-test Diego Domingos
2022-08-11 17:57   ` Glenn Washburn [this message]
2022-08-11 17:41 ` [PATCH 5/6] ibmvtpm: Add support for trusted boot using a vTPM 2.0 Diego Domingos
2022-08-11 17:41 ` [PATCH 6/6] ieee1275: implement vec5 for cas negotiation Diego Domingos
2022-08-16 15:11   ` Daniel Axtens
2022-11-24 17:56 ` [PATCH 0/6] Dynamic allocation of memory regions and IBM vTPM v2 Daniel Kiper
2022-11-30 19:47   ` Stefan Berger
2022-11-30 21:24     ` Stefan Berger
2022-11-30 22:42       ` Stefan Berger
2022-12-01  5:19         ` Glenn Washburn
2022-12-01 13:43           ` Stefan Berger
2022-12-01 14:02             ` Daniel Kiper
2022-12-01 14:22               ` Stefan Berger
2022-12-01 14:47                 ` Daniel Kiper
2022-12-01 14:58                   ` Stefan Berger
2022-12-01 15:51                     ` Daniel Kiper
2022-12-01 16:44                       ` Stefan Berger
2022-12-01 18:46                         ` Daniel Kiper
2022-12-02 12:54                   ` Lennart Sorensen
2022-12-01 13:59       ` Daniel Kiper
2022-12-01 13:52     ` Daniel Kiper

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=20220811125729.6289c29b@crass-HP-ZBook-15-G2 \
    --to=development@efficientek.com \
    --cc=diegodo@linux.vnet.ibm.com \
    --cc=dja@axtens.net \
    --cc=grub-devel@gnu.org \
    --cc=stefanb@linux.ibm.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.