Skip to content

Commit 8fb1e91

Browse files
committed
Merge branch 'akpm' (patches from Andrew)
Merge misc fixes from Andrew Morton: "9 patches. Subsystems affected by this patch series: mm (thp, memcg, gup, migration, memory-hotplug), lib, and x86" * emailed patches from Andrew Morton <akpm@linux-foundation.org>: mm: don't rely on system state to detect hot-plug operations mm: replace memmap_context by meminit_context arch/x86/lib/usercopy_64.c: fix __copy_user_flushcache() cache writeback lib/memregion.c: include memregion.h lib/string.c: implement stpcpy mm/migrate: correct thp migration stats mm/gup: fix gup_fast with dynamic page table folding mm: memcontrol: fix missing suffix of workingset_restore mm, THP, swap: fix allocating cluster for swapfile by mistake
2 parents ce26842 + f85086f commit 8fb1e91

17 files changed

Lines changed: 181 additions & 84 deletions

File tree

Documentation/admin-guide/cgroup-v2.rst

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1324,15 +1324,26 @@ PAGE_SIZE multiple when read back.
13241324
pgmajfault
13251325
Number of major page faults incurred
13261326

1327-
workingset_refault
1328-
Number of refaults of previously evicted pages
1327+
workingset_refault_anon
1328+
Number of refaults of previously evicted anonymous pages.
13291329

1330-
workingset_activate
1331-
Number of refaulted pages that were immediately activated
1330+
workingset_refault_file
1331+
Number of refaults of previously evicted file pages.
13321332

1333-
workingset_restore
1334-
Number of restored pages which have been detected as an active
1335-
workingset before they got reclaimed.
1333+
workingset_activate_anon
1334+
Number of refaulted anonymous pages that were immediately
1335+
activated.
1336+
1337+
workingset_activate_file
1338+
Number of refaulted file pages that were immediately activated.
1339+
1340+
workingset_restore_anon
1341+
Number of restored anonymous pages which have been detected as
1342+
an active workingset before they got reclaimed.
1343+
1344+
workingset_restore_file
1345+
Number of restored file pages which have been detected as an
1346+
active workingset before they got reclaimed.
13361347

13371348
workingset_nodereclaim
13381349
Number of times a shadow node has been reclaimed

arch/ia64/mm/init.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -538,7 +538,7 @@ virtual_memmap_init(u64 start, u64 end, void *arg)
538538
if (map_start < map_end)
539539
memmap_init_zone((unsigned long)(map_end - map_start),
540540
args->nid, args->zone, page_to_pfn(map_start),
541-
MEMMAP_EARLY, NULL);
541+
MEMINIT_EARLY, NULL);
542542
return 0;
543543
}
544544

