Skip to content

Commit

Permalink
Merge tag 'memblock-v5.20-rc1' of git://git.kernel.org/pub/scm/linux/…
Browse files Browse the repository at this point in the history
…kernel/git/rppt/memblock

Pull memblock updates from Mike Rapoport:

 - An optimization in memblock_add_range() to reduce array traversals

 - Improvements to the memblock test suite

* tag 'memblock-v5.20-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/rppt/memblock:
  memblock test: Modify the obsolete description in README
  memblock tests: fix compilation errors
  memblock tests: change build options to run-time options
  memblock tests: remove completed TODO items
  memblock tests: set memblock_debug to enable memblock_dbg() messages
  memblock tests: add verbose output to memblock tests
  memblock tests: Makefile: add arguments to control verbosity
  memblock: avoid some repeat when add new range
  • Loading branch information
Linus Torvalds committed Aug 9, 2022
2 parents 1588632 + 04d9490 commit b8dcef8
Show file tree
Hide file tree
Showing 14 changed files with 920 additions and 370 deletions.
11 changes: 11 additions & 0 deletions mm/memblock.c
Original file line number Diff line number Diff line change
Expand Up @@ -597,6 +597,17 @@ static int __init_memblock memblock_add_range(struct memblock_type *type,
type->total_size = size;
return 0;
}

/*
* The worst case is when new range overlaps all existing regions,
* then we'll need type->cnt + 1 empty regions in @type. So if
* type->cnt * 2 + 1 is less than type->max, we know
* that there is enough empty regions in @type, and we can insert
* regions directly.
*/
if (type->cnt * 2 + 1 < type->max)
insert = true;

repeat:
/*
* The following is executed twice. Once with %false @insert and
Expand Down
3 changes: 1 addition & 2 deletions tools/testing/memblock/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,8 @@ help:
@echo ' clean - Remove generated files and symlinks in the directory'
@echo ''
@echo 'Configuration:'
@echo ' make MEMBLOCK_DEBUG=1 - enable memblock_dbg() messages'
@echo ' make NUMA=1 - simulate enabled NUMA'
@echo ' make MOVABLE_NODE=1 - override `movable_node_is_enabled`'
@echo ' definition to simulate movable NUMA nodes'
@echo ' make 32BIT_PHYS_ADDR_T=1 - Use 32 bit physical addresses'

vpath %.c ../../lib
Expand Down
17 changes: 14 additions & 3 deletions tools/testing/memblock/README
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,23 @@ To run the tests, build the main target and run it:

$ make && ./main

A successful run produces no output. It is also possible to override different
configuration parameters. For example, to simulate enabled NUMA, use:
A successful run produces no output. It is possible to control the behavior
by passing options from command line. For example, to include verbose output,
append the `-v` options when you run the tests:

$ ./main -v

This will print information about which functions are being tested and the
number of test cases that passed.

For the full list of options from command line, see `./main --help`.

It is also possible to override different configuration parameters to change
the test functions. For example, to simulate enabled NUMA, use:

$ make NUMA=1

For the full list of options, see `make help`.
For the full list of build options, see `make help`.

Project structure
=================
Expand Down
14 changes: 3 additions & 11 deletions tools/testing/memblock/TODO
Original file line number Diff line number Diff line change
@@ -1,25 +1,17 @@
TODO
=====

1. Add verbose output (e.g., what is being tested and how many tests cases are
passing)

2. Add flags to Makefile:
+ verbosity level
+ enable memblock_dbg() messages (i.e. pass "-D CONFIG_DEBUG_MEMORY_INIT"
flag)

3. Add tests trying to memblock_add() or memblock_reserve() 129th region.
1. Add tests trying to memblock_add() or memblock_reserve() 129th region.
This will trigger memblock_double_array(), make sure it succeeds.
*Important:* These tests require valid memory ranges, use dummy physical
memory block from common.c to implement them. It is also very
likely that the current MEM_SIZE won't be enough for these
test cases. Use realloc to adjust the size accordingly.

4. Add test cases using this functions (implement them for both directions):
2. Add test cases using this functions (implement them for both directions):
+ memblock_alloc_raw()
+ memblock_alloc_exact_nid_raw()
+ memblock_alloc_try_nid_raw()

5. Add tests for memblock_alloc_node() to check if the correct NUMA node is set
3. Add tests for memblock_alloc_node() to check if the correct NUMA node is set
for the new region
11 changes: 11 additions & 0 deletions tools/testing/memblock/internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,17 @@
#ifndef _MM_INTERNAL_H
#define _MM_INTERNAL_H

/*
* Enable memblock_dbg() messages
*/
#ifdef MEMBLOCK_DEBUG
static int memblock_debug = 1;
#endif

#define pr_warn_ratelimited(fmt, ...) printf(fmt, ##__VA_ARGS__)

bool mirrored_kernelcore = false;

struct page {};

void memblock_free_pages(struct page *page, unsigned long pfn,
Expand Down
8 changes: 3 additions & 5 deletions tools/testing/memblock/linux/memory_hotplug.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,11 @@
#include <linux/cache.h>
#include <linux/types.h>

extern bool movable_node_enabled;

static inline bool movable_node_is_enabled(void)
{
#ifdef MOVABLE_NODE
return true;
#else
return false;
#endif
return movable_node_enabled;
}

#endif
2 changes: 2 additions & 0 deletions tools/testing/memblock/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
#include "tests/alloc_api.h"
#include "tests/alloc_helpers_api.h"
#include "tests/alloc_nid_api.h"
#include "tests/common.h"

int main(int argc, char **argv)
{
parse_args(argc, argv);
memblock_basic_checks();
memblock_alloc_checks();
memblock_alloc_helpers_checks();
Expand Down
10 changes: 5 additions & 5 deletions tools/testing/memblock/scripts/Makefile.include
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ ifeq ($(NUMA), 1)
CFLAGS += -D CONFIG_NUMA
endif

# Simulate movable NUMA memory regions
ifeq ($(MOVABLE_NODE), 1)
CFLAGS += -D MOVABLE_NODE
endif

# Use 32 bit physical addresses.
# Remember to install 32-bit version of dependencies.
ifeq ($(32BIT_PHYS_ADDR_T), 1)
CFLAGS += -m32 -U CONFIG_PHYS_ADDR_T_64BIT
LDFLAGS += -m32
endif

# Enable memblock_dbg() messages
ifeq ($(MEMBLOCK_DEBUG), 1)
CFLAGS += -D MEMBLOCK_DEBUG
endif
Loading

0 comments on commit b8dcef8

Please sign in to comment.