Skip to content

Commit b8dcef8

Browse files
committed
Merge tag 'memblock-v5.20-rc1' of git://git.kernel.org/pub/scm/linux/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
2 parents 1588632 + 04d9490 commit b8dcef8

File tree

14 files changed

+920
-370
lines changed

14 files changed

+920
-370
lines changed

mm/memblock.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -597,6 +597,17 @@ static int __init_memblock memblock_add_range(struct memblock_type *type,
597597
type->total_size = size;
598598
return 0;
599599
}
600+
601+
/*
602+
* The worst case is when new range overlaps all existing regions,
603+
* then we'll need type->cnt + 1 empty regions in @type. So if
604+
* type->cnt * 2 + 1 is less than type->max, we know
605+
* that there is enough empty regions in @type, and we can insert
606+
* regions directly.
607+
*/
608+
if (type->cnt * 2 + 1 < type->max)
609+
insert = true;
610+
600611
repeat:
601612
/*
602613
* The following is executed twice. Once with %false @insert and

tools/testing/memblock/Makefile

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,8 @@ help:
4545
@echo ' clean - Remove generated files and symlinks in the directory'
4646
@echo ''
4747
@echo 'Configuration:'
48+
@echo ' make MEMBLOCK_DEBUG=1 - enable memblock_dbg() messages'
4849
@echo ' make NUMA=1 - simulate enabled NUMA'
49-
@echo ' make MOVABLE_NODE=1 - override `movable_node_is_enabled`'
50-
@echo ' definition to simulate movable NUMA nodes'
5150
@echo ' make 32BIT_PHYS_ADDR_T=1 - Use 32 bit physical addresses'
5251

5352
vpath %.c ../../lib

tools/testing/memblock/README

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,23 @@ To run the tests, build the main target and run it:
3333

3434
$ make && ./main
3535

36-
A successful run produces no output. It is also possible to override different
37-
configuration parameters. For example, to simulate enabled NUMA, use:
36+
A successful run produces no output. It is possible to control the behavior
37+
by passing options from command line. For example, to include verbose output,
38+
append the `-v` options when you run the tests:
39+
40+
$ ./main -v
41+
42+
This will print information about which functions are being tested and the
43+
number of test cases that passed.
44+
45+
For the full list of options from command line, see `./main --help`.
46+
47+
It is also possible to override different configuration parameters to change
48+
the test functions. For example, to simulate enabled NUMA, use:
3849

3950
$ make NUMA=1
4051

41-
For the full list of options, see `make help`.
52+
For the full list of build options, see `make help`.
4253

4354
Project structure
4455
=================

tools/testing/memblock/TODO

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,17 @@
11
TODO
22
=====
33

4-
1. Add verbose output (e.g., what is being tested and how many tests cases are
5-
passing)
6-
7-
2. Add flags to Makefile:
8-
+ verbosity level
9-
+ enable memblock_dbg() messages (i.e. pass "-D CONFIG_DEBUG_MEMORY_INIT"
10-
flag)
11-
12-
3. Add tests trying to memblock_add() or memblock_reserve() 129th region.
4+
1. Add tests trying to memblock_add() or memblock_reserve() 129th region.
135
This will trigger memblock_double_array(), make sure it succeeds.
146
*Important:* These tests require valid memory ranges, use dummy physical
157
memory block from common.c to implement them. It is also very
168
likely that the current MEM_SIZE won't be enough for these
179
test cases. Use realloc to adjust the size accordingly.
1810

19-
4. Add test cases using this functions (implement them for both directions):
11+
2. Add test cases using this functions (implement them for both directions):
2012
+ memblock_alloc_raw()
2113
+ memblock_alloc_exact_nid_raw()
2214
+ memblock_alloc_try_nid_raw()
2315

24-
5. Add tests for memblock_alloc_node() to check if the correct NUMA node is set
16+
3. Add tests for memblock_alloc_node() to check if the correct NUMA node is set
2517
for the new region

tools/testing/memblock/internal.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,17 @@
22
#ifndef _MM_INTERNAL_H
33
#define _MM_INTERNAL_H
44

5+
/*
6+
* Enable memblock_dbg() messages
7+
*/
8+
#ifdef MEMBLOCK_DEBUG
9+
static int memblock_debug = 1;
10+
#endif
11+
12+
#define pr_warn_ratelimited(fmt, ...) printf(fmt, ##__VA_ARGS__)
13+
14+
bool mirrored_kernelcore = false;
15+
516
struct page {};
617

718
void memblock_free_pages(struct page *page, unsigned long pfn,

tools/testing/memblock/linux/memory_hotplug.h

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,11 @@
77
#include <linux/cache.h>
88
#include <linux/types.h>
99

10+
extern bool movable_node_enabled;
11+
1012
static inline bool movable_node_is_enabled(void)
1113
{
12-
#ifdef MOVABLE_NODE
13-
return true;
14-
#else
15-
return false;
16-
#endif
14+
return movable_node_enabled;
1715
}
1816

1917
#endif

tools/testing/memblock/main.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@
33
#include "tests/alloc_api.h"
44
#include "tests/alloc_helpers_api.h"
55
#include "tests/alloc_nid_api.h"
6+
#include "tests/common.h"
67

78
int main(int argc, char **argv)
89
{
10+
parse_args(argc, argv);
911
memblock_basic_checks();
1012
memblock_alloc_checks();
1113
memblock_alloc_helpers_checks();

tools/testing/memblock/scripts/Makefile.include

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@ ifeq ($(NUMA), 1)
66
CFLAGS += -D CONFIG_NUMA
77
endif
88

9-
# Simulate movable NUMA memory regions
10-
ifeq ($(MOVABLE_NODE), 1)
11-
CFLAGS += -D MOVABLE_NODE
12-
endif
13-
149
# Use 32 bit physical addresses.
1510
# Remember to install 32-bit version of dependencies.
1611
ifeq ($(32BIT_PHYS_ADDR_T), 1)
1712
CFLAGS += -m32 -U CONFIG_PHYS_ADDR_T_64BIT
1813
LDFLAGS += -m32
1914
endif
15+
16+
# Enable memblock_dbg() messages
17+
ifeq ($(MEMBLOCK_DEBUG), 1)
18+
CFLAGS += -D MEMBLOCK_DEBUG
19+
endif

0 commit comments

Comments
 (0)