Skip to content

Commit aa48655

Browse files
committed
Merge tag 'memblock-v6.12-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/rppt/memblock
Pull memblock updates from Mike Rapoport: - new memblock_estimated_nr_free_pages() helper to replace totalram_pages() which is less accurate when CONFIG_DEFERRED_STRUCT_PAGE_INIT is set - fixes for memblock tests * tag 'memblock-v6.12-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/rppt/memblock: s390/mm: get estimated free pages by memblock api kernel/fork.c: get estimated free pages by memblock api mm/memblock: introduce a new helper memblock_estimated_nr_free_pages() memblock test: fix implicit declaration of function 'strscpy' memblock test: fix implicit declaration of function 'isspace' memblock test: fix implicit declaration of function 'memparse' memblock test: add the definition of __setup() memblock test: fix implicit declaration of function 'virt_to_phys' tools/testing: abstract two init.h into common include directory memblock tests: include export.h in linkage.h as kernel dose memblock tests: include memory_hotplug.h in mmzone.h as kernel dose
2 parents eb5b0f9 + cb088e3 commit aa48655

File tree

16 files changed

+104
-15
lines changed

16 files changed

+104
-15
lines changed

arch/s390/mm/init.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ EXPORT_SYMBOL(zero_page_mask);
6262

6363
static void __init setup_zero_pages(void)
6464
{
65-
unsigned long total_pages = PHYS_PFN(memblock_phys_mem_size() - memblock_reserved_size());
65+
unsigned long total_pages = memblock_estimated_nr_free_pages();
6666
unsigned int order;
6767
struct page *page;
6868
int i;

include/linux/memblock.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,7 @@ static inline __init_memblock bool memblock_bottom_up(void)
467467

468468
phys_addr_t memblock_phys_mem_size(void);
469469
phys_addr_t memblock_reserved_size(void);
470+
unsigned long memblock_estimated_nr_free_pages(void);
470471
phys_addr_t memblock_start_of_DRAM(void);
471472
phys_addr_t memblock_end_of_DRAM(void);
472473
void memblock_enforce_memory_limit(phys_addr_t memory_limit);

kernel/fork.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -999,7 +999,7 @@ void __init __weak arch_task_cache_init(void) { }
999999
static void __init set_max_threads(unsigned int max_threads_suggested)
10001000
{
10011001
u64 threads;
1002-
unsigned long nr_pages = PHYS_PFN(memblock_phys_mem_size() - memblock_reserved_size());
1002+
unsigned long nr_pages = memblock_estimated_nr_free_pages();
10031003

10041004
/*
10051005
* The number of threads shall be limited such that the thread

mm/memblock.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1731,6 +1731,23 @@ phys_addr_t __init_memblock memblock_reserved_size(void)
17311731
return memblock.reserved.total_size;
17321732
}
17331733

1734+
/**
1735+
* memblock_estimated_nr_free_pages - return estimated number of free pages
1736+
* from memblock point of view
1737+
*
1738+
* During bootup, subsystems might need a rough estimate of the number of free
1739+
* pages in the whole system, before precise numbers are available from the
1740+
* buddy. Especially with CONFIG_DEFERRED_STRUCT_PAGE_INIT, the numbers
1741+
* obtained from the buddy might be very imprecise during bootup.
1742+
*
1743+
* Return:
1744+
* An estimated number of free pages from memblock point of view.
1745+
*/
1746+
unsigned long __init memblock_estimated_nr_free_pages(void)
1747+
{
1748+
return PHYS_PFN(memblock_phys_mem_size() - memblock_reserved_size());
1749+
}
1750+
17341751
/* lowest address */
17351752
phys_addr_t __init_memblock memblock_start_of_DRAM(void)
17361753
{

tools/include/linux/compiler.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -128,10 +128,6 @@
128128
# define unlikely(x) __builtin_expect(!!(x), 0)
129129
#endif
130130

131-
#ifndef __init
132-
# define __init
133-
#endif
134-
135131
#include <linux/types.h>
136132

137133
/*

tools/testing/memblock/linux/init.h renamed to tools/include/linux/init.h

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
11
/* SPDX-License-Identifier: GPL-2.0 */
2-
#ifndef _LINUX_INIT_H
3-
#define _LINUX_INIT_H
2+
#ifndef _TOOLS_LINUX_INIT_H_
3+
#define _TOOLS_LINUX_INIT_H_
44

55
#include <linux/compiler.h>
6-
#include <asm/export.h>
7-
#include <linux/memory_hotplug.h>
6+
7+
#ifndef __init
8+
# define __init
9+
#endif
10+
11+
#ifndef __exit
12+
# define __exit
13+
#endif
814

915
#define __section(section) __attribute__((__section__(section)))
1016

@@ -28,7 +34,10 @@ struct obs_kernel_param {
2834
__aligned(__alignof__(struct obs_kernel_param)) = \
2935
{ __setup_str_##unique_id, fn, early }
3036

37+
#define __setup(str, fn) \
38+
__setup_param(str, fn, fn, 0)
39+
3140
#define early_param(str, fn) \
3241
__setup_param(str, fn, fn, 1)
3342

34-
#endif
43+
#endif /* _TOOLS_LINUX_INIT_H_ */

tools/include/linux/linkage.h

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

4+
#include <linux/export.h>
5+
46
#define SYM_FUNC_START(x) .globl x; x:
57

68
#define SYM_FUNC_END(x)

tools/include/linux/mm.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@ static inline void *phys_to_virt(unsigned long address)
2525
return __va(address);
2626
}
2727

28+
#define virt_to_phys virt_to_phys
29+
static inline phys_addr_t virt_to_phys(volatile void *address)
30+
{
31+
return (phys_addr_t)address;
32+
}
33+
2834
void reserve_bootmem_region(phys_addr_t start, phys_addr_t end, int nid);
2935

3036
static inline void totalram_pages_inc(void)

tools/include/linux/pfn.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@
77
#define PFN_UP(x) (((x) + PAGE_SIZE - 1) >> PAGE_SHIFT)
88
#define PFN_DOWN(x) ((x) >> PAGE_SHIFT)
99
#define PFN_PHYS(x) ((phys_addr_t)(x) << PAGE_SHIFT)
10+
#define PHYS_PFN(x) ((unsigned long)((x) >> PAGE_SHIFT))
1011
#endif

tools/include/linux/string.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ void argv_free(char **argv);
1212

1313
int strtobool(const char *s, bool *res);
1414

15+
#define strscpy strcpy
16+
1517
/*
1618
* glibc based builds needs the extern while uClibc doesn't.
1719
* However uClibc headers also define __GLIBC__ hence the hack below
@@ -49,4 +51,5 @@ extern char *strim(char *);
4951
extern void remove_spaces(char *s);
5052

5153
extern void *memchr_inv(const void *start, int c, size_t bytes);
54+
extern unsigned long long memparse(const char *ptr, char **retptr);
5255
#endif /* _TOOLS_LINUX_STRING_H_ */

0 commit comments

Comments
 (0)