@@ -547,8 +547,8 @@ memmap_init (unsigned long size, int nid, unsigned long zone,
547547
unsigned long start_pfn)
548548
{
549549
if (!vmem_map) {
550-
memmap_init_zone(size, nid, zone, start_pfn, MEMMAP_EARLY,
551-
NULL);
550+
memmap_init_zone(size, nid, zone, start_pfn,
551+
MEMINIT_EARLY, NULL);
552552
} else {
553553
struct page *start;
554554
struct memmap_init_callback_data args;

arch/s390/include/asm/pgtable.h

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1260,26 +1260,44 @@ static inline pgd_t *pgd_offset_raw(pgd_t *pgd, unsigned long address)
12601260

12611261
#define pgd_offset(mm, address) pgd_offset_raw(READ_ONCE((mm)->pgd), address)
12621262

1263-
static inline p4d_t *p4d_offset(pgd_t *pgd, unsigned long address)
1263+
static inline p4d_t *p4d_offset_lockless(pgd_t *pgdp, pgd_t pgd, unsigned long address)
12641264
{
1265-
if ((pgd_val(*pgd) & _REGION_ENTRY_TYPE_MASK) >= _REGION_ENTRY_TYPE_R1)
1266-
return (p4d_t *) pgd_deref(*pgd) + p4d_index(address);
1267-
return (p4d_t *) pgd;
1265+
if ((pgd_val(pgd) & _REGION_ENTRY_TYPE_MASK) >= _REGION_ENTRY_TYPE_R1)
1266+
return (p4d_t *) pgd_deref(pgd) + p4d_index(address);
1267+
return (p4d_t *) pgdp;
12681268
}
1269+
#define p4d_offset_lockless p4d_offset_lockless
12691270

1270-
static inline pud_t *pud_offset(p4d_t *p4d, unsigned long address)
1271+
static inline p4d_t *p4d_offset(pgd_t *pgdp, unsigned long address)
12711272
{
1272-
if ((p4d_val(*p4d) & _REGION_ENTRY_TYPE_MASK) >= _REGION_ENTRY_TYPE_R2)
1273-
return (pud_t *) p4d_deref(*p4d) + pud_index(address);
1274-
return (pud_t *) p4d;
1273+
return p4d_offset_lockless(pgdp, *pgdp, address);
1274+
}
1275+
1276+
static inline pud_t *pud_offset_lockless(p4d_t *p4dp, p4d_t p4d, unsigned long address)
1277+
{
1278+
if ((p4d_val(p4d) & _REGION_ENTRY_TYPE_MASK) >= _REGION_ENTRY_TYPE_R2)
1279+
return (pud_t *) p4d_deref(p4d) + pud_index(address);
1280+
return (pud_t *) p4dp;
1281+
}
1282+
#define pud_offset_lockless pud_offset_lockless
1283+
1284+
static inline pud_t *pud_offset(p4d_t *p4dp, unsigned long address)
1285+
{
1286+
return pud_offset_lockless(p4dp, *p4dp, address);
12751287
}
12761288
#define pud_offset pud_offset
12771289

1278-
static inline pmd_t *pmd_offset(pud_t *pud, unsigned long address)
1290+
static inline pmd_t *pmd_offset_lockless(pud_t *pudp, pud_t pud, unsigned long address)
1291+
{
1292+
if ((pud_val(pud) & _REGION_ENTRY_TYPE_MASK) >= _REGION_ENTRY_TYPE_R3)
1293+
return (pmd_t *) pud_deref(pud) + pmd_index(address);
1294+
return (pmd_t *) pudp;
1295+
}
1296+
#define pmd_offset_lockless pmd_offset_lockless
1297+
1298+
static inline pmd_t *pmd_offset(pud_t *pudp, unsigned long address)
12791299
{
1280-
if ((pud_val(*pud) & _REGION_ENTRY_TYPE_MASK) >= _REGION_ENTRY_TYPE_R3)
1281-
return (pmd_t *) pud_deref(*pud) + pmd_index(address);
1282-
return (pmd_t *) pud;
1300+
return pmd_offset_lockless(pudp, *pudp, address);
12831301
}
12841302
#define pmd_offset pmd_offset
12851303

arch/x86/lib/usercopy_64.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ long __copy_user_flushcache(void *dst, const void __user *src, unsigned size)
120120
*/
121121
if (size < 8) {
122122
if (!IS_ALIGNED(dest, 4) || size != 4)
123-
clean_cache_range(dst, 1);
123+
clean_cache_range(dst, size);
124124
} else {
125125
if (!IS_ALIGNED(dest, 8)) {
126126
dest = ALIGN(dest, boot_cpu_data.x86_clflush_size);

drivers/base/node.c

Lines changed: 55 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -761,14 +761,36 @@ static int __ref get_nid_for_pfn(unsigned long pfn)
761761
return pfn_to_nid(pfn);
762762
}
763763

764+
static int do_register_memory_block_under_node(int nid,
765+
struct memory_block *mem_blk)
766+
{
767+
int ret;
768+
769+
/*
770+
* If this memory block spans multiple nodes, we only indicate
771+
* the last processed node.
772+
*/
773+
mem_blk->nid = nid;
774+
775+
ret = sysfs_create_link_nowarn(&node_devices[nid]->dev.kobj,
776+
&mem_blk->dev.kobj,
777+
kobject_name(&mem_blk->dev.kobj));
778+
if (ret)
779+
return ret;
780+
781+
return sysfs_create_link_nowarn(&mem_blk->dev.kobj,
782+
&node_devices[nid]->dev.kobj,
783+
kobject_name(&node_devices[nid]->dev.kobj));
784+
}
785+
764786
/* register memory section under specified node if it spans that node */
765-
static int register_mem_sect_under_node(struct memory_block *mem_blk,
766-
void *arg)
787+
static int register_mem_block_under_node_early(struct memory_block *mem_blk,
788+
void *arg)
767789
{
768790
unsigned long memory_block_pfns = memory_block_size_bytes() / PAGE_SIZE;
769791
unsigned long start_pfn = section_nr_to_pfn(mem_blk->start_section_nr);
770792
unsigned long end_pfn = start_pfn + memory_block_pfns - 1;
771-
int ret, nid = *(int *)arg;
793+
int nid = *(int *)arg;
772794
unsigned long pfn;
773795

774796
for (pfn = start_pfn; pfn <= end_pfn; pfn++) {
@@ -785,38 +807,33 @@ static int register_mem_sect_under_node(struct memory_block *mem_blk,
785807
}
786808

787809
/*
788-
* We need to check if page belongs to nid only for the boot
789-
* case, during hotplug we know that all pages in the memory
790-
* block belong to the same node.
791-
*/
792-
if (system_state == SYSTEM_BOOTING) {
793-
page_nid = get_nid_for_pfn(pfn);
794-
if (page_nid < 0)
795-
continue;
796-
if (page_nid != nid)
797-
continue;
798-
}
799-
800-
/*
801-
* If this memory block spans multiple nodes, we only indicate
802-
* the last processed node.
810+
* We need to check if page belongs to nid only at the boot
811+
* case because node's ranges can be interleaved.
803812
*/
804-
mem_blk->nid = nid;
805-
806-
ret = sysfs_create_link_nowarn(&node_devices[nid]->dev.kobj,
807-
&mem_blk->dev.kobj,
808-
kobject_name(&mem_blk->dev.kobj));
809-
if (ret)
810-
return ret;
813+
page_nid = get_nid_for_pfn(pfn);
814+
if (page_nid < 0)
815+
continue;
816+
if (page_nid != nid)
817+
continue;
811818

812-
return sysfs_create_link_nowarn(&mem_blk->dev.kobj,
813-
&node_devices[nid]->dev.kobj,
814-
kobject_name(&node_devices[nid]->dev.kobj));
819+
return do_register_memory_block_under_node(nid, mem_blk);
815820
}
816821
/* mem section does not span the specified node */
817822
return 0;
818823
}
819824

825+
/*
826+
* During hotplug we know that all pages in the memory block belong to the same
827+
* node.
828+
*/
829+
static int register_mem_block_under_node_hotplug(struct memory_block *mem_blk,
830+
void *arg)
831+
{
832+
int nid = *(int *)arg;
833+
834+
return do_register_memory_block_under_node(nid, mem_blk);
835+
}
836+
820837
/*
821838
* Unregister a memory block device under the node it spans. Memory blocks
822839
* with multiple nodes cannot be offlined and therefore also never be removed.
@@ -832,11 +849,19 @@ void unregister_memory_block_under_nodes(struct memory_block *mem_blk)
832849
kobject_name(&node_devices[mem_blk->nid]->dev.kobj));
833850
}
834851

835-
int link_mem_sections(int nid, unsigned long start_pfn, unsigned long end_pfn)
852+
int link_mem_sections(int nid, unsigned long start_pfn, unsigned long end_pfn,
853+
enum meminit_context context)
836854
{
855+
walk_memory_blocks_func_t func;
856+
857+
if (context == MEMINIT_HOTPLUG)
858+
func = register_mem_block_under_node_hotplug;
859+
else
860+
func = register_mem_block_under_node_early;
861+
837862
return walk_memory_blocks(PFN_PHYS(start_pfn),
838863
PFN_PHYS(end_pfn - start_pfn), (void *)&nid,
839-
register_mem_sect_under_node);
864+
func);
840865
}
841866

842867
#ifdef CONFIG_HUGETLBFS

include/linux/mm.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2416,7 +2416,7 @@ extern int __meminit __early_pfn_to_nid(unsigned long pfn,
24162416

24172417
extern void set_dma_reserve(unsigned long new_dma_reserve);
24182418
extern void memmap_init_zone(unsigned long, int, unsigned long, unsigned long,
2419-
enum memmap_context, struct vmem_altmap *);
2419+
enum meminit_context, struct vmem_altmap *);
24202420
extern void setup_per_zone_wmarks(void);
24212421
extern int __meminit init_per_zone_wmark_min(void);
24222422
extern void mem_init(void);

include/linux/mmzone.h

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -824,10 +824,15 @@ bool zone_watermark_ok(struct zone *z, unsigned int order,
824824
unsigned int alloc_flags);
825825
bool zone_watermark_ok_safe(struct zone *z, unsigned int order,
826826
unsigned long mark, int highest_zoneidx);
827-
enum memmap_context {
828-
MEMMAP_EARLY,
829-
MEMMAP_HOTPLUG,
827+
/*
828+
* Memory initialization context, use to differentiate memory added by
829+
* the platform statically or via memory hotplug interface.
830+
*/
831+
enum meminit_context {
832+
MEMINIT_EARLY,
833+
MEMINIT_HOTPLUG,
830834
};
835+
831836
extern void init_currently_empty_zone(struct zone *zone, unsigned long start_pfn,
832837
unsigned long size);
833838

include/linux/node.h

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,11 +99,13 @@ extern struct node *node_devices[];
9999
typedef void (*node_registration_func_t)(struct node *);
100100

101101
#if defined(CONFIG_MEMORY_HOTPLUG_SPARSE) && defined(CONFIG_NUMA)
102-
extern int link_mem_sections(int nid, unsigned long start_pfn,
103-
unsigned long end_pfn);
102+
int link_mem_sections(int nid, unsigned long start_pfn,
103+
unsigned long end_pfn,
104+
enum meminit_context context);
104105
#else
105106
static inline int link_mem_sections(int nid, unsigned long start_pfn,
106-
unsigned long end_pfn)
107+
unsigned long end_pfn,
108+
enum meminit_context context)
107109
{
108110
return 0;
109111
}
@@ -128,7 +130,8 @@ static inline int register_one_node(int nid)
128130
if (error)
129131
return error;
130132
/* link memory sections under this node */
131-
error = link_mem_sections(nid, start_pfn, end_pfn);
133+
error = link_mem_sections(nid, start_pfn, end_pfn,
134+
MEMINIT_EARLY);
132135
}
133136

134137
return error;

include/linux/pgtable.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1427,6 +1427,16 @@ typedef unsigned int pgtbl_mod_mask;
14271427
#define mm_pmd_folded(mm) __is_defined(__PAGETABLE_PMD_FOLDED)
14281428
#endif
14291429

1430+
#ifndef p4d_offset_lockless
1431+
#define p4d_offset_lockless(pgdp, pgd, address) p4d_offset(&(pgd), address)
1432+
#endif
1433+
#ifndef pud_offset_lockless
1434+
#define pud_offset_lockless(p4dp, p4d, address) pud_offset(&(p4d), address)
1435+
#endif
1436+
#ifndef pmd_offset_lockless
1437+
#define pmd_offset_lockless(pudp, pud, address) pmd_offset(&(pud), address)
1438+
#endif
1439+
14301440
/*
14311441
* p?d_leaf() - true if this entry is a final mapping to a physical address.
14321442
* This differs from p?d_huge() by the fact that they are always available (if

lib/memregion.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
/* identifiers for device / performance-differentiated memory regions */
33
#include <linux/idr.h>
44
#include <linux/types.h>
5+
#include <linux/memregion.h>
56

67
static DEFINE_IDA(memregion_ids);
78

0 commit comments

Comments
 (0)