Skip to content

Commit

Permalink
Merge tag 'memblock-v6.12-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:

 - 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
  • Loading branch information
torvalds committed Sep 25, 2024
2 parents eb5b0f9 + cb088e3 commit aa48655
Show file tree
Hide file tree
Showing 16 changed files with 104 additions and 15 deletions.
2 changes: 1 addition & 1 deletion arch/s390/mm/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ EXPORT_SYMBOL(zero_page_mask);

static void __init setup_zero_pages(void)
{
unsigned long total_pages = PHYS_PFN(memblock_phys_mem_size() - memblock_reserved_size());
unsigned long total_pages = memblock_estimated_nr_free_pages();
unsigned int order;
struct page *page;
int i;
Expand Down
1 change: 1 addition & 0 deletions include/linux/memblock.h
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,7 @@ static inline __init_memblock bool memblock_bottom_up(void)

phys_addr_t memblock_phys_mem_size(void);
phys_addr_t memblock_reserved_size(void);
unsigned long memblock_estimated_nr_free_pages(void);
phys_addr_t memblock_start_of_DRAM(void);
phys_addr_t memblock_end_of_DRAM(void);
void memblock_enforce_memory_limit(phys_addr_t memory_limit);
Expand Down
2 changes: 1 addition & 1 deletion kernel/fork.c
Original file line number Diff line number Diff line change
Expand Up @@ -999,7 +999,7 @@ void __init __weak arch_task_cache_init(void) { }
static void __init set_max_threads(unsigned int max_threads_suggested)
{
u64 threads;
unsigned long nr_pages = PHYS_PFN(memblock_phys_mem_size() - memblock_reserved_size());
unsigned long nr_pages = memblock_estimated_nr_free_pages();

/*
* The number of threads shall be limited such that the thread
Expand Down
17 changes: 17 additions & 0 deletions mm/memblock.c
Original file line number Diff line number Diff line change
Expand Up @@ -1731,6 +1731,23 @@ phys_addr_t __init_memblock memblock_reserved_size(void)
return memblock.reserved.total_size;
}

/**
* memblock_estimated_nr_free_pages - return estimated number of free pages
* from memblock point of view
*
* During bootup, subsystems might need a rough estimate of the number of free
* pages in the whole system, before precise numbers are available from the
* buddy. Especially with CONFIG_DEFERRED_STRUCT_PAGE_INIT, the numbers
* obtained from the buddy might be very imprecise during bootup.
*
* Return:
* An estimated number of free pages from memblock point of view.
*/
unsigned long __init memblock_estimated_nr_free_pages(void)
{
return PHYS_PFN(memblock_phys_mem_size() - memblock_reserved_size());
}

/* lowest address */
phys_addr_t __init_memblock memblock_start_of_DRAM(void)
{
Expand Down
4 changes: 0 additions & 4 deletions tools/include/linux/compiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,6 @@
# define unlikely(x) __builtin_expect(!!(x), 0)
#endif

#ifndef __init
# define __init
#endif

#include <linux/types.h>

/*
Expand Down
19 changes: 14 additions & 5 deletions tools/testing/memblock/linux/init.h → tools/include/linux/init.h
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
/* SPDX-License-Identifier: GPL-2.0 */
#ifndef _LINUX_INIT_H
#define _LINUX_INIT_H
#ifndef _TOOLS_LINUX_INIT_H_
#define _TOOLS_LINUX_INIT_H_

#include <linux/compiler.h>
#include <asm/export.h>
#include <linux/memory_hotplug.h>

#ifndef __init
# define __init
#endif

#ifndef __exit
# define __exit
#endif

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

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

#define __setup(str, fn) \
__setup_param(str, fn, fn, 0)

#define early_param(str, fn) \
__setup_param(str, fn, fn, 1)

#endif
#endif /* _TOOLS_LINUX_INIT_H_ */
2 changes: 2 additions & 0 deletions tools/include/linux/linkage.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#ifndef _TOOLS_INCLUDE_LINUX_LINKAGE_H
#define _TOOLS_INCLUDE_LINUX_LINKAGE_H

#include <linux/export.h>

#define SYM_FUNC_START(x) .globl x; x:

#define SYM_FUNC_END(x)
Expand Down
6 changes: 6 additions & 0 deletions tools/include/linux/mm.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ static inline void *phys_to_virt(unsigned long address)
return __va(address);
}

#define virt_to_phys virt_to_phys
static inline phys_addr_t virt_to_phys(volatile void *address)
{
return (phys_addr_t)address;
}

void reserve_bootmem_region(phys_addr_t start, phys_addr_t end, int nid);

static inline void totalram_pages_inc(void)
Expand Down
1 change: 1 addition & 0 deletions tools/include/linux/pfn.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@
#define PFN_UP(x) (((x) + PAGE_SIZE - 1) >> PAGE_SHIFT)
#define PFN_DOWN(x) ((x) >> PAGE_SHIFT)
#define PFN_PHYS(x) ((phys_addr_t)(x) << PAGE_SHIFT)
#define PHYS_PFN(x) ((unsigned long)((x) >> PAGE_SHIFT))
#endif
3 changes: 3 additions & 0 deletions tools/include/linux/string.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ void argv_free(char **argv);

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

#define strscpy strcpy

/*
* glibc based builds needs the extern while uClibc doesn't.
* However uClibc headers also define __GLIBC__ hence the hack below
Expand Down Expand Up @@ -49,4 +51,5 @@ extern char *strim(char *);
extern void remove_spaces(char *s);

extern void *memchr_inv(const void *start, int c, size_t bytes);
extern unsigned long long memparse(const char *ptr, char **retptr);
#endif /* _TOOLS_LINUX_STRING_H_ */
53 changes: 53 additions & 0 deletions tools/lib/cmdline.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// SPDX-License-Identifier: GPL-2.0-only
/*
* From lib/cmdline.c
*/
#include <stdlib.h>

#if __has_attribute(__fallthrough__)
# define fallthrough __attribute__((__fallthrough__))
#else
# define fallthrough do {} while (0) /* fallthrough */
#endif

unsigned long long memparse(const char *ptr, char **retptr)
{
char *endptr; /* local pointer to end of parsed string */

unsigned long long ret = strtoll(ptr, &endptr, 0);

switch (*endptr) {
case 'E':
case 'e':
ret <<= 10;
fallthrough;
case 'P':
case 'p':
ret <<= 10;
fallthrough;
case 'T':
case 't':
ret <<= 10;
fallthrough;
case 'G':
case 'g':
ret <<= 10;
fallthrough;
case 'M':
case 'm':
ret <<= 10;
fallthrough;
case 'K':
case 'k':
ret <<= 10;
endptr++;
fallthrough;
default:
break;
}

if (retptr)
*retptr = endptr;

return ret;
}
2 changes: 1 addition & 1 deletion tools/testing/memblock/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ LDFLAGS += -fsanitize=address -fsanitize=undefined
TARGETS = main
TEST_OFILES = tests/alloc_nid_api.o tests/alloc_helpers_api.o tests/alloc_api.o \
tests/basic_api.o tests/common.o tests/alloc_exact_nid_api.o
DEP_OFILES = memblock.o lib/slab.o mmzone.o slab.o
DEP_OFILES = memblock.o lib/slab.o mmzone.o slab.o cmdline.o
OFILES = main.o $(DEP_OFILES) $(TEST_OFILES)
EXTR_SRC = ../../../mm/memblock.c

Expand Down
2 changes: 2 additions & 0 deletions tools/testing/memblock/linux/kernel.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,7 @@
#include <linux/printk.h>
#include <linux/linkage.h>
#include <linux/kconfig.h>
#include <linux/string.h>
#include <linux/ctype.h>

#endif
1 change: 1 addition & 0 deletions tools/testing/memblock/linux/mmzone.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#define _TOOLS_MMZONE_H

#include <linux/atomic.h>
#include <linux/memory_hotplug.h>

struct pglist_data *first_online_pgdat(void);
struct pglist_data *next_online_pgdat(struct pglist_data *pgdat);
Expand Down
2 changes: 1 addition & 1 deletion tools/testing/radix-tree/maple.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
#include "test.h"
#include <stdlib.h>
#include <time.h>
#include "linux/init.h"
#include <linux/init.h>

#define module_init(x)
#define module_exit(x)
Expand Down
2 changes: 0 additions & 2 deletions tools/testing/shared/linux/init.h

This file was deleted.

0 comments on commit aa48655

Please sign in to comment.