incoming
Subsystems (103)
Andrew Morton
maintainerPATCH 125/262 mm: shmem: don't truncate page if memory failure happens
In reply to Andrew MortonFrom: Yang Shi <[email protected]>
Subject: mm: shmem: don't truncate page if memory failure happens
The current behavior of memory failure is to truncate the page cache regardless of dirty or clean. If the page is dirty the later access will get the obsolete data from disk without any notification to the users. This may cause silent data loss. It is even worse for shmem since shmem is in-memory filesystem, truncating page cache means discarding data blocks. The later read would return all zero.
The right approach is to keep the corrupted page in page cache, any later access would return error for syscalls or SIGBUS for page fault, until the file is truncated, hole punched or removed. The regular storage backed filesystems would be more complicated so this patch is focused on shmem. This also unblock the support for soft offlining shmem THP.
---
mm/memory-failure.c | 14 +++++++++++--- mm/shmem.c | 38 +++++++++++++++++++++++++++++++++++--- mm/userfaultfd.c | 5 +++++ 3 files changed, 51 insertions(+), 6 deletions(-)
mm/memory-failure.c renamed from mm/memory-failure.c~mm-shmem-dont-truncate-page-if-memory-failure-happens +11 -3
@@ -58,6 +58,7 @@#include <linux/ratelimit.h> #include <linux/page-isolation.h> #include <linux/pagewalk.h> +#include <linux/shmem_fs.h> #include "internal.h" #include "ras/ras_event.h"
@@ -867,6 +868,7 @@ static int me_pagecache_clean(struct pag {int ret;struct address_space *mapping; +bool extra_pins;delete_from_lru_cache (p);
@@ -896,17 +898,23 @@ static int me_pagecache_clean(struct pag }/* +* The shmem page is kept in page cache instead of truncating +* so is expected to have an extra refcount after error-handling. +*/ + extra_pins =shmem_mapping (mapping); + +/* * Truncation is a bit tricky. Enable it per file system for now. * * Open: to take i_rwsem or not for this? Right now we don't. */ ret =truncate_error_page (p,page_to_pfn (p), mapping); +if (has_extra_refcount (ps, p, extra_pins)) + ret =MF_FAILED ; + out:unlock_page (p); -if (has_extra_refcount (ps, p, false)) - ret =MF_FAILED ; -return ret; }
mm/shmem.c renamed from mm/shmem.c~mm-shmem-dont-truncate-page-if-memory-failure-happens +35 -3
@@ -2454,6 +2454,7 @@ shmem_write_begin(struct file *file, strstruct inode *inode = mapping->host;struct shmem_inode_info *info =SHMEM_I (inode);pgoff_t index = pos >>PAGE_SHIFT ; +int ret =0 ;/* i_rwsem is held by caller */ if (unlikely(info->seals & (F_SEAL_GROW |
@@ -2464,7 +2465,15 @@ shmem_write_begin(struct file *file, strreturn -EPERM ; } -return shmem_getpage (inode, index, pagep,SGP_WRITE ); + ret =shmem_getpage (inode, index, pagep,SGP_WRITE ); + +if (*pagep &&PageHWPoison (*pagep)) { +unlock_page (*pagep); +put_page (*pagep); + ret = -EIO ; + } + +return ret; } static int
@@ -2551,6 +2560,12 @@ static ssize_t shmem_file_read_iter(struif (sgp ==SGP_CACHE )set_page_dirty (page);unlock_page (page); + +if (PageHWPoison (page)) { +put_page (page); + error = -EIO ; +break ; + } }/*
@@ -3112,7 +3127,8 @@ static const char *shmem_get_link(struct page =find_get_page (inode->i_mapping,0 );if (!page)return ERR_PTR (-ECHILD ); -if (!PageUptodate (page)) { +if (PageHWPoison (page) || + !PageUptodate (page)) {put_page (page);return ERR_PTR (-ECHILD ); }
@@ -3120,6 +3136,11 @@ static const char *shmem_get_link(struct error =shmem_getpage (inode,0 , &page,SGP_READ );if (error)return ERR_PTR (error); +if (page &&PageHWPoison (page)) { +unlock_page (page); +put_page (page); +return ERR_PTR (-ECHILD ); + }unlock_page (page); }set_delayed_call (done, shmem_put_link, page);
@@ -3770,6 +3791,13 @@ static void shmem_destroy_inodecache(voikmem_cache_destroy (shmem_inode_cachep); } +/* Keep the page in page cache instead of truncating it */ +static int shmem_error_remove_page (struct address_space *mapping, +struct page *page) +{ +return 0 ; +} +const struct address_space_operations shmem_aops = { .writepage = shmem_writepage, .set_page_dirty = __set_page_dirty_no_writeback,
@@ -3780,7 +3808,7 @@ const struct address_space_operations sh#ifdef CONFIG_MIGRATION .migratepage = migrate_page, #endif - .error_remove_page = generic_error_remove_page, + .error_remove_page = shmem_error_remove_page, };EXPORT_SYMBOL (shmem_aops);
@@ -4191,6 +4219,10 @@ struct page *shmem_read_mapping_page_gfp page =ERR_PTR (error); elseunlock_page (page ); + +if (PageHWPoison (page)) + page =ERR_PTR (-EIO ); +return page;#else /*
mm/userfaultfd.c renamed from mm/userfaultfd.c~mm-shmem-dont-truncate-page-if-memory-failure-happens +5 -0
@@ -232,6 +232,11 @@ static int mcontinue_atomic_pte(struct m goto out; } +if (PageHWPoison (page)) { + ret = -EIO ; + goto out_release; + } + ret =mfill_atomic_install_pte (dst_mm, dst_pmd, dst_vma, dst_addr, page, false, wp_copy);if (ret)
_
Andrew Morton
maintainerPATCH 126/262 mm: hwpoison: handle non-anonymous THP correctly
In reply to Andrew MortonFrom: Yang Shi <[email protected]>
Subject: mm: hwpoison: handle non-anonymous THP correctly
Currently hwpoison doesn't handle non-anonymous THP, but since v4.8 THP support for tmpfs and read-only file cache has been added. They could be offlined by split THP, just like anonymous THP.
---
mm/memory-failure.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-)
mm/memory-failure.c renamed from mm/memory-failure.c~mm-hwpoison-handle-non-anonymous-thp-correctly +2 -5
@@ -1444,14 +1444,11 @@ static int identify_page_state(unsignedstatic int try_to_split_thp_page (struct page *page,const char *msg) {lock_page (page); -if (!PageAnon (page) ||unlikely (split_huge_page (page))) { +if (unlikely (split_huge_page (page))) {unsigned long pfn =page_to_pfn (page);unlock_page (page); -if (!PageAnon (page)) -pr_info ("%s: %#lx: non anonymous thp\n" , msg, pfn); -else -pr_info ("%s: %#lx: thp split failed\n" , msg, pfn); +pr_info ("%s: %#lx: thp split failed\n" , msg, pfn);put_page (page);return -EBUSY ; }
_
Andrew Morton
maintainerPATCH 127/262 mm/hugetlb: drop __unmap_hugepage_range definition from hugetlb.h
In reply to Andrew MortonFrom: Peter Xu <[email protected]>
Subject: mm/hugetlb: drop __unmap_hugepage_range definition from hugetlb.h
Remove __unmap_hugepage_range() from the header file, because it is only used in hugetlb.c.
---
include/linux/hugetlb.h | 10 ---------- mm/hugetlb.c | 6 +++--- 2 files changed, 3 insertions(+), 13 deletions(-)
include/linux/hugetlb.h renamed from include/linux/hugetlb.h~mm-hugetlb-drop-__unmap_hugepage_range-definition-from-hugetlbh +0 -10
@@ -143,9 +143,6 @@ void __unmap_hugepage_range_final(structstruct vm_area_struct *vma, unsigned long start, unsigned long end, struct page *ref_page); -void __unmap_hugepage_range (struct mmu_gather *tlb,struct vm_area_struct *vma, -unsigned long start,unsigned long end, -struct page *ref_page);void hugetlb_report_meminfo (struct seq_file *);int hugetlb_report_node_meminfo (char *buf,int len,int nid);void hugetlb_show_meminfo (void );
@@ -382,13 +379,6 @@ static inline void __unmap_hugepage_rang struct vm_area_struct *vma, unsigned long start, unsigned long end, struct page *ref_page) { -BUG (); -} - -static inline void __unmap_hugepage_range (struct mmu_gather *tlb, -struct vm_area_struct *vma,unsigned long start, -unsigned long end,struct page *ref_page) -{BUG (); }
mm/hugetlb.c renamed from mm/hugetlb.c~mm-hugetlb-drop-__unmap_hugepage_range-definition-from-hugetlbh +3 -3
@@ -4426,9 +4426,9 @@ again:return ret; } -void __unmap_hugepage_range (struct mmu_gather *tlb,struct vm_area_struct *vma, -unsigned long start,unsigned long end, -struct page *ref_page) +static void __unmap_hugepage_range (struct mmu_gather *tlb,struct vm_area_struct *vma, +unsigned long start,unsigned long end, +struct page *ref_page) {struct mm_struct *mm = vma->vm_mm;unsigned long address;
_
Andrew Morton
maintainerPATCH 128/262 hugetlb: add demote hugetlb page sysfs interfaces
In reply to Andrew MortonFrom: Mike Kravetz <[email protected]>
Subject: hugetlb: add demote hugetlb page sysfs interfaces
Patch series "hugetlb: add demote/split page functionality", v4.
The concurrent use of multiple hugetlb page sizes on a single system is becoming more common. One of the reasons is better TLB support for gigantic page sizes on x86 hardware. In addition, hugetlb pages are being used to back VMs in hosting environments.
When using hugetlb pages to back VMs, it is often desirable to preallocate hugetlb pools. This avoids the delay and uncertainty of allocating hugetlb pages at VM startup. In addition, preallocating huge pages minimizes the issue of memory fragmentation that increases the longer the system is up and running.
In such environments, a combination of larger and smaller hugetlb pages are preallocated in anticipation of backing VMs of various sizes. Over time, the preallocated pool of smaller hugetlb pages may become depleted while larger hugetlb pages still remain. In such situations, it is desirable to convert larger hugetlb pages to smaller hugetlb pages.
Converting larger to smaller hugetlb pages can be accomplished today by first freeing the larger page to the buddy allocator and then allocating the smaller pages. For example, to convert 50 GB pages on x86:
gb_pages=cat .../hugepages-1048576kB/nr_hugepages m2_pages=cat .../hugepages-2048kB/nr_hugepages
echo $(($gb_pages - 50)) > .../hugepages-1048576kB/nr_hugepages echo $(($m2_pages + 25600)) > .../hugepages-2048kB/nr_hugepages
On an idle system this operation is fairly reliable and results are as expected. The number of 2MB pages is increased as expected and the time of the operation is a second or two.
However, when there is activity on the system the following issues arise:
1) This process can take quite some time, especially if allocation of the smaller pages is not immediate and requires migration/compaction.
2) There is no guarantee that the total size of smaller pages allocated will match the size of the larger page which was freed. This is because the area freed by the larger page could quickly be fragmented.
In a test environment with a load that continually fills the page cache with clean pages, results such as the following can be observed:
Unexpected number of 2MB pages allocated: Expected 25600, have 19944
real 0m42.092s user 0m0.008s sys 0m41.467s
To address these issues, introduce the concept of hugetlb page demotion. Demotion provides a means of 'in place' splitting of a hugetlb page to pages of a smaller size. This avoids freeing pages to buddy and then trying to allocate from buddy.
Page demotion is controlled via sysfs files that reside in the per-hugetlb page size and per node directories.
- demote_size Target page size for demotion, a smaller huge page size.
File can be written to chose a smaller huge page size if multiple are available.
- demote Writable number of hugetlb pages to be demoted
To demote 50 GB huge pages, one would:
cat .../hugepages-1048576kB/free_hugepages /* optional, verify free pages */
cat .../hugepages-1048576kB/demote_size /* optional, verify target size */
echo 50 > .../hugepages-1048576kB/demote
Only hugetlb pages which are free at the time of the request can be demoted. Demotion does not add to the complexity of surplus pages and honors reserved huge pages. Therefore, when a value is written to the sysfs demote file, that value is only the maximum number of pages which will be demoted. It is possible fewer will actually be demoted. The recently introduced per-hstate mutex is used to synchronize demote operations with other operations that modify hugetlb pools.
Real world use cases
--------------------
The above scenario describes a real world use case where hugetlb pages are used to back VMs on x86. Both issues of long allocation times and not necessarily getting the expected number of smaller huge pages after a free and allocate cycle have been experienced. The occurrence of these issues is dependent on other activity within the host and can not be predicted.
This patch (of 5):
Two new sysfs files are added to demote hugtlb pages. These files are both per-hugetlb page size and per node. Files are:
demote_size - The size in Kb that pages are demoted to. (read-write) demote - The number of huge pages to demote. (write-only)
By default, demote_size is the next smallest huge page size. Valid huge page sizes less than huge page size may be written to this file. When huge pages are demoted, they are demoted to this size.
Writing a value to demote will result in an attempt to demote that number of hugetlb pages to an appropriate number of demote_size pages.
NOTE: Demote interfaces are only provided for huge page sizes if there is a smaller target demote huge page size. For example, on x86 1GB huge pages will have demote interfaces. 2MB huge pages will not have demote interfaces.
This patch does not provide full demote functionality. It only provides the sysfs interfaces.
It also provides documentation for the new interfaces.
---
Documentation/admin-guide/mm/hugetlbpage.rst | 30 +++ include/linux/hugetlb.h | 1 mm/hugetlb.c | 155 ++++++++++++++++- 3 files changed, 183 insertions(+), 3 deletions(-)
Documentation/admin-guide/mm/hugetlbpage.rst renamed from Documentation/admin-guide/mm/hugetlbpage.rst~hugetlb-add-demote-hugetlb-page-sysfs-interfaces +28 -2
@@ -234,8 +234,12 @@ will exist, of the form:: hugepages-${size}kB -Inside each of these directories, the same set of files will exist:: +Inside each of these directories, the set of files contained in ``/proc`` +will exist. In addition, two additional interfaces for demoting huge +pages may exist:: + demote + demote_size nr_hugepages nr_hugepages_mempolicy nr_overcommit_hugepages
@@ -243,7 +247,29 @@ Inside each of these directories, the sa resv_hugepages surplus_hugepages -which function as described above for the default huge page-sized case. +The demote interfaces provide the ability to split a huge page into +smaller huge pages. For example, the x86 architecture supports both +1GB and 2MB huge pages sizes. A 1GB huge page can be split into 512 +2MB huge pages. Demote interfaces are not available for the smallest +huge page size. The demote interfaces are: + +demote_size + is the size of demoted pages. When a page is demoted a corresponding + number of huge pages of demote_size will be created. By default, + demote_size is set to the next smaller huge page size. If there are + multiple smaller huge page sizes, demote_size can be set to any of + these smaller sizes. Only huge page sizes less than the current huge + pages size are allowed. + +demote + is used to demote a number of huge pages. A user with root privileges + can write to this file. It may not be possible to demote the + requested number of huge pages. To determine how many pages were + actually demoted, compare the value of nr_hugepages before and after + writing to the demote interface. demote is a write only interface. + +The interfaces which are the same as in ``/proc`` (all except demote and +demote_size) function as described above for the default huge page-sized case. .. _mem_policy_and_hp_alloc:
include/linux/hugetlb.h renamed from include/linux/hugetlb.h~hugetlb-add-demote-hugetlb-page-sysfs-interfaces +1 -0
@@ -586,6 +586,7 @@ struct hstate {int next_nid_to_alloc;int next_nid_to_free;unsigned int order; +unsigned int demote_order;unsigned long mask;unsigned long max_huge_pages;unsigned long nr_huge_pages;
mm/hugetlb.c renamed from mm/hugetlb.c~hugetlb-add-demote-hugetlb-page-sysfs-interfaces +154 -1
194 lines not on this page · raw message
_
Andrew Morton
maintainerPATCH 129/262 mm/cma: add cma_pages_valid to determine if pages are in CMA
In reply to Andrew MortonFrom: Mike Kravetz <[email protected]>
Subject: mm/cma: add cma_pages_valid to determine if pages are in CMA
Add new interface cma_pages_valid() which indicates if the specified pages are part of a CMA region. This interface will be used in a subsequent patch by hugetlb code.
In order to keep the same amount of DEBUG information, a pr_debug() call was added to cma_pages_valid(). In the case where the page passed to cma_release is not in cma region, the debug message will be printed from cma_pages_valid as opposed to cma_release.
---
include/linux/cma.h | 1 + mm/cma.c | 24 ++++++++++++++++++++---- 2 files changed, 21 insertions(+), 4 deletions(-)
include/linux/cma.h renamed from include/linux/cma.h~mm-cma-add-cma_pages_valid-to-determine-if-pages-are-in-cma +1 -0
@@ -46,6 +46,7 @@ extern int cma_init_reserved_mem(phys_ad struct cma **res_cma);extern struct page *cma_alloc (struct cma *cma,unsigned long count,unsigned int align,bool no_warn); +extern bool cma_pages_valid (struct cma *cma,const struct page *pages,unsigned long count);extern bool cma_release (struct cma *cma,const struct page *pages,unsigned long count);extern int cma_for_each_area (int (*it)(struct cma *cma,void *data),void *data);
mm/cma.c renamed from mm/cma.c~mm-cma-add-cma_pages_valid-to-determine-if-pages-are-in-cma +20 -4
@@ -524,6 +524,25 @@ out:return page; } +bool cma_pages_valid (struct cma *cma,const struct page *pages, +unsigned long count) +{ +unsigned long pfn; + +if (!cma || !pages) +return false; + + pfn =page_to_pfn (pages); + +if (pfn < cma->base_pfn || pfn >= cma->base_pfn + cma->count) { +pr_debug ("%s(page %p, count %lu)\n" , __func__, + (void *)pages, count); +return false; + } + +return true; +} +/** * cma_release() - release allocated pages * @cma: Contiguous memory region for which the allocation is performed.
@@ -539,16 +558,13 @@ bool cma_release(struct cma *cma, const {unsigned long pfn; -if (!cma || !pages) +if (!cma_pages_valid (cma, pages, count))return false;pr_debug ("%s(page %p, count %lu)\n" , __func__, (void *)pages, count); pfn =page_to_pfn (pages); -if (pfn < cma->base_pfn || pfn >= cma->base_pfn + cma->count) -return false; -VM_BUG_ON (pfn + count > cma->base_pfn + cma->count);free_contig_range (pfn, count);
_
Andrew Morton
maintainerPATCH 130/262 hugetlb: be sure to free demoted CMA pages to CMA
In reply to Andrew MortonFrom: Mike Kravetz <[email protected]>
Subject: hugetlb: be sure to free demoted CMA pages to CMA
When huge page demotion is fully implemented, gigantic pages can be demoted to a smaller huge page size. For example, on x86 a 1G page can be demoted to 512 2M pages. However, gigantic pages can potentially be allocated from CMA. If a gigantic page which was allocated from CMA is demoted, the corresponding demoted pages needs to be returned to CMA.
Use the new interface cma_pages_valid() to determine if a non-gigantic hugetlb page should be freed to CMA. Also, clear mapping field of these pages as expected by cma_release.
This also requires a change to CMA region creation for gigantic pages. CMA uses a per-region bit map to track allocations. When setting up the region, you specify how many pages each bit represents. Currently, only gigantic pages are allocated/freed from CMA so the region is set up such that one bit represents a gigantic page size allocation.
With demote, a gigantic page (allocation) could be split into smaller size pages. And, these smaller size pages will be freed to CMA. So, since the per-region bit map needs to be set up to represent the smallest allocation/free size, it now needs to be set to the smallest huge page size which can be freed to CMA.
Unfortunately, we set up the CMA region for huge pages before we set up huge pages sizes (hstates). So, technically we do not know the smallest huge page size as this can change via command line options and architecture specific code. Therefore, at region setup time we use HUGETLB_PAGE_ORDER as the smallest possible huge page size that can be given back to CMA. It is possible that this value is sub-optimal for some architectures/config options. If needed, this can be addressed in follow on work.
---
mm/hugetlb.c | 41 +++++++++++++++++++++++++++++++++++++++-- 1 file changed, 39 insertions(+), 2 deletions(-)
mm/hugetlb.c renamed from mm/hugetlb.c~hugetlb-be-sure-to-free-demoted-cma-pages-to-cma +39 -2
@@ -50,6 +50,16 @@ struct hstate hstates[HUGE_MAX_HSTATE];#ifdef CONFIG_CMA static struct cma *hugetlb_cma[MAX_NUMNODES ]; +static bool hugetlb_cma_page (struct page *page,unsigned int order) +{ +return cma_pages_valid (hugetlb_cma[page_to_nid (page)], page, +1 << order); +} +#else +static bool hugetlb_cma_page (struct page *page,unsigned int order) +{ +return false; +}#endif static unsigned long hugetlb_cma_size__initdata ;
@@ -1272,6 +1282,7 @@ static void destroy_compound_gigantic_paatomic_set (compound_pincount_ptr (page),0 );for (i =1 ; i < nr_pages; i++, p =mem_map_next (p, page, i)) { + p->mapping =NULL ;clear_compound_head (p);set_page_refcounted (p); }
@@ -1476,7 +1487,13 @@ static void __update_and_free_page(struc1 << PG_active |1 << PG_private | 1 << PG_writeback); } -if (hstate_is_gigantic (h)) { + +/* +* Non-gigantic pages demoted from CMA allocated gigantic pages +* need to be given back to CMA in free_gigantic_page. +*/ +if (hstate_is_gigantic (h) || +hugetlb_cma_page (page,huge_page_order (h))) {destroy_compound_gigantic_page (page,huge_page_order (h));free_gigantic_page (page,huge_page_order (h)); }else {
@@ -3001,9 +3018,13 @@ static void __init hugetlb_init_hstates(* h->demote_order is initially 0. * - We can not demote gigantic pages if runtime freeing * is not supported, so skip this. +* - If CMA allocation is possible, we can not demote +* HUGETLB_PAGE_ORDER or smaller size pages. */ if (hstate_is_gigantic (h) && !gigantic_page_runtime_supported ())continue ; +if (hugetlb_cma_size && h->order <=HUGETLB_PAGE_ORDER ) +continue ;for_each_hstate (h2) {if (h2 == h)continue ;
@@ -3555,6 +3576,8 @@ static ssize_t demote_size_store(structif (!demote_hstate)return -EINVAL ; demote_order = demote_hstate->order; +if (demote_order <HUGETLB_PAGE_ORDER ) +return -EINVAL ;/* demote order must be smaller than hstate order */ h =kobj_to_hstate (kobj, &nid);
@@ -6543,6 +6566,7 @@ void __init hugetlb_cma_reserve(int ordeif (hugetlb_cma_size < (PAGE_SIZE << order)) {pr_warn ("hugetlb_cma: cma area should be at least %lu MiB\n" , (PAGE_SIZE << order) /SZ_1M ); + hugetlb_cma_size =0 ;return ; }
@@ -6563,7 +6587,13 @@ void __init hugetlb_cma_reserve(int orde size =round_up (size,PAGE_SIZE << order);snprintf (name,sizeof (name),"hugetlb%d" , nid); - res =cma_declare_contiguous_nid (0 , size,0 ,PAGE_SIZE << order, +/* +* Note that 'order per bit' is based on smallest size that +* may be returned to CMA allocator in the case of +* huge page demotion. +*/ + res =cma_declare_contiguous_nid (0 , size,0 , +PAGE_SIZE <<HUGETLB_PAGE_ORDER ,0 , false, name, &hugetlb_cma[nid], nid);if (res) {
@@ -6579,6 +6609,13 @@ void __init hugetlb_cma_reserve(int ordeif (reserved >= hugetlb_cma_size)break ; } + +if (!reserved) +/* +* hugetlb_cma_size is used to determine if allocations from +* cma are possible. Set to zero if no cma regions are set up. +*/ + hugetlb_cma_size =0 ; }void __init hugetlb_cma_check (void )
_
Andrew Morton
maintainerPATCH 131/262 hugetlb: add demote bool to gigantic page routines
In reply to Andrew MortonFrom: Mike Kravetz <[email protected]>
Subject: hugetlb: add demote bool to gigantic page routines
The routines remove_hugetlb_page and destroy_compound_gigantic_page will remove a gigantic page and make the set of base pages ready to be returned to a lower level allocator. In the process of doing this, they make all base pages reference counted.
The routine prep_compound_gigantic_page creates a gigantic page from a set of base pages. It assumes that all these base pages are reference counted.
During demotion, a gigantic page will be split into huge pages of a smaller size. This logically involves use of the routines, remove_hugetlb_page, and destroy_compound_gigantic_page followed by prep_compound*_page for each smaller huge page.
When pages are reference counted (ref count >= 0), additional speculative ref counts could be taken as described in previous commits
[1] and [2]. This could result in errors while demoting a huge page. Quite a bit of code would need to be created to handle all possible issues.
Instead of dealing with the possibility of speculative ref counts, avoid the possibility by keeping ref counts at zero during the demote process. Add a boolean 'demote' to the routines remove_hugetlb_page, destroy_compound_gigantic_page and prep_compound_gigantic_page. If the boolean is set, the remove and destroy routines will not reference count pages and the prep routine will not expect reference counted pages.
'*_for_demote' wrappers of the routines will be added in a subsequent patch where this functionality is used.
[1] https://lore.kernel.org/linux-mm/[email protected]/
[2] https://lore.kernel.org/linux-mm/[email protected]/
---
mm/hugetlb.c | 54 +++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 43 insertions(+), 11 deletions(-)
mm/hugetlb.c renamed from mm/hugetlb.c~hugetlb-add-demote-bool-to-gigantic-page-routines +43 -11
@@ -1271,8 +1271,8 @@ static int hstate_next_node_to_free(stru nr_nodes--)#ifdef CONFIG_ARCH_HAS_GIGANTIC_PAGE -static void destroy_compound_gigantic_page (struct page *page, -unsigned int order) +static void __destroy_compound_gigantic_page (struct page *page, +unsigned int order,bool demote) {int i;int nr_pages =1 << order;
@@ -1284,7 +1284,8 @@ static void destroy_compound_gigantic_pafor (i =1 ; i < nr_pages; i++, p =mem_map_next (p, page, i)) { p->mapping =NULL ;clear_compound_head (p); -set_page_refcounted (p); +if (!demote) +set_page_refcounted (p); }set_compound_order (page,0 );
@@ -1292,6 +1293,12 @@ static void destroy_compound_gigantic_pa__ClearPageHead (page); } +static void destroy_compound_gigantic_page (struct page *page, +unsigned int order) +{ +__destroy_compound_gigantic_page (page, order, false); +} +static void free_gigantic_page (struct page *page,unsigned int order) {/*
@@ -1364,12 +1371,15 @@ static inline void destroy_compound_giga/* * Remove hugetlb page from lists, and update dtor so that page appears -* as just a compound page. A reference is held on the page. +* as just a compound page. +* +* A reference is held on the page, except in the case of demote. * * Must be called with hugetlb lock held. */ -static void remove_hugetlb_page (struct hstate *h,struct page *page, -bool adjust_surplus) +static void __remove_hugetlb_page (struct hstate *h,struct page *page, +bool adjust_surplus, +bool demote) {int nid =page_to_nid (page);
@@ -1407,8 +1417,12 @@ static void remove_hugetlb_page(struct h* * This handles the case where more than one ref is held when and * after update_and_free_page is called. +* +* In the case of demote we do not ref count the page as it will soon +* be turned into a page of smaller size. */ -set_page_refcounted (page); +if (!demote) +set_page_refcounted (page);if (hstate_is_gigantic (h))set_compound_page_dtor (page,NULL_COMPOUND_DTOR );else
@@ -1418,6 +1432,12 @@ static void remove_hugetlb_page(struct h h->nr_huge_pages_node[nid]--; } +static void remove_hugetlb_page (struct hstate *h,struct page *page, +bool adjust_surplus) +{ +__remove_hugetlb_page (h, page, adjust_surplus, false); +} +static void add_hugetlb_page (struct hstate *h,struct page *page,bool adjust_surplus) {
@@ -1681,7 +1701,8 @@ static void prep_new_huge_page(struct hsspin_unlock_irq (&hugetlb_lock); } -static bool prep_compound_gigantic_page (struct page *page,unsigned int order) +static bool __prep_compound_gigantic_page (struct page *page,unsigned int order, +bool demote) {int i, j;int nr_pages =1 << order;
@@ -1719,10 +1740,16 @@ static bool prep_compound_gigantic_page(* the set of pages can not be converted to a gigantic page. * The caller who allocated the pages should then discard the * pages using the appropriate free interface. +* +* In the case of demote, the ref count will be zero. */ -if (!page_ref_freeze (p,1 )) { -pr_warn ("HugeTLB page can not be used due to unexpected inflated ref count\n" ); - goto out_error; +if (!demote) { +if (!page_ref_freeze (p,1 )) { +pr_warn ("HugeTLB page can not be used due to unexpected inflated ref count\n" ); + goto out_error; + } + }else { +VM_BUG_ON_PAGE (page_count (p), p); }set_page_count (p,0 );set_compound_head (p, page);
@@ -1747,6 +1774,11 @@ out_error:return false; } +static bool prep_compound_gigantic_page (struct page *page,unsigned int order) +{ +return __prep_compound_gigantic_page (page, order, false); +} +/* * PageHuge() only returns true for hugetlbfs pages, but not for normal or * transparent huge pages. See the PageTransHuge() documentation for more
_
Andrew Morton
maintainerPATCH 132/262 hugetlb: add hugetlb demote page support
In reply to Andrew MortonFrom: Mike Kravetz <[email protected]>
Subject: hugetlb: add hugetlb demote page support
Demote page functionality will split a huge page into a number of huge pages of a smaller size. For example, on x86 a 1GB huge page can be demoted into 512 2M huge pages. Demotion is done 'in place' by simply splitting the huge page.
Added '*_for_demote' wrappers for remove_hugetlb_page, destroy_compound_hugetlb_page and prep_compound_gigantic_page for use by demote code.
---
mm/hugetlb.c | 100 +++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 92 insertions(+), 8 deletions(-)
mm/hugetlb.c renamed from mm/hugetlb.c~hugetlb-add-hugetlb-demote-page-support +92 -8
@@ -1270,7 +1270,7 @@ static int hstate_next_node_to_free(stru ((node =hstate_next_node_to_free (hs, mask)) ||1 ); \ nr_nodes--) -#ifdef CONFIG_ARCH_HAS_GIGANTIC_PAGE +/* used to demote non-gigantic_huge pages as well */ static void __destroy_compound_gigantic_page (struct page *page,unsigned int order,bool demote) {
@@ -1293,6 +1293,13 @@ static void __destroy_compound_gigantic___ClearPageHead (page); } +static void destroy_compound_hugetlb_page_for_demote (struct page *page, +unsigned int order) +{ +__destroy_compound_gigantic_page (page, order, true); +} + +#ifdef CONFIG_ARCH_HAS_GIGANTIC_PAGE static void destroy_compound_gigantic_page (struct page *page,unsigned int order) {
@@ -1438,6 +1445,12 @@ static void remove_hugetlb_page(struct h__remove_hugetlb_page (h, page, adjust_surplus, false); } +static void remove_hugetlb_page_for_demote (struct hstate *h,struct page *page, +bool adjust_surplus) +{ +__remove_hugetlb_page (h, page, adjust_surplus, true); +} +static void add_hugetlb_page (struct hstate *h,struct page *page,bool adjust_surplus) {
@@ -1779,6 +1792,12 @@ static bool prep_compound_gigantic_page(return __prep_compound_gigantic_page (page, order, false); } +static bool prep_compound_gigantic_page_for_demote (struct page *page, +unsigned int order) +{ +return __prep_compound_gigantic_page (page, order, true); +} +/* * PageHuge() only returns true for hugetlbfs pages, but not for normal or * transparent huge pages. See the PageTransHuge() documentation for more
@@ -3304,9 +3323,72 @@ out:return 0 ; } +static int demote_free_huge_page (struct hstate *h,struct page *page) +{ +int i, nid =page_to_nid (page); +struct hstate *target_hstate; +int rc =0 ; + + target_hstate =size_to_hstate (PAGE_SIZE << h->demote_order); + +remove_hugetlb_page_for_demote (h, page, false); +spin_unlock_irq (&hugetlb_lock); + + rc =alloc_huge_page_vmemmap (h, page); +if (rc) { +/* Allocation of vmemmmap failed, we can not demote page */ +spin_lock_irq (&hugetlb_lock); +set_page_refcounted (page); +add_hugetlb_page (h, page, false); +return rc; + } + +/* +* Use destroy_compound_hugetlb_page_for_demote for all huge page +* sizes as it will not ref count pages. +*/ +destroy_compound_hugetlb_page_for_demote (page,huge_page_order (h)); + +/* +* Taking target hstate mutex synchronizes with set_max_huge_pages. +* Without the mutex, pages added to target hstate could be marked +* as surplus. +* +* Note that we already hold h->resize_lock. To prevent deadlock, +* use the convention of always taking larger size hstate mutex first. +*/ +mutex_lock (&target_hstate->resize_lock); +for (i =0 ; i <pages_per_huge_page (h); + i +=pages_per_huge_page (target_hstate)) { +if (hstate_is_gigantic (target_hstate)) +prep_compound_gigantic_page_for_demote (page + i, + target_hstate->order); +else +prep_compound_page (page + i, target_hstate->order); +set_page_private (page + i,0 ); +set_page_refcounted (page + i); +prep_new_huge_page (target_hstate, page + i, nid); +put_page (page + i); + } +mutex_unlock (&target_hstate->resize_lock); + +spin_lock_irq (&hugetlb_lock); + +/* +* Not absolutely necessary, but for consistency update max_huge_pages +* based on pool changes for the demoted page. +*/ + h->max_huge_pages--; + target_hstate->max_huge_pages +=pages_per_huge_page (h); + +return rc; +} +static int demote_pool_huge_page (struct hstate *h,nodemask_t *nodes_allowed) __must_hold(&hugetlb_lock) { +int nr_nodes, node; +struct page *page;int rc =0 ;lockdep_assert_held (&hugetlb_lock);
@@ -3317,9 +3399,15 @@ static int demote_pool_huge_page(structreturn -EINVAL ;/* internal error */ } -/* -* TODO - demote fucntionality will be added in subsequent patch -*/ +for_each_node_mask_to_free (h, nr_nodes, node, nodes_allowed) { +if (!list_empty (&h->hugepage_freelists[node])) { + page =list_entry (h->hugepage_freelists[node].next, + struct page, lru); + rc =demote_free_huge_page (h, page); +break ; + } + } +return rc; }
@@ -3554,10 +3642,6 @@ static ssize_t demote_store(struct kobje/* * Check for available pages to demote each time thorough the * loop as demote_pool_huge_page will drop hugetlb_lock. -* -* NOTE: demote_pool_huge_page does not yet drop hugetlb_lock -* but will when full demote functionality is added in a later -* patch. */ if (nid !=NUMA_NO_NODE ) nr_available = h->free_huge_pages_node[nid];
_
Andrew Morton
maintainerPATCH 133/262 mm: khugepaged: recalculate min_free_kbytes after stopping khugepaged
In reply to Andrew MortonFrom: Liangcai Fan <[email protected]>
Subject: mm: khugepaged: recalculate min_free_kbytes after stopping khugepaged
When initializing transparent huge pages, min_free_kbytes would be calculated according to what khugepaged expected.
So when disable transparent huge pages, min_free_kbytes should be recalculated instead of the higher value set by khugepaged.
---
include/linux/mm.h | 1 + mm/khugepaged.c | 10 ++++++++-- mm/page_alloc.c | 7 ++++++- 3 files changed, 15 insertions(+), 3 deletions(-)
include/linux/mm.h renamed from include/linux/mm.h~mm-khugepaged-recalculate-min_free_kbytes-after-stopping-khugepaged +1 -0
@@ -2453,6 +2453,7 @@ extern void memmap_init_range(unsigned l unsigned long, unsigned long, enum meminit_context, struct vmem_altmap *, int migratetype);extern void setup_per_zone_wmarks (void ); +extern void calculate_min_free_kbytes (void );extern int __meminit init_per_zone_wmark_min (void );extern void mem_init (void );extern void __init mmap_init (void );
mm/khugepaged.c renamed from mm/khugepaged.c~mm-khugepaged-recalculate-min_free_kbytes-after-stopping-khugepaged +8 -2
@@ -2299,6 +2299,11 @@ static void set_recommended_min_free_kbyint nr_zones =0 ;unsigned long recommended_min; +if (!khugepaged_enabled ()) { +calculate_min_free_kbytes (); + goto update_wmarks; + } +for_each_populated_zone (zone) {/* * We don't need to worry about fragmentation of
@@ -2334,6 +2339,8 @@ static void set_recommended_min_free_kby min_free_kbytes = recommended_min; } + +update_wmarks:setup_per_zone_wmarks (); }
@@ -2355,12 +2362,11 @@ int start_stop_khugepaged(void)if (!list_empty (&khugepaged_scan.mm_head))wake_up_interruptible (&khugepaged_wait); - -set_recommended_min_free_kbytes (); }else if (khugepaged_thread) {kthread_stop (khugepaged_thread); khugepaged_thread =NULL ; } +set_recommended_min_free_kbytes (); fail:mutex_unlock (&khugepaged_mutex);return err;
mm/page_alloc.c renamed from mm/page_alloc.c~mm-khugepaged-recalculate-min_free_kbytes-after-stopping-khugepaged +6 -1
@@ -8469,7 +8469,7 @@ void setup_per_zone_wmarks(void)* 8192MB: 11584k * 16384MB: 16384k */ -int __meminit init_per_zone_wmark_min (void ) +void calculate_min_free_kbytes (void ) {unsigned long lowmem_kbytes;int new_min_free_kbytes;
@@ -8483,6 +8483,11 @@ int __meminit init_per_zone_wmark_min(vopr_warn ("min_free_kbytes is not updated to %d because user defined value %d is preferred\n" , new_min_free_kbytes, user_min_free_kbytes); +} + +int __meminit init_per_zone_wmark_min (void ) +{ +calculate_min_free_kbytes ();setup_per_zone_wmarks ();refresh_zone_stat_thresholds ();setup_per_zone_lowmem_reserve ();
_
Andrew Morton
maintainerPATCH 134/262 mm, hugepages: add mremap() support for hugepage backed vma
In reply to Andrew MortonFrom: Mina Almasry <[email protected]>
Subject: mm, hugepages: add mremap() support for hugepage backed vma
Support mremap() for hugepage backed vma segment by simply repositioning page table entries. The page table entries are repositioned to the new virtual address on mremap().
Hugetlb mremap() support is of course generic; my motivating use case is a library (hugepage_text), which reloads the ELF text of executables in hugepages. This significantly increases the execution performance of said executables.
Restricts the mremap operation on hugepages to up to the size of the original mapping as the underlying hugetlb reservation is not yet capable of handling remapping to a larger size.
During the mremap() operation we detect pmd_share'd mappings and we unshare those during the mremap(). On access and fault the sharing is established again.
---
include/linux/hugetlb.h | 19 ++++++ mm/hugetlb.c | 111 +++++++++++++++++++++++++++++++++++--- mm/mremap.c | 36 +++++++++++- 3 files changed, 157 insertions(+), 9 deletions(-)
include/linux/hugetlb.h renamed from include/linux/hugetlb.h~mm-hugepages-add-mremap-support-for-hugepage-backed-vma +19 -0
@@ -124,6 +124,7 @@ struct hugepage_subpool *hugepage_new_suvoid hugepage_put_subpool (struct hugepage_subpool *spool);void reset_vma_resv_huge_pages (struct vm_area_struct *vma); +void clear_vma_resv_huge_pages (struct vm_area_struct *vma);int hugetlb_sysctl_handler (struct ctl_table *,int ,void *,size_t *,loff_t *);int hugetlb_overcommit_handler (struct ctl_table *,int ,void *,size_t *,loff_t *);
@@ -132,6 +133,10 @@ int hugetlb_treat_movable_handler(structint hugetlb_mempolicy_sysctl_handler (struct ctl_table *,int ,void *,size_t *,loff_t *); +int move_hugetlb_page_tables (struct vm_area_struct *vma, +struct vm_area_struct *new_vma, +unsigned long old_addr,unsigned long new_addr, +unsigned long len);int copy_hugetlb_page_range (struct mm_struct *,struct mm_struct *,struct vm_area_struct *); long follow_hugetlb_page(struct mm_struct *, struct vm_area_struct *, struct page **, struct vm_area_struct **,
@@ -215,6 +220,10 @@ static inline void reset_vma_resv_huge_p { } +static inline void clear_vma_resv_huge_pages (struct vm_area_struct *vma) +{ +} +static inline unsigned long hugetlb_total_pages (void ) {return 0 ;
@@ -260,6 +269,16 @@ static inline int copy_hugetlb_page_rang {BUG ();return 0 ; +} + +static inline int move_hugetlb_page_tables (struct vm_area_struct *vma, +struct vm_area_struct *new_vma, +unsigned long old_addr, +unsigned long new_addr, +unsigned long len) +{ +BUG (); +return 0 ; }static inline void hugetlb_report_meminfo (struct seq_file *m)
mm/hugetlb.c renamed from mm/hugetlb.c~mm-hugepages-add-mremap-support-for-hugepage-backed-vma +105 -6
129 lines not on this page · raw message
mm/mremap.c renamed from mm/mremap.c~mm-hugepages-add-mremap-support-for-hugepage-backed-vma +33 -3
@@ -489,6 +489,10 @@ unsigned long move_page_tables(struct vm old_end = old_addr + len;flush_cache_range (vma, old_addr, old_end); +if (is_vm_hugetlb_page (vma)) +return move_hugetlb_page_tables (vma, new_vma, old_addr, + new_addr, len); +mmu_notifier_range_init (&range,MMU_NOTIFY_UNMAP ,0 , vma, vma->vm_mm, old_addr, old_end);mmu_notifier_invalidate_range_start (&range);
@@ -646,6 +650,10 @@ static unsigned long move_vma(struct vm_mremap_userfaultfd_prep (new_vma, uf); } +if (is_vm_hugetlb_page (vma)) { +clear_vma_resv_huge_pages (vma); + } +/* Conceal VM_ACCOUNT so old reservation is not undone */ if (vm_flags &VM_ACCOUNT && !(flags &MREMAP_DONTUNMAP )) { vma->vm_flags &= ~VM_ACCOUNT ;
@@ -739,9 +747,6 @@ static struct vm_area_struct *vma_to_res (vma->vm_flags & (VM_DONTEXPAND | VM_PFNMAP)))return ERR_PTR (-EINVAL ); -if (is_vm_hugetlb_page (vma)) -return ERR_PTR (-EINVAL ); -/* We can't remap across vm area boundaries */ if (old_len > vma->vm_end - addr)return ERR_PTR (-EFAULT );
@@ -937,6 +942,31 @@ SYSCALL_DEFINE5(mremap, unsigned long, aif (mmap_write_lock_killable (current->mm))return -EINTR ; + vma =find_vma (mm, addr); +if (!vma || vma->vm_start > addr) { + ret =EFAULT ; + goto out; + } + +if (is_vm_hugetlb_page (vma)) { +struct hstate *h__maybe_unused =hstate_vma (vma); + + old_len =ALIGN (old_len,huge_page_size (h)); + new_len =ALIGN (new_len,huge_page_size (h)); + +/* addrs must be huge page aligned */ +if (addr & ~huge_page_mask (h)) + goto out; +if (new_addr & ~huge_page_mask (h)) + goto out; + +/* +* Don't allow remap expansion, because the underlying hugetlb +* reservation is not yet capable to handle split reservation. +*/ +if (new_len > old_len) + goto out; + }if (flags & (MREMAP_FIXED |MREMAP_DONTUNMAP )) { ret = mremap_to(addr, old_len, new_addr, new_len,
_
Andrew Morton
maintainerPATCH 135/262 mm, hugepages: add hugetlb vma mremap() test
In reply to Andrew MortonFrom: Mina Almasry <[email protected]>
Subject: mm, hugepages: add hugetlb vma mremap() test
---
tools/testing/selftests/vm/.gitignore | 1 tools/testing/selftests/vm/Makefile | 1 tools/testing/selftests/vm/hugepage-mremap.c | 160 +++++++++++++++++ tools/testing/selftests/vm/run_vmtests.sh | 11 + 4 files changed, 173 insertions(+)
tools/testing/selftests/vm/.gitignore renamed from tools/testing/selftests/vm/.gitignore~mm-hugepages-add-hugetlb-vma-mremap-test +1 -0
@@ -1,5 +1,6 @@ # SPDX-License-Identifier: GPL-2.0-only hugepage-mmap +hugepage-mremap hugepage-shm khugepaged map_hugetlb
tools/testing/selftests/vm/hugepage-mremap.c new file +160 -0
160 lines not on this page · raw message
tools/testing/selftests/vm/Makefile renamed from tools/testing/selftests/vm/Makefile~mm-hugepages-add-hugetlb-vma-mremap-test +1 -0
@@ -29,6 +29,7 @@ TEST_GEN_FILES = compaction_test TEST_GEN_FILES += gup_test TEST_GEN_FILES += hmm-tests TEST_GEN_FILES += hugepage-mmap +TEST_GEN_FILES += hugepage-mremap TEST_GEN_FILES += hugepage-shm TEST_GEN_FILES += khugepaged TEST_GEN_FILES += madv_populate
tools/testing/selftests/vm/run_vmtests.sh renamed from tools/testing/selftests/vm/run_vmtests.sh~mm-hugepages-add-hugetlb-vma-mremap-test +11 -0
@@ -108,6 +108,17 @@ else echo "[PASS]" fi +echo "-----------------------" +echo "running hugepage-mremap" +echo "-----------------------" +./hugepage-mremap +if [ $? -ne 0 ]; then + echo "[FAIL]" + exitcode=1 +else + echo "[PASS]" +fi + echo "NOTE: The above hugetlb tests provide minimal coverage. Use" echo " https://github.com/libhugetlbfs/libhugetlbfs.git for" echo " hugetlb regression testing."
_
Andrew Morton
maintainerPATCH 136/262 hugetlb: support node specified when using cma for gigantic hugepages
In reply to Andrew MortonFrom: Baolin Wang <[email protected]>
Subject: hugetlb: support node specified when using cma for gigantic hugepages
Now the size of CMA area for gigantic hugepages runtime allocation is balanced for all online nodes, but we also want to specify the size of CMA per-node, or only one node in some cases, which are similar with patch [1].
For example, on some multi-nodes systems, each node's memory can be different, allocating the same size of CMA for each node is not suitable for the low-memory nodes. Meanwhile some workloads like DPDK mentioned by Zhenguo in patch [1] only need hugepages in one node.
On the other hand, we have some machines with multiple types of memory, like DRAM and PMEM (persistent memory). On this system, we may want to specify all the hugepages only on DRAM node, or specify the proportion of DRAM node and PMEM node, to tuning the performance of the workloads.
Thus this patch adds node format for 'hugetlb_cma' parameter to support specifying the size of CMA per-node. An example is as follows:
hugetlb_cma=0:5G,2:5G
which means allocating 5G size of CMA area on node 0 and node 2 respectively. And the users should use the node specific sysfs file to allocate the gigantic hugepages if specified the CMA size on that node.
[1]
https://lkml.kernel.org/r/[email protected]
---
Documentation/admin-guide/kernel-parameters.txt | 6 mm/hugetlb.c | 86 ++++++++++++-- 2 files changed, 81 insertions(+), 11 deletions(-)
Documentation/admin-guide/kernel-parameters.txt renamed from Documentation/admin-guide/kernel-parameters.txt~hugetlb-support-node-specified-when-using-cma-for-gigantic-hugepages +4 -2
@@ -1587,8 +1587,10 @@ registers. Default set by CONFIG_HPET_MMAP_DEFAULT. hugetlb_cma= [HW,CMA] The size of a CMA area used for allocation - of gigantic hugepages. - Format: nn[KMGTPE] + of gigantic hugepages. Or using node format, the size + of a CMA area per node can be specified. + Format: nn[KMGTPE] or (node format) + <node>:nn[KMGTPE][,<node>:nn[KMGTPE]] Reserve a CMA area of given size and allocate gigantic hugepages using the CMA allocator. If enabled, the
mm/hugetlb.c renamed from mm/hugetlb.c~hugetlb-support-node-specified-when-using-cma-for-gigantic-hugepages +77 -9
122 lines not on this page · raw message
_
Andrew Morton
maintainerPATCH 137/262 mm: remove duplicate include in hugepage-mremap.c
In reply to Andrew MortonFrom: Ran Jianping <[email protected]>
Subject: mm: remove duplicate include in hugepage-mremap.c
Remove duplicate includes 'unistd.h' included in
'/tools/testing/selftests/vm/hugepage-mremap.c' is duplicated.It is also included on 23 line.
---
tools/testing/selftests/vm/hugepage-mremap.c | 1 - 1 file changed, 1 deletion(-)
tools/testing/selftests/vm/hugepage-mremap.c renamed from tools/testing/selftests/vm/hugepage-mremap.c~mm-remove-duplicate-include-in-hugepage-mremapc +0 -1
@@ -15,7 +15,6 @@#include <errno.h> #include <fcntl.h> /* Definition of O_* constants */ #include <sys/syscall.h> /* Definition of SYS_* constants */ -#include <unistd.h> #include <linux/userfaultfd.h> #include <sys/ioctl.h>
_
Andrew Morton
maintainerPATCH 138/262 hugetlb_cgroup: remove unused hugetlb_cgroup_from_counter macro
In reply to Andrew MortonFrom: Baolin Wang <[email protected]>
Subject: hugetlb_cgroup: remove unused hugetlb_cgroup_from_counter macro
Patch series "Some cleanups and improvements for hugetlb".
This patchset does some cleanups and improvements for hugetlb and hugetlb_cgroup.
This patch (of 4):
Since commit 726b7bbe ("hugetlb_cgroup: fix illegal access to memory"), the hugetlb_cgroup_from_counter() macro is not used any more, remove it.
---
mm/hugetlb_cgroup.c | 3 --- 1 file changed, 3 deletions(-)
mm/hugetlb_cgroup.c renamed from mm/hugetlb_cgroup.c~hugetlb_cgroup-remove-unused-hugetlb_cgroup_from_counter-macro +0 -3
@@ -27,9 +27,6 @@#define MEMFILE_IDX (val) (((val) >> 16) & 0xffff)#define MEMFILE_ATTR (val) ((val) & 0xffff) -#define hugetlb_cgroup_from_counter (counter, idx) \ - container_of(counter, struct hugetlb_cgroup, hugepage[idx]) -static struct hugetlb_cgroup *root_h_cgroup__read_mostly ; static inline struct page_counter *
_
Andrew Morton
maintainerPATCH 139/262 hugetlb: replace the obsolete hugetlb_instantiation_mutex in the comments
In reply to Andrew MortonFrom: Baolin Wang <[email protected]>
Subject: hugetlb: replace the obsolete hugetlb_instantiation_mutex in the comments
After commit 8382d914ebf7 ("mm, hugetlb: improve page-fault scalability"), the hugetlb_instantiation_mutex lock had been replaced by hugetlb_fault_mutex_table to serializes faults on the same logical page. Thus update the obsolete hugetlb_instantiation_mutex related comments.
---
mm/hugetlb.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
mm/hugetlb.c renamed from mm/hugetlb.c~hugetlb-replace-the-obsolete-hugetlb_instantiation_mutex-in-the-comments +1 -1
@@ -5014,7 +5014,7 @@ static void unmap_ref_private(struct mm_/* * Hugetlb_cow() should be called with page lock of the original hugepage held. -* Called with hugetlb_instantiation_mutex held and pte_page locked so we +* Called with hugetlb_fault_mutex_table held and pte_page locked so we * cannot race with other handlers or page migration. * Keep the pte_same checks anyway to make transition from the mutex easier. */
_
Andrew Morton
maintainerPATCH 140/262 hugetlb: remove redundant validation in has_same_uncharge_info()
In reply to Andrew MortonFrom: Baolin Wang <[email protected]>
Subject: hugetlb: remove redundant validation in has_same_uncharge_info()
The callers of has_same_uncharge_info() has accessed the original file_region and new file_region, and they are impossible to be NULL now. So we can remove the file_region validation in has_same_uncharge_info() to simplify the code.
---
mm/hugetlb.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
mm/hugetlb.c renamed from mm/hugetlb.c~hugetlb-remove-redundant-validation-in-has_same_uncharge_info +1 -2
@@ -332,8 +332,7 @@ static bool has_same_uncharge_info(struc struct file_region *org) {#ifdef CONFIG_CGROUP_HUGETLB -return rg && org && - rg->reservation_counter == org->reservation_counter && +return rg->reservation_counter == org->reservation_counter && rg->css == org->css;#else
_
Andrew Morton
maintainerPATCH 141/262 hugetlb: remove redundant VM_BUG_ON() in add_reservation_in_range()
In reply to Andrew MortonFrom: Baolin Wang <[email protected]>
Subject: hugetlb: remove redundant VM_BUG_ON() in add_reservation_in_range()
When calling hugetlb_resv_map_add(), we've guaranteed that the parameter 'to' is always larger than 'from', so it never returns a negative value from hugetlb_resv_map_add(). Thus remove the redundant VM_BUG_ON().
---
mm/hugetlb.c | 1 - 1 file changed, 1 deletion(-)
mm/hugetlb.c renamed from mm/hugetlb.c~hugetlb-remove-redundant-vm_bug_on-in-add_reservation_in_range +0 -1
@@ -445,7 +445,6 @@ static long add_reservation_in_range(str add +=hugetlb_resv_map_add (resv, rg, last_accounted_offset, t, h, h_cg, regions_needed); -VM_BUG_ON (add <0 );return add; }
_
Andrew Morton
maintainerPATCH 142/262 hugetlb: remove unnecessary set_page_count in prep_compound_gigantic_page
In reply to Andrew MortonFrom: Mike Kravetz <[email protected]>
Subject: hugetlb: remove unnecessary set_page_count in prep_compound_gigantic_page
In commit 7118fc2906e29 ("hugetlb: address ref count racing in prep_compound_gigantic_page"), page_ref_freeze is used to atomically zero the ref count of tail pages iff they are 1. The unconditional call to set_page_count(0) was left in the code. This call is after page_ref_freeze so it is really a noop.
Remove redundant and unnecessary set_page_count call.
---
mm/hugetlb.c | 1 - 1 file changed, 1 deletion(-)
mm/hugetlb.c renamed from mm/hugetlb.c~hugetlb-remove-unnecessary-set_page_count-in-prep_compound_gigantic_page +0 -1
@@ -1792,7 +1792,6 @@ static bool __prep_compound_gigantic_pag }else {VM_BUG_ON_PAGE (page_count (p), p); } -set_page_count (p,0 );set_compound_head (p, page); }atomic_set (compound_mapcount_ptr (page),-1 );
_
Andrew Morton
maintainerPATCH 143/262 userfaultfd/selftests: don't rely on GNU extensions for random numbers
In reply to Andrew MortonFrom: Axel Rasmussen <[email protected]>
Subject: userfaultfd/selftests: don't rely on GNU extensions for random numbers
Patch series "Small userfaultfd selftest fixups", v2.
This patch (of 3):
Two arguments for doing this:
First, and maybe most importantly, the resulting code is significantly shorter / simpler.
Then, we avoid using GNU libc extensions. Why does this matter? It makes testing userfaultfd with the selftest easier e.g. on distros which use something other than glibc (e.g., Alpine, which uses musl); basically, it makes the test more portable.
---
tools/testing/selftests/vm/userfaultfd.c | 26 +++------------------ 1 file changed, 4 insertions(+), 22 deletions(-)
tools/testing/selftests/vm/userfaultfd.c renamed from tools/testing/selftests/vm/userfaultfd.c~userfaultfd-selftests-dont-rely-on-gnu-extensions-for-random-numbers +4 -22
@@ -57,6 +57,7 @@#include <assert.h> #include <inttypes.h> #include <stdint.h> +#include <sys/random.h> #include "../kselftest.h"
@@ -518,22 +519,10 @@ static void continue_range(int ufd, __u6static void *locking_thread (void *arg) {unsigned long cpu = (unsigned long ) arg; -struct random_data rand;unsigned long page_nr = *(&(page_nr));/* uninitialized warning */ -int32_t rand_nr;unsigned long long count; -char randstate[64 ]; -unsigned int seed; -if (bounces &BOUNCE_RANDOM ) { - seed = (unsigned int )time (NULL ) - bounces; -if (!(bounces &BOUNCE_RACINGFAULTS )) - seed += cpu; -bzero (&rand,sizeof (rand)); -bzero (&randstate,sizeof (randstate)); -if (initstate_r (seed, randstate,sizeof (randstate), &rand)) -err ("initstate_r failed" ); - }else { +if (!(bounces &BOUNCE_RANDOM )) { page_nr = -bounces;if (!(bounces &BOUNCE_RACINGFAULTS )) page_nr += cpu * nr_pages_per_cpu;
@@ -541,15 +530,8 @@ static void *locking_thread(void *arg)while (!finished) {if (bounces &BOUNCE_RANDOM ) { -if (random_r (&rand, &rand_nr)) -err ("random_r failed" ); - page_nr = rand_nr; -if (sizeof (page_nr) >sizeof (rand_nr)) { -if (random_r (&rand, &rand_nr)) -err ("random_r failed" ); - page_nr |= (((unsigned long ) rand_nr) <<16 ) << -16 ; - } +if (getrandom (&page_nr,sizeof (page_nr),0 ) !=sizeof (page_nr)) +err ("getrandom failed" ); }else page_nr +=1 ; page_nr %= nr_pages;
_
Andrew Morton
maintainerPATCH 144/262 userfaultfd/selftests: fix feature support detection
In reply to Andrew MortonFrom: Axel Rasmussen <[email protected]>
Subject: userfaultfd/selftests: fix feature support detection
Before any tests are run, in set_test_type, we decide what feature(s) we are going to be testing, based upon our command line arguments. However, the supported features are not just a function of the memory type being used, so this is broken.
For instance, consider writeprotect support. It is "normally" supported for anonymous memory, but furthermore it requires that the kernel has CONFIG_HAVE_ARCH_USERFAULTFD_WP. So, it is *not* supported at all on aarch64, for example.
So, this commit fixes this by querying the kernel for the set of features it supports in set_test_type, by opening a userfaultfd and issuing a UFFDIO_API ioctl. Based upon the reported features, we toggle what tests are enabled.
---
tools/testing/selftests/vm/userfaultfd.c | 54 ++++++++++++--------- 1 file changed, 31 insertions(+), 23 deletions(-)
tools/testing/selftests/vm/userfaultfd.c renamed from tools/testing/selftests/vm/userfaultfd.c~userfaultfd-selftests-fix-feature-support-detection +31 -23
@@ -346,6 +346,16 @@ static struct uffd_test_ops hugetlb_uffdstatic struct uffd_test_ops *uffd_test_ops; +static inline uint64_t uffd_minor_feature (void ) +{ +if (test_type ==TEST_HUGETLB && map_shared) +return UFFD_FEATURE_MINOR_HUGETLBFS ; +else if (test_type ==TEST_SHMEM ) +return UFFD_FEATURE_MINOR_SHMEM ; +else +return 0 ; +} +static void userfaultfd_open (uint64_t *features) {struct uffdio_api uffdio_api;
@@ -406,7 +416,7 @@ static void uffd_test_ctx_clear(void)munmap_area ((void **)&area_dst_alias); } -static void uffd_test_ctx_init_ext (uint64_t *features) +static void uffd_test_ctx_init (uint64_t features) {unsigned long nr, cpu;
@@ -415,7 +425,7 @@ static void uffd_test_ctx_init_ext(uint6 uffd_test_ops->allocate_area ((void **)&area_src); uffd_test_ops->allocate_area ((void **)&area_dst); -userfaultfd_open (features); +userfaultfd_open (&features); count_verify =malloc (nr_pages *sizeof (unsigned long long ));if (!count_verify)
@@ -463,11 +473,6 @@ static void uffd_test_ctx_init_ext(uint6err ("pipe" ); } -static inline void uffd_test_ctx_init (uint64_t features) -{ -uffd_test_ctx_init_ext (&features); -} -static int my_bcmp (char *str1,char *str2,size_t n) {unsigned long i;
@@ -1208,7 +1213,6 @@ static int userfaultfd_minor_test(void)void *expected_page;char c;struct uffd_stats stats = {0 }; -uint64_t req_features, features_out;if (!test_uffdio_minor)return 0 ;
@@ -1216,21 +1220,7 @@ static int userfaultfd_minor_test(void)printf ("testing minor faults: " );fflush (stdout); -if (test_type ==TEST_HUGETLB ) - req_features =UFFD_FEATURE_MINOR_HUGETLBFS ; -else if (test_type ==TEST_SHMEM ) - req_features =UFFD_FEATURE_MINOR_SHMEM ; -else -return 1 ; - - features_out = req_features; -uffd_test_ctx_init_ext (&features_out); -/* If kernel reports required features aren't supported, skip test. */ -if ((features_out & req_features) != req_features) { -printf ("skipping test due to lack of feature support\n" ); -fflush (stdout); -return 0 ; - } +uffd_test_ctx_init (uffd_minor_feature ()); uffdio_register.range.start = (unsigned long )area_dst_alias; uffdio_register.range.len = nr_pages * page_size;
@@ -1591,6 +1581,8 @@ unsigned long default_huge_page_size(voistatic void set_test_type (const char *type) { +uint64_t features =UFFD_API_FEATURES ; +if (!strcmp (type,"anon" )) { test_type =TEST_ANON ; uffd_test_ops = &anon_uffd_test_ops;
@@ -1624,6 +1616,22 @@ static void set_test_type(const char *tyif ((unsigned long )area_count (NULL ,0 ) +sizeof (unsigned long long ) *2 > page_size)err ("Impossible to run this test" ); + +/* +* Whether we can test certain features depends not just on test type, +* but also on whether or not this particular kernel supports the +* feature. +*/ + +userfaultfd_open (&features); + + test_uffdio_wp = test_uffdio_wp && + (features &UFFD_FEATURE_PAGEFAULT_FLAG_WP ); + test_uffdio_minor = test_uffdio_minor && + (features &uffd_minor_feature ()); + +close (uffd); + uffd =-1 ; }static void sigalrm (int sig)
_
Andrew Morton
maintainerPATCH 145/262 userfaultfd/selftests: fix calculation of expected ioctls
In reply to Andrew MortonFrom: Axel Rasmussen <[email protected]>
Subject: userfaultfd/selftests: fix calculation of expected ioctls
Today, we assert that the ioctls the kernel reports as supported for a registration match a precomputed list. We decide which ioctls are supported by examining the memory type. Then, in several locations we "fix up" this list by adding or removing things this initial decision got wrong.
What ioctls the kernel reports is actually a function of several things:
- The memory type
- Kernel feature support (e.g., no writeprotect on aarch64)
- The registration type (e.g., CONTINUE only supported for MINOR mode)
So, we can't fully compute this at the start, in set_test_type. It varies per test, depending on what registration mode(s) those tests use.
Instead, introduce a new function which computes the correct list. This centralizes the add/remove of ioctls depending on these function inputs in one place, so we don't have to repeat ourselves in various tests.
Not only is the resulting code a bit shorter, but it fixes a real bug in the existing code: previously, we would incorrectly require the writeprotect ioctl to be present on aarch64, where it isn't actually supported.
---
tools/testing/selftests/vm/userfaultfd.c | 77 ++++++++++----------- 1 file changed, 38 insertions(+), 39 deletions(-)
tools/testing/selftests/vm/userfaultfd.c renamed from tools/testing/selftests/vm/userfaultfd.c~userfaultfd-selftests-fix-calculation-of-expected-ioctls +38 -39
@@ -308,37 +308,24 @@ static void shmem_alias_mapping(__u64 *s }struct uffd_test_ops { -unsigned long expected_ioctls;void (*allocate_area)(void **alloc_area);void (*release_pages)(char *rel_area);void (*alias_mapping)(__u64 *start,size_t len,unsigned long offset); }; -#define SHMEM_EXPECTED_IOCTLS ((1 << _UFFDIO_WAKE) | \ - (1 << _UFFDIO_COPY) | \ - (1 << _UFFDIO_ZEROPAGE)) - -#define ANON_EXPECTED_IOCTLS ((1 << _UFFDIO_WAKE) | \ - (1 << _UFFDIO_COPY) | \ - (1 << _UFFDIO_ZEROPAGE) | \ - (1 << _UFFDIO_WRITEPROTECT)) -static struct uffd_test_ops anon_uffd_test_ops = { - .expected_ioctls =ANON_EXPECTED_IOCTLS , .allocate_area = anon_allocate_area, .release_pages = anon_release_pages, .alias_mapping = noop_alias_mapping, };static struct uffd_test_ops shmem_uffd_test_ops = { - .expected_ioctls =SHMEM_EXPECTED_IOCTLS , .allocate_area = shmem_allocate_area, .release_pages = shmem_release_pages, .alias_mapping = shmem_alias_mapping, };static struct uffd_test_ops hugetlb_uffd_test_ops = { - .expected_ioctls =UFFD_API_RANGE_IOCTLS_BASIC & ~(1 << _UFFDIO_CONTINUE), .allocate_area = hugetlb_allocate_area, .release_pages = hugetlb_release_pages, .alias_mapping = hugetlb_alias_mapping,
@@ -356,6 +343,33 @@ static inline uint64_t uffd_minor_featurreturn 0 ; } +static uint64_t get_expected_ioctls (uint64_t mode) +{ +uint64_t ioctls =UFFD_API_RANGE_IOCTLS ; + +if (test_type ==TEST_HUGETLB ) + ioctls &= ~(1 << _UFFDIO_ZEROPAGE); + +if (!((mode &UFFDIO_REGISTER_MODE_WP ) && test_uffdio_wp)) + ioctls &= ~(1 << _UFFDIO_WRITEPROTECT); + +if (!((mode &UFFDIO_REGISTER_MODE_MINOR ) && test_uffdio_minor)) + ioctls &= ~(1 << _UFFDIO_CONTINUE); + +return ioctls; +} + +static void assert_expected_ioctls_present (uint64_t mode,uint64_t ioctls) +{ +uint64_t expected =get_expected_ioctls (mode); +uint64_t actual = ioctls & expected; + +if (actual != expected) { +err ("missing ioctl(s): expected %" PRIx64" actual: %" PRIx64, + expected, actual); + } +} +static void userfaultfd_open (uint64_t *features) {struct uffdio_api uffdio_api;
@@ -1017,11 +1031,9 @@ static int __uffdio_zeropage(int ufd, un {struct uffdio_zeropage uffdio_zeropage;int ret; -unsigned long has_zeropage; +bool has_zeropage =get_expected_ioctls (0 ) & (1 << _UFFDIO_ZEROPAGE);__s64 res; - has_zeropage = uffd_test_ops->expected_ioctls & (1 << _UFFDIO_ZEROPAGE); -if (offset >= nr_pages * page_size)err ("unexpected offset %lu" , offset); uffdio_zeropage.range.start = (unsigned long ) area_dst + offset;
@@ -1061,7 +1073,6 @@ static int uffdio_zeropage(int ufd, unsistatic int userfaultfd_zeropage_test (void ) {struct uffdio_register uffdio_register; -unsigned long expected_ioctls;printf ("testing UFFDIO_ZEROPAGE: " );fflush (stdout);
@@ -1076,9 +1087,8 @@ static int userfaultfd_zeropage_test(voiif (ioctl (uffd,UFFDIO_REGISTER , &uffdio_register))err ("register failure" ); - expected_ioctls = uffd_test_ops->expected_ioctls; -if ((uffdio_register.ioctls & expected_ioctls) != expected_ioctls) -err ("unexpected missing ioctl for anon memory" ); +assert_expected_ioctls_present ( + uffdio_register.mode, uffdio_register.ioctls);if (uffdio_zeropage (uffd,0 ))if (my_bcmp (area_dst, zeropage, page_size))
@@ -1091,7 +1101,6 @@ static int userfaultfd_zeropage_test(voistatic int userfaultfd_events_test (void ) {struct uffdio_register uffdio_register; -unsigned long expected_ioctls;pthread_t uffd_mon;int err, features;pid_t pid;
@@ -1115,9 +1124,8 @@ static int userfaultfd_events_test(void)if (ioctl (uffd,UFFDIO_REGISTER , &uffdio_register))err ("register failure" ); - expected_ioctls = uffd_test_ops->expected_ioctls; -if ((uffdio_register.ioctls & expected_ioctls) != expected_ioctls) -err ("unexpected missing ioctl for anon memory" ); +assert_expected_ioctls_present ( + uffdio_register.mode, uffdio_register.ioctls);if (pthread_create (&uffd_mon, &attr, uffd_poll_thread, &stats))err ("uffd_poll_thread create" );
@@ -1145,7 +1153,6 @@ static int userfaultfd_events_test(void)static int userfaultfd_sig_test (void ) {struct uffdio_register uffdio_register; -unsigned long expected_ioctls;unsigned long userfaults;pthread_t uffd_mon;int err, features;
@@ -1169,9 +1176,8 @@ static int userfaultfd_sig_test(void)if (ioctl (uffd,UFFDIO_REGISTER , &uffdio_register))err ("register failure" ); - expected_ioctls = uffd_test_ops->expected_ioctls; -if ((uffdio_register.ioctls & expected_ioctls) != expected_ioctls) -err ("unexpected missing ioctl for anon memory" ); +assert_expected_ioctls_present ( + uffdio_register.mode, uffdio_register.ioctls);if (faulting_process (1 ))err ("faulting process failed" );
@@ -1206,7 +1212,6 @@ static int userfaultfd_sig_test(void)static int userfaultfd_minor_test (void ) {struct uffdio_register uffdio_register; -unsigned long expected_ioctls;unsigned long p;pthread_t uffd_mon;uint8_t expected_byte;
@@ -1228,10 +1233,8 @@ static int userfaultfd_minor_test(void)if (ioctl (uffd,UFFDIO_REGISTER , &uffdio_register))err ("register failure" ); - expected_ioctls = uffd_test_ops->expected_ioctls; - expected_ioctls |=1 << _UFFDIO_CONTINUE; -if ((uffdio_register.ioctls & expected_ioctls) != expected_ioctls) -err ("unexpected missing ioctl(s)" ); +assert_expected_ioctls_present ( + uffdio_register.mode, uffdio_register.ioctls);/* * After registering with UFFD, populate the non-UFFD-registered side of
@@ -1428,8 +1431,6 @@ static int userfaultfd_stress(void)pthread_attr_setstacksize (&attr,16 *1024 *1024 );while (bounces--) { -unsigned long expected_ioctls; -printf ("bounces: %d, mode:" , bounces);if (bounces &BOUNCE_RANDOM )printf (" rnd" );
@@ -1457,10 +1458,8 @@ static int userfaultfd_stress(void) uffdio_register.mode |=UFFDIO_REGISTER_MODE_WP ;if (ioctl (uffd,UFFDIO_REGISTER , &uffdio_register))err ("register failure" ); - expected_ioctls = uffd_test_ops->expected_ioctls; -if ((uffdio_register.ioctls & expected_ioctls) != - expected_ioctls) -err ("unexpected missing ioctl for anon memory" ); +assert_expected_ioctls_present ( + uffdio_register.mode, uffdio_register.ioctls);if (area_dst_alias) { uffdio_register.range.start = (unsigned long)
_
Andrew Morton
maintainerPATCH 146/262 mm/page_isolation: fix potential missing call to unset_migratetype_isolate()
In reply to Andrew MortonFrom: Miaohe Lin <[email protected]>
Subject: mm/page_isolation: fix potential missing call to unset_migratetype_isolate()
In start_isolate_page_range() undo path, pfn_to_online_page() just checks the first pfn in a pageblock while __first_valid_page() will traverse the pageblock until the first online pfn is found. So we may miss the call to unset_migratetype_isolate() in undo path and pages will remain isolated unexpectedly. Fix this by calling undo_isolate_page_range() and this will also help to simplify the code further. Note we shouldn't ever trigger it because MAX_ORDER-1 aligned pfn ranges shouldn't contain memory holes now.
---
mm/page_isolation.c | 20 +++----------------- 1 file changed, 3 insertions(+), 17 deletions(-)
mm/page_isolation.c renamed from mm/page_isolation.c~mm-page_isolation-fix-potential-missing-call-to-unset_migratetype_isolate +3 -17
@@ -183,7 +183,6 @@ int start_isolate_page_range(unsigned lo unsigned migratetype, int flags) {unsigned long pfn; -unsigned long undo_pfn;struct page *page;BUG_ON (!IS_ALIGNED (start_pfn, pageblock_nr_pages));
@@ -193,25 +192,12 @@ int start_isolate_page_range(unsigned lo pfn < end_pfn; pfn += pageblock_nr_pages) { page =__first_valid_page (pfn, pageblock_nr_pages); -if (page) { -if (set_migratetype_isolate (page, migratetype, flags)) { - undo_pfn = pfn; - goto undo; - } +if (page &&set_migratetype_isolate (page, migratetype, flags)) { +undo_isolate_page_range (start_pfn, pfn, migratetype); +return -EBUSY ; } }return 0 ; -undo: -for (pfn = start_pfn; - pfn < undo_pfn; - pfn += pageblock_nr_pages) { -struct page *page =pfn_to_online_page (pfn); -if (!page) -continue ; -unset_migratetype_isolate (page, migratetype); - } - -return -EBUSY ; }/*
_
Andrew Morton
maintainerPATCH 147/262 mm/page_isolation: guard against possible putback unisolated page
In reply to Andrew MortonFrom: Miaohe Lin <[email protected]>
Subject: mm/page_isolation: guard against possible putback unisolated page
Isolating a free page in an isolated pageblock is expected to always work as watermarks don't apply here. But if __isolate_free_page() failed, due to condition changes, the page will be left on the free list. And the page will be put back to free list again via __putback_isolated_page(). This may trigger VM_BUG_ON_PAGE() on page->flags checking in __free_one_page() if PageReported is set. Or we will corrupt the free list because list_add() will be called for pages already on another list. Add a VM_WARN_ON() to complain about this change.
---
mm/page_isolation.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)
mm/page_isolation.c renamed from mm/page_isolation.c~mm-page_isolation-guard-against-possible-putback-unisolated-page +7 -2
@@ -94,8 +94,13 @@ static void unset_migratetype_isolate(st buddy = page + (buddy_pfn - pfn);if (!is_migrate_isolate_page (buddy)) { -__isolate_free_page (page, order); - isolated_page = true; + isolated_page = !!__isolate_free_page (page, order); +/* +* Isolating a free page in an isolated pageblock +* is expected to always work as watermarks don't +* apply here. +*/ +VM_WARN_ON (!isolated_page); } } }
_
Andrew Morton
maintainerPATCH 148/262 mm/vmscan.c: fix -Wunused-but-set-variable warning
In reply to Andrew MortonFrom: Kai Song <[email protected]>
Subject: mm/vmscan.c: fix -Wunused-but-set-variable warning
We fix the following warning when building kernel with W=1:mm/vmscan.c:1362:6: warning: variable 'err' set but not used [-Wunused-but-set-variable]
---
mm/vmscan.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
mm/vmscan.c renamed from mm/vmscan.c~mm-vmscanc-fix-wunused-but-set-variable-warning +1 -2
@@ -1337,7 +1337,6 @@ static unsigned int demote_page_list(str {int target_nid =next_demotion_node (pgdat->node_id);unsigned int nr_succeeded; -int err;if (list_empty (demote_pages))return 0 ;
@@ -1346,7 +1345,7 @@ static unsigned int demote_page_list(strreturn 0 ;/* Demotion ignores all cpuset and mempolicy settings */ - err =migrate_pages (demote_pages, alloc_demote_page,NULL , +migrate_pages (demote_pages, alloc_demote_page,NULL , target_nid,MIGRATE_ASYNC ,MR_DEMOTION , &nr_succeeded);
_
Andrew Morton
maintainerPATCH 149/262 mm/vmscan: throttle reclaim until some writeback completes if congested
In reply to Andrew MortonFrom: Mel Gorman <[email protected]>
Subject: mm/vmscan: throttle reclaim until some writeback completes if congested
Patch series "Remove dependency on congestion_wait in mm/", v5.
This series that removes all calls to congestion_wait in mm/ and deletes wait_iff_congested. It's not a clever implementation but congestion_wait has been broken for a long time
(https://lore.kernel.org/linux-mm/[email protected]/).
Even if congestion throttling worked, it was never a great idea. While excessive dirty/writeback pages at the tail of the LRU is one possibility that reclaim may be slow, there is also the problem of too many pages being isolated and reclaim failing for other reasons (elevated references, too many pages isolated, excessive LRU contention etc).
This series replaces the "congestion" throttling with 3 different types.
o If there are too many dirty/writeback pages, sleep until a timeout or enough pages get cleaned
o If too many pages are isolated, sleep until enough isolated pages are either reclaimed or put back on the LRU
o If no progress is being made, direct reclaim tasks sleep until another task makes progress with acceptable efficiency.
This was initially tested with a mix of workloads that used to trigger corner cases that no longer work. A new test case was created called "stutterp" (pagereclaim-stutterp-noreaders in mmtests) using a freshly created XFS filesystem. Note that it may be necessary to increase the timeout of ssh if executing remotely as ssh itself can get throttled and the connection may timeout.
stutterp varies the number of "worker" processes from 4 up to NR_CPUS*4 to check the impact as the number of direct reclaimers increase. It has four types of worker.
o One "anon latency" worker creates small mappings with mmap() and times how long it takes to fault the mapping reading it 4K at a time
o X file writers which is fio randomly writing X files where the total size of the files add up to the allowed dirty_ratio. fio is allowed to run for a warmup period to allow some file-backed pages to accumulate. The duration of the warmup is based on the best-case linear write speed of the storage.
o Y file readers which is fio randomly reading small files
o Z anon memory hogs which continually map (100-dirty_ratio)% of memory
o Total estimated WSS = (100+dirty_ration) percentage of memory
X+Y+Z+1 == NR_WORKERS varying from 4 up to NR_CPUS*4
The intent is to maximise the total WSS with a mix of file and anon memory where some anonymous memory must be swapped and there is a high likelihood of dirty/writeback pages reaching the end of the LRU.
The test can be configured to have no background readers to stress dirty/writeback pages. The results below are based on having zero readers.
The short summary of the results is that the series works and stalls until some event occurs but the timeouts may need adjustment.
The test results are not broken down by patch as the series should be treated as one block that replaces a broken throttling mechanism with a working one.
Finally, three machines were tested but I'm reporting the worst set of results. The other two machines had much better latencies for example.
First the results of the "anon latency" latency
stutterp
5.15.0-rc1 5.15.0-rc1
vanilla mm-reclaimcongest-v5r4
Amean mmap-4 31.4003 ( 0.00%) 2661.0198 (-8374.52%)
Amean mmap-7 38.1641 ( 0.00%) 149.2891 (-291.18%)
Amean mmap-12 60.0981 ( 0.00%) 187.8105 (-212.51%)
Amean mmap-21 161.2699 ( 0.00%) 213.9107 ( -32.64%)
Amean mmap-30 174.5589 ( 0.00%) 377.7548 (-116.41%)
Amean mmap-48 8106.8160 ( 0.00%) 1070.5616 ( 86.79%)
Stddev mmap-4 41.3455 ( 0.00%) 27573.9676 (-66591.66%)
Stddev mmap-7 53.5556 ( 0.00%) 4608.5860 (-8505.23%)
Stddev mmap-12 171.3897 ( 0.00%) 5559.4542 (-3143.75%)
Stddev mmap-21 1506.6752 ( 0.00%) 5746.2507 (-281.39%)
Stddev mmap-30 557.5806 ( 0.00%) 7678.1624 (-1277.05%)
Stddev mmap-48 61681.5718 ( 0.00%) 14507.2830 ( 76.48%)
Max-90 mmap-4 31.4243 ( 0.00%) 83.1457 (-164.59%)
Max-90 mmap-7 41.0410 ( 0.00%) 41.0720 ( -0.08%)
Max-90 mmap-12 66.5255 ( 0.00%) 53.9073 ( 18.97%)
Max-90 mmap-21 146.7479 ( 0.00%) 105.9540 ( 27.80%)
Max-90 mmap-30 193.9513 ( 0.00%) 64.3067 ( 66.84%)
Max-90 mmap-48 277.9137 ( 0.00%) 591.0594 (-112.68%)
Max mmap-4 1913.8009 ( 0.00%) 299623.9695 (-15555.96%)
Max mmap-7 2423.9665 ( 0.00%) 204453.1708 (-8334.65%)
Max mmap-12 6845.6573 ( 0.00%) 221090.3366 (-3129.64%)
Max mmap-21 56278.6508 ( 0.00%) 213877.3496 (-280.03%)
Max mmap-30 19716.2990 ( 0.00%) 216287.6229 (-997.00%)
Max mmap-48 477923.9400 ( 0.00%) 245414.8238 ( 48.65%)For most thread counts, the time to mmap() is unfortunately increased. In earlier versions of the series, this was lower but a large number of throttling events were reaching their timeout increasing the amount of inefficient scanning of the LRU. There is no prioritisation of reclaim tasks making progress based on each tasks rate of page allocation versus progress of reclaim. The variance is also impacted for high worker counts but in all cases, the differences in latency are not statistically significant due to very large maximum outliers. Max-90 shows that 90% of the stalls are comparable but the Max results show the massive outliers which are increased to to stalling.
It is expected that this will be very machine dependant. Due to the test design, reclaim is difficult so allocations stall and there are variances depending on whether THPs can be allocated or not. The amount of memory will affect exactly how bad the corner cases are and how often they trigger. The warmup period calculation is not ideal as it's based on linear writes where as fio is randomly writing multiple files from multiple tasks so the start state of the test is variable. For example, these are the latencies on a single-socket machine that had more memory
Amean mmap-4 42.2287 ( 0.00%) 49.6838 * -17.65%* Amean mmap-7 216.4326 ( 0.00%) 47.4451 * 78.08%* Amean mmap-12 2412.0588 ( 0.00%) 51.7497 ( 97.85%) Amean mmap-21 5546.2548 ( 0.00%) 51.8862 ( 99.06%) Amean mmap-30 1085.3121 ( 0.00%) 72.1004 ( 93.36%)
The overall system CPU usage and elapsed time is as follows
5.15.0-rc3 5.15.0-rc3
vanilla mm-reclaimcongest-v5r4
Duration User 6989.03 983.42
Duration System 7308.12 799.68
Duration Elapsed 2277.67 2092.98The patches reduce system CPU usage by 89% as the vanilla kernel is rarely stalling.
The high-level /proc/vmstats show
5.15.0-rc1 5.15.0-rc1
vanilla mm-reclaimcongest-v5r2Ops Direct pages scanned 1056608451.00 503594991.00
Ops Kswapd pages scanned 109795048.00 147289810.00
Ops Kswapd pages reclaimed 63269243.00 31036005.00
Ops Direct pages reclaimed 10803973.00 6328887.00
Ops Kswapd efficiency % 57.62 21.07
Ops Kswapd velocity 48204.98 57572.86
Ops Direct efficiency % 1.02 1.26
Ops Direct velocity 463898.83 196845.97
Kswapd scanned less pages but the detailed pattern is different. The vanilla kernel scans slowly over time where as the patches exhibits burst patterns of scan activity. Direct reclaim scanning is reduced by 52% due to stalling.
The pattern for stealing pages is also slightly different. Both kernels exhibit spikes but the vanilla kernel when reclaiming shows pages being reclaimed over a period of time where as the patches tend to reclaim in spikes. The difference is that vanilla is not throttling and instead scanning constantly finding some pages over time where as the patched kernel throttles and reclaims in spikes.
Ops Percentage direct scans 90.59 77.37
For direct reclaim, vanilla scanned 90.59% of pages where as with the patches, 77.37% were direct reclaim due to throttling
Ops Page writes by reclaim 2613590.00 1687131.00
Page writes from reclaim context are reduced.
Ops Page writes anon 2932752.00 1917048.00
And there is less swapping.
Ops Page reclaim immediate 996248528.00 107664764.00
The number of pages encountered at the tail of the LRU tagged for immediate reclaim but still dirty/writeback is reduced by 89%.
Ops Slabs scanned 164284.00 153608.00
Slab scan activity is similar.
ftrace was used to gather stall activity
Vanilla
-------
1 writeback_wait_iff_congested: usec_timeout=100000 usec_delayed=16000
2 writeback_wait_iff_congested: usec_timeout=100000 usec_delayed=12000
8 writeback_wait_iff_congested: usec_timeout=100000 usec_delayed=8000
29 writeback_wait_iff_congested: usec_timeout=100000 usec_delayed=4000 82394 writeback_wait_iff_congested: usec_timeout=100000 usec_delayed=0
The fast majority of wait_iff_congested calls do not stall at all. What is likely happening is that cond_resched() reschedules the task for a short period when the BDI is not registering congestion (which it never will in this test setup).
1 writeback_congestion_wait: usec_timeout=100000 usec_delayed=120000
2 writeback_congestion_wait: usec_timeout=100000 usec_delayed=132000
4 writeback_congestion_wait: usec_timeout=100000 usec_delayed=112000
380 writeback_congestion_wait: usec_timeout=100000 usec_delayed=108000
778 writeback_congestion_wait: usec_timeout=100000 usec_delayed=104000congestion_wait if called always exceeds the timeout as there is no trigger to wake it up.
Bottom line: Vanilla will throttle but it's not effective.
Patch series
------------
Kswapd throttle activity was always due to scanning pages tagged for immediate reclaim at the tail of the LRU
1 usec_timeout=100000 usect_delayed=72000 reason=VMSCAN_THROTTLE_WRITEBACK
4 usec_timeout=100000 usect_delayed=20000 reason=VMSCAN_THROTTLE_WRITEBACK
5 usec_timeout=100000 usect_delayed=12000 reason=VMSCAN_THROTTLE_WRITEBACK
6 usec_timeout=100000 usect_delayed=16000 reason=VMSCAN_THROTTLE_WRITEBACK
11 usec_timeout=100000 usect_delayed=100000 reason=VMSCAN_THROTTLE_WRITEBACK
11 usec_timeout=100000 usect_delayed=8000 reason=VMSCAN_THROTTLE_WRITEBACK
94 usec_timeout=100000 usect_delayed=0 reason=VMSCAN_THROTTLE_WRITEBACK
112 usec_timeout=100000 usect_delayed=4000 reason=VMSCAN_THROTTLE_WRITEBACKThe majority of events did not stall or stalled for a short period. Roughly 16% of stalls reached the timeout before expiry. For direct reclaim, the number of times stalled for each reason were
6624 reason=VMSCAN_THROTTLE_ISOLATED
93246 reason=VMSCAN_THROTTLE_NOPROGRESS
96934 reason=VMSCAN_THROTTLE_WRITEBACK
The most common reason to stall was due to excessive pages tagged for immediate reclaim at the tail of the LRU followed by a failure to make forward. A relatively small number were due to too many pages isolated from the LRU by parallel threads
For VMSCAN_THROTTLE_ISOLATED, the breakdown of delays was
9 usec_timeout=20000 usect_delayed=4000 reason=VMSCAN_THROTTLE_ISOLATED
12 usec_timeout=20000 usect_delayed=16000 reason=VMSCAN_THROTTLE_ISOLATED
83 usec_timeout=20000 usect_delayed=20000 reason=VMSCAN_THROTTLE_ISOLATED6520 usec_timeout=20000 usect_delayed=0 reason=VMSCAN_THROTTLE_ISOLATED
Most did not stall at all. A small number reached the timeout.
For VMSCAN_THROTTLE_NOPROGRESS, the breakdown of stalls were all over the map
1 usec_timeout=500000 usect_delayed=324000 reason=VMSCAN_THROTTLE_NOPROGRESS
1 usec_timeout=500000 usect_delayed=332000 reason=VMSCAN_THROTTLE_NOPROGRESS
1 usec_timeout=500000 usect_delayed=348000 reason=VMSCAN_THROTTLE_NOPROGRESS
1 usec_timeout=500000 usect_delayed=360000 reason=VMSCAN_THROTTLE_NOPROGRESS
2 usec_timeout=500000 usect_delayed=228000 reason=VMSCAN_THROTTLE_NOPROGRESS
2 usec_timeout=500000 usect_delayed=260000 reason=VMSCAN_THROTTLE_NOPROGRESS
2 usec_timeout=500000 usect_delayed=340000 reason=VMSCAN_THROTTLE_NOPROGRESS
2 usec_timeout=500000 usect_delayed=364000 reason=VMSCAN_THROTTLE_NOPROGRESS
2 usec_timeout=500000 usect_delayed=372000 reason=VMSCAN_THROTTLE_NOPROGRESS
2 usec_timeout=500000 usect_delayed=428000 reason=VMSCAN_THROTTLE_NOPROGRESS
2 usec_timeout=500000 usect_delayed=460000 reason=VMSCAN_THROTTLE_NOPROGRESS
2 usec_timeout=500000 usect_delayed=464000 reason=VMSCAN_THROTTLE_NOPROGRESS
3 usec_timeout=500000 usect_delayed=244000 reason=VMSCAN_THROTTLE_NOPROGRESS
3 usec_timeout=500000 usect_delayed=252000 reason=VMSCAN_THROTTLE_NOPROGRESS
3 usec_timeout=500000 usect_delayed=272000 reason=VMSCAN_THROTTLE_NOPROGRESS
4 usec_timeout=500000 usect_delayed=188000 reason=VMSCAN_THROTTLE_NOPROGRESS
4 usec_timeout=500000 usect_delayed=268000 reason=VMSCAN_THROTTLE_NOPROGRESS
4 usec_timeout=500000 usect_delayed=328000 reason=VMSCAN_THROTTLE_NOPROGRESS
4 usec_timeout=500000 usect_delayed=380000 reason=VMSCAN_THROTTLE_NOPROGRESS
4 usec_timeout=500000 usect_delayed=392000 reason=VMSCAN_THROTTLE_NOPROGRESS
4 usec_timeout=500000 usect_delayed=432000 reason=VMSCAN_THROTTLE_NOPROGRESS
5 usec_timeout=500000 usect_delayed=204000 reason=VMSCAN_THROTTLE_NOPROGRESS
5 usec_timeout=500000 usect_delayed=220000 reason=VMSCAN_THROTTLE_NOPROGRESS
5 usec_timeout=500000 usect_delayed=412000 reason=VMSCAN_THROTTLE_NOPROGRESS
5 usec_timeout=500000 usect_delayed=436000 reason=VMSCAN_THROTTLE_NOPROGRESS
6 usec_timeout=500000 usect_delayed=488000 reason=VMSCAN_THROTTLE_NOPROGRESS
7 usec_timeout=500000 usect_delayed=212000 reason=VMSCAN_THROTTLE_NOPROGRESS
7 usec_timeout=500000 usect_delayed=300000 reason=VMSCAN_THROTTLE_NOPROGRESS
7 usec_timeout=500000 usect_delayed=316000 reason=VMSCAN_THROTTLE_NOPROGRESS
7 usec_timeout=500000 usect_delayed=472000 reason=VMSCAN_THROTTLE_NOPROGRESS
8 usec_timeout=500000 usect_delayed=248000 reason=VMSCAN_THROTTLE_NOPROGRESS
8 usec_timeout=500000 usect_delayed=356000 reason=VMSCAN_THROTTLE_NOPROGRESS
8 usec_timeout=500000 usect_delayed=456000 reason=VMSCAN_THROTTLE_NOPROGRESS
9 usec_timeout=500000 usect_delayed=124000 reason=VMSCAN_THROTTLE_NOPROGRESS
9 usec_timeout=500000 usect_delayed=376000 reason=VMSCAN_THROTTLE_NOPROGRESS
9 usec_timeout=500000 usect_delayed=484000 reason=VMSCAN_THROTTLE_NOPROGRESS
10 usec_timeout=500000 usect_delayed=172000 reason=VMSCAN_THROTTLE_NOPROGRESS
10 usec_timeout=500000 usect_delayed=420000 reason=VMSCAN_THROTTLE_NOPROGRESS
10 usec_timeout=500000 usect_delayed=452000 reason=VMSCAN_THROTTLE_NOPROGRESS
11 usec_timeout=500000 usect_delayed=256000 reason=VMSCAN_THROTTLE_NOPROGRESS
12 usec_timeout=500000 usect_delayed=112000 reason=VMSCAN_THROTTLE_NOPROGRESS
12 usec_timeout=500000 usect_delayed=116000 reason=VMSCAN_THROTTLE_NOPROGRESS
12 usec_timeout=500000 usect_delayed=144000 reason=VMSCAN_THROTTLE_NOPROGRESS
12 usec_timeout=500000 usect_delayed=152000 reason=VMSCAN_THROTTLE_NOPROGRESS
12 usec_timeout=500000 usect_delayed=264000 reason=VMSCAN_THROTTLE_NOPROGRESS
12 usec_timeout=500000 usect_delayed=384000 reason=VMSCAN_THROTTLE_NOPROGRESS
12 usec_timeout=500000 usect_delayed=424000 reason=VMSCAN_THROTTLE_NOPROGRESS
12 usec_timeout=500000 usect_delayed=492000 reason=VMSCAN_THROTTLE_NOPROGRESS
13 usec_timeout=500000 usect_delayed=184000 reason=VMSCAN_THROTTLE_NOPROGRESS
13 usec_timeout=500000 usect_delayed=444000 reason=VMSCAN_THROTTLE_NOPROGRESS
14 usec_timeout=500000 usect_delayed=308000 reason=VMSCAN_THROTTLE_NOPROGRESS
14 usec_timeout=500000 usect_delayed=440000 reason=VMSCAN_THROTTLE_NOPROGRESS
14 usec_timeout=500000 usect_delayed=476000 reason=VMSCAN_THROTTLE_NOPROGRESS
16 usec_timeout=500000 usect_delayed=140000 reason=VMSCAN_THROTTLE_NOPROGRESS
17 usec_timeout=500000 usect_delayed=232000 reason=VMSCAN_THROTTLE_NOPROGRESS
17 usec_timeout=500000 usect_delayed=240000 reason=VMSCAN_THROTTLE_NOPROGRESS
17 usec_timeout=500000 usect_delayed=280000 reason=VMSCAN_THROTTLE_NOPROGRESS
18 usec_timeout=500000 usect_delayed=404000 reason=VMSCAN_THROTTLE_NOPROGRESS
20 usec_timeout=500000 usect_delayed=148000 reason=VMSCAN_THROTTLE_NOPROGRESS
20 usec_timeout=500000 usect_delayed=216000 reason=VMSCAN_THROTTLE_NOPROGRESS
20 usec_timeout=500000 usect_delayed=468000 reason=VMSCAN_THROTTLE_NOPROGRESS
21 usec_timeout=500000 usect_delayed=448000 reason=VMSCAN_THROTTLE_NOPROGRESS
23 usec_timeout=500000 usect_delayed=168000 reason=VMSCAN_THROTTLE_NOPROGRESS
23 usec_timeout=500000 usect_delayed=296000 reason=VMSCAN_THROTTLE_NOPROGRESS
25 usec_timeout=500000 usect_delayed=132000 reason=VMSCAN_THROTTLE_NOPROGRESS
25 usec_timeout=500000 usect_delayed=352000 reason=VMSCAN_THROTTLE_NOPROGRESS
26 usec_timeout=500000 usect_delayed=180000 reason=VMSCAN_THROTTLE_NOPROGRESS
27 usec_timeout=500000 usect_delayed=284000 reason=VMSCAN_THROTTLE_NOPROGRESS
28 usec_timeout=500000 usect_delayed=164000 reason=VMSCAN_THROTTLE_NOPROGRESS
29 usec_timeout=500000 usect_delayed=136000 reason=VMSCAN_THROTTLE_NOPROGRESS
30 usec_timeout=500000 usect_delayed=200000 reason=VMSCAN_THROTTLE_NOPROGRESS
30 usec_timeout=500000 usect_delayed=400000 reason=VMSCAN_THROTTLE_NOPROGRESS
31 usec_timeout=500000 usect_delayed=196000 reason=VMSCAN_THROTTLE_NOPROGRESS
32 usec_timeout=500000 usect_delayed=156000 reason=VMSCAN_THROTTLE_NOPROGRESS
33 usec_timeout=500000 usect_delayed=224000 reason=VMSCAN_THROTTLE_NOPROGRESS
35 usec_timeout=500000 usect_delayed=128000 reason=VMSCAN_THROTTLE_NOPROGRESS
35 usec_timeout=500000 usect_delayed=176000 reason=VMSCAN_THROTTLE_NOPROGRESS
36 usec_timeout=500000 usect_delayed=368000 reason=VMSCAN_THROTTLE_NOPROGRESS
36 usec_timeout=500000 usect_delayed=496000 reason=VMSCAN_THROTTLE_NOPROGRESS
37 usec_timeout=500000 usect_delayed=312000 reason=VMSCAN_THROTTLE_NOPROGRESS
38 usec_timeout=500000 usect_delayed=304000 reason=VMSCAN_THROTTLE_NOPROGRESS
40 usec_timeout=500000 usect_delayed=288000 reason=VMSCAN_THROTTLE_NOPROGRESS
43 usec_timeout=500000 usect_delayed=408000 reason=VMSCAN_THROTTLE_NOPROGRESS
55 usec_timeout=500000 usect_delayed=416000 reason=VMSCAN_THROTTLE_NOPROGRESS
56 usec_timeout=500000 usect_delayed=76000 reason=VMSCAN_THROTTLE_NOPROGRESS
58 usec_timeout=500000 usect_delayed=120000 reason=VMSCAN_THROTTLE_NOPROGRESS
59 usec_timeout=500000 usect_delayed=208000 reason=VMSCAN_THROTTLE_NOPROGRESS
61 usec_timeout=500000 usect_delayed=68000 reason=VMSCAN_THROTTLE_NOPROGRESS
71 usec_timeout=500000 usect_delayed=192000 reason=VMSCAN_THROTTLE_NOPROGRESS
71 usec_timeout=500000 usect_delayed=480000 reason=VMSCAN_THROTTLE_NOPROGRESS
79 usec_timeout=500000 usect_delayed=60000 reason=VMSCAN_THROTTLE_NOPROGRESS
82 usec_timeout=500000 usect_delayed=320000 reason=VMSCAN_THROTTLE_NOPROGRESS
82 usec_timeout=500000 usect_delayed=92000 reason=VMSCAN_THROTTLE_NOPROGRESS
85 usec_timeout=500000 usect_delayed=64000 reason=VMSCAN_THROTTLE_NOPROGRESS
85 usec_timeout=500000 usect_delayed=80000 reason=VMSCAN_THROTTLE_NOPROGRESS
88 usec_timeout=500000 usect_delayed=84000 reason=VMSCAN_THROTTLE_NOPROGRESS
90 usec_timeout=500000 usect_delayed=160000 reason=VMSCAN_THROTTLE_NOPROGRESS
90 usec_timeout=500000 usect_delayed=292000 reason=VMSCAN_THROTTLE_NOPROGRESS
94 usec_timeout=500000 usect_delayed=56000 reason=VMSCAN_THROTTLE_NOPROGRESS
118 usec_timeout=500000 usect_delayed=88000 reason=VMSCAN_THROTTLE_NOPROGRESS
119 usec_timeout=500000 usect_delayed=72000 reason=VMSCAN_THROTTLE_NOPROGRESS
126 usec_timeout=500000 usect_delayed=108000 reason=VMSCAN_THROTTLE_NOPROGRESS
146 usec_timeout=500000 usect_delayed=52000 reason=VMSCAN_THROTTLE_NOPROGRESS
148 usec_timeout=500000 usect_delayed=36000 reason=VMSCAN_THROTTLE_NOPROGRESS
148 usec_timeout=500000 usect_delayed=48000 reason=VMSCAN_THROTTLE_NOPROGRESS
159 usec_timeout=500000 usect_delayed=28000 reason=VMSCAN_THROTTLE_NOPROGRESS
178 usec_timeout=500000 usect_delayed=44000 reason=VMSCAN_THROTTLE_NOPROGRESS
183 usec_timeout=500000 usect_delayed=40000 reason=VMSCAN_THROTTLE_NOPROGRESS
237 usec_timeout=500000 usect_delayed=100000 reason=VMSCAN_THROTTLE_NOPROGRESS
266 usec_timeout=500000 usect_delayed=32000 reason=VMSCAN_THROTTLE_NOPROGRESS
313 usec_timeout=500000 usect_delayed=24000 reason=VMSCAN_THROTTLE_NOPROGRESS
347 usec_timeout=500000 usect_delayed=96000 reason=VMSCAN_THROTTLE_NOPROGRESS
470 usec_timeout=500000 usect_delayed=20000 reason=VMSCAN_THROTTLE_NOPROGRESS
559 usec_timeout=500000 usect_delayed=16000 reason=VMSCAN_THROTTLE_NOPROGRESS
964 usec_timeout=500000 usect_delayed=12000 reason=VMSCAN_THROTTLE_NOPROGRESS 2001 usec_timeout=500000 usect_delayed=104000 reason=VMSCAN_THROTTLE_NOPROGRESS 2447 usec_timeout=500000 usect_delayed=8000 reason=VMSCAN_THROTTLE_NOPROGRESS 7888 usec_timeout=500000 usect_delayed=4000 reason=VMSCAN_THROTTLE_NOPROGRESS
22727 usec_timeout=500000 usect_delayed=0 reason=VMSCAN_THROTTLE_NOPROGRESS 51305 usec_timeout=500000 usect_delayed=500000 reason=VMSCAN_THROTTLE_NOPROGRESS
The full timeout is often hit but a large number also do not stall at all. The remainder slept a little allowing other reclaim tasks to make progress.
While this timeout could be further increased, it could also negatively impact worst-case behaviour when there is no prioritisation of what task should make progress.
For VMSCAN_THROTTLE_WRITEBACK, the breakdown was
1 usec_timeout=100000 usect_delayed=44000 reason=VMSCAN_THROTTLE_WRITEBACK
2 usec_timeout=100000 usect_delayed=76000 reason=VMSCAN_THROTTLE_WRITEBACK
3 usec_timeout=100000 usect_delayed=80000 reason=VMSCAN_THROTTLE_WRITEBACK
5 usec_timeout=100000 usect_delayed=48000 reason=VMSCAN_THROTTLE_WRITEBACK
5 usec_timeout=100000 usect_delayed=84000 reason=VMSCAN_THROTTLE_WRITEBACK
6 usec_timeout=100000 usect_delayed=72000 reason=VMSCAN_THROTTLE_WRITEBACK
7 usec_timeout=100000 usect_delayed=88000 reason=VMSCAN_THROTTLE_WRITEBACK
11 usec_timeout=100000 usect_delayed=56000 reason=VMSCAN_THROTTLE_WRITEBACK
12 usec_timeout=100000 usect_delayed=64000 reason=VMSCAN_THROTTLE_WRITEBACK
16 usec_timeout=100000 usect_delayed=92000 reason=VMSCAN_THROTTLE_WRITEBACK
24 usec_timeout=100000 usect_delayed=68000 reason=VMSCAN_THROTTLE_WRITEBACK
28 usec_timeout=100000 usect_delayed=32000 reason=VMSCAN_THROTTLE_WRITEBACK
30 usec_timeout=100000 usect_delayed=60000 reason=VMSCAN_THROTTLE_WRITEBACK
30 usec_timeout=100000 usect_delayed=96000 reason=VMSCAN_THROTTLE_WRITEBACK
32 usec_timeout=100000 usect_delayed=52000 reason=VMSCAN_THROTTLE_WRITEBACK
42 usec_timeout=100000 usect_delayed=40000 reason=VMSCAN_THROTTLE_WRITEBACK
77 usec_timeout=100000 usect_delayed=28000 reason=VMSCAN_THROTTLE_WRITEBACK
99 usec_timeout=100000 usect_delayed=36000 reason=VMSCAN_THROTTLE_WRITEBACK
137 usec_timeout=100000 usect_delayed=24000 reason=VMSCAN_THROTTLE_WRITEBACK
190 usec_timeout=100000 usect_delayed=20000 reason=VMSCAN_THROTTLE_WRITEBACK
339 usec_timeout=100000 usect_delayed=16000 reason=VMSCAN_THROTTLE_WRITEBACK
518 usec_timeout=100000 usect_delayed=12000 reason=VMSCAN_THROTTLE_WRITEBACK
852 usec_timeout=100000 usect_delayed=8000 reason=VMSCAN_THROTTLE_WRITEBACK 3359 usec_timeout=100000 usect_delayed=4000 reason=VMSCAN_THROTTLE_WRITEBACK 7147 usec_timeout=100000 usect_delayed=0 reason=VMSCAN_THROTTLE_WRITEBACK
83962 usec_timeout=100000 usect_delayed=100000 reason=VMSCAN_THROTTLE_WRITEBACK
The majority hit the timeout in direct reclaim context although a sizable number did not stall at all. This is very different to kswapd where only a tiny percentage of stalls due to writeback reached the timeout.
Bottom line, the throttling appears to work and the wakeup events may limit worst case stalls. There might be some grounds for adjusting timeouts but it's likely futile as the worst-case scenarios depend on the workload, memory size and the speed of the storage. A better approach to improve the series further would be to prioritise tasks based on their rate of allocation with the caveat that it may be very expensive to track.
This patch (of 5):
Page reclaim throttles on wait_iff_congested under the following conditions:
o kswapd is encountering pages under writeback and marked for immediate reclaim implying that pages are cycling through the LRU faster than pages can be cleaned.
o Direct reclaim will stall if all dirty pages are backed by congested inodes.
wait_iff_congested is almost completely broken with few exceptions. This patch adds a new node-based workqueue and tracks the number of throttled tasks and pages written back since throttling started. If enough pages belonging to the node are written back then the throttled tasks will wake early. If not, the throttled tasks sleeps until the timeout expires.
---
include/linux/backing-dev.h | 1 include/linux/mmzone.h | 13 ++++ include/trace/events/vmscan.h | 34 ++++++++++++ include/trace/events/writeback.h | 7 -- mm/backing-dev.c | 48 ---------------- mm/filemap.c | 1 mm/internal.h | 11 +++ mm/page_alloc.c | 5 + mm/vmscan.c | 82 ++++++++++++++++++++++++----- mm/vmstat.c | 1 10 files changed, 135 insertions(+), 68 deletions(-)
include/linux/backing-dev.h renamed from include/linux/backing-dev.h~mm-vmscan-throttle-reclaim-until-some-writeback-completes-if-congested +0 -1
@@ -154,7 +154,6 @@ static inline int wb_congested(struct bd }long congestion_wait (int sync,long timeout); -long wait_iff_congested (int sync,long timeout);static inline bool mapping_can_writeback (struct address_space *mapping) {
include/linux/mmzone.h renamed from include/linux/mmzone.h~mm-vmscan-throttle-reclaim-until-some-writeback-completes-if-congested +13 -0
@@ -199,6 +199,7 @@ enum node_stat_item {NR_VMSCAN_IMMEDIATE ,/* Prioritise for reclaim when writeback ends */ NR_DIRTIED ,/* page dirtyings since bootup */ NR_WRITTEN ,/* page writings since bootup */ +NR_THROTTLED_WRITTEN ,/* NR_WRITTEN while reclaim throttled */ NR_KERNEL_MISC_RECLAIMABLE ,/* reclaimable non-slab kernel pages */ NR_FOLL_PIN_ACQUIRED ,/* via: pin_user_page(), gup flag: FOLL_PIN */ NR_FOLL_PIN_RELEASED, /* pages returned via unpin_user_page() */
@@ -272,6 +273,11 @@ enum lru_list { NR_LRU_LISTS }; +enum vmscan_throttle_state { +VMSCAN_THROTTLE_WRITEBACK , +NR_VMSCAN_THROTTLE , +}; +#define for_each_lru (lru) for (lru = 0; lru < NR_LRU_LISTS; lru++)#define for_each_evictable_lru (lru) for (lru = 0; lru <= LRU_ACTIVE_FILE; lru++)
@@ -841,6 +847,13 @@ typedef struct pglist_data {int node_id;wait_queue_head_t kswapd_wait;wait_queue_head_t pfmemalloc_wait; + +/* workqueues for throttling reclaim for different reasons. */ +wait_queue_head_t reclaim_wait[NR_VMSCAN_THROTTLE ]; + +atomic_t nr_writeback_throttled;/* nr of writeback-throttled tasks */ +unsigned long nr_reclaim_start;/* nr pages written while throttled +* when throttling started. */ struct task_struct *kswapd;/* Protected by mem_hotplug_begin/end() */ int kswapd_order;
include/trace/events/vmscan.h renamed from include/trace/events/vmscan.h~mm-vmscan-throttle-reclaim-until-some-writeback-completes-if-congested +34 -0
@@ -27,6 +27,14 @@ {RECLAIM_WB_ASYNC, "RECLAIM_WB_ASYNC"} \ ) : "RECLAIM_WB_NONE" +#define _VMSCAN_THROTTLE_WRITEBACK (1 << VMSCAN_THROTTLE_WRITEBACK) + +#define show_throttle_flags (flags) \ + (flags) ? __print_flags(flags, "|", \ + {_VMSCAN_THROTTLE_WRITEBACK, "VMSCAN_THROTTLE_WRITEBACK"} \ + ) : "VMSCAN_THROTTLE_NONE" + +#define trace_reclaim_flags (file) ( \ (file ? RECLAIM_WB_FILE : RECLAIM_WB_ANON) | \ (RECLAIM_WB_ASYNC) \
@@ -454,6 +462,32 @@ DEFINE_EVENT(mm_vmscan_direct_reclaim_enTP_ARGS (nr_reclaimed) ); +TRACE_EVENT (mm_vmscan_throttled, + + TP_PROTO(int nid, int usec_timeout, int usec_delayed, int reason), + +TP_ARGS (nid, usec_timeout, usec_delayed, reason), + +TP_STRUCT__entry ( + __field(int, nid) + __field(int, usec_timeout) + __field(int, usec_delayed) +__field (int, reason) + ), + +TP_fast_assign ( + __entry->nid = nid; + __entry->usec_timeout = usec_timeout; + __entry->usec_delayed = usec_delayed; + __entry->reason = 1U << reason; + ), + +TP_printk ("nid=%d usec_timeout=%d usect_delayed=%d reason=%s" , + __entry->nid, + __entry->usec_timeout, + __entry->usec_delayed, +show_throttle_flags (__entry->reason)) +);#endif /* _TRACE_VMSCAN_H */ /* This part must be outside protection */
include/trace/events/writeback.h renamed from include/trace/events/writeback.h~mm-vmscan-throttle-reclaim-until-some-writeback-completes-if-congested +0 -7
@@ -763,13 +763,6 @@ DEFINE_EVENT(writeback_congest_waited_teTP_ARGS (usec_timeout, usec_delayed) ); -DEFINE_EVENT (writeback_congest_waited_template, writeback_wait_iff_congested, - - TP_PROTO(unsigned int usec_timeout, unsigned int usec_delayed), - -TP_ARGS (usec_timeout, usec_delayed) -); - DECLARE_EVENT_CLASS(writeback_single_inode_template, TP_PROTO(struct inode *inode,
mm/backing-dev.c renamed from mm/backing-dev.c~mm-vmscan-throttle-reclaim-until-some-writeback-completes-if-congested +0 -48
51 lines not on this page · raw message
mm/filemap.c renamed from mm/filemap.c~mm-vmscan-throttle-reclaim-until-some-writeback-completes-if-congested +1 -0
@@ -1612,6 +1612,7 @@ void end_page_writeback(struct page *pagsmp_mb__after_atomic ();wake_up_page (page, PG_writeback); +acct_reclaim_writeback (page);put_page (page); }EXPORT_SYMBOL (end_page_writeback);
mm/internal.h renamed from mm/internal.h~mm-vmscan-throttle-reclaim-until-some-writeback-completes-if-congested +11 -0
@@ -34,6 +34,17 @@void page_writeback_init (void ); +void __acct_reclaim_writeback (pg_data_t *pgdat,struct page *page, +int nr_throttled); +static inline void acct_reclaim_writeback (struct page *page) +{ +pg_data_t *pgdat =page_pgdat (page); +int nr_throttled =atomic_read (&pgdat->nr_writeback_throttled); + +if (nr_throttled) +__acct_reclaim_writeback (pgdat, page, nr_throttled); +} +vm_fault_t do_swap_page (struct vm_fault *vmf); void free_pgtables(struct mmu_gather *tlb, struct vm_area_struct *start_vma,
mm/page_alloc.c renamed from mm/page_alloc.c~mm-vmscan-throttle-reclaim-until-some-writeback-completes-if-congested +5 -0
@@ -7408,6 +7408,8 @@ static void pgdat_init_kcompactd(structstatic void __meminit pgdat_init_internals (struct pglist_data *pgdat) { +int i; +pgdat_resize_init (pgdat);pgdat_init_split_queue (pgdat);
@@ -7416,6 +7418,9 @@ static void __meminit pgdat_init_internainit_waitqueue_head (&pgdat->kswapd_wait);init_waitqueue_head (&pgdat->pfmemalloc_wait); +for (i =0 ; i <NR_VMSCAN_THROTTLE ; i++) +init_waitqueue_head (&pgdat->reclaim_wait[i]); +pgdat_page_ext_init (pgdat);lruvec_init (&pgdat->__lruvec); }
mm/vmscan.c renamed from mm/vmscan.c~mm-vmscan-throttle-reclaim-until-some-writeback-completes-if-congested +70 -12
125 lines not on this page · raw message
mm/vmstat.c renamed from mm/vmstat.c~mm-vmscan-throttle-reclaim-until-some-writeback-completes-if-congested +1 -0
@@ -1225,6 +1225,7 @@ const char * const vmstat_text[] = {"nr_vmscan_immediate_reclaim" ,"nr_dirtied" ,"nr_written" , +"nr_throttled_written" ,"nr_kernel_misc_reclaimable" ,"nr_foll_pin_acquired" , "nr_foll_pin_released",
_
Matthew Wilcox
maintainerRe: [patch 149/262] mm/vmscan: throttle reclaim until some writeback completes if congested
mm/filemap.c void end_page_writeback(struct page *pag · line 1618
Quoted 10 lines · Andrew Morton
mm/filemap.c renamed from mm/filemap.c~mm-vmscan-throttle-reclaim-until-some-writeback-completes-if-congested +1
-0@@ -1612,6 +1612,7 @@ void end_page_writeback(struct page *pagsmp_mb__after_atomic ();wake_up_page (page, PG_writeback); +acct_reclaim_writeback (page);put_page (page); }EXPORT_SYMBOL (end_page_writeback);
hmm? I think you based on some older version of Linus' tree that didn't have folios. This fixup patch was against an older fixup patch that you did, but maybe it's enough for Linus to apply ...
mm/filemap.c +1 -1
@@ -1607,7 +1607,7 @@ void folio_end_writeback(struct folio *folio)smp_mb__after_atomic ();folio_wake (folio, PG_writeback); -acct_reclaim_writeback (folio_page (folio,0 )); +acct_reclaim_writeback (folio);folio_put (folio); }EXPORT_SYMBOL (folio_end_writeback);
mm/internal.h +4 -4
@@ -41,15 +41,15 @@ static inline void *folio_raw_mapping(struct folio *folio)return (void *)(mapping & ~PAGE_MAPPING_FLAGS ); } -void __acct_reclaim_writeback (pg_data_t *pgdat,struct page *page, +void __acct_reclaim_writeback (pg_data_t *pgdat,struct folio *folio,int nr_throttled); -static inline void acct_reclaim_writeback (struct page *page) +static inline void acct_reclaim_writeback (struct folio *folio) { -pg_data_t *pgdat =page_pgdat (page); +pg_data_t *pgdat =folio_pgdat (folio);int nr_throttled =atomic_read (&pgdat->nr_writeback_throttled);if (nr_throttled) -__acct_reclaim_writeback (pgdat, page, nr_throttled); +__acct_reclaim_writeback (pgdat, folio, nr_throttled); }static inline void wake_throttle_isolated (pg_data_t *pgdat)
mm/vmscan.c +2 -2
@@ -1085,12 +1085,12 @@ void reclaim_throttle(pg_data_t *pgdat, enum vmscan_throttle_state reason)* pages to clean. If enough pages have been cleaned since throttling * started then wakeup the throttled tasks. */ -void __acct_reclaim_writeback (pg_data_t *pgdat,struct page *page, +void __acct_reclaim_writeback (pg_data_t *pgdat,struct folio *folio,int nr_throttled) {unsigned long nr_written; -inc_node_page_state (page,NR_THROTTLED_WRITTEN ); +node_stat_add_folio (folio,NR_THROTTLED_WRITTEN );/* * This is an inaccurate read as the per-cpu deltas may not
Re: [patch 149/262] mm/vmscan: throttle reclaim until some writeback completes if congested
Quoted 3 lines · Matthew Wilcox
hmm? I think you based on some older version of Linus' tree that didn't have folios.
Andrew these days actually maintains a base commit model exactly so that he doesn't end up rebasing during development.
So the whole series is based on plain 5.15, and I'll take care of the conflict resolution.
This workflow can result in more conflicts for me than what Andrew used to do ("send against current linus tip"), but it means that when conflicts happen, they get all the merge resolution help that git gives you, and hopefully what gets tested (over the months that it can be in -mm) is closer to what gets sent to me.
Linus
Re: [patch 149/262] mm/vmscan: throttle reclaim until some writeback completes if congested
Quoted 6 lines · Linus Torvalds
This workflow can result in more conflicts for me than what Andrew used to do ("send against current linus tip"), but it means that when conflicts happen, they get all the merge resolution help that git gives you, and hopefully what gets tested (over the months that it can be in -mm) is closer to what gets sent to me.
.. and resolving the conflicts (none of which looked bad), I think that part of the resolution ends up doing very similar things to your fixup patch.
So it looks all good.
Famous last words.
Linus
Re: [patch 149/262] mm/vmscan: throttle reclaim until some writeback completes if congested
Quoted 9 lines · Linus Torvalds
Quoted 6 lines · Linus Torvalds
This workflow can result in more conflicts for me than what Andrew used to do ("send against current linus tip"), but it means that when conflicts happen, they get all the merge resolution help that git gives you, and hopefully what gets tested (over the months that it can be in -mm) is closer to what gets sent to me.
Quoted 3 lines
.. and resolving the conflicts (none of which looked bad), I think that part of the resolution ends up doing very similar things to your fixup patch.
If this needed resolution, didn't the resolution exist in -next already?
Quoted 6 lines
So it looks all good.
Famous last words.
Linus
Andrew Morton
maintainerRe: [patch 149/262] mm/vmscan: throttle reclaim until some writeback completes if congested
Quoted 10 lines · On Sat, 6 Nov 2021 22:13:34 +0100 Vlastimil Babka <[email protected]> wrote:
Quoted 9 lines · Linus Torvalds
Quoted 6 lines · Linus Torvalds
This workflow can result in more conflicts for me than what Andrew used to do ("send against current linus tip"), but it means that when conflicts happen, they get all the merge resolution help that git gives you, and hopefully what gets tested (over the months that it can be in -mm) is closer to what gets sent to me.
Quoted 5 lines
Quoted 3 lines
.. and resolving the conflicts (none of which looked bad), I think that part of the resolution ends up doing very similar things to your fixup patch.
If this needed resolution, didn't the resolution exist in -next already?
Yes, but I had it queued after linux-next.patch so it got lost in the unholy mess that linux-next becomes during the merge window.
I'm still figuring this out. In retrospect I should have moved this patch "mm/vmscan: throttle reclaim until some writeback completes if congested" to the post-linux-next section weeks ago, then waited for the prerequisites to be merged into mainline. That way the unaltered, tested patch would have smoothly slotted in late in the merge window.
Re: [patch 149/262] mm/vmscan: throttle reclaim until some writeback completes if congested
In reply to Vlastimil BabkaQuoted 2 lines · Vlastimil Babka
If this needed resolution, didn't the resolution exist in -next already?
Oh, I'm sure it was there in -next.
But I just always do my own merge resolution anyway because I want to see what's going on.
I don't look at other peoples resolutions, and I much prefer to actually look at the history itself in order to actually understand what the history and cause for the conflicts is (and what the proper resolution was).
Of course, in many cases it's so trivial that there's not a lot to "understand", and most merge conflicts by far are not the kind that need a lot of thought.
But just to clarify: I do actually like seeing people send their resolutions to me (possibly as an addendum to the pull request email, or possibly as a separate "resolved" branch).
I don't use those to guide my resolution, but if there is any subtle issues at all, I will then compare the end results to verify that they agreed. Often any differences tend to be just whitespace or similar, but it can be interesting to see when there are meaningful semantic differences.
Linus
Matthew Wilcox
maintainerRe: [patch 149/262] mm/vmscan: throttle reclaim until some writeback completes if congested
In reply to Linus TorvaldsQuoted 9 lines · Linus Torvalds
Quoted 6 lines · Linus Torvalds
This workflow can result in more conflicts for me than what Andrew used to do ("send against current linus tip"), but it means that when conflicts happen, they get all the merge resolution help that git gives you, and hopefully what gets tested (over the months that it can be in -mm) is closer to what gets sent to me.
Quoted 3 lines
.. and resolving the conflicts (none of which looked bad), I think that part of the resolution ends up doing very similar things to your fixup patch.
Reviewed what you did in the merge commit, looks good to me. And I've learned I need to run git log --cc instead of -p in order to see all changes to a file.
Re: [patch 149/262] mm/vmscan: throttle reclaim until some writeback completes if congested
Quoted 4 lines · Matthew Wilcox
Reviewed what you did in the merge commit, looks good to me. And I've learned I need to run git log --cc instead of -p in order to see all changes to a file.
Heh.
If this is your first time using "--cc" (although it's the default for "git show", so you may have used it without being aware of it), it's very useful and powerful, but it's worth keeping in mind that it's also a lot more limited than the merge-time "git diff" output.
At merge time, git has computed the shared state parenthood, and "git diff" knows about not only the current state, but also the state of both parents and the base state of the file (in a three-way merge kind of sense, although with recursive merges the "base state" may be much more complex than just a shared parent state).
But "git log --cc" (and related "show commit" kind of things, like "git show" and friends) only sees the final result and the parent information. The full common parent and base state isn't there after-the-fact.
That means that "git log --cc" doesn't have quite as much information to go by, and the "--cc" output can sometimes be a bit misleading.
In particular, if there was a conflict, and the resolution ended up basically being "take one side where the conflict was", then "git log --cc" will not show the conflict resolution as a conflict at all - it will just think "ok, development was done on that branch, the other side was irrelevant".
So "--cc" is very useful, and often shows that interesting sub-part of the merge where there were conflicts. But it's definitely somewhat limited, and can end up looking like there was no conflict at all even when there was something.
Linus
Andrew Morton
maintainerPATCH 150/262 mm/vmscan: throttle reclaim and compaction when too may pages are isolated
In reply to Andrew MortonFrom: Mel Gorman <[email protected]>
Subject: mm/vmscan: throttle reclaim and compaction when too may pages are isolated
Page reclaim throttles on congestion if too many parallel reclaim instances have isolated too many pages. This makes no sense, excessive parallelisation has nothing to do with writeback or congestion.
This patch creates an additional workqueue to sleep on when too many pages are isolated. The throttled tasks are woken when the number of isolated pages is reduced or a timeout occurs. There may be some false positive wakeups for GFP_NOIO/GFP_NOFS callers but the tasks will throttle again if necessary.
---
include/linux/mmzone.h | 1 + include/trace/events/vmscan.h | 4 +++- mm/compaction.c | 10 ++++++++-- mm/internal.h | 11 +++++++++++ mm/vmscan.c | 22 ++++++++++++++++------ 5 files changed, 39 insertions(+), 9 deletions(-)
include/linux/mmzone.h renamed from include/linux/mmzone.h~mm-vmscan-throttle-reclaim-and-compaction-when-too-may-pages-are-isolated +1 -0
@@ -275,6 +275,7 @@ enum lru_list {enum vmscan_throttle_state {VMSCAN_THROTTLE_WRITEBACK , +VMSCAN_THROTTLE_ISOLATED ,NR_VMSCAN_THROTTLE , };
include/trace/events/vmscan.h renamed from include/trace/events/vmscan.h~mm-vmscan-throttle-reclaim-and-compaction-when-too-may-pages-are-isolated +3 -1
@@ -28,10 +28,12 @@ ) : "RECLAIM_WB_NONE"#define _VMSCAN_THROTTLE_WRITEBACK (1 << VMSCAN_THROTTLE_WRITEBACK) +#define _VMSCAN_THROTTLE_ISOLATED (1 << VMSCAN_THROTTLE_ISOLATED)#define show_throttle_flags (flags) \ (flags) ? __print_flags(flags, "|", \ - {_VMSCAN_THROTTLE_WRITEBACK, "VMSCAN_THROTTLE_WRITEBACK"} \ + {_VMSCAN_THROTTLE_WRITEBACK, "VMSCAN_THROTTLE_WRITEBACK"}, \ + {_VMSCAN_THROTTLE_ISOLATED, "VMSCAN_THROTTLE_ISOLATED"} \ ) : "VMSCAN_THROTTLE_NONE"
mm/compaction.c renamed from mm/compaction.c~mm-vmscan-throttle-reclaim-and-compaction-when-too-may-pages-are-isolated +8 -2
@@ -761,6 +761,8 @@ isolate_freepages_range(struct compact_c/* Similar to reclaim, but different enough that they don't share logic */ static bool too_many_isolated (pg_data_t *pgdat) { +bool too_many; +unsigned long active, inactive, isolated; inactive = node_page_state(pgdat, NR_INACTIVE_FILE) +
@@ -770,7 +772,11 @@ static bool too_many_isolated(pg_data_t isolated =node_page_state (pgdat,NR_ISOLATED_FILE ) +node_page_state (pgdat,NR_ISOLATED_ANON ); -return isolated > (inactive + active) /2 ; + too_many = isolated > (inactive + active) /2 ; +if (!too_many) +wake_throttle_isolated (pgdat); + +return too_many; }/**
@@ -822,7 +828,7 @@ isolate_migratepages_block(struct compacif (cc->mode ==MIGRATE_ASYNC )return -EAGAIN ; -congestion_wait (BLK_RW_ASYNC ,HZ /10 ); +reclaim_throttle (pgdat,VMSCAN_THROTTLE_ISOLATED ,HZ /10 );if (fatal_signal_pending (current))return -EINTR ;
mm/internal.h renamed from mm/internal.h~mm-vmscan-throttle-reclaim-and-compaction-when-too-may-pages-are-isolated +11 -0
@@ -45,6 +45,15 @@ static inline void acct_reclaim_writebac__acct_reclaim_writeback (pgdat, page, nr_throttled); } +static inline void wake_throttle_isolated (pg_data_t *pgdat) +{ +wait_queue_head_t *wqh; + + wqh = &pgdat->reclaim_wait[VMSCAN_THROTTLE_ISOLATED ]; +if (waitqueue_active (wqh)) +wake_up (wqh); +} +vm_fault_t do_swap_page (struct vm_fault *vmf); void free_pgtables(struct mmu_gather *tlb, struct vm_area_struct *start_vma,
@@ -121,6 +130,8 @@ extern unsigned long highest_memmap_pfn;*/ extern int isolate_lru_page (struct page *page);extern void putback_lru_page (struct page *page); +extern void reclaim_throttle (pg_data_t *pgdat,enum vmscan_throttle_state reason, +long timeout);/* * in mm/rmap.c:
mm/vmscan.c renamed from mm/vmscan.c~mm-vmscan-throttle-reclaim-and-compaction-when-too-may-pages-are-isolated +16 -6
@@ -1006,12 +1006,12 @@ static void handle_write_error(struct adunlock_page (page); } -static void -reclaim_throttle (pg_data_t *pgdat,enum vmscan_throttle_state reason, +void reclaim_throttle (pg_data_t *pgdat,enum vmscan_throttle_state reason,long timeout) {wait_queue_head_t *wqh = &pgdat->reclaim_wait[reason];long ret; +bool acct_writeback = (reason ==VMSCAN_THROTTLE_WRITEBACK );DEFINE_WAIT (wait);/*
@@ -1023,7 +1023,8 @@ reclaim_throttle(pg_data_t *pgdat, enum current->flags & (PF_IO_WORKER|PF_KTHREAD))return ; -if (atomic_inc_return (&pgdat->nr_writeback_throttled) ==1 ) { +if (acct_writeback && +atomic_inc_return (&pgdat->nr_writeback_throttled) ==1 ) {WRITE_ONCE (pgdat->nr_reclaim_start,node_page_state (pgdat,NR_THROTTLED_WRITTEN )); }
@@ -1031,7 +1032,9 @@ reclaim_throttle(pg_data_t *pgdat, enumprepare_to_wait (wqh, &wait,TASK_UNINTERRUPTIBLE ); ret =schedule_timeout (timeout);finish_wait (wqh, &wait); -atomic_dec (&pgdat->nr_writeback_throttled); + +if (acct_writeback) +atomic_dec (&pgdat->nr_writeback_throttled); trace_mm_vmscan_throttled(pgdat->node_id, jiffies_to_usecs(timeout), jiffies_to_usecs(timeout - ret),
@@ -2175,6 +2178,7 @@ static int too_many_isolated(struct pgli struct scan_control *sc) {unsigned long inactive, isolated; +bool too_many;if (current_is_kswapd ())return 0 ;
@@ -2198,7 +2202,13 @@ static int too_many_isolated(struct pgliif ((sc->gfp_mask & (__GFP_IO | __GFP_FS)) == (__GFP_IO | __GFP_FS)) inactive >>=3 ; -return isolated > inactive; + too_many = isolated > inactive; + +/* Wake up tasks throttled due to too_many_isolated. */ +if (!too_many) +wake_throttle_isolated (pgdat); + +return too_many; }/*
@@ -2307,8 +2317,8 @@ shrink_inactive_list(unsigned long nr_toreturn 0 ;/* wait a bit for the reclaimer. */ -msleep (100 ); stalled = true; +reclaim_throttle (pgdat,VMSCAN_THROTTLE_ISOLATED ,HZ /10 );/* We are about to die and free our memory. Return now. */ if (fatal_signal_pending (current))
_
Andrew Morton
maintainerPATCH 151/262 mm/vmscan: throttle reclaim when no progress is being made
In reply to Andrew MortonFrom: Mel Gorman <[email protected]>
Subject: mm/vmscan: throttle reclaim when no progress is being made
Memcg reclaim throttles on congestion if no reclaim progress is made. This makes little sense, it might be due to writeback or a host of other factors.
For !memcg reclaim, it's messy. Direct reclaim primarily is throttled in the page allocator if it is failing to make progress. Kswapd throttles if too many pages are under writeback and marked for immediate reclaim.
This patch explicitly throttles if reclaim is failing to make progress.
---
include/linux/mmzone.h | 1 + include/trace/events/vmscan.h | 4 +++- mm/memcontrol.c | 10 +--------- mm/vmscan.c | 28 ++++++++++++++++++++++++++++ 4 files changed, 33 insertions(+), 10 deletions(-)
include/linux/mmzone.h renamed from include/linux/mmzone.h~mm-vmscan-throttle-reclaim-when-no-progress-is-being-made +1 -0
@@ -276,6 +276,7 @@ enum lru_list {enum vmscan_throttle_state {VMSCAN_THROTTLE_WRITEBACK ,VMSCAN_THROTTLE_ISOLATED , +VMSCAN_THROTTLE_NOPROGRESS ,NR_VMSCAN_THROTTLE , };
include/trace/events/vmscan.h renamed from include/trace/events/vmscan.h~mm-vmscan-throttle-reclaim-when-no-progress-is-being-made +3 -1
@@ -29,11 +29,13 @@#define _VMSCAN_THROTTLE_WRITEBACK (1 << VMSCAN_THROTTLE_WRITEBACK)#define _VMSCAN_THROTTLE_ISOLATED (1 << VMSCAN_THROTTLE_ISOLATED) +#define _VMSCAN_THROTTLE_NOPROGRESS (1 << VMSCAN_THROTTLE_NOPROGRESS)#define show_throttle_flags (flags) \ (flags) ? __print_flags(flags, "|", \ {_VMSCAN_THROTTLE_WRITEBACK, "VMSCAN_THROTTLE_WRITEBACK"}, \ - {_VMSCAN_THROTTLE_ISOLATED, "VMSCAN_THROTTLE_ISOLATED"} \ + {_VMSCAN_THROTTLE_ISOLATED, "VMSCAN_THROTTLE_ISOLATED"}, \ + {_VMSCAN_THROTTLE_NOPROGRESS, "VMSCAN_THROTTLE_NOPROGRESS"} \ ) : "VMSCAN_THROTTLE_NONE"
mm/memcontrol.c renamed from mm/memcontrol.c~mm-vmscan-throttle-reclaim-when-no-progress-is-being-made +1 -9
@@ -3487,19 +3487,11 @@ static int mem_cgroup_force_empty(struct/* try to free all pages in this cgroup */ while (nr_retries &&page_counter_read (&memcg->memory)) { -int progress; -if (signal_pending (current))return -EINTR ; - progress =try_to_free_mem_cgroup_pages (memcg,1 , -GFP_KERNEL , true); -if (!progress) { +if (!try_to_free_mem_cgroup_pages (memcg,1 ,GFP_KERNEL , true)) nr_retries--; -/* maybe some writeback is necessary */ -congestion_wait (BLK_RW_ASYNC ,HZ /10 ); - } - }return 0 ;
mm/vmscan.c renamed from mm/vmscan.c~mm-vmscan-throttle-reclaim-when-no-progress-is-being-made +28 -0
@@ -3322,6 +3322,33 @@ static inline bool compaction_ready(strureturn zone_watermark_ok_safe (zone,0 , watermark, sc->reclaim_idx); } +static void consider_reclaim_throttle (pg_data_t *pgdat,struct scan_control *sc) +{ +/* If reclaim is making progress, wake any throttled tasks. */ +if (sc->nr_reclaimed) { +wait_queue_head_t *wqh; + + wqh = &pgdat->reclaim_wait[VMSCAN_THROTTLE_NOPROGRESS ]; +if (waitqueue_active (wqh)) +wake_up (wqh); + +return ; + } + +/* +* Do not throttle kswapd on NOPROGRESS as it will throttle on +* VMSCAN_THROTTLE_WRITEBACK if there are too many pages under +* writeback and marked for immediate reclaim at the tail of +* the LRU. +*/ +if (current_is_kswapd ()) +return ; + +/* Throttle if making no progress at high prioities. */ +if (sc->priority <DEF_PRIORITY -2 ) +reclaim_throttle (pgdat,VMSCAN_THROTTLE_NOPROGRESS ,HZ /10 ); +} +/* * This is the direct reclaim path, for page-allocating processes. We only * try to reclaim pages from zones which will satisfy the caller's allocation
@@ -3406,6 +3433,7 @@ static void shrink_zones(struct zonelistcontinue ; last_pgdat = zone->zone_pgdat;shrink_node (zone->zone_pgdat, sc); +consider_reclaim_throttle (zone->zone_pgdat, sc); }/*
_
Andrew Morton
maintainerPATCH 152/262 mm/writeback: throttle based on page writeback instead of congestion
In reply to Andrew MortonFrom: Mel Gorman <[email protected]>
Subject: mm/writeback: throttle based on page writeback instead of congestion
do_writepages throttles on congestion if the writepages() fails due to a lack of memory but congestion_wait() is partially broken as the congestion state is not updated for all BDIs.
This patch stalls waiting for a number of pages to complete writeback that located on the local node. The main weakness is that there is no correlation between the location of the inode's pages and locality but that is still better than congestion_wait.
---
mm/page-writeback.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-)
mm/page-writeback.c renamed from mm/page-writeback.c~mm-writeback-throttle-based-on-page-writeback-instead-of-congestion +9 -2
@@ -2366,8 +2366,15 @@ int do_writepages(struct address_space * ret =generic_writepages (mapping, wbc);if ((ret != -ENOMEM ) || (wbc->sync_mode !=WB_SYNC_ALL ))break ; -cond_resched (); -congestion_wait (BLK_RW_ASYNC ,HZ /50 ); + +/* +* Lacking an allocation context or the locality or writeback +* state of any of the inode's pages, throttle based on +* writeback activity on the local node. It's as good a +* guess as any. +*/ +reclaim_throttle (NODE_DATA (numa_node_id ()), +VMSCAN_THROTTLE_WRITEBACK ,HZ /50 ); }/* * Usually few pages are written by now from those we've just submitted
_
Andrew Morton
maintainerPATCH 153/262 mm/page_alloc: remove the throttling logic from the page allocator
In reply to Andrew MortonFrom: Mel Gorman <[email protected]>
Subject: mm/page_alloc: remove the throttling logic from the page allocator
The page allocator stalls based on the number of pages that are waiting for writeback to start but this should now be redundant. shrink_inactive_list() will wake flusher threads if the LRU tail are unqueued dirty pages so the flusher should be active. If it fails to make progress due to pages under writeback not being completed quickly then it should stall on VMSCAN_THROTTLE_WRITEBACK.
---
mm/page_alloc.c | 21 +-------------------- 1 file changed, 1 insertion(+), 20 deletions(-)
mm/page_alloc.c renamed from mm/page_alloc.c~mm-page_alloc-remove-the-throttling-logic-from-the-page-allocator +1 -20
@@ -4791,30 +4791,11 @@ should_reclaim_retry(gfp_t gfp_mask, unstrace_reclaim_retry_zone (z, order, reclaimable, available, min_wmark, *no_progress_loops, wmark);if (wmark) { -/* -* If we didn't make any progress and have a lot of -* dirty + writeback pages then we should wait for -* an IO to complete to slow down the reclaim and -* prevent from pre mature OOM -*/ -if (!did_some_progress) { -unsigned long write_pending; - - write_pending =zone_page_state_snapshot (zone, -NR_ZONE_WRITE_PENDING ); - -if (2 * write_pending > reclaimable) { -congestion_wait (BLK_RW_ASYNC ,HZ /10 ); -return true; - } - } - ret = true; - goto out; +break ; } } -out:/* * Memory allocation/reclaim might be called from a WQ context and the * current implementation of the WQ concurrency control doesn't
_
Andrew Morton
maintainerPATCH 154/262 mm/vmscan: centralise timeout values for reclaim_throttle
In reply to Andrew MortonFrom: Mel Gorman <[email protected]>
Subject: mm/vmscan: centralise timeout values for reclaim_throttle
Neil Brown raised concerns about callers of reclaim_throttle specifying a timeout value. The original timeout values to congestion_wait() were probably pulled out of thin air or copy&pasted from somewhere else. This patch centralises the timeout values and selects a timeout based on the reason for reclaim throttling. These figures are also pulled out of the same thin air but better values may be derived
Running a workload that is throttling for inappropriate periods and tracing mm_vmscan_throttled can be used to pick a more appropriate value. Excessive throttling would pick a lower timeout where as excessive CPU usage in reclaim context would select a larger timeout. Ideally a large value would always be used and the wakeups would occur before a timeout but that requires careful testing.
---
mm/compaction.c | 2 - mm/internal.h | 3 -- mm/page-writeback.c | 2 - mm/vmscan.c | 50 +++++++++++++++++++++++++++++++----------- 4 files changed, 40 insertions(+), 17 deletions(-)
mm/compaction.c renamed from mm/compaction.c~mm-vmscan-centralise-timeout-values-for-reclaim_throttle +1 -1
@@ -828,7 +828,7 @@ isolate_migratepages_block(struct compacif (cc->mode ==MIGRATE_ASYNC )return -EAGAIN ; -reclaim_throttle (pgdat,VMSCAN_THROTTLE_ISOLATED ,HZ /10 ); +reclaim_throttle (pgdat,VMSCAN_THROTTLE_ISOLATED );if (fatal_signal_pending (current))return -EINTR ;
mm/internal.h renamed from mm/internal.h~mm-vmscan-centralise-timeout-values-for-reclaim_throttle +1 -2
@@ -130,8 +130,7 @@ extern unsigned long highest_memmap_pfn;*/ extern int isolate_lru_page (struct page *page);extern void putback_lru_page (struct page *page); -extern void reclaim_throttle (pg_data_t *pgdat,enum vmscan_throttle_state reason, -long timeout); +extern void reclaim_throttle (pg_data_t *pgdat,enum vmscan_throttle_state reason);/* * in mm/rmap.c:
mm/page-writeback.c renamed from mm/page-writeback.c~mm-vmscan-centralise-timeout-values-for-reclaim_throttle +1 -1
@@ -2374,7 +2374,7 @@ int do_writepages(struct address_space ** guess as any. */ reclaim_throttle (NODE_DATA (numa_node_id ()), -VMSCAN_THROTTLE_WRITEBACK ,HZ /50 ); +VMSCAN_THROTTLE_WRITEBACK ); }/* * Usually few pages are written by now from those we've just submitted
mm/vmscan.c renamed from mm/vmscan.c~mm-vmscan-centralise-timeout-values-for-reclaim_throttle +37 -13
94 lines not on this page · raw message
_
Andrew Morton
maintainerPATCH 155/262 mm/vmscan: increase the timeout if page reclaim is not making progress
In reply to Andrew MortonFrom: Mel Gorman <[email protected]>
Subject: mm/vmscan: increase the timeout if page reclaim is not making progress
Tracing of the stutterp workload showed the following delays
1 usect_delayed=124000 reason=VMSCAN_THROTTLE_NOPROGRESS 1 usect_delayed=128000 reason=VMSCAN_THROTTLE_NOPROGRESS 1 usect_delayed=176000 reason=VMSCAN_THROTTLE_NOPROGRESS 1 usect_delayed=536000 reason=VMSCAN_THROTTLE_NOPROGRESS 1 usect_delayed=544000 reason=VMSCAN_THROTTLE_NOPROGRESS 1 usect_delayed=556000 reason=VMSCAN_THROTTLE_NOPROGRESS 1 usect_delayed=624000 reason=VMSCAN_THROTTLE_NOPROGRESS 1 usect_delayed=716000 reason=VMSCAN_THROTTLE_NOPROGRESS 1 usect_delayed=772000 reason=VMSCAN_THROTTLE_NOPROGRESS 2 usect_delayed=512000 reason=VMSCAN_THROTTLE_NOPROGRESS
16 usect_delayed=120000 reason=VMSCAN_THROTTLE_NOPROGRESS 53 usect_delayed=116000 reason=VMSCAN_THROTTLE_NOPROGRESS
116 usect_delayed=112000 reason=VMSCAN_THROTTLE_NOPROGRESS
5907 usect_delayed=108000 reason=VMSCAN_THROTTLE_NOPROGRESS
71741 usect_delayed=104000 reason=VMSCAN_THROTTLE_NOPROGRESS
All the throttling hit the full timeout and then there was wakeup delays meaning that the wakeups are premature as no other reclaimer such as kswapd has made progress. This patch increases the maximum timeout.
---
mm/vmscan.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
mm/vmscan.c renamed from mm/vmscan.c~mm-vmscan-increase-the-timeout-if-page-reclaim-is-not-making-progress +1 -1
@@ -1042,7 +1042,7 @@ void reclaim_throttle(pg_data_t *pgdat,break ;case VMSCAN_THROTTLE_NOPROGRESS : - timeout =HZ /10 ; + timeout =HZ /2 ;break ;case VMSCAN_THROTTLE_ISOLATED : timeout =HZ /50 ;
_
Andrew Morton
maintainerPATCH 156/262 mm/vmscan: delay waking of tasks throttled on NOPROGRESS
In reply to Andrew MortonFrom: Mel Gorman <[email protected]>
Subject: mm/vmscan: delay waking of tasks throttled on NOPROGRESS
Tracing indicates that tasks throttled on NOPROGRESS are woken prematurely resulting in occasional massive spikes in direct reclaim activity. This patch wakes tasks throttled on NOPROGRESS if reclaim efficiency is at least 12%.
---
mm/vmscan.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
mm/vmscan.c renamed from mm/vmscan.c~mm-vmscan-delay-waking-of-tasks-throttled-on-noprogress +5 -2
@@ -3348,8 +3348,11 @@ static inline bool compaction_ready(strustatic void consider_reclaim_throttle (pg_data_t *pgdat,struct scan_control *sc) { -/* If reclaim is making progress, wake any throttled tasks. */ -if (sc->nr_reclaimed) { +/* +* If reclaim is making progress greater than 12% efficiency then +* wake all the NOPROGRESS throttled tasks. +*/ +if (sc->nr_reclaimed > (sc->nr_scanned >>3 )) {wait_queue_head_t *wqh; wqh = &pgdat->reclaim_wait[VMSCAN_THROTTLE_NOPROGRESS ];
_
Andrew Morton
maintainerPATCH 157/262 mm/vmpressure: fix data-race with memcg->socket_pressure
In reply to Andrew MortonFrom: Yuanzheng Song <[email protected]>
Subject: mm/vmpressure: fix data-race with memcg->socket_pressure
BUG: KCSAN: data-race in __sk_mem_reduce_allocated / vmpressure
write to 0xffff8881286f4938 of 8 bytes by task 24550 on cpu 3:
vmpressure+0x218/0x230 mm/vmpressure.c:307 shrink_node_memcgs+0x2b9/0x410 mm/vmscan.c:2658 shrink_node+0x9d2/0x11d0 mm/vmscan.c:2769 shrink_zones+0x29f/0x470 mm/vmscan.c:2972 do_try_to_free_pages+0x193/0x6e0 mm/vmscan.c:3027 try_to_free_mem_cgroup_pages+0x1c0/0x3f0 mm/vmscan.c:3345 reclaim_high mm/memcontrol.c:2440 [inline] mem_cgroup_handle_over_high+0x18b/0x4d0 mm/memcontrol.c:2624 tracehook_notify_resume include/linux/tracehook.h:197 [inline] exit_to_user_mode_loop kernel/entry/common.c:164 [inline] exit_to_user_mode_prepare+0x110/0x170 kernel/entry/common.c:191 syscall_exit_to_user_mode+0x16/0x30 kernel/entry/common.c:266 ret_from_fork+0x15/0x30 arch/x86/entry/entry_64.S:289
read to 0xffff8881286f4938 of 8 bytes by interrupt on cpu 1:
mem_cgroup_under_socket_pressure include/linux/memcontrol.h:1483 [inline] sk_under_memory_pressure include/net/sock.h:1314 [inline] __sk_mem_reduce_allocated+0x1d2/0x270 net/core/sock.c:2696 __sk_mem_reclaim+0x44/0x50 net/core/sock.c:2711 sk_mem_reclaim include/net/sock.h:1490 [inline] ...... net_rx_action+0x17a/0x480 net/core/dev.c:6864 __do_softirq+0x12c/0x2af kernel/softirq.c:298 run_ksoftirqd+0x13/0x20 kernel/softirq.c:653 smpboot_thread_fn+0x33f/0x510 kernel/smpboot.c:165 kthread+0x1fc/0x220 kernel/kthread.c:292 ret_from_fork+0x1f/0x30 arch/x86/entry/entry_64.S:296
When reading memcg->socket_pressure in mem_cgroup_under_socket_pressure() and writing memcg->socket_pressure in vmpressure() at the same time, the data-race occurs.
So fix it by using READ_ONCE() and WRITE_ONCE() to read and write memcg->socket_pressure.
---
include/linux/memcontrol.h | 2 +- mm/vmpressure.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
include/linux/memcontrol.h renamed from include/linux/memcontrol.h~mm-vmpressure-fix-data-race-with-memcg-socket_pressure +1 -1
@@ -1606,7 +1606,7 @@ static inline bool mem_cgroup_under_sockif (!cgroup_subsys_on_dfl (memory_cgrp_subsys) && memcg->tcpmem_pressure)return true;do { -if (time_before (jiffies, memcg->socket_pressure)) +if (time_before (jiffies,READ_ONCE (memcg->socket_pressure)))return true; }while ((memcg =parent_mem_cgroup (memcg)));return false;
mm/vmpressure.c renamed from mm/vmpressure.c~mm-vmpressure-fix-data-race-with-memcg-socket_pressure +1 -1
@@ -308,7 +308,7 @@ void vmpressure(gfp_t gfp, struct mem_cg* asserted for a second in which subsequent * pressure events can occur. */ - memcg->socket_pressure = jiffies +HZ ; +WRITE_ONCE (memcg->socket_pressure, jiffies +HZ ); } } }
_
Andrew Morton
maintainerPATCH 158/262 tools/vm/page_owner_sort.c: count and sort by mem
In reply to Andrew MortonFrom: Zhenliang Wei <[email protected]>
Subject: tools/vm/page_owner_sort.c: count and sort by mem
When viewing page owner information, we may be more concerned about the total memory rather than the times of stack appears. Therefore, the following adjustments are made:
1. Added the statistics on the total number of pages.
2. Added the optional parameter "-m" to configure the program to sort by memory (total pages).
The general output of page_owner is as follows:
Page allocated via order XXX, ... PFN XXX ... // Detailed stack Page allocated via order XXX, ... PFN XXX ... // Detailed stack
The original page_owner_sort ignores PFN rows, puts the remaining rows in buf, counts the times of buf, and finally sorts them according to the times. General output:
XXX times: Page allocated via order XXX, ... // Detailed stack
Now, we use regexp to extract the page order value from the buf, and count the total pages for the buf. General output:
XXX times, XXX pages:
Page allocated via order XXX, ...
// Detailed stack
By default, it is still sorted by the times of buf;
If you want to sort by the pages nums of buf, use the new -m parameter.
---
Documentation/vm/page_owner.rst | 23 +++++++ tools/vm/page_owner_sort.c | 94 +++++++++++++++++++++++++++--- 2 files changed, 107 insertions(+), 10 deletions(-)
Documentation/vm/page_owner.rst renamed from Documentation/vm/page_owner.rst~tools-vm-page_owner_sortc-count-and-sort-by-mem +22 -1
@@ -85,5 +85,26 @@ Usage cat /sys/kernel/debug/page_owner > page_owner_full.txt ./page_owner_sort page_owner_full.txt sorted_page_owner.txt + The general output of ``page_owner_full.txt`` is as follows: + + Page allocated via order XXX, ... + PFN XXX ... + // Detailed stack + + Page allocated via order XXX, ... + PFN XXX ... + // Detailed stack + + The ``page_owner_sort`` tool ignores ``PFN`` rows, puts the remaining rows + in buf, uses regexp to extract the page order value, counts the times + and pages of buf, and finally sorts them according to the times. + See the result about who allocated each page - in the ``sorted_page_owner.txt``. + in the ``sorted_page_owner.txt``. General output: + + XXX times, XXX pages: + Page allocated via order XXX, ... + // Detailed stack + + By default, ``page_owner_sort`` is sorted according to the times of buf. + If you want to sort by the pages nums of buf, use the ``-m`` parameter.
tools/vm/page_owner_sort.c renamed from tools/vm/page_owner_sort.c~tools-vm-page_owner_sortc-count-and-sort-by-mem +85 -9
163 lines not on this page · raw message
_
Andrew Morton
maintainerPATCH 159/262 tools/vm/page-types.c: make walk_file() aware of address range option
In reply to Andrew MortonFrom: Naoya Horiguchi <[email protected]>
Subject: tools/vm/page-types.c: make walk_file() aware of address range option
Patch series "tools/vm/page-types.c: a few improvements".
This patchset adds some improvements on tools/vm/page-types.c. Patch 1/3 makes -a option (specify address range) work with -f (file cache mode). Patch 2/3 and 3/3 are to fix minor formatting issues of this tool. These would make life a little easier for the users of this tool.
Please see individual patches for more details about specific issues.
This patch (of 3):
-a|--addr option is used to limit the range of address to be scanned for page status. It works now for physical address space (dafult mode) or for virtual address space (with -p option), but not for file address space (with -f option). So make walk_file() aware of -a option.
---
tools/vm/page-types.c | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-)
tools/vm/page-types.c renamed from tools/vm/page-types.c~tools-vm-page-typesc-make-walk_file-aware-of-address-range-option +18 -6
@@ -967,22 +967,19 @@ static struct sigaction sigbus_action = .sa_flags = SA_SIGINFO, }; -static void walk_file (const char *name,const struct stat *st) +static void walk_file_range (const char *name,int fd, +unsigned long off,unsigned long end) {uint8_t vec[PAGEMAP_BATCH ];uint64_t buf[PAGEMAP_BATCH ], flags;uint64_t cgroup =0 ;uint64_t mapcnt =0 ;unsigned long nr_pages, pfn, i; -off_t off, end = st->st_size; -int fd;ssize_t len;void *ptr;int first =1 ; - fd =checked_open (name,O_RDONLY |O_NOATIME |O_NOFOLLOW ); - -for (off =0 ; off < end; off += len) { +for (; off < end; off += len) { nr_pages = (end - off + page_size -1 ) / page_size;if (nr_pages >PAGEMAP_BATCH ) nr_pages =PAGEMAP_BATCH ;
@@ -1043,6 +1040,21 @@ got_sigbus: flags, cgroup, mapcnt, buf[i]); } } +} + +static void walk_file (const char *name,const struct stat *st) +{ +int i; +int fd; + + fd =checked_open (name,O_RDONLY |O_NOATIME |O_NOFOLLOW ); + +if (!nr_addr_ranges) +add_addr_range (0 , st->st_size / page_size); + +for (i =0 ; i < nr_addr_ranges; i++) +walk_file_range (name, fd, opt_offset[i] * page_size, + (opt_offset[i] + opt_size[i]) * page_size);close (fd); }
_
Andrew Morton
maintainerPATCH 160/262 tools/vm/page-types.c: move show_file() to summary output
In reply to Andrew MortonFrom: Naoya Horiguchi <[email protected]>
Subject: tools/vm/page-types.c: move show_file() to summary output
Currently file info from show_file() is printed out within page list like below, but this is inconvenient a little to utilize the page list from other scripts (maybe needs additional filtering).
$ ./page-types -f page-types.c -l
foffset offset len flags
page-types.c Inode: 15108680 Size: 30953 (8 pages)
Modify: Sat Oct 2 23:11:20 2021 (2399 seconds ago)
Access: Sat Oct 2 23:11:28 2021 (2391 seconds ago)
0 d9f59e 1 ___U_lA____________________________________
1 1031eb5 1 __RU_l_____________________________________
2 13bf717 1 __RU_l_____________________________________
3 13ac333 1 ___U_lA____________________________________
4 d9f59f 1 __RU_l_____________________________________
5 183fd49 1 ___U_lA____________________________________
6 13cbf69 1 ___U_lA____________________________________
7 d9ef05 1 ___U_lA____________________________________ flags page-count MB symbolic-flags long-symbolic-flags
0x000000000000002c 3 0 __RU_l_____________________________________ referenced,uptodate,lru
0x0000000000000068 5 0 ___U_lA____________________________________ uptodate,lru,activetotal 8 0
With this patch file info is printed out in summary part like below:
$ ./page-types -f page-types.c -l
foffset offset len flags
0 d9f59e 1 ___U_lA_____________________________________
1 1031eb5 1 __RU_l______________________________________
2 13bf717 1 __RU_l______________________________________
3 13ac333 1 ___U_lA_____________________________________
4 d9f59f 1 __RU_l______________________________________
5 183fd49 1 ___U_lA_____________________________________
6 13cbf69 1 ___U_lA_____________________________________ page-types.c Inode: 15108680 Size: 30953 (8 pages)
Modify: Sat Oct 2 23:11:20 2021 (2435 seconds ago)
Access: Sat Oct 2 23:11:28 2021 (2427 seconds ago)
flags page-count MB symbolic-flags long-symbolic-flags
0x000000000000002c 3 0 __RU_l______________________________________ referenced,uptodate,lru
0x0000000000000068 4 0 ___U_lA_____________________________________ uptodate,lru,active
total 7 0---
tools/vm/page-types.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-)
tools/vm/page-types.c renamed from tools/vm/page-types.c~tools-vm-page-typesc-move-show_file-to-summary-output +7 -3
@@ -1034,7 +1034,6 @@ got_sigbus:if (first && opt_list) { first =0 ;flush_page_range (); -show_file (name, st); }add_page (off / page_size + i, pfn, flags, cgroup, mapcnt, buf[i]);
@@ -1074,10 +1073,10 @@ int walk_tree(const char *name, const streturn 0 ; } +struct stat st; +static void walk_page_cache (void ) { -struct stat st; - kpageflags_fd =checked_open (opt_kpageflags,O_RDONLY ); pagemap_fd =checked_open ("/proc/self/pagemap" ,O_RDONLY );sigaction (SIGBUS , &sigbus_action,NULL );
@@ -1374,6 +1373,11 @@ int main(int argc, char *argv[])if (opt_list)printf ("\n\n" ); +if (opt_file) { +show_file (opt_file, &st); +printf ("\n" ); + } +show_summary ();if (opt_list_mapcnt)
_
Andrew Morton
maintainerPATCH 161/262 tools/vm/page-types.c: print file offset in hexadecimal
In reply to Andrew MortonFrom: Naoya Horiguchi <[email protected]>
Subject: tools/vm/page-types.c: print file offset in hexadecimal
In page list mode (with -l and -L option), virtual address and physical address are printed in hexadecimal, but file offset is not, which is confusing, so let's align it.
---
tools/vm/page-types.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
tools/vm/page-types.c renamed from tools/vm/page-types.c~tools-vm-page-typesc-print-file-offset-in-hexadecimal +2 -2
@@ -390,7 +390,7 @@ static void show_page_range(unsigned lonif (opt_pid)printf ("%lx\t" , voff);if (opt_file) -printf ("%lu\t" , voff); +printf ("%lx\t" , voff);if (opt_list_cgroup)printf ("@%llu\t" , (unsigned long long )cgroup0);if (opt_list_mapcnt)
@@ -418,7 +418,7 @@ static void show_page(unsigned long voffif (opt_pid)printf ("%lx\t" , voffset);if (opt_file) -printf ("%lu\t" , voffset); +printf ("%lx\t" , voffset);if (opt_list_cgroup)printf ("@%llu\t" , (unsigned long long )cgroup);if (opt_list_mapcnt)
_
Andrew Morton
maintainerPATCH 162/262 arch_numa: simplify numa_distance allocation
In reply to Andrew MortonFrom: Mike Rapoport <[email protected]>
Subject: arch_numa: simplify numa_distance allocation
Patch series "memblock: cleanup memblock_free interface", v2.
This is the fix for memblock freeing APIs mismatch [1].
The first patch is a cleanup of numa_distance allocation in arch_numa I've spotted during the conversion. The second patch is a fix for Xen memory freeing on some of the error paths.
[1] https://lore.kernel.org/all/CAHk-=wj9k4LZTz+svCxLYs5Y1=+yKrbAUArH1+ghyG3OLd8VVg@mail.gmail.com
This patch (of 6):
Memory allocation of numa_distance uses memblock_phys_alloc_range() without actual range limits, converts the returned physical address to virtual and then only uses the virtual address for further initialization.
Simplify this by replacing memblock_phys_alloc_range() with memblock_alloc().
---
drivers/base/arch_numa.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/base/arch_numa.c renamed from drivers/base/arch_numa.c~arch_numa-simplify-numa_distance-allocation +2 -4
@@ -337,15 +337,13 @@ void __init numa_free_distance(void)static int __init numa_alloc_distance (void ) {size_t size; -u64 phys;int i, j; size = nr_node_ids * nr_node_ids *sizeof (numa_distance[0 ]); - phys =memblock_phys_alloc_range (size,PAGE_SIZE ,0 ,PFN_PHYS (max_pfn)); -if (WARN_ON (!phys)) + numa_distance =memblock_alloc (size,PAGE_SIZE ); +if (WARN_ON (!numa_distance))return -ENOMEM ; - numa_distance =__va (phys); numa_distance_cnt = nr_node_ids;/* fill with the default distances */
_
Andrew Morton
maintainerPATCH 163/262 xen/x86: free_p2m_page: use memblock_free_ptr() to free a virtual pointer
In reply to Andrew MortonFrom: Mike Rapoport <[email protected]>
Subject: xen/x86: free_p2m_page: use memblock_free_ptr() to free a virtual pointer
free_p2m_page() wrongly passes a virtual pointer to memblock_free() that treats it as a physical address.
Call memblock_free_ptr() instead that gets a virtual address to free the memory.
---
arch/x86/xen/p2m.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/xen/p2m.c renamed from arch/x86/xen/p2m.c~xen-x86-free_p2m_page-use-memblock_free_ptr-to-free-a-virtual-pointer +1 -1
@@ -197,7 +197,7 @@ static void * __ref alloc_p2m_page(void)static void __ref free_p2m_page (void *p) {if (unlikely (!slab_is_available ())) { -memblock_free ((unsigned long )p,PAGE_SIZE ); +memblock_free_ptr (p,PAGE_SIZE );return ; }
_
Andrew Morton
maintainerPATCH 164/262 memblock: drop memblock_free_early_nid() and memblock_free_early()
In reply to Andrew MortonFrom: Mike Rapoport <[email protected]>
Subject: memblock: drop memblock_free_early_nid() and memblock_free_early()
memblock_free_early_nid() is unused and memblock_free_early() is an alias for memblock_free().
Replace calls to memblock_free_early() with calls to memblock_free() and remove memblock_free_early() and memblock_free_early_nid().
---
arch/mips/mm/init.c | 2 +- arch/powerpc/platforms/pseries/svm.c | 3 +-- arch/s390/kernel/smp.c | 2 +- drivers/base/arch_numa.c | 2 +- drivers/s390/char/sclp_early.c | 2 +- include/linux/memblock.h | 12 ------------ kernel/dma/swiotlb.c | 2 +- lib/cpumask.c | 2 +- mm/percpu.c | 8 ++++---- mm/sparse.c | 2 +- 10 files changed, 12 insertions(+), 25 deletions(-)
arch/mips/mm/init.c renamed from arch/mips/mm/init.c~memblock-drop-memblock_free_early_nid-and-memblock_free_early +1 -1
@@ -529,7 +529,7 @@ static void * __init pcpu_fc_alloc(unsigstatic void __init pcpu_fc_free (void *ptr,size_t size) { -memblock_free_early (__pa (ptr), size); +memblock_free (__pa (ptr), size); }void __init setup_per_cpu_areas (void )
arch/powerpc/platforms/pseries/svm.c renamed from arch/powerpc/platforms/pseries/svm.c~memblock-drop-memblock_free_early_nid-and-memblock_free_early +1 -2
@@ -56,8 +56,7 @@ void __init svm_swiotlb_init(void)return ; -memblock_free_early (__pa (vstart), -PAGE_ALIGN (io_tlb_nslabs <<IO_TLB_SHIFT )); +memblock_free (__pa (vstart),PAGE_ALIGN (io_tlb_nslabs <<IO_TLB_SHIFT ));panic ("SVM: Cannot allocate SWIOTLB buffer" ); }
arch/s390/kernel/smp.c renamed from arch/s390/kernel/smp.c~memblock-drop-memblock_free_early_nid-and-memblock_free_early +1 -1
@@ -880,7 +880,7 @@ void __init smp_detect_cpus(void)/* Add CPUs present at boot */ __smp_rescan_cpus (info, true); -memblock_free_early ((unsigned long )info,sizeof (*info)); +memblock_free ((unsigned long )info,sizeof (*info)); }/*
drivers/base/arch_numa.c renamed from drivers/base/arch_numa.c~memblock-drop-memblock_free_early_nid-and-memblock_free_early +1 -1
@@ -166,7 +166,7 @@ static void * __init pcpu_fc_alloc(unsigstatic void __init pcpu_fc_free (void *ptr,size_t size) { -memblock_free_early (__pa (ptr), size); +memblock_free (__pa (ptr), size); }#ifdef CONFIG_NEED_PER_CPU_PAGE_FIRST_CHUNK
drivers/s390/char/sclp_early.c renamed from drivers/s390/char/sclp_early.c~memblock-drop-memblock_free_early_nid-and-memblock_free_early +1 -1
@@ -139,7 +139,7 @@ int __init sclp_early_get_core_info(stru }sclp_fill_core_info (info, sccb); out: -memblock_free_early ((unsigned long )sccb, length); +memblock_free ((unsigned long )sccb, length);return rc; }
include/linux/memblock.h renamed from include/linux/memblock.h~memblock-drop-memblock_free_early_nid-and-memblock_free_early +0 -12
@@ -441,18 +441,6 @@ static inline void *memblock_alloc_node( MEMBLOCK_ALLOC_ACCESSIBLE, nid); } -static inline void memblock_free_early (phys_addr_t base, -phys_addr_t size) -{ -memblock_free (base, size); -} - -static inline void memblock_free_early_nid (phys_addr_t base, -phys_addr_t size,int nid) -{ -memblock_free (base, size); -} -static inline void memblock_free_late (phys_addr_t base,phys_addr_t size) {__memblock_free_late (base, size);
kernel/dma/swiotlb.c renamed from kernel/dma/swiotlb.c~memblock-drop-memblock_free_early_nid-and-memblock_free_early +1 -1
@@ -247,7 +247,7 @@ swiotlb_init(int verbose)return ; fail_free_mem: -memblock_free_early (__pa (tlb), bytes); +memblock_free (__pa (tlb), bytes); fail:pr_warn ("Cannot allocate buffer" ); }
lib/cpumask.c renamed from lib/cpumask.c~memblock-drop-memblock_free_early_nid-and-memblock_free_early +1 -1
@@ -188,7 +188,7 @@ EXPORT_SYMBOL(free_cpumask_var);*/ void __init free_bootmem_cpumask_var (cpumask_var_t mask) { -memblock_free_early (__pa (mask),cpumask_size ()); +memblock_free (__pa (mask),cpumask_size ()); }#endif
mm/percpu.c renamed from mm/percpu.c~memblock-drop-memblock_free_early_nid-and-memblock_free_early +4 -4
@@ -2472,7 +2472,7 @@ struct pcpu_alloc_info * __init pcpu_all*/ void __init pcpu_free_alloc_info (struct pcpu_alloc_info *ai) { -memblock_free_early (__pa (ai), ai->__ai_size); +memblock_free (__pa (ai), ai->__ai_size); }/**
@@ -3134,7 +3134,7 @@ out_free_areas: out_free:pcpu_free_alloc_info (ai);if (areas) -memblock_free_early (__pa (areas), areas_size); +memblock_free (__pa (areas), areas_size); return rc; }#endif /* BUILD_EMBED_FIRST_CHUNK */
@@ -3256,7 +3256,7 @@ enomem:free_fn (page_address (pages[j]),PAGE_SIZE ); rc = -ENOMEM ; out_free_ar: -memblock_free_early (__pa (pages), pages_size); +memblock_free (__pa (pages), pages_size);pcpu_free_alloc_info (ai);return rc; }
@@ -3286,7 +3286,7 @@ static void * __init pcpu_dfl_fc_alloc(ustatic void __init pcpu_dfl_fc_free (void *ptr,size_t size) { -memblock_free_early (__pa (ptr), size); +memblock_free (__pa (ptr), size); }void __init setup_per_cpu_areas (void )
mm/sparse.c renamed from mm/sparse.c~memblock-drop-memblock_free_early_nid-and-memblock_free_early +1 -1
@@ -451,7 +451,7 @@ static void *sparsemap_buf_end __meminitstatic inline void __meminit sparse_buffer_free (unsigned long size) {WARN_ON (!sparsemap_buf || size ==0 ); -memblock_free_early (__pa (sparsemap_buf), size); +memblock_free (__pa (sparsemap_buf), size); }static void __init sparse_buffer_init (unsigned long size,int nid)
_
Andrew Morton
maintainerPATCH 165/262 memblock: stop aliasing __memblock_free_late with memblock_free_late
In reply to Andrew MortonFrom: Mike Rapoport <[email protected]>
Subject: memblock: stop aliasing __memblock_free_late with memblock_free_late
memblock_free_late() is a NOP wrapper for __memblock_free_late(), there is no point to keep this indirection.
Drop the wrapper and rename __memblock_free_late() to memblock_free_late().
---
include/linux/memblock.h | 7 +------ mm/memblock.c | 8 ++++---- 2 files changed, 5 insertions(+), 10 deletions(-)
include/linux/memblock.h renamed from include/linux/memblock.h~memblock-stop-aliasing-__memblock_free_late-with-memblock_free_late +1 -6
@@ -133,7 +133,7 @@ void __next_mem_range_rev(u64 *idx, int struct memblock_type *type_b, phys_addr_t *out_start, phys_addr_t *out_end, int *out_nid); -void __memblock_free_late (phys_addr_t base,phys_addr_t size); +void memblock_free_late (phys_addr_t base,phys_addr_t size);#ifdef CONFIG_HAVE_MEMBLOCK_PHYS_MAP static inline void __next_physmem_range(u64 *idx, struct memblock_type *type,
@@ -441,11 +441,6 @@ static inline void *memblock_alloc_node( MEMBLOCK_ALLOC_ACCESSIBLE, nid); } -static inline void memblock_free_late (phys_addr_t base,phys_addr_t size) -{ -__memblock_free_late (base, size); -} -/* * Set the allocation direction to bottom-up or top-down. */
mm/memblock.c renamed from mm/memblock.c~memblock-stop-aliasing-__memblock_free_late-with-memblock_free_late +4 -4
@@ -366,14 +366,14 @@ void __init memblock_discard(void) addr =__pa (memblock.reserved.regions); size =PAGE_ALIGN (sizeof (struct memblock_region ) * memblock.reserved.max); -__memblock_free_late (addr, size); +memblock_free_late (addr, size); }if (memblock.memory.regions != memblock_memory_init_regions) { addr =__pa (memblock.memory.regions); size =PAGE_ALIGN (sizeof (struct memblock_region ) * memblock.memory.max); -__memblock_free_late (addr, size); +memblock_free_late (addr, size); } memblock_memory =NULL ;
@@ -1589,7 +1589,7 @@ void * __init memblock_alloc_try_nid( }/** -* __memblock_free_late - free pages directly to buddy allocator +* memblock_free_late - free pages directly to buddy allocator * @base: phys starting address of the boot memory block * @size: size of the boot memory block in bytes *
@@ -1597,7 +1597,7 @@ void * __init memblock_alloc_try_nid(* down, but we are still initializing the system. Pages are released directly * to the buddy allocator. */ -void __init __memblock_free_late (phys_addr_t base,phys_addr_t size) +void __init memblock_free_late (phys_addr_t base,phys_addr_t size) {phys_addr_t cursor, end;
_
Andrew Morton
maintainerPATCH 166/262 memblock: rename memblock_free to memblock_phys_free
In reply to Andrew MortonFrom: Mike Rapoport <[email protected]>
Subject: memblock: rename memblock_free to memblock_phys_free
Since memblock_free() operates on a physical range, make its name reflect it and rename it to memblock_phys_free(), so it will be a logical counterpart to memblock_phys_alloc().
The callers are updated with the below semantic patch:
@@
expression addr;
expression size;
@@
- memblock_free(addr, size);
+ memblock_phys_free(addr, size);
---
arch/alpha/kernel/core_irongate.c | 3 ++- arch/arc/mm/init.c | 2 +- arch/arm/mach-hisi/platmcpm.c | 2 +- arch/arm/mm/init.c | 2 +- arch/arm64/mm/mmu.c | 4 ++-- arch/mips/mm/init.c | 2 +- arch/mips/sgi-ip30/ip30-setup.c | 6 +++--- arch/powerpc/kernel/dt_cpu_ftrs.c | 4 ++-- arch/powerpc/kernel/paca.c | 8 ++++---- arch/powerpc/kernel/setup-common.c | 2 +- arch/powerpc/kernel/setup_64.c | 2 +- arch/powerpc/platforms/powernv/pci-ioda.c | 2 +- arch/powerpc/platforms/pseries/svm.c | 3 ++- arch/riscv/kernel/setup.c | 5 +++-- arch/s390/kernel/setup.c | 8 ++++---- arch/s390/kernel/smp.c | 4 ++-- arch/s390/kernel/uv.c | 2 +- arch/s390/mm/kasan_init.c | 2 +- arch/sh/boards/mach-ap325rxa/setup.c | 2 +- arch/sh/boards/mach-ecovec24/setup.c | 4 ++-- arch/sh/boards/mach-kfr2r09/setup.c | 2 +- arch/sh/boards/mach-migor/setup.c | 2 +- arch/sh/boards/mach-se/7724/setup.c | 4 ++-- arch/sparc/kernel/smp_64.c | 2 +- arch/um/kernel/mem.c | 2 +- arch/x86/kernel/setup.c | 4 ++-- arch/x86/mm/init.c | 2 +- arch/x86/xen/mmu_pv.c | 6 +++--- arch/x86/xen/setup.c | 6 +++--- drivers/base/arch_numa.c | 2 +- drivers/firmware/efi/memmap.c | 2 +- drivers/of/kexec.c | 3 +-- drivers/of/of_reserved_mem.c | 5 +++-- drivers/s390/char/sclp_early.c | 2 +- drivers/usb/early/xhci-dbc.c | 10 +++++----- drivers/xen/swiotlb-xen.c | 2 +- include/linux/memblock.h | 2 +- init/initramfs.c | 2 +- kernel/dma/swiotlb.c | 2 +- lib/cpumask.c | 2 +- mm/cma.c | 2 +- mm/memblock.c | 8 ++++---- mm/memory_hotplug.c | 2 +- mm/percpu.c | 8 ++++---- mm/sparse.c | 2 +- 45 files changed, 79 insertions(+), 76 deletions(-)
arch/alpha/kernel/core_irongate.c renamed from arch/alpha/kernel/core_irongate.c~memblock-rename-memblock_free-to-memblock_phys_free +2 -1
@@ -233,7 +233,8 @@ albacore_init_arch(void)unsigned long size; size = initrd_end - initrd_start; -memblock_free (__pa (initrd_start),PAGE_ALIGN (size)); +memblock_phys_free (__pa (initrd_start), +PAGE_ALIGN (size));if (!move_initrd (pci_mem)) printk("irongate_init_arch: initrd too big " "(%ldK)\ndisabling initrd\n",
arch/arc/mm/init.c renamed from arch/arc/mm/init.c~memblock-rename-memblock_free-to-memblock_phys_free +1 -1
@@ -173,7 +173,7 @@ static void __init highmem_init(void)#ifdef CONFIG_HIGHMEM unsigned long tmp; -memblock_free (high_mem_start, high_mem_sz); +memblock_phys_free (high_mem_start, high_mem_sz);for (tmp = min_high_pfn; tmp < max_high_pfn; tmp++)free_highmem_page (pfn_to_page (tmp));#endif
arch/arm64/mm/mmu.c renamed from arch/arm64/mm/mmu.c~memblock-rename-memblock_free-to-memblock_phys_free +2 -2
@@ -738,8 +738,8 @@ void __init paging_init(void)cpu_replace_ttbr1 (lm_alias (swapper_pg_dir)); init_mm.pgd = swapper_pg_dir; -memblock_free (__pa_symbol (init_pg_dir), -__pa_symbol (init_pg_end) -__pa_symbol (init_pg_dir)); +memblock_phys_free (__pa_symbol (init_pg_dir), +__pa_symbol (init_pg_end) -__pa_symbol (init_pg_dir));memblock_allow_resize (); }
arch/arm/mach-hisi/platmcpm.c renamed from arch/arm/mach-hisi/platmcpm.c~memblock-rename-memblock_free-to-memblock_phys_free +1 -1
@@ -339,7 +339,7 @@ err_fabric: err_sysctrl:iounmap (relocation); err_reloc: -memblock_free (hip04_boot_method[0 ], hip04_boot_method[1 ]); +memblock_phys_free (hip04_boot_method[0 ], hip04_boot_method[1 ]); err:return ret; }
arch/arm/mm/init.c renamed from arch/arm/mm/init.c~memblock-rename-memblock_free-to-memblock_phys_free +1 -1
@@ -158,7 +158,7 @@ phys_addr_t __init arm_memblock_steal(phpanic ("Failed to steal %pa bytes at %pS\n" , &size, (void *)_RET_IP_); -memblock_free (phys, size); +memblock_phys_free (phys, size);memblock_remove (phys, size);return phys;
arch/mips/mm/init.c renamed from arch/mips/mm/init.c~memblock-rename-memblock_free-to-memblock_phys_free +1 -1
@@ -529,7 +529,7 @@ static void * __init pcpu_fc_alloc(unsigstatic void __init pcpu_fc_free (void *ptr,size_t size) { -memblock_free (__pa (ptr), size); +memblock_phys_free (__pa (ptr), size); }void __init setup_per_cpu_areas (void )
arch/mips/sgi-ip30/ip30-setup.c renamed from arch/mips/sgi-ip30/ip30-setup.c~memblock-rename-memblock_free-to-memblock_phys_free +3 -3
@@ -69,10 +69,10 @@ static void __init ip30_mem_init(void) total_mem += size;if (addr >=IP30_REAL_MEMORY_START ) -memblock_free (addr, size); +memblock_phys_free (addr, size);else if ((addr + size) >IP30_REAL_MEMORY_START ) -memblock_free (IP30_REAL_MEMORY_START , - size -IP30_MAX_PROM_MEMORY ); +memblock_phys_free (IP30_REAL_MEMORY_START , + size -IP30_MAX_PROM_MEMORY ); }pr_info ("Detected %luMB of physical memory.\n" ,MEM_SHIFT (total_mem)); }
arch/powerpc/kernel/dt_cpu_ftrs.c renamed from arch/powerpc/kernel/dt_cpu_ftrs.c~memblock-rename-memblock_free-to-memblock_phys_free +2 -2
@@ -1095,8 +1095,8 @@ static int __init dt_cpu_ftrs_scan_callbcpufeatures_setup_finished (); -memblock_free (__pa (dt_cpu_features), -sizeof (struct dt_cpu_feature )*nr_dt_cpu_features); +memblock_phys_free (__pa (dt_cpu_features), +sizeof (struct dt_cpu_feature ) * nr_dt_cpu_features);return 0 ; }
arch/powerpc/kernel/paca.c renamed from arch/powerpc/kernel/paca.c~memblock-rename-memblock_free-to-memblock_phys_free +4 -4
@@ -322,8 +322,8 @@ void __init free_unused_pacas(void) new_ptrs_size =sizeof (struct paca_struct *) * nr_cpu_ids;if (new_ptrs_size < paca_ptrs_size) -memblock_free (__pa (paca_ptrs) + new_ptrs_size, - paca_ptrs_size - new_ptrs_size); +memblock_phys_free (__pa (paca_ptrs) + new_ptrs_size, + paca_ptrs_size - new_ptrs_size); paca_nr_cpu_ids = nr_cpu_ids; paca_ptrs_size = new_ptrs_size;
@@ -331,8 +331,8 @@ void __init free_unused_pacas(void)#ifdef CONFIG_PPC_BOOK3S_64 if (early_radix_enabled ()) {/* Ugly fixup, see new_slb_shadow() */ -memblock_free (__pa (paca_ptrs[boot_cpuid]->slb_shadow_ptr), -sizeof (struct slb_shadow )); +memblock_phys_free (__pa (paca_ptrs[boot_cpuid]->slb_shadow_ptr), +sizeof (struct slb_shadow )); paca_ptrs[boot_cpuid]->slb_shadow_ptr =NULL ; }#endif
arch/powerpc/kernel/setup_64.c renamed from arch/powerpc/kernel/setup_64.c~memblock-rename-memblock_free-to-memblock_phys_free +1 -1
@@ -812,7 +812,7 @@ static void * __init pcpu_alloc_bootmem(static void __init pcpu_free_bootmem (void *ptr,size_t size) { -memblock_free (__pa (ptr), size); +memblock_phys_free (__pa (ptr), size); }static int pcpu_cpu_distance (unsigned int from,unsigned int to)
arch/powerpc/kernel/setup-common.c renamed from arch/powerpc/kernel/setup-common.c~memblock-rename-memblock_free-to-memblock_phys_free +1 -1
@@ -825,7 +825,7 @@ static void __init smp_setup_pacas(void)set_hard_smp_processor_id (cpu, cpu_to_phys_id[cpu]); } -memblock_free (__pa (cpu_to_phys_id), nr_cpu_ids *sizeof (u32)); +memblock_phys_free (__pa (cpu_to_phys_id), nr_cpu_ids *sizeof (u32)); cpu_to_phys_id =NULL ; }#endif
arch/powerpc/platforms/powernv/pci-ioda.c renamed from arch/powerpc/platforms/powernv/pci-ioda.c~memblock-rename-memblock_free-to-memblock_phys_free +1 -1
@@ -2981,7 +2981,7 @@ static void __init pnv_pci_init_ioda_phbif (!phb->hose) {pr_err (" Can't allocate PCI controller for %pOF\n" , np); -memblock_free (__pa (phb),sizeof (struct pnv_phb )); +memblock_phys_free (__pa (phb),sizeof (struct pnv_phb ));return ; }
arch/powerpc/platforms/pseries/svm.c renamed from arch/powerpc/platforms/pseries/svm.c~memblock-rename-memblock_free-to-memblock_phys_free +2 -1
@@ -56,7 +56,8 @@ void __init svm_swiotlb_init(void)return ; -memblock_free (__pa (vstart),PAGE_ALIGN (io_tlb_nslabs <<IO_TLB_SHIFT )); +memblock_phys_free (__pa (vstart), +PAGE_ALIGN (io_tlb_nslabs <<IO_TLB_SHIFT ));panic ("SVM: Cannot allocate SWIOTLB buffer" ); }
arch/riscv/kernel/setup.c renamed from arch/riscv/kernel/setup.c~memblock-rename-memblock_free-to-memblock_phys_free +3 -2
@@ -230,13 +230,14 @@ static void __init init_resources(void)/* Clean-up any unused pre-allocated resources */ if (res_idx >=0 ) -memblock_free (__pa (mem_res), (res_idx +1 ) *sizeof (*mem_res)); +memblock_phys_free (__pa (mem_res), + (res_idx +1 ) *sizeof (*mem_res));return ; error:/* Better an empty resource tree than an inconsistent one */ release_child_resources (&iomem_resource); -memblock_free (__pa (mem_res), mem_res_sz); +memblock_phys_free (__pa (mem_res), mem_res_sz); }
arch/s390/kernel/setup.c renamed from arch/s390/kernel/setup.c~memblock-rename-memblock_free-to-memblock_phys_free +4 -4
@@ -693,7 +693,7 @@ static void __init reserve_crashkernel(v }if (register_memory_notifier (&kdump_mem_nb)) { -memblock_free (crash_base, crash_size); +memblock_phys_free (crash_base, crash_size);return ; }
@@ -748,7 +748,7 @@ static void __init free_mem_detect_info(get_mem_detect_reserved (&start, &size);if (size) -memblock_free (start, size); +memblock_phys_free (start, size); }static const char *__init get_mem_info_source (void )
@@ -793,7 +793,7 @@ static void __init check_initrd(void)if (initrd_data.start && initrd_data.size && !memblock_is_region_memory (initrd_data.start, initrd_data.size)) {pr_err ("The initial RAM disk does not fit into the memory\n" ); -memblock_free (initrd_data.start, initrd_data.size); +memblock_phys_free (initrd_data.start, initrd_data.size); initrd_start = initrd_end =0 ; }#endif
@@ -890,7 +890,7 @@ static void __init setup_randomness(voidif (stsi (vmms,3 ,2 ,2 ) ==0 && vmms->count)add_device_randomness (&vmms->vm,sizeof (vmms->vm[0 ]) * vmms->count); -memblock_free ((unsigned long ) vmms,PAGE_SIZE ); +memblock_phys_free ((unsigned long )vmms,PAGE_SIZE ); }/*
arch/s390/kernel/smp.c renamed from arch/s390/kernel/smp.c~memblock-rename-memblock_free-to-memblock_phys_free +2 -2
@@ -723,7 +723,7 @@ void __init smp_save_dump_cpus(void)/* Get the CPU registers */ smp_save_cpu_regs (sa, addr, is_boot_cpu, page); } -memblock_free (page,PAGE_SIZE ); +memblock_phys_free (page,PAGE_SIZE ); diag_amode31_ops.diag308_reset ();pcpu_set_smt (0 ); }
@@ -880,7 +880,7 @@ void __init smp_detect_cpus(void)/* Add CPUs present at boot */ __smp_rescan_cpus (info, true); -memblock_free ((unsigned long )info,sizeof (*info)); +memblock_phys_free ((unsigned long )info,sizeof (*info)); }/*
arch/s390/kernel/uv.c renamed from arch/s390/kernel/uv.c~memblock-rename-memblock_free-to-memblock_phys_free +1 -1
@@ -64,7 +64,7 @@ void __init setup_uv(void) }if (uv_init (uv_stor_base, uv_info.uv_base_stor_len)) { -memblock_free (uv_stor_base, uv_info.uv_base_stor_len); +memblock_phys_free (uv_stor_base, uv_info.uv_base_stor_len); goto fail; }
arch/s390/mm/kasan_init.c renamed from arch/s390/mm/kasan_init.c~memblock-rename-memblock_free-to-memblock_phys_free +1 -1
@@ -399,5 +399,5 @@ void __init kasan_copy_shadow_mapping(vovoid __init kasan_free_early_identity (void ) { -memblock_free (pgalloc_pos, pgalloc_freeable - pgalloc_pos); +memblock_phys_free (pgalloc_pos, pgalloc_freeable - pgalloc_pos); }
arch/sh/boards/mach-ap325rxa/setup.c renamed from arch/sh/boards/mach-ap325rxa/setup.c~memblock-rename-memblock_free-to-memblock_phys_free +1 -1
@@ -560,7 +560,7 @@ static void __init ap325rxa_mv_mem_reserif (!phys)panic ("Failed to allocate CEU memory\n" ); -memblock_free (phys, size); +memblock_phys_free (phys, size);memblock_remove (phys, size); ceu_dma_membase = phys;
arch/sh/boards/mach-ecovec24/setup.c renamed from arch/sh/boards/mach-ecovec24/setup.c~memblock-rename-memblock_free-to-memblock_phys_free +2 -2
@@ -1502,7 +1502,7 @@ static void __init ecovec_mv_mem_reserveif (!phys)panic ("Failed to allocate CEU0 memory\n" ); -memblock_free (phys, size); +memblock_phys_free (phys, size);memblock_remove (phys, size); ceu0_dma_membase = phys;
@@ -1510,7 +1510,7 @@ static void __init ecovec_mv_mem_reserveif (!phys)panic ("Failed to allocate CEU1 memory\n" ); -memblock_free (phys, size); +memblock_phys_free (phys, size);memblock_remove (phys, size); ceu1_dma_membase = phys; }
arch/sh/boards/mach-kfr2r09/setup.c renamed from arch/sh/boards/mach-kfr2r09/setup.c~memblock-rename-memblock_free-to-memblock_phys_free +1 -1
@@ -633,7 +633,7 @@ static void __init kfr2r09_mv_mem_reservif (!phys)panic ("Failed to allocate CEU memory\n" ); -memblock_free (phys, size); +memblock_phys_free (phys, size);memblock_remove (phys, size); ceu_dma_membase = phys;
arch/sh/boards/mach-migor/setup.c renamed from arch/sh/boards/mach-migor/setup.c~memblock-rename-memblock_free-to-memblock_phys_free +1 -1
@@ -633,7 +633,7 @@ static void __init migor_mv_mem_reserve(if (!phys)panic ("Failed to allocate CEU memory\n" ); -memblock_free (phys, size); +memblock_phys_free (phys, size);memblock_remove (phys, size); ceu_dma_membase = phys;
arch/sh/boards/mach-se/7724/setup.c renamed from arch/sh/boards/mach-se/7724/setup.c~memblock-rename-memblock_free-to-memblock_phys_free +2 -2
@@ -966,7 +966,7 @@ static void __init ms7724se_mv_mem_reserif (!phys)panic ("Failed to allocate CEU0 memory\n" ); -memblock_free (phys, size); +memblock_phys_free (phys, size);memblock_remove (phys, size); ceu0_dma_membase = phys;
@@ -974,7 +974,7 @@ static void __init ms7724se_mv_mem_reserif (!phys)panic ("Failed to allocate CEU1 memory\n" ); -memblock_free (phys, size); +memblock_phys_free (phys, size);memblock_remove (phys, size); ceu1_dma_membase = phys; }
arch/sparc/kernel/smp_64.c renamed from arch/sparc/kernel/smp_64.c~memblock-rename-memblock_free-to-memblock_phys_free +1 -1
@@ -1567,7 +1567,7 @@ static void * __init pcpu_alloc_bootmem(static void __init pcpu_free_bootmem (void *ptr,size_t size) { -memblock_free (__pa (ptr), size); +memblock_phys_free (__pa (ptr), size); }static int __init pcpu_cpu_distance (unsigned int from,unsigned int to)
arch/um/kernel/mem.c renamed from arch/um/kernel/mem.c~memblock-rename-memblock_free-to-memblock_phys_free +1 -1
@@ -47,7 +47,7 @@ void __init mem_init(void)*/ brk_end = (unsigned long )UML_ROUND_UP (sbrk (0 ));map_memory (brk_end,__pa (brk_end), uml_reserved - brk_end,1 ,1 ,0 ); -memblock_free (__pa (brk_end), uml_reserved - brk_end); +memblock_phys_free (__pa (brk_end), uml_reserved - brk_end); uml_reserved = brk_end;/* this will put all low memory onto the freelists */
arch/x86/kernel/setup.c renamed from arch/x86/kernel/setup.c~memblock-rename-memblock_free-to-memblock_phys_free +2 -2
@@ -322,7 +322,7 @@ static void __init reserve_initrd(void)relocate_initrd (); - memblock_free(ramdisk_image, ramdisk_end - ramdisk_image); + memblock_phys_free(ramdisk_image, ramdisk_end - ramdisk_image); }#else
@@ -521,7 +521,7 @@ static void __init reserve_crashkernel(v }if (crash_base >= (1ULL <<32 ) &&reserve_crashkernel_low ()) { -memblock_free (crash_base, crash_size); +memblock_phys_free (crash_base, crash_size);return ; }
arch/x86/mm/init.c renamed from arch/x86/mm/init.c~memblock-rename-memblock_free-to-memblock_phys_free +1 -1
@@ -618,7 +618,7 @@ static void __init memory_map_top_down(u*/ addr =memblock_phys_alloc_range (PMD_SIZE ,PMD_SIZE , map_start, map_end); -memblock_free (addr,PMD_SIZE ); +memblock_phys_free (addr,PMD_SIZE ); real_end = addr +PMD_SIZE ;/* step_size need to be small so pgt_buf from BRK could cover it */
arch/x86/xen/mmu_pv.c renamed from arch/x86/xen/mmu_pv.c~memblock-rename-memblock_free-to-memblock_phys_free +3 -3
@@ -1025,7 +1025,7 @@ static void __init xen_free_ro_pages(unsfor (; vaddr < vaddr_end; vaddr +=PAGE_SIZE )make_lowmem_page_readwrite (vaddr); -memblock_free (paddr, size); +memblock_phys_free (paddr, size); }static void __init xen_cleanmfnmap_free_pgtbl (void *pgtbl,bool unpin)
@@ -1151,7 +1151,7 @@ static void __init xen_pagetable_p2m_frexen_cleanhighmap (addr, addr + size); size =PAGE_ALIGN (xen_start_info->nr_pages *sizeof (unsigned long )); -memblock_free (__pa (addr), size); +memblock_phys_free (__pa (addr), size); }else {xen_cleanmfnmap (addr); }
@@ -1955,7 +1955,7 @@ void __init xen_relocate_p2m(void) pfn_end = p2m_pfn_end; } -memblock_free (PFN_PHYS (pfn),PAGE_SIZE * (pfn_end - pfn)); +memblock_phys_free (PFN_PHYS (pfn),PAGE_SIZE * (pfn_end - pfn));while (pfn < pfn_end) {if (pfn == p2m_pfn) { pfn = p2m_pfn_end;
arch/x86/xen/setup.c renamed from arch/x86/xen/setup.c~memblock-rename-memblock_free-to-memblock_phys_free +3 -3
@@ -153,7 +153,7 @@ static void __init xen_del_extra_mem(unsbreak ; } } -memblock_free (PFN_PHYS (start_pfn),PFN_PHYS (n_pfns)); +memblock_phys_free (PFN_PHYS (start_pfn),PFN_PHYS (n_pfns)); }/*
@@ -719,7 +719,7 @@ static void __init xen_reserve_xen_mfnlireturn ;xen_relocate_p2m (); -memblock_free (start, size); +memblock_phys_free (start, size); }/**
@@ -885,7 +885,7 @@ char * __init xen_memory_setup(void)xen_phys_memcpy (new_area, start, size);pr_info ("initrd moved from [mem %#010llx-%#010llx] to [mem %#010llx-%#010llx]\n" , start, start + size, new_area, new_area + size); -memblock_free (start, size); +memblock_phys_free (start, size); boot_params.hdr.ramdisk_image = new_area; boot_params.ext_ramdisk_image = new_area >>32 ; }
drivers/base/arch_numa.c renamed from drivers/base/arch_numa.c~memblock-rename-memblock_free-to-memblock_phys_free +1 -1
@@ -166,7 +166,7 @@ static void * __init pcpu_fc_alloc(unsigstatic void __init pcpu_fc_free (void *ptr,size_t size) { -memblock_free (__pa (ptr), size); +memblock_phys_free (__pa (ptr), size); }#ifdef CONFIG_NEED_PER_CPU_PAGE_FIRST_CHUNK
drivers/firmware/efi/memmap.c renamed from drivers/firmware/efi/memmap.c~memblock-rename-memblock_free-to-memblock_phys_free +1 -1
@@ -35,7 +35,7 @@ void __init __efi_memmap_free(u64 phys,if (slab_is_available ())memblock_free_late (phys, size);else -memblock_free (phys, size); +memblock_phys_free (phys, size); }else if (flags &EFI_MEMMAP_SLAB ) {struct page *p =pfn_to_page (PHYS_PFN (phys));unsigned int order =get_order (size);
drivers/of/kexec.c renamed from drivers/of/kexec.c~memblock-rename-memblock_free-to-memblock_phys_free +1 -2
@@ -171,8 +171,7 @@ int ima_free_kexec_buffer(void)if (ret)return ret; -return memblock_free (addr, size); - +return memblock_phys_free (addr, size); }/**
drivers/of/of_reserved_mem.c renamed from drivers/of/of_reserved_mem.c~memblock-rename-memblock_free-to-memblock_phys_free +3 -2
@@ -46,7 +46,7 @@ static int __init early_init_dt_alloc_reif (nomap) { err =memblock_mark_nomap (base, size);if (err) -memblock_free (base, size); +memblock_phys_free (base, size);kmemleak_ignore_phys (base); }
@@ -284,7 +284,8 @@ void __init fdt_init_reserved_mem(void)if (nomap)memblock_clear_nomap (rmem->base, rmem->size);else -memblock_free (rmem->base, rmem->size); +memblock_phys_free (rmem->base, + rmem->size); } } }
drivers/s390/char/sclp_early.c renamed from drivers/s390/char/sclp_early.c~memblock-rename-memblock_free-to-memblock_phys_free +1 -1
@@ -139,7 +139,7 @@ int __init sclp_early_get_core_info(stru }sclp_fill_core_info (info, sccb); out: -memblock_free ((unsigned long )sccb, length); +memblock_phys_free ((unsigned long )sccb, length);return rc; }
drivers/usb/early/xhci-dbc.c renamed from drivers/usb/early/xhci-dbc.c~memblock-rename-memblock_free-to-memblock_phys_free +5 -5
@@ -185,7 +185,7 @@ static void __init xdbc_free_ring(structif (!seg)return ; -memblock_free (seg->dma,PAGE_SIZE ); +memblock_phys_free (seg->dma,PAGE_SIZE ); ring->segment =NULL ; }
@@ -665,10 +665,10 @@ int __init early_xdbc_setup_hardware(voixdbc_free_ring (&xdbc.in_ring);if (xdbc.table_dma) -memblock_free (xdbc.table_dma,PAGE_SIZE ); +memblock_phys_free (xdbc.table_dma,PAGE_SIZE );if (xdbc.out_dma) -memblock_free (xdbc.out_dma,PAGE_SIZE ); +memblock_phys_free (xdbc.out_dma,PAGE_SIZE ); xdbc.table_base =NULL ; xdbc.out_buf =NULL ;
@@ -987,8 +987,8 @@ free_and_quit:xdbc_free_ring (&xdbc.evt_ring);xdbc_free_ring (&xdbc.out_ring);xdbc_free_ring (&xdbc.in_ring); -memblock_free (xdbc.table_dma,PAGE_SIZE ); -memblock_free (xdbc.out_dma,PAGE_SIZE ); +memblock_phys_free (xdbc.table_dma,PAGE_SIZE ); +memblock_phys_free (xdbc.out_dma,PAGE_SIZE );writel (0 , &xdbc.xdbc_reg->control);early_iounmap (xdbc.xhci_base, xdbc.xhci_length);
drivers/xen/swiotlb-xen.c renamed from drivers/xen/swiotlb-xen.c~memblock-rename-memblock_free-to-memblock_phys_free +1 -1
@@ -241,7 +241,7 @@ retry:*/ rc =xen_swiotlb_fixup (start, nslabs);if (rc) { -memblock_free (__pa (start),PAGE_ALIGN (bytes)); +memblock_phys_free (__pa (start),PAGE_ALIGN (bytes));if (nslabs >1024 && repeat--) {/* Min is 2MB */ nslabs =max (1024UL ,ALIGN (nslabs >>1 ,IO_TLB_SEGSIZE ));
include/linux/memblock.h renamed from include/linux/memblock.h~memblock-rename-memblock_free-to-memblock_phys_free +1 -1
@@ -103,7 +103,7 @@ void memblock_allow_resize(void);int memblock_add_node (phys_addr_t base,phys_addr_t size,int nid);int memblock_add (phys_addr_t base,phys_addr_t size);int memblock_remove (phys_addr_t base,phys_addr_t size); -int memblock_free (phys_addr_t base,phys_addr_t size); +int memblock_phys_free (phys_addr_t base,phys_addr_t size);int memblock_reserve (phys_addr_t base,phys_addr_t size);#ifdef CONFIG_HAVE_MEMBLOCK_PHYS_MAP int memblock_physmem_add (phys_addr_t base,phys_addr_t size);
init/initramfs.c renamed from init/initramfs.c~memblock-rename-memblock_free-to-memblock_phys_free +1 -1
@@ -607,7 +607,7 @@ void __weak __init free_initrd_mem(unsigunsigned long aligned_start =ALIGN_DOWN (start,PAGE_SIZE );unsigned long aligned_end =ALIGN (end,PAGE_SIZE ); -memblock_free (__pa (aligned_start), aligned_end - aligned_start); +memblock_phys_free (__pa (aligned_start), aligned_end - aligned_start);#endif free_reserved_area((void *)start, (void *)end, POISON_FREE_INITMEM,
kernel/dma/swiotlb.c renamed from kernel/dma/swiotlb.c~memblock-rename-memblock_free-to-memblock_phys_free +1 -1
@@ -247,7 +247,7 @@ swiotlb_init(int verbose)return ; fail_free_mem: -memblock_free (__pa (tlb), bytes); +memblock_phys_free (__pa (tlb), bytes); fail:pr_warn ("Cannot allocate buffer" ); }
lib/cpumask.c renamed from lib/cpumask.c~memblock-rename-memblock_free-to-memblock_phys_free +1 -1
@@ -188,7 +188,7 @@ EXPORT_SYMBOL(free_cpumask_var);*/ void __init free_bootmem_cpumask_var (cpumask_var_t mask) { -memblock_free (__pa (mask),cpumask_size ()); +memblock_phys_free (__pa (mask),cpumask_size ()); }#endif
mm/cma.c renamed from mm/cma.c~memblock-rename-memblock_free-to-memblock_phys_free +1 -1
@@ -378,7 +378,7 @@ int __init cma_declare_contiguous_nid(phreturn 0 ; free_mem: -memblock_free (base, size); +memblock_phys_free (base, size); err:pr_err ("Failed to reserve %ld MiB\n" , (unsigned long )size /SZ_1M );return ret;
mm/memblock.c renamed from mm/memblock.c~memblock-rename-memblock_free-to-memblock_phys_free +4 -4
@@ -806,18 +806,18 @@ int __init_memblock memblock_remove(phys void __init_memblock memblock_free_ptr(void *ptr, size_t size) {if (ptr) -memblock_free (__pa (ptr), size); +memblock_phys_free (__pa (ptr), size); }/** -* memblock_free - free boot memory block +* memblock_phys_free - free boot memory block * @base: phys starting address of the boot memory block * @size: size of the boot memory block in bytes * * Free boot memory block previously allocated by memblock_alloc_xx() API. * The freeing memory will not be released to the buddy allocator. */ -int __init_memblock memblock_free(phys_addr_t base, phys_addr_t size) +int __init_memblock memblock_phys_free(phys_addr_t base, phys_addr_t size) {phys_addr_t end = base + size -1 ;
@@ -1937,7 +1937,7 @@ static void __init free_memmap(unsigned* memmap array. */ if (pg < pgend) -memblock_free (pg, pgend - pg); +memblock_phys_free (pg, pgend - pg); }/*
mm/memory_hotplug.c renamed from mm/memory_hotplug.c~memblock-rename-memblock_free-to-memblock_phys_free +1 -1
@@ -2204,7 +2204,7 @@ static int __ref try_remove_memory(u64 sarch_remove_memory (start, size, altmap);if (IS_ENABLED (CONFIG_ARCH_KEEP_MEMBLOCK )) { -memblock_free (start, size); +memblock_phys_free (start, size);memblock_remove (start, size); }
mm/percpu.c renamed from mm/percpu.c~memblock-rename-memblock_free-to-memblock_phys_free +4 -4
@@ -2472,7 +2472,7 @@ struct pcpu_alloc_info * __init pcpu_all*/ void __init pcpu_free_alloc_info (struct pcpu_alloc_info *ai) { -memblock_free (__pa (ai), ai->__ai_size); +memblock_phys_free (__pa (ai), ai->__ai_size); }/**
@@ -3134,7 +3134,7 @@ out_free_areas: out_free:pcpu_free_alloc_info (ai);if (areas) -memblock_free (__pa (areas), areas_size); +memblock_phys_free (__pa (areas), areas_size); return rc; }#endif /* BUILD_EMBED_FIRST_CHUNK */
@@ -3256,7 +3256,7 @@ enomem:free_fn (page_address (pages[j]),PAGE_SIZE ); rc = -ENOMEM ; out_free_ar: -memblock_free (__pa (pages), pages_size); +memblock_phys_free (__pa (pages), pages_size);pcpu_free_alloc_info (ai);return rc; }
@@ -3286,7 +3286,7 @@ static void * __init pcpu_dfl_fc_alloc(ustatic void __init pcpu_dfl_fc_free (void *ptr,size_t size) { -memblock_free (__pa (ptr), size); +memblock_phys_free (__pa (ptr), size); }void __init setup_per_cpu_areas (void )
mm/sparse.c renamed from mm/sparse.c~memblock-rename-memblock_free-to-memblock_phys_free +1 -1
@@ -451,7 +451,7 @@ static void *sparsemap_buf_end __meminitstatic inline void __meminit sparse_buffer_free (unsigned long size) {WARN_ON (!sparsemap_buf || size ==0 ); -memblock_free (__pa (sparsemap_buf), size); +memblock_phys_free (__pa (sparsemap_buf), size); }static void __init sparse_buffer_init (unsigned long size,int nid)
_
Andrew Morton
maintainerPATCH 167/262 memblock: use memblock_free for freeing virtual pointers
In reply to Andrew MortonFrom: Mike Rapoport <[email protected]>
Subject: memblock: use memblock_free for freeing virtual pointers
Rename memblock_free_ptr() to memblock_free() and use memblock_free() when freeing a virtual pointer so that memblock_free() will be a counterpart of memblock_alloc()
The callers are updated with the below semantic patch and manual addition of (void *) casting to pointers that are represented by unsigned long variables.
@@
identifier vaddr;
expression size;
@@
(
- memblock_phys_free(__pa(vaddr), size);
+ memblock_free(vaddr, size);
|
- memblock_free_ptr(vaddr, size);
+ memblock_free(vaddr, size);
)
---
arch/alpha/kernel/core_irongate.c | 3 +-- arch/mips/mm/init.c | 2 +- arch/powerpc/kernel/dt_cpu_ftrs.c | 4 ++-- arch/powerpc/kernel/setup-common.c | 2 +- arch/powerpc/kernel/setup_64.c | 2 +- arch/powerpc/platforms/powernv/pci-ioda.c | 2 +- arch/powerpc/platforms/pseries/svm.c | 3 +-- arch/riscv/kernel/setup.c | 5 ++--- arch/sparc/kernel/smp_64.c | 2 +- arch/um/kernel/mem.c | 2 +- arch/x86/kernel/setup_percpu.c | 2 +- arch/x86/mm/kasan_init_64.c | 4 ++-- arch/x86/mm/numa.c | 2 +- arch/x86/mm/numa_emulation.c | 2 +- arch/x86/xen/mmu_pv.c | 2 +- arch/x86/xen/p2m.c | 2 +- drivers/base/arch_numa.c | 4 ++-- drivers/macintosh/smu.c | 2 +- drivers/xen/swiotlb-xen.c | 2 +- include/linux/memblock.h | 2 +- init/initramfs.c | 2 +- init/main.c | 4 ++-- kernel/dma/swiotlb.c | 2 +- kernel/printk/printk.c | 4 ++-- lib/bootconfig.c | 2 +- lib/cpumask.c | 2 +- mm/memblock.c | 6 +++--- mm/percpu.c | 8 ++++---- mm/sparse.c | 2 +- 29 files changed, 40 insertions(+), 43 deletions(-)
arch/alpha/kernel/core_irongate.c renamed from arch/alpha/kernel/core_irongate.c~memblock-use-memblock_free-for-freeing-virtual-pointers +1 -2
@@ -233,8 +233,7 @@ albacore_init_arch(void)unsigned long size; size = initrd_end - initrd_start; -memblock_phys_free (__pa (initrd_start), -PAGE_ALIGN (size)); +memblock_free ((void *)initrd_start,PAGE_ALIGN (size));if (!move_initrd (pci_mem)) printk("irongate_init_arch: initrd too big " "(%ldK)\ndisabling initrd\n",
arch/mips/mm/init.c renamed from arch/mips/mm/init.c~memblock-use-memblock_free-for-freeing-virtual-pointers +1 -1
@@ -529,7 +529,7 @@ static void * __init pcpu_fc_alloc(unsigstatic void __init pcpu_fc_free (void *ptr,size_t size) { -memblock_phys_free (__pa (ptr), size); +memblock_free (ptr, size); }void __init setup_per_cpu_areas (void )
arch/powerpc/kernel/dt_cpu_ftrs.c renamed from arch/powerpc/kernel/dt_cpu_ftrs.c~memblock-use-memblock_free-for-freeing-virtual-pointers +2 -2
@@ -1095,8 +1095,8 @@ static int __init dt_cpu_ftrs_scan_callbcpufeatures_setup_finished (); -memblock_phys_free (__pa (dt_cpu_features), -sizeof (struct dt_cpu_feature ) * nr_dt_cpu_features); +memblock_free (dt_cpu_features, +sizeof (struct dt_cpu_feature ) * nr_dt_cpu_features);return 0 ; }
arch/powerpc/kernel/setup_64.c renamed from arch/powerpc/kernel/setup_64.c~memblock-use-memblock_free-for-freeing-virtual-pointers +1 -1
@@ -812,7 +812,7 @@ static void * __init pcpu_alloc_bootmem(static void __init pcpu_free_bootmem (void *ptr,size_t size) { -memblock_phys_free (__pa (ptr), size); +memblock_free (ptr, size); }static int pcpu_cpu_distance (unsigned int from,unsigned int to)
arch/powerpc/kernel/setup-common.c renamed from arch/powerpc/kernel/setup-common.c~memblock-use-memblock_free-for-freeing-virtual-pointers +1 -1
@@ -825,7 +825,7 @@ static void __init smp_setup_pacas(void) set_hard_smp_processor_id(cpu, cpu_to_phys_id[cpu]); } -memblock_phys_free (__pa (cpu_to_phys_id), nr_cpu_ids *sizeof (u32)); +memblock_free (cpu_to_phys_id, nr_cpu_ids *sizeof (u32)); cpu_to_phys_id =NULL ; }#endif
arch/powerpc/platforms/powernv/pci-ioda.c renamed from arch/powerpc/platforms/powernv/pci-ioda.c~memblock-use-memblock_free-for-freeing-virtual-pointers +1 -1
@@ -2981,7 +2981,7 @@ static void __init pnv_pci_init_ioda_phbif (!phb->hose) {pr_err (" Can't allocate PCI controller for %pOF\n" , np); -memblock_phys_free (__pa (phb),sizeof (struct pnv_phb )); +memblock_free (phb,sizeof (struct pnv_phb ));return ; }
arch/powerpc/platforms/pseries/svm.c renamed from arch/powerpc/platforms/pseries/svm.c~memblock-use-memblock_free-for-freeing-virtual-pointers +1 -2
@@ -56,8 +56,7 @@ void __init svm_swiotlb_init(void)return ; -memblock_phys_free (__pa (vstart), -PAGE_ALIGN (io_tlb_nslabs <<IO_TLB_SHIFT )); +memblock_free (vstart,PAGE_ALIGN (io_tlb_nslabs <<IO_TLB_SHIFT ));panic ("SVM: Cannot allocate SWIOTLB buffer" ); }
arch/riscv/kernel/setup.c renamed from arch/riscv/kernel/setup.c~memblock-use-memblock_free-for-freeing-virtual-pointers +2 -3
@@ -230,14 +230,13 @@ static void __init init_resources(void)/* Clean-up any unused pre-allocated resources */ if (res_idx >=0 ) -memblock_phys_free (__pa (mem_res), - (res_idx +1 ) *sizeof (*mem_res)); +memblock_free (mem_res, (res_idx +1 ) *sizeof (*mem_res));return ; error:/* Better an empty resource tree than an inconsistent one */ release_child_resources (&iomem_resource); -memblock_phys_free (__pa (mem_res), mem_res_sz); +memblock_free (mem_res, mem_res_sz); }
arch/sparc/kernel/smp_64.c renamed from arch/sparc/kernel/smp_64.c~memblock-use-memblock_free-for-freeing-virtual-pointers +1 -1
@@ -1567,7 +1567,7 @@ static void * __init pcpu_alloc_bootmem(static void __init pcpu_free_bootmem (void *ptr,size_t size) { -memblock_phys_free (__pa (ptr), size); +memblock_free (ptr, size); }static int __init pcpu_cpu_distance (unsigned int from,unsigned int to)
arch/um/kernel/mem.c renamed from arch/um/kernel/mem.c~memblock-use-memblock_free-for-freeing-virtual-pointers +1 -1
@@ -47,7 +47,7 @@ void __init mem_init(void)*/ brk_end = (unsigned long )UML_ROUND_UP (sbrk (0 ));map_memory (brk_end,__pa (brk_end), uml_reserved - brk_end,1 ,1 ,0 ); -memblock_phys_free (__pa (brk_end), uml_reserved - brk_end); +memblock_free ((void *)brk_end, uml_reserved - brk_end); uml_reserved = brk_end;/* this will put all low memory onto the freelists */
arch/x86/kernel/setup_percpu.c renamed from arch/x86/kernel/setup_percpu.c~memblock-use-memblock_free-for-freeing-virtual-pointers +1 -1
@@ -135,7 +135,7 @@ static void * __init pcpu_fc_alloc(unsigstatic void __init pcpu_fc_free (void *ptr,size_t size) { -memblock_free_ptr (ptr, size); +memblock_free (ptr, size); }static int __init pcpu_cpu_distance (unsigned int from,unsigned int to)
arch/x86/mm/kasan_init_64.c renamed from arch/x86/mm/kasan_init_64.c~memblock-use-memblock_free-for-freeing-virtual-pointers +2 -2
@@ -49,7 +49,7 @@ static void __init kasan_populate_pmd(pm p =early_alloc (PMD_SIZE , nid, false);if (p &&pmd_set_huge (pmd,__pa (p),PAGE_KERNEL ))return ; -memblock_free_ptr (p,PMD_SIZE ); +memblock_free (p,PMD_SIZE ); } p =early_alloc (PAGE_SIZE , nid, true);
@@ -85,7 +85,7 @@ static void __init kasan_populate_pud(pu p =early_alloc (PUD_SIZE , nid, false);if (p &&pud_set_huge (pud,__pa (p),PAGE_KERNEL ))return ; -memblock_free_ptr (p,PUD_SIZE ); +memblock_free (p,PUD_SIZE ); } p =early_alloc (PAGE_SIZE , nid, true);
arch/x86/mm/numa.c renamed from arch/x86/mm/numa.c~memblock-use-memblock_free-for-freeing-virtual-pointers +1 -1
@@ -355,7 +355,7 @@ void __init numa_reset_distance(void)/* numa_distance could be 1LU marking allocation failure, test cnt */ if (numa_distance_cnt) -memblock_free_ptr (numa_distance, size); +memblock_free (numa_distance, size); numa_distance_cnt =0 ; numa_distance =NULL ;/* enable table creation */ }
arch/x86/mm/numa_emulation.c renamed from arch/x86/mm/numa_emulation.c~memblock-use-memblock_free-for-freeing-virtual-pointers +1 -1
@@ -517,7 +517,7 @@ void __init numa_emulation(struct numa_m }/* free the copied physical distance table */ -memblock_free_ptr (phys_dist, phys_size); +memblock_free (phys_dist, phys_size);return ; no_emu:
arch/x86/xen/mmu_pv.c renamed from arch/x86/xen/mmu_pv.c~memblock-use-memblock_free-for-freeing-virtual-pointers +1 -1
@@ -1151,7 +1151,7 @@ static void __init xen_pagetable_p2m_frexen_cleanhighmap (addr, addr + size); size =PAGE_ALIGN (xen_start_info->nr_pages *sizeof (unsigned long )); -memblock_phys_free (__pa (addr), size); +memblock_free ((void *)addr, size); }else {xen_cleanmfnmap (addr); }
arch/x86/xen/p2m.c renamed from arch/x86/xen/p2m.c~memblock-use-memblock_free-for-freeing-virtual-pointers +1 -1
@@ -197,7 +197,7 @@ static void * __ref alloc_p2m_page(void)static void __ref free_p2m_page (void *p) {if (unlikely (!slab_is_available ())) { -memblock_free_ptr (p,PAGE_SIZE ); +memblock_free (p,PAGE_SIZE );return ; }
drivers/base/arch_numa.c renamed from drivers/base/arch_numa.c~memblock-use-memblock_free-for-freeing-virtual-pointers +2 -2
@@ -166,7 +166,7 @@ static void * __init pcpu_fc_alloc(unsigstatic void __init pcpu_fc_free (void *ptr,size_t size) { -memblock_phys_free (__pa (ptr), size); +memblock_free (ptr, size); }#ifdef CONFIG_NEED_PER_CPU_PAGE_FIRST_CHUNK
@@ -326,7 +326,7 @@ void __init numa_free_distance(void) size = numa_distance_cnt * numa_distance_cnt *sizeof (numa_distance[0 ]); -memblock_free_ptr (numa_distance, size); +memblock_free (numa_distance, size); numa_distance_cnt =0 ; numa_distance =NULL ; }
drivers/macintosh/smu.c renamed from drivers/macintosh/smu.c~memblock-use-memblock_free-for-freeing-virtual-pointers +1 -1
@@ -570,7 +570,7 @@ fail_msg_node: fail_db_node:of_node_put (smu->db_node); fail_bootmem: -memblock_free_ptr (smu,sizeof (struct smu_device )); +memblock_free (smu,sizeof (struct smu_device )); smu =NULL ; fail_np:of_node_put (np);
drivers/xen/swiotlb-xen.c renamed from drivers/xen/swiotlb-xen.c~memblock-use-memblock_free-for-freeing-virtual-pointers +1 -1
@@ -241,7 +241,7 @@ retry:*/ rc =xen_swiotlb_fixup (start, nslabs);if (rc) { -memblock_phys_free (__pa (start),PAGE_ALIGN (bytes)); +memblock_free (start,PAGE_ALIGN (bytes));if (nslabs >1024 && repeat--) {/* Min is 2MB */ nslabs =max (1024UL ,ALIGN (nslabs >>1 ,IO_TLB_SEGSIZE ));
include/linux/memblock.h renamed from include/linux/memblock.h~memblock-use-memblock_free-for-freeing-virtual-pointers +1 -1
@@ -118,7 +118,7 @@ int memblock_mark_nomap(phys_addr_t baseint memblock_clear_nomap (phys_addr_t base,phys_addr_t size);void memblock_free_all (void ); -void memblock_free_ptr (void *ptr,size_t size); +void memblock_free (void *ptr,size_t size);void reset_node_managed_pages (pg_data_t *pgdat);void reset_all_zones_managed_pages (void );
init/initramfs.c renamed from init/initramfs.c~memblock-use-memblock_free-for-freeing-virtual-pointers +1 -1
@@ -607,7 +607,7 @@ void __weak __init free_initrd_mem(unsigunsigned long aligned_start =ALIGN_DOWN (start,PAGE_SIZE );unsigned long aligned_end =ALIGN (end,PAGE_SIZE ); -memblock_phys_free (__pa (aligned_start), aligned_end - aligned_start); +memblock_free ((void *)aligned_start, aligned_end - aligned_start);#endif free_reserved_area((void *)start, (void *)end, POISON_FREE_INITMEM,
init/main.c renamed from init/main.c~memblock-use-memblock_free-for-freeing-virtual-pointers +2 -2
@@ -382,7 +382,7 @@ static char * __init xbc_make_cmdline(co ret =xbc_snprint_cmdline (new_cmdline, len +1 , root);if (ret <0 || ret > len) {pr_err ("Failed to print extra kernel cmdline.\n" ); -memblock_free_ptr (new_cmdline, len +1 ); +memblock_free (new_cmdline, len +1 );return NULL ; }
@@ -925,7 +925,7 @@ static void __init print_unknown_bootopt end +=sprintf (end," %s" , *p);pr_notice ("Unknown command line parameters:%s\n" , unknown_options); -memblock_free_ptr (unknown_options, len); +memblock_free (unknown_options, len); } asmlinkage __visible void __init __no_sanitize_address start_kernel(void)
kernel/dma/swiotlb.c renamed from kernel/dma/swiotlb.c~memblock-use-memblock_free-for-freeing-virtual-pointers +1 -1
@@ -247,7 +247,7 @@ swiotlb_init(int verbose)return ; fail_free_mem: -memblock_phys_free (__pa (tlb), bytes); +memblock_free (tlb, bytes); fail:pr_warn ("Cannot allocate buffer" ); }
kernel/printk/printk.c renamed from kernel/printk/printk.c~memblock-use-memblock_free-for-freeing-virtual-pointers +2 -2
@@ -1166,9 +1166,9 @@ void __init setup_log_buf(int early)return ; err_free_descs: -memblock_free_ptr (new_descs, new_descs_size); +memblock_free (new_descs, new_descs_size); err_free_log_buf: -memblock_free_ptr (new_log_buf, new_log_buf_len); +memblock_free (new_log_buf, new_log_buf_len); }static bool __read_mostly ignore_loglevel;
lib/bootconfig.c renamed from lib/bootconfig.c~memblock-use-memblock_free-for-freeing-virtual-pointers +1 -1
@@ -792,7 +792,7 @@ void __init xbc_destroy_all(void) xbc_data =NULL ; xbc_data_size =0 ; xbc_node_num =0 ; -memblock_free_ptr (xbc_nodes,sizeof (struct xbc_node ) *XBC_NODE_MAX ); +memblock_free (xbc_nodes,sizeof (struct xbc_node ) *XBC_NODE_MAX ); xbc_nodes =NULL ; brace_index =0 ; }
lib/cpumask.c renamed from lib/cpumask.c~memblock-use-memblock_free-for-freeing-virtual-pointers +1 -1
@@ -188,7 +188,7 @@ EXPORT_SYMBOL(free_cpumask_var);*/ void __init free_bootmem_cpumask_var (cpumask_var_t mask) { -memblock_phys_free (__pa (mask),cpumask_size ()); +memblock_free (mask,cpumask_size ()); }#endif
mm/memblock.c renamed from mm/memblock.c~memblock-use-memblock_free-for-freeing-virtual-pointers +3 -3
@@ -472,7 +472,7 @@ static int __init_memblock memblock_doubkfree (old_array); else if (old_array != memblock_memory_init_regions && old_array != memblock_reserved_init_regions) - memblock_free_ptr(old_array, old_alloc_size); + memblock_free(old_array, old_alloc_size);/* * Reserve the new array if that comes from the memblock. Otherwise, we
@@ -796,14 +796,14 @@ int __init_memblock memblock_remove(phys }/** -* memblock_free_ptr - free boot memory allocation +* memblock_free - free boot memory allocation * @ptr: starting address of the boot memory allocation * @size: size of the boot memory block in bytes * * Free boot memory block previously allocated by memblock_alloc_xx() API. * The freeing memory will not be released to the buddy allocator. */ -void __init_memblock memblock_free_ptr(void *ptr, size_t size) +void __init_memblock memblock_free(void *ptr, size_t size) {if (ptr)memblock_phys_free (__pa (ptr), size);
mm/percpu.c renamed from mm/percpu.c~memblock-use-memblock_free-for-freeing-virtual-pointers +4 -4
@@ -2472,7 +2472,7 @@ struct pcpu_alloc_info * __init pcpu_all*/ void __init pcpu_free_alloc_info (struct pcpu_alloc_info *ai) { -memblock_phys_free (__pa (ai), ai->__ai_size); +memblock_free (ai, ai->__ai_size); }/**
@@ -3134,7 +3134,7 @@ out_free_areas: out_free:pcpu_free_alloc_info (ai);if (areas) -memblock_phys_free (__pa (areas), areas_size); +memblock_free (areas, areas_size); return rc; }#endif /* BUILD_EMBED_FIRST_CHUNK */
@@ -3256,7 +3256,7 @@ enomem:free_fn (page_address (pages[j]),PAGE_SIZE ); rc = -ENOMEM ; out_free_ar: -memblock_phys_free (__pa (pages), pages_size); +memblock_free (pages, pages_size);pcpu_free_alloc_info (ai);return rc; }
@@ -3286,7 +3286,7 @@ static void * __init pcpu_dfl_fc_alloc(ustatic void __init pcpu_dfl_fc_free (void *ptr,size_t size) { -memblock_phys_free (__pa (ptr), size); +memblock_free (ptr, size); }void __init setup_per_cpu_areas (void )
mm/sparse.c renamed from mm/sparse.c~memblock-use-memblock_free-for-freeing-virtual-pointers +1 -1
@@ -451,7 +451,7 @@ static void *sparsemap_buf_end __meminitstatic inline void __meminit sparse_buffer_free (unsigned long size) {WARN_ON (!sparsemap_buf || size ==0 ); -memblock_phys_free (__pa (sparsemap_buf), size); +memblock_free (sparsemap_buf, size); }static void __init sparse_buffer_init (unsigned long size,int nid)
_
Andrew Morton
maintainerPATCH 168/262 mm: mark the OOM reaper thread as freezable
In reply to Andrew MortonFrom: Sultan Alsawaf <[email protected]>
Subject: mm: mark the OOM reaper thread as freezable
The OOM reaper alters user address space which might theoretically alter the snapshot if reaping is allowed to happen after the freezer quiescent state. To this end, the reaper kthread uses wait_event_freezable() while waiting for any work so that it cannot run while the system freezes.
However, the current implementation doesn't respect the freezer because all kernel threads are created with the PF_NOFREEZE flag, so they are automatically excluded from freezing operations. This means that the OOM reaper can race with system snapshotting if it has work to do while the system is being frozen.
Fix this by adding a set_freezable() call which will clear the PF_NOFREEZE flag and thus make the OOM reaper visible to the freezer.
Please note that the OOM reaper altering the snapshot this way is mostly a theoretical concern and has not been observed in practice.
---
mm/oom_kill.c | 2 ++ 1 file changed, 2 insertions(+)
mm/oom_kill.c renamed from mm/oom_kill.c~mm-mark-the-oom-reaper-thread-as-freezable +2 -0
@@ -641,6 +641,8 @@ done:static int oom_reaper (void *unused) { +set_freezable (); +while (true) {struct task_struct *tsk =NULL ;
_
Andrew Morton
maintainerPATCH 169/262 hugetlbfs: extend the definition of hugepages parameter to support node allocation
In reply to Andrew MortonFrom: Zhenguo Yao <[email protected]>
Subject: hugetlbfs: extend the definition of hugepages parameter to support node allocation
We can specify the number of hugepages to allocate at boot. But the hugepages is balanced in all nodes at present. In some scenarios, we only need hugepages in one node. For example: DPDK needs hugepages which are in the same node as NIC.
If DPDK needs four hugepages of 1G size in node1 and system has 16 numa nodes we must reserve 64 hugepages on the kernel cmdline. But only four hugepages are used. The others should be free after boot. If the system memory is low(for example: 64G), it will be an impossible task.
So extend the hugepages parameter to support specifying hugepages on a specific node. For example add following parameter:
hugepagesz=1G hugepages=0:1,1:3
It will allocate 1 hugepage in node0 and 3 hugepages in node1.
---
Documentation/admin-guide/kernel-parameters.txt | 8 Documentation/admin-guide/mm/hugetlbpage.rst | 12 + arch/powerpc/mm/hugetlbpage.c | 9 include/linux/hugetlb.h | 6 mm/hugetlb.c | 153 +++++++++++--- 5 files changed, 155 insertions(+), 33 deletions(-)
arch/powerpc/mm/hugetlbpage.c renamed from arch/powerpc/mm/hugetlbpage.c~hugetlbfs-extend-the-definition-of-hugepages-parameter-to-support-node-allocation +7 -2
@@ -229,17 +229,22 @@ static int __init pseries_alloc_bootmem_ m->hstate = hstate; return 1; } + +bool __init hugetlb_node_alloc_supported (void ) +{ +return false; +}#endif -int __init alloc_bootmem_huge_page (struct hstate *h) +int __init alloc_bootmem_huge_page (struct hstate *h,int nid) {#ifdef CONFIG_PPC_BOOK3S_64 if (firmware_has_feature (FW_FEATURE_LPAR ) && !radix_enabled ())return pseries_alloc_bootmem_huge_page (h);#endif -return __alloc_bootmem_huge_page (h); +return __alloc_bootmem_huge_page (h, nid); }#ifndef CONFIG_PPC_BOOK3S_64
Documentation/admin-guide/kernel-parameters.txt renamed from Documentation/admin-guide/kernel-parameters.txt~hugetlbfs-extend-the-definition-of-hugepages-parameter-to-support-node-allocation +5 -3
@@ -1601,9 +1601,11 @@ the number of pages of hugepagesz to be allocated. If this is the first HugeTLB parameter on the command line, it specifies the number of pages to allocate for - the default huge page size. See also - Documentation/admin-guide/mm/hugetlbpage.rst. - Format: <integer> + the default huge page size. If using node format, the + number of pages to allocate per-node can be specified. + See also Documentation/admin-guide/mm/hugetlbpage.rst. + Format: <integer> or (node format) + <node>:<integer>[,<node>:<integer>] hugepagesz= [HW] The size of the HugeTLB pages. This is used in
Documentation/admin-guide/mm/hugetlbpage.rst renamed from Documentation/admin-guide/mm/hugetlbpage.rst~hugetlbfs-extend-the-definition-of-hugepages-parameter-to-support-node-allocation +11 -1
@@ -128,7 +128,9 @@ hugepages implicitly specifies the number of huge pages of default size to allocate. If the number of huge pages of default size is implicitly specified, it can not be overwritten by a hugepagesz,hugepages - parameter pair for the default size. + parameter pair for the default size. This parameter also has a + node format. The node format specifies the number of huge pages + to allocate on specific nodes. For example, on an architecture with 2M default huge page size::
@@ -138,6 +140,14 @@ hugepages indicating that the hugepages=512 parameter is ignored. If a hugepages parameter is preceded by an invalid hugepagesz parameter, it will be ignored. + + Node format example:: + + hugepagesz=2M hugepages=0:1,1:2 + + It will allocate 1 2M hugepage on node0 and 2 2M hugepages on node1. + If the node number is invalid, the parameter will be ignored. + default_hugepagesz Specify the default huge page size. This parameter can only be specified once on the command line. default_hugepagesz can
include/linux/hugetlb.h renamed from include/linux/hugetlb.h~hugetlbfs-extend-the-definition-of-hugepages-parameter-to-support-node-allocation +4 -2
@@ -615,6 +615,7 @@ struct hstate {unsigned long nr_overcommit_huge_pages;struct list_head hugepage_activelist;struct list_head hugepage_freelists[MAX_NUMNODES ]; +unsigned int max_huge_pages_node[MAX_NUMNODES ];unsigned int nr_huge_pages_node[MAX_NUMNODES ];unsigned int free_huge_pages_node[MAX_NUMNODES ];unsigned int surplus_huge_pages_node[MAX_NUMNODES ];
@@ -647,8 +648,9 @@ void restore_reserve_on_error(struct hst unsigned long address, struct page *page);/* arch callback */ -int __init __alloc_bootmem_huge_page (struct hstate *h); -int __init alloc_bootmem_huge_page (struct hstate *h); +int __init __alloc_bootmem_huge_page (struct hstate *h,int nid); +int __init alloc_bootmem_huge_page (struct hstate *h,int nid); +bool __init hugetlb_node_alloc_supported (void );void __init hugetlb_add_hstate (unsigned order);bool __init arch_hugetlb_valid_size (unsigned long size);
mm/hugetlb.c renamed from mm/hugetlb.c~hugetlbfs-extend-the-definition-of-hugepages-parameter-to-support-node-allocation +128 -25
241 lines not on this page · raw message
_
Andrew Morton
maintainerPATCH 170/262 mm/migrate: de-duplicate migrate_reason strings
In reply to Andrew MortonFrom: John Hubbard <[email protected]>
Subject: mm/migrate: de-duplicate migrate_reason strings
In order to remove the need to manually keep three different files in synch, provide a common definition of the mapping between enum migrate_reason, and the associated strings for each enum item.
1. Use the tracing system's mapping of enums to strings, by redefining and reusing the MIGRATE_REASON and supporting macros, and using that to populate the string array in mm/debug.c.
2. Move enum migrate_reason to migrate_mode.h. This is not strictly necessary for this patch, but migrate mode and migrate reason go together, so this will slightly clarify things.
---
include/linux/migrate.h | 19 +------------------ include/linux/migrate_mode.h | 13 +++++++++++++ mm/debug.c | 20 +++++++++++--------- 3 files changed, 25 insertions(+), 27 deletions(-)
include/linux/migrate.h renamed from include/linux/migrate.h~mm-migrate-de-duplicate-migrate_reason-strings +1 -18
@@ -19,24 +19,7 @@ struct migration_target_control;*/ #define MIGRATEPAGE_SUCCESS 0 -/* -* Keep sync with: -* - macro MIGRATE_REASON in include/trace/events/migrate.h -* - migrate_reason_names[MR_TYPES] in mm/debug.c -*/ -enum migrate_reason { -MR_COMPACTION , -MR_MEMORY_FAILURE , -MR_MEMORY_HOTPLUG , -MR_SYSCALL ,/* also applies to cpusets */ -MR_MEMPOLICY_MBIND , -MR_NUMA_MISPLACED , -MR_CONTIG_RANGE , -MR_LONGTERM_PIN , -MR_DEMOTION , -MR_TYPES -}; - +/* Defined in mm/debug.c: */ extern const char *migrate_reason_names[MR_TYPES ];#ifdef CONFIG_MIGRATION
include/linux/migrate_mode.h renamed from include/linux/migrate_mode.h~mm-migrate-de-duplicate-migrate_reason-strings +13 -0
@@ -19,4 +19,17 @@ enum migrate_mode { MIGRATE_SYNC_NO_COPY, }; +enum migrate_reason { +MR_COMPACTION , +MR_MEMORY_FAILURE , +MR_MEMORY_HOTPLUG , +MR_SYSCALL ,/* also applies to cpusets */ +MR_MEMPOLICY_MBIND , +MR_NUMA_MISPLACED , +MR_CONTIG_RANGE , +MR_LONGTERM_PIN , +MR_DEMOTION , +MR_TYPES +}; +#endif /* MIGRATE_MODE_H_INCLUDED */
mm/debug.c renamed from mm/debug.c~mm-migrate-de-duplicate-migrate_reason-strings +11 -9
@@ -16,17 +16,19 @@#include <linux/ctype.h> #include "internal.h" +#include <trace/events/migrate.h> + +/* +* Define EM() and EMe() so that MIGRATE_REASON from trace/events/migrate.h can +* be used to populate migrate_reason_names[]. +*/ +#undef EM +#undef EMe +#define EM (a, b) b, +#define EMe (a, b) bconst char *migrate_reason_names[MR_TYPES ] = { -"compaction" , -"memory_failure" , -"memory_hotplug" , -"syscall_or_cpuset" , -"mempolicy_mbind" , -"numa_misplaced" , -"contig_range" , -"longterm_pin" , -"demotion" , +MIGRATE_REASON };const struct trace_print_flags pageflag_names[] = {
_
Andrew Morton
maintainerPATCH 171/262 mm: migrate: make demotion knob depend on migration
In reply to Andrew MortonFrom: Yang Shi <[email protected]>
Subject: mm: migrate: make demotion knob depend on migration
The memory demotion needs to call migrate_pages() to do the jobs. And it is controlled by a knob, however, the knob doesn't depend on CONFIG_MIGRATION. The knob could be truned on even though MIGRATION is disabled, this will not cause any crash since migrate_pages() would just return -ENOSYS. But it is definitely not optimal to go through demotion path then retry regular swap every time.
And it doesn't make too much sense to have the knob visible to the users when !MIGRATION. Move the related code from mempolicy.[h|c] to migrate.[h|c].
---
include/linux/mempolicy.h | 4 -- include/linux/migrate.h | 4 ++ mm/mempolicy.c | 61 ------------------------------------ mm/migrate.c | 61 ++++++++++++++++++++++++++++++++++++ 4 files changed, 65 insertions(+), 65 deletions(-)
include/linux/mempolicy.h renamed from include/linux/mempolicy.h~mm-migrate-make-demotion-knob-depend-on-migration +0 -4
@@ -183,8 +183,6 @@ extern bool vma_migratable(struct vm_areextern int mpol_misplaced (struct page *,struct vm_area_struct *,unsigned long );extern void mpol_put_task_policy (struct task_struct *); -extern bool numa_demotion_enabled; -static inline bool mpol_is_preferred_many (struct mempolicy *pol) {return (pol->mode ==MPOL_PREFERRED_MANY );
@@ -300,8 +298,6 @@ static inline nodemask_t *policy_nodemasreturn NULL ; } -#define numa_demotion_enabled false -static inline bool mpol_is_preferred_many (struct mempolicy *pol) {return false;
include/linux/migrate.h renamed from include/linux/migrate.h~mm-migrate-make-demotion-knob-depend-on-migration +4 -0
@@ -40,6 +40,8 @@ extern int migrate_huge_page_move_mappin struct page *newpage, struct page *page);extern int migrate_page_move_mapping (struct address_space *mapping,struct page *newpage,struct page *page,int extra_count); + +extern bool numa_demotion_enabled;#else static inline void putback_movable_pages (struct list_head *l) {}
@@ -65,6 +67,8 @@ static inline int migrate_huge_page_move {return -ENOSYS ; } + +#define numa_demotion_enabled false#endif /* CONFIG_MIGRATION */ #ifdef CONFIG_COMPACTION
mm/mempolicy.c renamed from mm/mempolicy.c~mm-migrate-make-demotion-knob-depend-on-migration +0 -61
64 lines not on this page · raw message
mm/migrate.c renamed from mm/migrate.c~mm-migrate-make-demotion-knob-depend-on-migration +61 -0
64 lines not on this page · raw message
_
Andrew Morton
maintainerPATCH 172/262 selftests/vm/transhuge-stress: fix ram size thinko
In reply to Andrew MortonFrom: "George G. Davis" <[email protected]>
Subject: selftests/vm/transhuge-stress: fix ram size thinko
When executing transhuge-stress with an argument to specify the virtual memory size for testing, the ram size is reported as 0, e.g.
transhuge-stress 384
thp-mmap: allocate 192 transhuge pages, using 384 MiB virtual memory and 0 MiB of ram
thp-mmap: 0.184 s/loop, 0.957 ms/page, 2090.265 MiB/s 192 succeed, 0 failed
This appears to be due to a thinko in commit 0085d61fe05e ("selftests/vm/transhuge-stress: stress test for memory compaction"), where, at a guess, the intent was to base "xyz MiB of ram" on ram size. Here are results after using ram size:
thp-mmap: allocate 192 transhuge pages, using 384 MiB virtual memory and 14 MiB of ram
---
tools/testing/selftests/vm/transhuge-stress.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/testing/selftests/vm/transhuge-stress.c renamed from tools/testing/selftests/vm/transhuge-stress.c~selftests-vm-transhuge-stress-fix-ram-size-thinko +1 -1
@@ -79,7 +79,7 @@ int main(int argc, char **argv)warnx ("allocate %zd transhuge pages, using %zd MiB virtual memory" " and %zd MiB of ram" , len >>HPAGE_SHIFT , len >>20 , - len >> (20 +HPAGE_SHIFT -PAGE_SHIFT -1 )); + ram >> (20 +HPAGE_SHIFT -PAGE_SHIFT -1 )); pagemap_fd =open ("/proc/self/pagemap" ,O_RDONLY );if (pagemap_fd <0 )
_
Andrew Morton
maintainerPATCH 173/262 mm, thp: lock filemap when truncating page cache
In reply to Andrew MortonFrom: Rongwei Wang <[email protected]>
Subject: mm, thp: lock filemap when truncating page cache
Patch series "fix two bugs for file THP".
This patch (of 2):
Transparent huge page has supported read-only non-shmem files. The file- backed THP is collapsed by khugepaged and truncated when written (for shared libraries).
However, there is a race when multiple writers truncate the same page cache concurrently.
In that case, subpage(s) of file THP can be revealed by find_get_entry in truncate_inode_pages_range, which will trigger PageTail BUG_ON in truncate_inode_page, as follows.
page:000000009e420ff2 refcount:1 mapcount:0 mapping:0000000000000000 index:0x7ff pfn:0x50c3ff head:0000000075ff816d order:9 compound_mapcount:0 compound_pincount:0
flags: 0x37fffe0000010815(locked|uptodate|lru|arch_1|head)
raw: 37fffe0000000000 fffffe0013108001 dead000000000122 dead000000000400 raw: 0000000000000001 0000000000000000 00000000ffffffff 0000000000000000 head: 37fffe0000010815 fffffe001066bd48 ffff000404183c20 0000000000000000 head: 0000000000000600 0000000000000000 00000001ffffffff ffff000c0345a000 page dumped because: VM_BUG_ON_PAGE(PageTail(page)) ------------[ cut here ]------------ kernel BUG at mm/truncate.c:213! Internal error: Oops - BUG: 0 [#1] SMP Modules linked in: xfs(E) libcrc32c(E) rfkill(E) ... CPU: 14 PID: 11394 Comm: check_madvise_d Kdump: ... Hardware name: ECS, BIOS 0.0.0 02/06/2015 pstate: 60400005 (nZCv daif +PAN -UAO -TCO BTYPE=--) pc : truncate_inode_page+0x64/0x70 lr : truncate_inode_page+0x64/0x70
sp : ffff80001b60b900
x29: ffff80001b60b900 x28: 00000000000007ff
x27: ffff80001b60b9a0 x26: 0000000000000000
x25: 000000000000000f x24: ffff80001b60b9a0
x23: ffff80001b60ba18 x22: ffff0001e0999ea8
x21: ffff0000c21db300 x20: ffffffffffffffff
x19: fffffe001310ffc0 x18: 0000000000000020
x17: 0000000000000000 x16: 0000000000000000
x15: ffff0000c21db960 x14: 3030306666666620
x13: 6666666666666666 x12: 3130303030303030
x11: ffff8000117b69b8 x10: 00000000ffff8000
x9 : ffff80001012690c x8 : 0000000000000000
x7 : ffff8000114f69b8 x6 : 0000000000017ffd
x5 : ffff0007fffbcbc8 x4 : ffff80001b60b5c0
x3 : 0000000000000001 x2 : 0000000000000000
x1 : 0000000000000000 x0 : 0000000000000000
Call trace: truncate_inode_page+0x64/0x70 truncate_inode_pages_range+0x550/0x7e4 truncate_pagecache+0x58/0x80 do_dentry_open+0x1e4/0x3c0 vfs_open+0x38/0x44 do_open+0x1f0/0x310 path_openat+0x114/0x1dc do_filp_open+0x84/0x134 do_sys_openat2+0xbc/0x164 __arm64_sys_openat+0x74/0xc0 el0_svc_common.constprop.0+0x88/0x220 do_el0_svc+0x30/0xa0 el0_svc+0x20/0x30 el0_sync_handler+0x1a4/0x1b0 el0_sync+0x180/0x1c0 Code: aa0103e0 900061e1 910ec021 9400d300 (d4210000) ---[ end trace f70cdb42cb7c2d42 ]--- Kernel panic - not syncing: Oops - BUG: Fatal exception
This patch mainly to lock filemap when one enter truncate_pagecache(), avoiding truncating the same page cache concurrently.
---
fs/open.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
fs/open.c renamed from fs/open.c~mm-thp-lock-filemap-when-truncating-page-cache +4 -1
@@ -856,8 +856,11 @@ static int do_dentry_open(struct file *f* of THPs into the page cache will fail. */ smp_mb (); -if (filemap_nr_thps (inode->i_mapping)) +if (filemap_nr_thps (inode->i_mapping)) { +filemap_invalidate_lock (inode->i_mapping);truncate_pagecache (inode,0 ); +filemap_invalidate_unlock (inode->i_mapping); + } }return 0 ;
_
Andrew Morton
maintainerPATCH 174/262 mm, thp: fix incorrect unmap behavior for private pages
In reply to Andrew MortonFrom: Rongwei Wang <[email protected]>
Subject: mm, thp: fix incorrect unmap behavior for private pages
When truncating pagecache on file THP, the private pages of a process should not be unmapped mapping. This incorrect behavior on a dynamic shared libraries which will cause related processes to happen core dump.
A simple test for a DSO (Prerequisite is the DSO mapped in file THP):
int main(int argc, char *argv[])
{
int fd;
fd = open(argv[1], O_WRONLY);
if (fd < 0) {
perror("open");
}
close(fd);
return 0;
}The test only to open a target DSO, and do nothing. But this operation will lead one or more process to happen core dump. This patch mainly to fix this bug.
---
fs/open.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-)
fs/open.c renamed from fs/open.c~mm-thp-fix-incorrect-unmap-behavior-for-private-pages +10 -1
@@ -857,8 +857,17 @@ static int do_dentry_open(struct file *f*/ smp_mb ();if (filemap_nr_thps (inode->i_mapping)) { +struct address_space *mapping = inode->i_mapping; +filemap_invalidate_lock (inode->i_mapping); -truncate_pagecache (inode,0 ); +/* +* unmap_mapping_range just need to be called once +* here, because the private pages is not need to be +* unmapped mapping (e.g. data segment of dynamic +* shared libraries here). +*/ +unmap_mapping_range (mapping,0 ,0 ,0 ); +truncate_inode_pages (mapping,0 );filemap_invalidate_unlock (inode->i_mapping); } }
_
Andrew Morton
maintainerPATCH 175/262 mm/readahead.c: fix incorrect comments for get_init_ra_size
In reply to Andrew MortonFrom: Lin Feng <[email protected]>
Subject: mm/readahead.c: fix incorrect comments for get_init_ra_size
In fact, formated values returned by get_init_ra_size are not that intuitive. This patch make the comments reflect its truth.
---
mm/readahead.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
mm/readahead.c renamed from mm/readahead.c~mm-readaheadc-fix-incorrect-comments-for-get_init_ra_size +1 -1
@@ -309,7 +309,7 @@ void force_page_cache_ra(struct readahea* Set the initial window size, round to next power of 2 and square * for small size, x 4 for medium, and x 2 for large * for 128k (32 page) max ra -* 1-8 page = 32k initial, > 8 page = 128k initial +* 1-2 page = 16k, 3-4 page 32k, 5-8 page = 64k, > 8 page = 128k initial */ static unsigned long get_init_ra_size (unsigned long size,unsigned long max) {
_
Andrew Morton
maintainerPATCH 176/262 mm: nommu: kill arch_get_unmapped_area()
In reply to Andrew MortonFrom: Kefeng Wang <[email protected]>
Subject: mm: nommu: kill arch_get_unmapped_area()
When nommu, the arch_get_unmapped_area() will not be called, just kill it.
---
mm/nommu.c | 6 ------ 1 file changed, 6 deletions(-)
mm/nommu.c renamed from mm/nommu.c~mm-nommu-kill-arch_get_unmapped_area +0 -6
@@ -1639,12 +1639,6 @@ int remap_vmalloc_range(struct vm_area_s }EXPORT_SYMBOL (remap_vmalloc_range); -unsigned long arch_get_unmapped_area (struct file *file,unsigned long addr, -unsigned long len,unsigned long pgoff,unsigned long flags) -{ -return -ENOMEM ; -} -vm_fault_t filemap_fault (struct vm_fault *vmf) {BUG ();
_
Andrew Morton
maintainerPATCH 177/262 selftest/vm: fix ksm selftest to run with different NUMA topologies
In reply to Andrew MortonFrom: "Aneesh Kumar K.V" <[email protected]>
Subject: selftest/vm: fix ksm selftest to run with different NUMA topologies
Platforms can have non-contiguous NUMA nodes like below
#numactl -H
available: 2 nodes (0,8)
.....
node distances:
node 0 8
0: 10 40 8: 40 10
#numactl -H
available: 1 nodes (1)
....
node distances:
node 1
1: 10
Hence update the test to not assume the presence of Node 0 and 1 and also use numa_num_configured_nodes() instead of numa_max_node for finding whether to skip the test.
---
tools/testing/selftests/vm/ksm_tests.c | 29 ++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-)
tools/testing/selftests/vm/ksm_tests.c renamed from tools/testing/selftests/vm/ksm_tests.c~selftest-vm-fix-ksm-selftest-to-run-with-different-numa-topologies +26 -3
@@ -354,12 +354,34 @@ err_out:return KSFT_FAIL ; } +static int get_next_mem_node (int node) +{ + +long node_size; +int mem_node =0 ; +int i, max_node =numa_max_node (); + +for (i = node +1 ; i <= max_node + node; i++) { + mem_node = i % (max_node +1 ); + node_size =numa_node_size (mem_node,NULL ); +if (node_size >0 ) +break ; + } +return mem_node; +} + +static int get_first_mem_node (void ) +{ +return get_next_mem_node (numa_max_node ()); +} +static int check_ksm_numa_merge (int mapping,int prot,int timeout,bool merge_across_nodes,size_t page_size) {void *numa1_map_ptr, *numa2_map_ptr;struct timespec start_time;int page_count =2 ; +int first_node;if (clock_gettime (CLOCK_MONOTONIC_RAW , &start_time)) {perror ("clock_gettime" );
@@ -370,7 +392,7 @@ static int check_ksm_numa_merge(int mappperror ("NUMA support not enabled" );return KSFT_SKIP ; } -if (numa_max_node () <1 ) { +if (numa_num_configured_nodes () <=1 ) {printf ("At least 2 NUMA nodes must be available\n" );return KSFT_SKIP ; }
@@ -378,8 +400,9 @@ static int check_ksm_numa_merge(int mappreturn KSFT_FAIL ;/* allocate 2 pages in 2 different NUMA nodes and fill them with the same data */ - numa1_map_ptr =numa_alloc_onnode (page_size,0 ); - numa2_map_ptr =numa_alloc_onnode (page_size,1 ); + first_node =get_first_mem_node (); + numa1_map_ptr =numa_alloc_onnode (page_size, first_node); + numa2_map_ptr =numa_alloc_onnode (page_size,get_next_mem_node (first_node));if (!numa1_map_ptr || !numa2_map_ptr) {perror ("numa_alloc_onnode" );return KSFT_FAIL ;
_
Andrew Morton
maintainerPATCH 178/262 selftests: vm: add KSM huge pages merging time test
In reply to Andrew MortonFrom: Pedro Demarchi Gomes <[email protected]>
Subject: selftests: vm: add KSM huge pages merging time test
Add test case of KSM merging time using mostly huge pages
---
tools/testing/selftests/vm/ksm_tests.c | 125 ++++++++++++++++++++++- 1 file changed, 124 insertions(+), 1 deletion(-)
tools/testing/selftests/vm/ksm_tests.c renamed from tools/testing/selftests/vm/ksm_tests.c~selftests-vm-add-ksm-huge-pages-merging-time-test +124 -1
@@ -5,6 +5,10 @@#include <time.h> #include <string.h> #include <numa.h> +#include <unistd.h> +#include <fcntl.h> +#include <stdint.h> +#include <err.h> #include "../kselftest.h" #include "../../../../include/vdso/time64.h"
@@ -18,6 +22,15 @@#define KSM_MERGE_ACROSS_NODES_DEFAULT true#define MB (1ul << 20) +#define PAGE_SHIFT 12 +#define HPAGE_SHIFT 21 + +#define PAGE_SIZE (1 << PAGE_SHIFT) +#define HPAGE_SIZE (1 << HPAGE_SHIFT) + +#define PAGEMAP_PRESENT (ent) (((ent) & (1ull << 63)) != 0) +#define PAGEMAP_PFN (ent) ((ent) & ((1ull << 55) - 1)) +struct ksm_sysfs {unsigned long max_page_sharing;unsigned long merge_across_nodes;
@@ -34,6 +47,7 @@ enum ksm_test_name {CHECK_KSM_ZERO_PAGE_MERGE ,CHECK_KSM_NUMA_MERGE ,KSM_MERGE_TIME , +KSM_MERGE_TIME_HUGE_PAGES , KSM_COW_TIME };
@@ -100,6 +114,9 @@ static void print_help(void)" -P evaluate merging time and speed.\n" " For this test, the size of duplicated memory area (in MiB)\n" " must be provided using -s option\n" +" -H evaluate merging time and speed of area allocated mostly with huge pages\n" +" For this test, the size of duplicated memory area (in MiB)\n" +" must be provided using -s option\n" " -C evaluate the time required to break COW of merged pages.\n\n"); printf(" -a: specify the access protections of pages.\n"
@@ -439,6 +456,101 @@ err_out:return KSFT_FAIL ; } +int64_t allocate_transhuge (void *ptr,int pagemap_fd) +{ +uint64_t ent[2 ]; + +/* drop pmd */ +if (mmap (ptr,HPAGE_SIZE ,PROT_READ |PROT_WRITE , +MAP_FIXED |MAP_ANONYMOUS | +MAP_NORESERVE |MAP_PRIVATE ,-1 ,0 ) != ptr) +errx (2 ,"mmap transhuge" ); + +if (madvise (ptr,HPAGE_SIZE ,MADV_HUGEPAGE )) +err (2 ,"MADV_HUGEPAGE" ); + +/* allocate transparent huge page */ + *(volatile void **)ptr = ptr; + +if (pread (pagemap_fd, ent,sizeof (ent), + (uintptr_t )ptr >> (PAGE_SHIFT -3 )) !=sizeof (ent)) +err (2 ,"read pagemap" ); + +if (PAGEMAP_PRESENT (ent[0 ]) &&PAGEMAP_PRESENT (ent[1 ]) && +PAGEMAP_PFN (ent[0 ]) +1 ==PAGEMAP_PFN (ent[1 ]) && + !(PAGEMAP_PFN (ent[0 ]) & ((1 << (HPAGE_SHIFT -PAGE_SHIFT )) -1 ))) +return PAGEMAP_PFN (ent[0 ]); + +return -1 ; +} + +static int ksm_merge_hugepages_time (int mapping,int prot,int timeout,size_t map_size) +{ +void *map_ptr, *map_ptr_orig; +struct timespec start_time, end_time; +unsigned long scan_time_ns; +int pagemap_fd, n_normal_pages, n_huge_pages; + + map_size *=MB ; +size_t len = map_size; + + len -= len %HPAGE_SIZE ; + map_ptr_orig =mmap (NULL , len +HPAGE_SIZE ,PROT_READ |PROT_WRITE , +MAP_ANONYMOUS |MAP_NORESERVE |MAP_PRIVATE ,-1 ,0 ); + map_ptr = map_ptr_orig +HPAGE_SIZE - (uintptr_t )map_ptr_orig %HPAGE_SIZE ; + +if (map_ptr_orig ==MAP_FAILED ) +err (2 ,"initial mmap" ); + +if (madvise (map_ptr, len +HPAGE_SIZE ,MADV_HUGEPAGE )) +err (2 ,"MADV_HUGEPAGE" ); + + pagemap_fd =open ("/proc/self/pagemap" ,O_RDONLY ); +if (pagemap_fd <0 ) +err (2 ,"open pagemap" ); + + n_normal_pages =0 ; + n_huge_pages =0 ; +for (void *p = map_ptr; p < map_ptr + len; p +=HPAGE_SIZE ) { +if (allocate_transhuge (p, pagemap_fd) <0 ) + n_normal_pages++; +else + n_huge_pages++; + } +printf ("Number of normal pages: %d\n" , n_normal_pages); +printf ("Number of huge pages: %d\n" , n_huge_pages); + +memset (map_ptr,'*' , len); + +if (clock_gettime (CLOCK_MONOTONIC_RAW , &start_time)) { +perror ("clock_gettime" ); + goto err_out; + } +if (ksm_merge_pages (map_ptr, map_size, start_time, timeout)) + goto err_out; +if (clock_gettime (CLOCK_MONOTONIC_RAW , &end_time)) { +perror ("clock_gettime" ); + goto err_out; + } + + scan_time_ns = (end_time.tv_sec - start_time.tv_sec) *NSEC_PER_SEC + + (end_time.tv_nsec - start_time.tv_nsec); + +printf ("Total size: %lu MiB\n" , map_size /MB ); +printf ("Total time: %ld.%09ld s\n" , scan_time_ns /NSEC_PER_SEC , + scan_time_ns %NSEC_PER_SEC ); +printf ("Average speed: %.3f MiB/s\n" , (map_size /MB ) / + ((double )scan_time_ns /NSEC_PER_SEC )); + +munmap (map_ptr_orig, len +HPAGE_SIZE ); +return KSFT_PASS ; + +err_out: +printf ("Not OK\n" ); +munmap (map_ptr_orig, len +HPAGE_SIZE ); +return KSFT_FAIL ; +} +static int ksm_merge_time (int mapping,int prot,int timeout,size_t map_size) {void *map_ptr;
@@ -564,7 +676,7 @@ int main(int argc, char *argv[])bool merge_across_nodes =KSM_MERGE_ACROSS_NODES_DEFAULT ;long size_MB =0 ; -while ((opt =getopt (argc, argv,"ha:p:l:z:m:s:MUZNPC" )) !=-1 ) { +while ((opt =getopt (argc, argv,"ha:p:l:z:m:s:MUZNPCH" )) !=-1 ) {switch (opt) {case 'a' : prot =str_to_prot (optarg);
@@ -618,6 +730,9 @@ int main(int argc, char *argv[])case 'P' : test_name =KSM_MERGE_TIME ;break ; +case 'H' : + test_name =KSM_MERGE_TIME_HUGE_PAGES ; +break ;case 'C' : test_name =KSM_COW_TIME ;break ;
@@ -670,6 +785,14 @@ int main(int argc, char *argv[]) ret =ksm_merge_time (MAP_PRIVATE |MAP_ANONYMOUS , prot, ksm_scan_limit_sec, size_MB);break ; +case KSM_MERGE_TIME_HUGE_PAGES : +if (size_MB ==0 ) { +printf ("Option '-s' is required.\n" ); +return KSFT_FAIL ; + } + ret =ksm_merge_hugepages_time (MAP_PRIVATE |MAP_ANONYMOUS , prot, + ksm_scan_limit_sec, size_MB); +break ;case KSM_COW_TIME : ret =ksm_cow_time (MAP_PRIVATE |MAP_ANONYMOUS , prot, ksm_scan_limit_sec, page_size);
_
Andrew Morton
maintainerPATCH 179/262 mm/vmstat: annotate data race for zone->free_area[order].nr_free
In reply to Andrew MortonFrom: Liu Shixin <[email protected]>
Subject: mm/vmstat: annotate data race for zone->free_area[order].nr_free
KCSAN reports a data-race on v5.10 which also exists on mainline:
==================================================================
BUG: KCSAN: data-race in extfrag_for_order+0x33/0x2d0
race at unknown origin, with read to 0xffff9ee9bfffab48 of 8 bytes by task 34 on cpu 1:
extfrag_for_order+0x33/0x2d0 kcompactd+0x5f0/0xce0 kthread+0x1f9/0x220 ret_from_fork+0x22/0x30
Reported by Kernel Concurrency Sanitizer on:
CPU: 1 PID: 34 Comm: kcompactd0 Not tainted 5.10.0+ #2 Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS Ubuntu-1.8.2-1ubuntu1 04/01/2014 ==================================================================
Access to zone->free_area[order].nr_free in extfrag_for_order()/frag_show_print() is lockless. That's intentional and the stats are a rough estimate anyway. Annotate them with data_race().
---
mm/vmstat.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-)
mm/vmstat.c renamed from mm/vmstat.c~mm-vmstat-annotate-data-race-for-zone-free_areanr_free +12 -3
@@ -1070,8 +1070,13 @@ static void fill_contig_page_info(structfor (order =0 ; order <MAX_ORDER ; order++) {unsigned long blocks; -/* Count number of free blocks */ - blocks = zone->free_area[order].nr_free; +/* +* Count number of free blocks. +* +* Access to nr_free is lockless as nr_free is used only for +* diagnostic purposes. Use data_race to avoid KCSAN warning. +*/ + blocks =data_race (zone->free_area[order].nr_free); info->free_blocks_total += blocks;/* Count free base pages */
@@ -1446,7 +1451,11 @@ static void frag_show_print(struct seq_fseq_printf (m,"Node %d, zone %8s " , pgdat->node_id, zone->name);for (order =0 ; order <MAX_ORDER ; ++order) -seq_printf (m,"%6lu " , zone->free_area[order].nr_free); +/* +* Access to nr_free is lockless as nr_free is used only for +* printing purposes. Use data_race to avoid KCSAN warning. +*/ +seq_printf (m,"%6lu " ,data_race (zone->free_area[order].nr_free));seq_putc (m,'\n' ); }
_
Andrew Morton
maintainerPATCH 180/262 mm: vmstat.c: make extfrag_index show more pretty
In reply to Andrew MortonFrom: Lin Feng <[email protected]>
Subject: mm: vmstat.c: make extfrag_index show more pretty
fragmentation_index may return -1000 and the corresponding formated value showed by seq_printf will take a negative signatrue, but other positive formated values don't take a positive signatrue, so the output becomes unaligned.
before:
Node 0, zone DMA -1.000 -1.000 -1.000 -1.000 -1.000 -1.000 -1.000 -1.000 -1.000 -1.000 -1.000
Node 0, zone DMA32 -1.000 -1.000 -1.000 -1.000 -1.000 -1.000 -1.000 -1.000 -1.000 -1.000 -1.000
Node 0, zone Normal -1.000 -1.000 -1.000 -1.000 0.931 0.966 0.983 0.992 0.996 0.998 0.999
after this patch:
Node 0, zone DMA -1.000 -1.000 -1.000 -1.000 -1.000 -1.000 -1.000 -1.000 -1.000 -1.000 -1.000
Node 0, zone DMA32 -1.000 -1.000 -1.000 -1.000 -1.000 -1.000 -1.000 -1.000 -1.000 -1.000 -1.000
Node 0, zone Normal -1.000 -1.000 -1.000 -1.000 0.931 0.966 0.983 0.992 0.996 0.998 0.999
---
mm/vmstat.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
mm/vmstat.c renamed from mm/vmstat.c~mm-vmstatc-make-extfrag_index-show-more-pretty +1 -1
@@ -2191,7 +2191,7 @@ static void extfrag_show_print(struct sefor (order =0 ; order <MAX_ORDER ; ++order) {fill_contig_page_info (zone, order, &info); index =__fragmentation_index (order, &info); -seq_printf (m,"%d.%03d " , index /1000 , index %1000 ); +seq_printf (m,"%2d.%03d " , index /1000 , index %1000 ); }seq_putc (m,'\n' );
_
Andrew Morton
maintainerPATCH 181/262 selftests/vm: make MADV_POPULATE_(READ|WRITE) use in-tree headers
In reply to Andrew MortonFrom: David Hildenbrand <[email protected]>
Subject: selftests/vm: make MADV_POPULATE_(READ|WRITE) use in-tree headers
The madv_populate selftest currently builds with a warning when the local installed headers (via the distribution) don't include MADV_POPULATE_READ and MADV_POPULATE_WRITE. The warning is correct, because the test cannot locate the necessary header.
Reason is that the in-tree installed headers (usr/include) have a "linux" instead of a "sys" subdirectory.
Including "linux/mman.h" instead of "sys/mman.h" doesn't work (e.g., mmap() and madvise() are not defined that way). The only thing that seems to work is including "linux/mman.h" in addition to "sys/mman.h".
We can get rid of our availability check and simplify.
---
tools/testing/selftests/vm/madv_populate.c | 15 +-------------- 1 file changed, 1 insertion(+), 14 deletions(-)
tools/testing/selftests/vm/madv_populate.c renamed from tools/testing/selftests/vm/madv_populate.c~selftests-vm-make-madv_populate_readwrite-use-in-tree-headers +1 -14
@@ -14,12 +14,11 @@#include <unistd.h> #include <errno.h> #include <fcntl.h> +#include <linux/mman.h> #include <sys/mman.h> #include "../kselftest.h" -#if defined(MADV_POPULATE_READ ) && defined(MADV_POPULATE_WRITE ) -/* * For now, we're using 2 MiB of private anonymous memory for all tests. */
@@ -328,15 +327,3 @@ int main(int argc, char **argv) err, ksft_test_num());return ksft_exit_pass (); } - -#else /* defined(MADV_POPULATE_READ) && defined(MADV_POPULATE_WRITE) */ - -#warning "missing MADV_POPULATE_READ or MADV_POPULATE_WRITE definition" - -int main (int argc,char **argv) -{ -ksft_print_header (); -ksft_exit_skip ("MADV_POPULATE_READ or MADV_POPULATE_WRITE not defined\n" ); -} - -#endif /* defined(MADV_POPULATE_READ) && defined(MADV_POPULATE_WRITE) */
_
Andrew Morton
maintainerPATCH 182/262 mm/memory_hotplug: add static qualifier for online_policy_to_str()
In reply to Andrew MortonFrom: Tang Yizhou <[email protected]>
Subject: mm/memory_hotplug: add static qualifier for online_policy_to_str()
online_policy_to_str is only used in memory_hotplug.c and should be defined as static.
---
mm/memory_hotplug.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
mm/memory_hotplug.c renamed from mm/memory_hotplug.c~mm-memory_hotplug-add-static-qualifier-for-online_policy_to_str +1 -1
@@ -57,7 +57,7 @@ enum { ONLINE_POLICY_AUTO_MOVABLE, }; -const char *online_policy_to_str[] = { +static const char *const online_policy_to_str[] = { [ONLINE_POLICY_CONTIG_ZONES ] ="contig-zones" , [ONLINE_POLICY_AUTO_MOVABLE ] ="auto-movable" , };
_
Andrew Morton
maintainerPATCH 183/262 memory-hotplug.rst: fix two instances of "movablecore" that should be "movable_node"
In reply to Andrew MortonFrom: David Hildenbrand <[email protected]>
Subject: memory-hotplug.rst: fix two instances of "movablecore" that should be "movable_node"
Patch series "memory-hotplug.rst: document the "auto-movable" online policy".
Now that the memory-hotplug.rst overhaul is upstream, proper documentation for the "auto-movable" online policy, documenting all new toggles and options. Along, two fixes for the original overhaul.
This patch (of 3):
We really want to refer to the "movable_node" kernel command line parameter here.
---
Documentation/admin-guide/mm/memory-hotplug.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
Documentation/admin-guide/mm/memory-hotplug.rst renamed from Documentation/admin-guide/mm/memory-hotplug.rst~memory-hotplugrst-fix-two-instances-of-movablecore-that-should-be-movable_node +2 -2
@@ -166,7 +166,7 @@ Or alternatively:: % echo 1 > /sys/devices/system/memory/memoryXXX/online The kernel will select the target zone automatically, usually defaulting to -``ZONE_NORMAL`` unless ``movablecore=1`` has been specified on the kernel +``ZONE_NORMAL`` unless ``movable_node`` has been specified on the kernel command line or if the memory block would intersect the ZONE_MOVABLE already. One can explicitly request to associate an offline memory block with
@@ -393,7 +393,7 @@ command line parameters are relevant: ======================== ======================================================= ``memhp_default_state`` configure auto-onlining by essentially setting ``/sys/devices/system/memory/auto_online_blocks``. -``movablecore`` configure automatic zone selection of the kernel. When +``movable_node`` configure automatic zone selection in the kernel. When set, the kernel will default to ZONE_MOVABLE, unless other zones can be kept contiguous. ======================== =======================================================
_
Andrew Morton
maintainerPATCH 184/262 memory-hotplug.rst: fix wrong /sys/module/memory_hotplug/parameters/ path
In reply to Andrew MortonFrom: David Hildenbrand <[email protected]>
Subject: memory-hotplug.rst: fix wrong /sys/module/memory_hotplug/parameters/ path
We accidentially added a superfluous "s".
---
Documentation/admin-guide/mm/memory-hotplug.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Documentation/admin-guide/mm/memory-hotplug.rst renamed from Documentation/admin-guide/mm/memory-hotplug.rst~memory-hotplugrst-fix-wrong-sys-module-memory_hotplug-parameters-path +1 -1
@@ -410,7 +410,7 @@ them with ``memory_hotplug.`` such as:: and they can be observed (and some even modified at runtime) via:: - /sys/modules/memory_hotplug/parameters/ + /sys/module/memory_hotplug/parameters/ The following module parameters are currently defined:
_
Andrew Morton
maintainerPATCH 185/262 memory-hotplug.rst: document the "auto-movable" online policy
In reply to Andrew MortonFrom: David Hildenbrand <[email protected]>
Subject: memory-hotplug.rst: document the "auto-movable" online policy
In commit e83a437faa62 ("mm/memory_hotplug: introduce "auto-movable" online policy") we introduced a new memory online policy to automatically select a zone for memory blocks to be onlined. We added a way to set the active online policy and tunables for the auto-movable online policy. In follow-up commits we tweaked the "auto-movable" policy to also consider memory device details when selecting zones for memory blocks to be onlined.
Let's document the new toggles and how the two online policies we have work.
---
Documentation/admin-guide/mm/memory-hotplug.rst | 141 ++++++++++++-- 1 file changed, 121 insertions(+), 20 deletions(-)
Documentation/admin-guide/mm/memory-hotplug.rst renamed from Documentation/admin-guide/mm/memory-hotplug.rst~memory-hotplugrst-document-the-auto-movable-online-policy +121 -20
@@ -165,9 +165,8 @@ Or alternatively:: % echo 1 > /sys/devices/system/memory/memoryXXX/online -The kernel will select the target zone automatically, usually defaulting to -``ZONE_NORMAL`` unless ``movable_node`` has been specified on the kernel -command line or if the memory block would intersect the ZONE_MOVABLE already. +The kernel will select the target zone automatically, depending on the +configured ``online_policy``. One can explicitly request to associate an offline memory block with ZONE_MOVABLE by::
@@ -198,6 +197,9 @@ Auto-onlining can be enabled by writing % echo online > /sys/devices/system/memory/auto_online_blocks +Similarly to manual onlining, with ``online`` the kernel will select the +target zone automatically, depending on the configured ``online_policy``. + Modifying the auto-online behavior will only affect all subsequently added memory blocks only.
@@ -393,11 +395,16 @@ command line parameters are relevant: ======================== ======================================================= ``memhp_default_state`` configure auto-onlining by essentially setting ``/sys/devices/system/memory/auto_online_blocks``. -``movable_node`` configure automatic zone selection in the kernel. When - set, the kernel will default to ZONE_MOVABLE, unless - other zones can be kept contiguous. +``movable_node`` configure automatic zone selection in the kernel when + using the ``contig-zones`` online policy. When + set, the kernel will default to ZONE_MOVABLE when + onlining a memory block, unless other zones can be kept + contiguous. ======================== ======================================================= +See Documentation/admin-guide/kernel-parameters.txt for a more generic +description of these command line parameters. + Module Parameters ------------------
@@ -414,20 +421,114 @@ and they can be observed (and some even The following module parameters are currently defined: -======================== ======================================================= -``memmap_on_memory`` read-write: Allocate memory for the memmap from the - added memory block itself. Even if enabled, actual - support depends on various other system properties and - should only be regarded as a hint whether the behavior - would be desired. - - While allocating the memmap from the memory block - itself makes memory hotplug less likely to fail and - keeps the memmap on the same NUMA node in any case, it - can fragment physical memory in a way that huge pages - in bigger granularity cannot be formed on hotplugged - memory. -======================== ======================================================= +================================ =============================================== +``memmap_on_memory`` read-write: Allocate memory for the memmap from + the added memory block itself. Even if enabled, + actual support depends on various other system + properties and should only be regarded as a + hint whether the behavior would be desired. + + While allocating the memmap from the memory + block itself makes memory hotplug less likely + to fail and keeps the memmap on the same NUMA + node in any case, it can fragment physical + memory in a way that huge pages in bigger + granularity cannot be formed on hotplugged + memory. +``online_policy`` read-write: Set the basic policy used for + automatic zone selection when onlining memory + blocks without specifying a target zone. + ``contig-zones`` has been the kernel default + before this parameter was added. After an + online policy was configured and memory was + online, the policy should not be changed + anymore. + + When set to ``contig-zones``, the kernel will + try keeping zones contiguous. If a memory block + intersects multiple zones or no zone, the + behavior depends on the ``movable_node`` kernel + command line parameter: default to ZONE_MOVABLE + if set, default to the applicable kernel zone + (usually ZONE_NORMAL) if not set. + + When set to ``auto-movable``, the kernel will + try onlining memory blocks to ZONE_MOVABLE if + possible according to the configuration and + memory device details. With this policy, one + can avoid zone imbalances when eventually + hotplugging a lot of memory later and still + wanting to be able to hotunplug as much as + possible reliably, very desirable in + virtualized environments. This policy ignores + the ``movable_node`` kernel command line + parameter and isn't really applicable in + environments that require it (e.g., bare metal + with hotunpluggable nodes) where hotplugged + memory might be exposed via the + firmware-provided memory map early during boot + to the system instead of getting detected, + added and onlined later during boot (such as + done by virtio-mem or by some hypervisors + implementing emulated DIMMs). As one example, a + hotplugged DIMM will be onlined either + completely to ZONE_MOVABLE or completely to + ZONE_NORMAL, not a mixture. + As another example, as many memory blocks + belonging to a virtio-mem device will be + onlined to ZONE_MOVABLE as possible, + special-casing units of memory blocks that can + only get hotunplugged together. *This policy + does not protect from setups that are + problematic with ZONE_MOVABLE and does not + change the zone of memory blocks dynamically + after they were onlined.* +``auto_movable_ratio`` read-write: Set the maximum MOVABLE:KERNEL + memory ratio in % for the ``auto-movable`` + online policy. Whether the ratio applies only + for the system across all NUMA nodes or also + per NUMA nodes depends on the + ``auto_movable_numa_aware`` configuration. + + All accounting is based on present memory pages + in the zones combined with accounting per + memory device. Memory dedicated to the CMA + allocator is accounted as MOVABLE, although + residing on one of the kernel zones. The + possible ratio depends on the actual workload. + The kernel default is "301" %, for example, + allowing for hotplugging 24 GiB to a 8 GiB VM + and automatically onlining all hotplugged + memory to ZONE_MOVABLE in many setups. The + additional 1% deals with some pages being not + present, for example, because of some firmware + allocations. + + Note that ZONE_NORMAL memory provided by one + memory device does not allow for more + ZONE_MOVABLE memory for a different memory + device. As one example, onlining memory of a + hotplugged DIMM to ZONE_NORMAL will not allow + for another hotplugged DIMM to get onlined to + ZONE_MOVABLE automatically. In contrast, memory + hotplugged by a virtio-mem device that got + onlined to ZONE_NORMAL will allow for more + ZONE_MOVABLE memory within *the same* + virtio-mem device. +``auto_movable_numa_aware`` read-write: Configure whether the + ``auto_movable_ratio`` in the ``auto-movable`` + online policy also applies per NUMA + node in addition to the whole system across all + NUMA nodes. The kernel default is "Y". + + Disabling NUMA awareness can be helpful when + dealing with NUMA nodes that should be + completely hotunpluggable, onlining the memory + completely to ZONE_MOVABLE automatically if + possible. + + Parameter availability depends on CONFIG_NUMA. +================================ =============================================== ZONE_MOVABLE ============
_
Andrew Morton
maintainerPATCH 186/262 mm/memory_hotplug: remove CONFIG_X86_64_ACPI_NUMA dependency from CONFIG_MEMORY_HOTPLUG
In reply to Andrew MortonFrom: David Hildenbrand <[email protected]>
Subject: mm/memory_hotplug: remove CONFIG_X86_64_ACPI_NUMA dependency from CONFIG_MEMORY_HOTPLUG
Patch series "mm/memory_hotplug: Kconfig and 32 bit cleanups".
Some cleanups around CONFIG_MEMORY_HOTPLUG, including removing 32 bit leftovers of memory hotplug support.
This patch (of 6):
SPARSEMEM is the only possible memory model for x86-64, FLATMEM is not possible:
config ARCH_FLATMEM_ENABLE def_bool y depends on X86_32 && !NUMA
And X86_64_ACPI_NUMA (obviously) only supports x86-64:
config X86_64_ACPI_NUMA def_bool y depends on X86_64 && NUMA && ACPI && PCI
Let's just remove the CONFIG_X86_64_ACPI_NUMA dependency, as it does no longer make sense.
---
mm/Kconfig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
mm/Kconfig renamed from mm/Kconfig~mm-memory_hotplug-remove-config_x86_64_acpi_numa-dependency-from-config_memory_hotplug +1 -1
@@ -123,7 +123,7 @@ config ARCH_ENABLE_MEMORY_HOTPLUG config MEMORY_HOTPLUG bool "Allow for memory hot-add" select MEMORY_ISOLATION - depends on SPARSEMEM || X86_64_ACPI_NUMA + depends on SPARSEMEM depends on ARCH_ENABLE_MEMORY_HOTPLUG depends on 64BIT || BROKEN select NUMA_KEEP_MEMINFO if NUMA
_
Andrew Morton
maintainerPATCH 187/262 mm/memory_hotplug: remove CONFIG_MEMORY_HOTPLUG_SPARSE
In reply to Andrew MortonFrom: David Hildenbrand <[email protected]>
Subject: mm/memory_hotplug: remove CONFIG_MEMORY_HOTPLUG_SPARSE
CONFIG_MEMORY_HOTPLUG depends on CONFIG_SPARSEMEM, so there is no need for CONFIG_MEMORY_HOTPLUG_SPARSE anymore; adjust all instances to use CONFIG_MEMORY_HOTPLUG and remove CONFIG_MEMORY_HOTPLUG_SPARSE.
---
arch/powerpc/include/asm/machdep.h | 2 - arch/powerpc/kernel/setup_64.c | 2 - arch/powerpc/platforms/powernv/setup.c | 4 +- arch/powerpc/platforms/pseries/setup.c | 2 - drivers/base/Makefile | 2 - drivers/base/node.c | 9 ++---- drivers/virtio/Kconfig | 2 - include/linux/memory.h | 24 ++++++---------- include/linux/node.h | 4 +- lib/Kconfig.debug | 2 - mm/Kconfig | 4 -- mm/memory_hotplug.c | 2 - tools/testing/selftests/memory-hotplug/config | 1 13 files changed, 24 insertions(+), 36 deletions(-)
arch/powerpc/include/asm/machdep.h renamed from arch/powerpc/include/asm/machdep.h~mm-memory_hotplug-remove-config_memory_hotplug_sparse +1 -1
@@ -32,7 +32,7 @@ struct machdep_calls {void (*iommu_save)(void );void (*iommu_restore)(void );#endif -#ifdef CONFIG_MEMORY_HOTPLUG_SPARSE +#ifdef CONFIG_MEMORY_HOTPLUG unsigned long (*memory_block_size)(void );#endif #endif /* CONFIG_PPC64 */
arch/powerpc/kernel/setup_64.c renamed from arch/powerpc/kernel/setup_64.c~mm-memory_hotplug-remove-config_memory_hotplug_sparse +1 -1
@@ -912,7 +912,7 @@ void __init setup_per_cpu_areas(void) }#endif -#ifdef CONFIG_MEMORY_HOTPLUG_SPARSE +#ifdef CONFIG_MEMORY_HOTPLUG unsigned long memory_block_size_bytes (void ) {if (ppc_md.memory_block_size)
arch/powerpc/platforms/powernv/setup.c renamed from arch/powerpc/platforms/powernv/setup.c~mm-memory_hotplug-remove-config_memory_hotplug_sparse +2 -2
@@ -440,7 +440,7 @@ static void pnv_kexec_cpu_down(int crash }#endif /* CONFIG_KEXEC_CORE */ -#ifdef CONFIG_MEMORY_HOTPLUG_SPARSE +#ifdef CONFIG_MEMORY_HOTPLUG static unsigned long pnv_memory_block_size (void ) {/*
@@ -553,7 +553,7 @@ define_machine(powernv) {#ifdef CONFIG_KEXEC_CORE .kexec_cpu_down = pnv_kexec_cpu_down,#endif -#ifdef CONFIG_MEMORY_HOTPLUG_SPARSE +#ifdef CONFIG_MEMORY_HOTPLUG .memory_block_size = pnv_memory_block_size,#endif };
arch/powerpc/platforms/pseries/setup.c renamed from arch/powerpc/platforms/pseries/setup.c~mm-memory_hotplug-remove-config_memory_hotplug_sparse +1 -1
@@ -1089,7 +1089,7 @@ define_machine(pseries) { .machine_kexec = pSeries_machine_kexec, .kexec_cpu_down = pseries_kexec_cpu_down,#endif -#ifdef CONFIG_MEMORY_HOTPLUG_SPARSE +#ifdef CONFIG_MEMORY_HOTPLUG .memory_block_size = pseries_memory_block_size,#endif };
drivers/base/Makefile renamed from drivers/base/Makefile~mm-memory_hotplug-remove-config_memory_hotplug_sparse +1 -1
@@ -13,7 +13,7 @@ obj-y += power/ obj-$(CONFIG_ISA_BUS_API) += isa.o obj-y += firmware_loader/ obj-$(CONFIG_NUMA) += node.o -obj-$(CONFIG_MEMORY_HOTPLUG_SPARSE) += memory.o +obj-$(CONFIG_MEMORY_HOTPLUG) += memory.o ifeq ($(CONFIG_SYSFS),y) obj-$(CONFIG_MODULES) += module.o endif
drivers/base/node.c renamed from drivers/base/node.c~mm-memory_hotplug-remove-config_memory_hotplug_sparse +4 -5
@@ -629,7 +629,7 @@ static void node_device_release(struct d {struct node *node =to_node (dev); -#if defined(CONFIG_MEMORY_HOTPLUG_SPARSE ) && defined(CONFIG_HUGETLBFS ) +#if defined(CONFIG_MEMORY_HOTPLUG ) && defined(CONFIG_HUGETLBFS )/* * We schedule the work only when a memory section is * onlined/offlined on this node. When we come here,
@@ -782,7 +782,7 @@ int unregister_cpu_under_node(unsigned ireturn 0 ; } -#ifdef CONFIG_MEMORY_HOTPLUG_SPARSE +#ifdef CONFIG_MEMORY_HOTPLUG static int __ref get_nid_for_pfn (unsigned long pfn) {#ifdef CONFIG_DEFERRED_STRUCT_PAGE_INIT
@@ -958,10 +958,9 @@ static int node_memory_callback(struct nreturn NOTIFY_OK ; }#endif /* CONFIG_HUGETLBFS */ -#endif /* CONFIG_MEMORY_HOTPLUG_SPARSE */ +#endif /* CONFIG_MEMORY_HOTPLUG */ -#if !defined(CONFIG_MEMORY_HOTPLUG_SPARSE ) || \ - !defined(CONFIG_HUGETLBFS ) +#if !defined(CONFIG_MEMORY_HOTPLUG ) || !defined(CONFIG_HUGETLBFS )static inline int node_memory_callback (struct notifier_block *self,unsigned long action,void *arg) {
drivers/virtio/Kconfig renamed from drivers/virtio/Kconfig~mm-memory_hotplug-remove-config_memory_hotplug_sparse +1 -1
@@ -98,7 +98,7 @@ config VIRTIO_MEM default m depends on X86_64 depends on VIRTIO - depends on MEMORY_HOTPLUG_SPARSE + depends on MEMORY_HOTPLUG depends on MEMORY_HOTREMOVE depends on CONTIG_ALLOC help
include/linux/memory.h renamed from include/linux/memory.h~mm-memory_hotplug-remove-config_memory_hotplug_sparse +10 -14
@@ -110,7 +110,7 @@ struct mem_section;#define SLAB_CALLBACK_PRI 1#define IPC_CALLBACK_PRI 10 -#ifndef CONFIG_MEMORY_HOTPLUG_SPARSE +#ifndef CONFIG_MEMORY_HOTPLUG static inline void memory_dev_init (void ) {return ;
@@ -126,7 +126,14 @@ static inline int memory_notify(unsigned {return 0 ; } -#else +static inline int hotplug_memory_notifier (notifier_fn_t fn,int pri) +{ +return 0 ; +} +/* These aren't inline functions due to a GCC bug. */ +#define register_hotmemory_notifier (nb) ({ (void)(nb); 0; }) +#define unregister_hotmemory_notifier (nb) ({ (void)(nb); }) +#else /* CONFIG_MEMORY_HOTPLUG */ extern int register_memory_notifier (struct notifier_block *nb);extern void unregister_memory_notifier (struct notifier_block *nb); int create_memory_block_devices(unsigned long start, unsigned long size,
@@ -148,9 +155,6 @@ struct memory_group *memory_group_find_btypedef int (*walk_memory_groups_func_t )(struct memory_group *,void *);int walk_dynamic_memory_groups (int nid,walk_memory_groups_func_t func,struct memory_group *excluded,void *arg); -#endif /* CONFIG_MEMORY_HOTPLUG_SPARSE */ - -#ifdef CONFIG_MEMORY_HOTPLUG #define hotplug_memory_notifier (fn, pri) ({ \ static __meminitdata struct notifier_block fn##_mem_nb =\ { .notifier_call = fn, .priority = pri };\
@@ -158,15 +162,7 @@ int walk_dynamic_memory_groups(int nid, })#define register_hotmemory_notifier (nb) register_memory_notifier(nb)#define unregister_hotmemory_notifier (nb) unregister_memory_notifier(nb) -#else -static inline int hotplug_memory_notifier (notifier_fn_t fn,int pri) -{ -return 0 ; -} -/* These aren't inline functions due to a GCC bug. */ -#define register_hotmemory_notifier (nb) ({ (void)(nb); 0; }) -#define unregister_hotmemory_notifier (nb) ({ (void)(nb); }) -#endif +#endif /* CONFIG_MEMORY_HOTPLUG */ /* * Kernel text modification mutex, used for code patching. Users of this lock
include/linux/node.h renamed from include/linux/node.h~mm-memory_hotplug-remove-config_memory_hotplug_sparse +2 -2
@@ -85,7 +85,7 @@ struct node {struct device dev;struct list_head access_list; -#if defined(CONFIG_MEMORY_HOTPLUG_SPARSE ) && defined(CONFIG_HUGETLBFS ) +#if defined(CONFIG_MEMORY_HOTPLUG ) && defined(CONFIG_HUGETLBFS )struct work_struct node_work;#endif #ifdef CONFIG_HMEM_REPORTING
@@ -98,7 +98,7 @@ struct memory_block;extern struct node *node_devices[];typedef void (*node_registration_func_t )(struct node *); -#if defined(CONFIG_MEMORY_HOTPLUG_SPARSE ) && defined(CONFIG_NUMA ) +#if defined(CONFIG_MEMORY_HOTPLUG ) && defined(CONFIG_NUMA )void link_mem_sections (int nid,unsigned long start_pfn,unsigned long end_pfn,enum meminit_context context);
lib/Kconfig.debug renamed from lib/Kconfig.debug~mm-memory_hotplug-remove-config_memory_hotplug_sparse +1 -1
@@ -877,7 +877,7 @@ config DEBUG_MEMORY_INIT config MEMORY_NOTIFIER_ERROR_INJECT tristate "Memory hotplug notifier error injection module" - depends on MEMORY_HOTPLUG_SPARSE && NOTIFIER_ERROR_INJECTION + depends on MEMORY_HOTPLUG && NOTIFIER_ERROR_INJECTION help This option provides the ability to inject artificial errors to memory hotplug notifier chain callbacks. It is controlled through
mm/Kconfig renamed from mm/Kconfig~mm-memory_hotplug-remove-config_memory_hotplug_sparse +0 -4
@@ -128,10 +128,6 @@ config MEMORY_HOTPLUG depends on 64BIT || BROKEN select NUMA_KEEP_MEMINFO if NUMA -config MEMORY_HOTPLUG_SPARSE - def_bool y - depends on SPARSEMEM && MEMORY_HOTPLUG - config MEMORY_HOTPLUG_DEFAULT_ONLINE bool "Online the newly added memory blocks by default" depends on MEMORY_HOTPLUG
mm/memory_hotplug.c renamed from mm/memory_hotplug.c~mm-memory_hotplug-remove-config_memory_hotplug_sparse +0 -2
@@ -220,7 +220,6 @@ static void release_memory_resource(strukfree (res); } -#ifdef CONFIG_MEMORY_HOTPLUG_SPARSE static int check_pfn_span (unsigned long pfn,unsigned long nr_pages,const char *reason) {
@@ -1163,7 +1162,6 @@ failed_addition:mem_hotplug_done ();return ret; } -#endif /* CONFIG_MEMORY_HOTPLUG_SPARSE */ static void reset_node_present_pages (pg_data_t *pgdat) {
tools/testing/selftests/memory-hotplug/config renamed from tools/testing/selftests/memory-hotplug/config~mm-memory_hotplug-remove-config_memory_hotplug_sparse +0 -1
@@ -1,5 +1,4 @@ CONFIG_MEMORY_HOTPLUG=y -CONFIG_MEMORY_HOTPLUG_SPARSE=y CONFIG_NOTIFIER_ERROR_INJECTION=y CONFIG_MEMORY_NOTIFIER_ERROR_INJECT=m CONFIG_MEMORY_HOTREMOVE=y
_
Andrew Morton
maintainerPATCH 188/262 mm/memory_hotplug: restrict CONFIG_MEMORY_HOTPLUG to 64 bit
In reply to Andrew MortonFrom: David Hildenbrand <[email protected]>
Subject: mm/memory_hotplug: restrict CONFIG_MEMORY_HOTPLUG to 64 bit
32 bit support is broken in various ways: for example, we can online memory that should actually go to ZONE_HIGHMEM to ZONE_MOVABLE or in some cases even to one of the other kernel zones.
We marked it BROKEN in commit b59d02ed0869 ("mm/memory_hotplug: disable the functionality for 32b") almost one year ago. According to that commit it might be broken at least since 2017. Further, there is hardly a sane use case nowadays.
Let's just depend completely on 64bit, dropping the "BROKEN" dependency to make clear that we are not going to support it again. Next, we'll remove some HIGHMEM leftovers from memory hotplug code to clean up.
---
mm/Kconfig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
mm/Kconfig renamed from mm/Kconfig~mm-memory_hotplug-restrict-config_memory_hotplug-to-64-bit +1 -1
@@ -125,7 +125,7 @@ config MEMORY_HOTPLUG select MEMORY_ISOLATION depends on SPARSEMEM depends on ARCH_ENABLE_MEMORY_HOTPLUG - depends on 64BIT || BROKEN + depends on 64BIT select NUMA_KEEP_MEMINFO if NUMA config MEMORY_HOTPLUG_DEFAULT_ONLINE
_
Andrew Morton
maintainerPATCH 189/262 mm/memory_hotplug: remove HIGHMEM leftovers
In reply to Andrew MortonFrom: David Hildenbrand <[email protected]>
Subject: mm/memory_hotplug: remove HIGHMEM leftovers
We don't support CONFIG_MEMORY_HOTPLUG on 32 bit and consequently not HIGHMEM. Let's remove any leftover code -- including the unused "status_change_nid_high" field part of the memory notifier.
---
Documentation/core-api/memory-hotplug.rst | 3 Documentation/translations/zh_CN/core-api/memory-hotplug.rst | 4 - include/linux/memory.h | 1 mm/memory_hotplug.c | 36 ---------- 4 files changed, 2 insertions(+), 42 deletions(-)
Documentation/core-api/memory-hotplug.rst renamed from Documentation/core-api/memory-hotplug.rst~mm-memory_hotplug-remove-highmem-leftovers +0 -3
@@ -57,7 +57,6 @@ The third argument (arg) passes a pointe unsigned long start_pfn; unsigned long nr_pages; int status_change_nid_normal; - int status_change_nid_high; int status_change_nid; }
@@ -65,8 +64,6 @@ The third argument (arg) passes a pointe - nr_pages is # of pages of online/offline memory. - status_change_nid_normal is set node id when N_NORMAL_MEMORY of nodemask is (will be) set/clear, if this is -1, then nodemask status is not changed. -- status_change_nid_high is set node id when N_HIGH_MEMORY of nodemask - is (will be) set/clear, if this is -1, then nodemask status is not changed. - status_change_nid is set node id when N_MEMORY of nodemask is (will be) set/clear. It means a new(memoryless) node gets new memory by online and a node loses all memory. If this is -1, then nodemask status is not changed.
Documentation/translations/zh_CN/core-api/memory-hotplug.rst renamed from Documentation/translations/zh_CN/core-api/memory-hotplug.rst~mm-memory_hotplug-remove-highmem-leftovers +0 -4
@@ -63,7 +63,6 @@ memory_notify结构体的指针:: unsigned long start_pfn; unsigned long nr_pages; int status_change_nid_normal; - int status_change_nid_high; int status_change_nid; }
@@ -74,9 +73,6 @@ memory_notify结构体的指针:: - status_change_nid_normal是当nodemask的N_NORMAL_MEMORY被设置/清除时设置节 点id,如果是-1,则nodemask状态不改变。 -- status_change_nid_high是当nodemask的N_HIGH_MEMORY被设置/清除时设置的节点 - id,如果这个值为-1,那么nodemask状态不会改变。 - - status_change_nid是当nodemask的N_MEMORY被(将)设置/清除时设置的节点id。这 意味着一个新的(没上线的)节点通过联机获得新的内存,而一个节点失去了所有的内 存。如果这个值为-1,那么nodemask的状态就不会改变。
include/linux/memory.h renamed from include/linux/memory.h~mm-memory_hotplug-remove-highmem-leftovers +0 -1
@@ -96,7 +96,6 @@ struct memory_notify {unsigned long start_pfn;unsigned long nr_pages;int status_change_nid_normal; -int status_change_nid_high;int status_change_nid; };
mm/memory_hotplug.c renamed from mm/memory_hotplug.c~mm-memory_hotplug-remove-highmem-leftovers +2 -34
@@ -21,7 +21,6 @@#include <linux/memory.h> #include <linux/memremap.h> #include <linux/memory_hotplug.h> -#include <linux/highmem.h> #include <linux/vmalloc.h> #include <linux/ioport.h> #include <linux/delay.h>
@@ -585,10 +584,6 @@ void generic_online_page(struct page *padebug_pagealloc_map_pages (page,1 << order);__free_pages_core (page, order);totalram_pages_add (1UL << order); -#ifdef CONFIG_HIGHMEM -if (PageHighMem (page)) -totalhigh_pages_add (1UL << order); -#endif }EXPORT_SYMBOL_GPL (generic_online_page);
@@ -625,16 +620,11 @@ static void node_states_check_changes_on arg->status_change_nid =NUMA_NO_NODE ; arg->status_change_nid_normal =NUMA_NO_NODE ; - arg->status_change_nid_high =NUMA_NO_NODE ;if (!node_state (nid,N_MEMORY )) arg->status_change_nid = nid;if (zone_idx (zone) <=ZONE_NORMAL && !node_state (nid,N_NORMAL_MEMORY )) arg->status_change_nid_normal = nid; -#ifdef CONFIG_HIGHMEM -if (zone_idx (zone) <=ZONE_HIGHMEM && !node_state (nid,N_HIGH_MEMORY )) - arg->status_change_nid_high = nid; -#endif }static void node_states_set_node (int node,struct memory_notify *arg)
@@ -642,9 +632,6 @@ static void node_states_set_node(int nodif (arg->status_change_nid_normal >=0 )node_set_state (node,N_NORMAL_MEMORY ); -if (arg->status_change_nid_high >=0 ) -node_set_state (node,N_HIGH_MEMORY ); -if (arg->status_change_nid >=0 )node_set_state (node,N_MEMORY ); }
@@ -1801,7 +1788,6 @@ static void node_states_check_changes_of arg->status_change_nid =NUMA_NO_NODE ; arg->status_change_nid_normal =NUMA_NO_NODE ; - arg->status_change_nid_high =NUMA_NO_NODE ;/* * Check whether node_states[N_NORMAL_MEMORY] will be changed.
@@ -1816,24 +1802,9 @@ static void node_states_check_changes_ofif (zone_idx (zone) <=ZONE_NORMAL && nr_pages >= present_pages) arg->status_change_nid_normal =zone_to_nid (zone); -#ifdef CONFIG_HIGHMEM /* -* node_states[N_HIGH_MEMORY] contains nodes which -* have normal memory or high memory. -* Here we add the present_pages belonging to ZONE_HIGHMEM. -* If the zone is within the range of [0..ZONE_HIGHMEM), and -* we determine that the zones in that range become empty, -* we need to clear the node for N_HIGH_MEMORY. -*/ - present_pages += pgdat->node_zones[ZONE_HIGHMEM ].present_pages; -if (zone_idx (zone) <=ZONE_HIGHMEM && nr_pages >= present_pages) - arg->status_change_nid_high =zone_to_nid (zone); -#endif - -/* -* We have accounted the pages from [0..ZONE_NORMAL), and -* in case of CONFIG_HIGHMEM the pages from ZONE_HIGHMEM -* as well. +* We have accounted the pages from [0..ZONE_NORMAL); ZONE_HIGHMEM +* does not apply as we don't support 32bit. * Here we count the possible pages from ZONE_MOVABLE. * If after having accounted all the pages, we see that the nr_pages * to be offlined is over or equal to the accounted pages,
@@ -1851,9 +1822,6 @@ static void node_states_clear_node(int nif (arg->status_change_nid_normal >=0 )node_clear_state (node,N_NORMAL_MEMORY ); -if (arg->status_change_nid_high >=0 ) -node_clear_state (node,N_HIGH_MEMORY ); -if (arg->status_change_nid >=0 )node_clear_state (node,N_MEMORY ); }
_
Andrew Morton
maintainerPATCH 190/262 mm/memory_hotplug: remove stale function declarations
In reply to Andrew MortonFrom: David Hildenbrand <[email protected]>
Subject: mm/memory_hotplug: remove stale function declarations
These functions no longer exist.
---
include/linux/memory_hotplug.h | 3 --- 1 file changed, 3 deletions(-)
include/linux/memory_hotplug.h renamed from include/linux/memory_hotplug.h~mm-memory_hotplug-remove-stale-function-declarations +0 -3
@@ -98,9 +98,6 @@ static inline void zone_seqlock_init(str {seqlock_init (&zone->span_seqlock); } -extern int zone_grow_free_lists (struct zone *zone,unsigned long new_nr_pages); -extern int zone_grow_waitqueues (struct zone *zone,unsigned long nr_pages); -extern int add_one_highpage (struct page *page,int pfn,int bad_ppro);extern void adjust_present_page_count (struct page *page,struct memory_group *group,long nr_pages);
_
Andrew Morton
maintainerPATCH 191/262 x86: remove memory hotplug support on X86_32
In reply to Andrew MortonFrom: David Hildenbrand <[email protected]>
Subject: x86: remove memory hotplug support on X86_32
CONFIG_MEMORY_HOTPLUG was marked BROKEN over one year and we just restricted it to 64 bit. Let's remove the unused x86 32bit implementation and simplify the Kconfig.
---
arch/x86/Kconfig | 6 +++--- arch/x86/mm/init_32.c | 31 ------------------------------- 2 files changed, 3 insertions(+), 34 deletions(-)
arch/x86/Kconfig renamed from arch/x86/Kconfig~x86-remove-memory-hotplug-support-on-x86_32 +3 -3
@@ -62,7 +62,7 @@ config X86 select ARCH_32BIT_OFF_T if X86_32 select ARCH_CLOCKSOURCE_INIT select ARCH_ENABLE_HUGEPAGE_MIGRATION if X86_64 && HUGETLB_PAGE && MIGRATION - select ARCH_ENABLE_MEMORY_HOTPLUG if X86_64 || (X86_32 && HIGHMEM) + select ARCH_ENABLE_MEMORY_HOTPLUG if X86_64 select ARCH_ENABLE_MEMORY_HOTREMOVE if MEMORY_HOTPLUG select ARCH_ENABLE_SPLIT_PMD_PTLOCK if (PGTABLE_LEVELS > 2) && (X86_64 || X86_PAE) select ARCH_ENABLE_THP_MIGRATION if X86_64 && TRANSPARENT_HUGEPAGE
@@ -1614,7 +1614,7 @@ config ARCH_SELECT_MEMORY_MODEL config ARCH_MEMORY_PROBE bool "Enable sysfs memory/probe interface" - depends on X86_64 && MEMORY_HOTPLUG + depends on MEMORY_HOTPLUG help This option enables a sysfs memory/probe interface for testing. See Documentation/admin-guide/mm/memory-hotplug.rst for more information.
@@ -2394,7 +2394,7 @@ endmenu config ARCH_HAS_ADD_PAGES def_bool y - depends on X86_64 && ARCH_ENABLE_MEMORY_HOTPLUG + depends on ARCH_ENABLE_MEMORY_HOTPLUG config ARCH_MHP_MEMMAP_ON_MEMORY_ENABLE def_bool y
arch/x86/mm/init_32.c renamed from arch/x86/mm/init_32.c~x86-remove-memory-hotplug-support-on-x86_32 +0 -31
@@ -779,37 +779,6 @@ void __init mem_init(void)test_wp_bit (); } -#ifdef CONFIG_MEMORY_HOTPLUG -int arch_add_memory (int nid,u64 start,u64 size, -struct mhp_params *params) -{ -unsigned long start_pfn = start >>PAGE_SHIFT ; -unsigned long nr_pages = size >>PAGE_SHIFT ; -int ret; - -/* -* The page tables were already mapped at boot so if the caller -* requests a different mapping type then we must change all the -* pages with __set_memory_prot(). -*/ -if (params->pgprot.pgprot !=PAGE_KERNEL .pgprot) { - ret =__set_memory_prot (start, nr_pages, params->pgprot); -if (ret) -return ret; - } - -return __add_pages (nid, start_pfn, nr_pages, params); -} - -void arch_remove_memory (u64 start,u64 size,struct vmem_altmap *altmap) -{ -unsigned long start_pfn = start >>PAGE_SHIFT ; -unsigned long nr_pages = size >>PAGE_SHIFT ; - -__remove_pages (start_pfn, nr_pages, altmap); -} -#endif -int kernel_set_to_readonly__read_mostly ;static void mark_nxdata_nx (void )
_
Andrew Morton
maintainerPATCH 192/262 mm/memory_hotplug: handle memblock_add_node() failures in add_memory_resource()
In reply to Andrew MortonFrom: David Hildenbrand <[email protected]>
Subject: mm/memory_hotplug: handle memblock_add_node() failures in add_memory_resource()
Patch series "mm/memory_hotplug: full support for add_memory_driver_managed() with CONFIG_ARCH_KEEP_MEMBLOCK", v2.
Architectures that require CONFIG_ARCH_KEEP_MEMBLOCK=y, such as arm64, don't cleanly support add_memory_driver_managed() yet. Most prominently, kexec_file can still end up placing kexec images on such driver-managed memory, resulting in undesired behavior, for example, having kexec images located on memory not part of the firmware-provided memory map.
Teaching kexec to not place images on driver-managed memory is especially relevant for virtio-mem. Details can be found in commit 7b7b27214bba ("mm/memory_hotplug: introduce add_memory_driver_managed()").
Extend memblock with a new flag and set it from memory hotplug code when applicable. This is required to fully support virtio-mem on arm64, making also kexec_file behave like on x86-64.
This patch (of 2):
If memblock_add_node() fails, we're most probably running out of memory. While this is unlikely to happen, it can happen and having memory added without a memblock can be problematic for architectures that use memblock to detect valid memory. Let's fail in a nice way instead of silently ignoring the error.
---
mm/memory_hotplug.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
mm/memory_hotplug.c renamed from mm/memory_hotplug.c~mm-memory_hotplug-handle-memblock_add_node-failures-in-add_memory_resource +6 -2
@@ -1369,8 +1369,11 @@ int __ref add_memory_resource(int nid, smem_hotplug_begin (); -if (IS_ENABLED (CONFIG_ARCH_KEEP_MEMBLOCK )) -memblock_add_node (start, size, nid); +if (IS_ENABLED (CONFIG_ARCH_KEEP_MEMBLOCK )) { + ret =memblock_add_node (start, size, nid); +if (ret) + goto error_mem_hotplug_end; + } ret =__try_online_node (nid, false);if (ret <0 )
@@ -1443,6 +1446,7 @@ error:rollback_node_hotadd (nid);if (IS_ENABLED (CONFIG_ARCH_KEEP_MEMBLOCK ))memblock_remove (start, size); +error_mem_hotplug_end:mem_hotplug_done ();return ret; }
_
Andrew Morton
maintainerPATCH 193/262 memblock: improve MEMBLOCK_HOTPLUG documentation
In reply to Andrew MortonFrom: David Hildenbrand <[email protected]>
Subject: memblock: improve MEMBLOCK_HOTPLUG documentation
The description of MEMBLOCK_HOTPLUG is currently short and consequently
misleading: we're actually dealing with a memory region that might get hotunplugged later (i.e., the platform+firmware supports it), yet it is indicated in the firmware-provided memory map as system ram that will just get used by the system for any purpose when not taking special care. The firmware marked this memory region as a hot(un)plugged (e.g., hotplugged before reboot), implying that it might get hotunplugged again later.
Whether we consider this information depends on the "movable_node" kernel commandline parameter: only with "movable_node" set, we'll try keeping this memory hotunpluggable, for example, by not serving early allocations from this memory region and by letting the buddy manage it using the ZONE_MOVABLE.
Let's make this clearer by extending the documentation.
Note: kexec *has to* indicate this memory to the second kernel. With "movable_node" set, we don't want to place kexec-images on this memory. Without "movable_node" set, we don't care and can place kexec-images on this memory. In both cases, after successful memory hotunplug, kexec has to be re-armed to update the memory map for the second kernel and to place the kexec-images somewhere else.
---
include/linux/memblock.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
include/linux/memblock.h renamed from include/linux/memblock.h~memblock-improve-memblock_hotplug-documentation +5 -1
@@ -28,7 +28,11 @@ extern unsigned long long max_possible_p/** * enum memblock_flags - definition of memory region attributes * @MEMBLOCK_NONE: no special request -* @MEMBLOCK_HOTPLUG: hotpluggable region +* @MEMBLOCK_HOTPLUG: memory region indicated in the firmware-provided memory +* map during early boot as hot(un)pluggable system RAM (e.g., memory range +* that might get hotunplugged later). With "movable_node" set on the kernel +* commandline, try keeping this memory region hotunpluggable. Does not apply +* to memblocks added ("hotplugged") after early boot. * @MEMBLOCK_MIRROR: mirrored region * @MEMBLOCK_NOMAP: don't add to kernel direct mapping and treat as * reserved in the memory map; refer to memblock_mark_nomap() description
_
Andrew Morton
maintainerPATCH 194/262 memblock: allow to specify flags with memblock_add_node()
In reply to Andrew MortonFrom: David Hildenbrand <[email protected]>
Subject: memblock: allow to specify flags with memblock_add_node()
We want to specify flags when hotplugging memory. Let's prepare to pass flags to memblock_add_node() by adjusting all existing users.
Note that when hotplugging memory the system is already up and running and we might have concurrent memblock users: for example, while we're hotplugging memory, kexec_file code might search for suitable memory regions to place kexec images. It's important to add the memory directly to memblock via a single call with the right flags, instead of adding the memory first and apply flags later: otherwise, concurrent memblock users might temporarily stumble over memblocks with wrong flags, which will be important in a follow-up patch that introduces a new flag to properly handle add_memory_driver_managed().
---
arch/arc/mm/init.c | 4 ++-- arch/ia64/mm/contig.c | 2 +- arch/ia64/mm/init.c | 2 +- arch/m68k/mm/mcfmmu.c | 3 ++- arch/m68k/mm/motorola.c | 6 ++++-- arch/mips/loongson64/init.c | 4 +++- arch/mips/sgi-ip27/ip27-memory.c | 3 ++- arch/s390/kernel/setup.c | 3 ++- include/linux/memblock.h | 3 ++- include/linux/mm.h | 2 +- mm/memblock.c | 9 +++++---- mm/memory_hotplug.c | 2 +- 12 files changed, 26 insertions(+), 17 deletions(-)
arch/arc/mm/init.c renamed from arch/arc/mm/init.c~memblock-allow-to-specify-flags-with-memblock_add_node +2 -2
@@ -59,13 +59,13 @@ void __init early_init_dt_add_memory_arc low_mem_sz = size; in_use =1 ; -memblock_add_node (base, size,0 ); +memblock_add_node (base, size,0 ,MEMBLOCK_NONE ); }else {#ifdef CONFIG_HIGHMEM high_mem_start = base; high_mem_sz = size; in_use =1 ; -memblock_add_node (base, size,1 ); +memblock_add_node (base, size,1 ,MEMBLOCK_NONE );memblock_reserve (base, size);#endif }
arch/ia64/mm/contig.c renamed from arch/ia64/mm/contig.c~memblock-allow-to-specify-flags-with-memblock_add_node +1 -1
@@ -153,7 +153,7 @@ find_memory (void)efi_memmap_walk (find_max_min_low_pfn,NULL ); max_pfn = max_low_pfn; -memblock_add_node (0 ,PFN_PHYS (max_low_pfn),0 ); +memblock_add_node (0 ,PFN_PHYS (max_low_pfn),0 ,MEMBLOCK_NONE );find_initrd ();
arch/ia64/mm/init.c renamed from arch/ia64/mm/init.c~memblock-allow-to-specify-flags-with-memblock_add_node +1 -1
@@ -378,7 +378,7 @@ int __init register_active_ranges(u64 st#endif if (start < end) -memblock_add_node (__pa (start), end - start, nid); +memblock_add_node (__pa (start), end - start, nid,MEMBLOCK_NONE );return 0 ; }
arch/m68k/mm/mcfmmu.c renamed from arch/m68k/mm/mcfmmu.c~memblock-allow-to-specify-flags-with-memblock_add_node +2 -1
@@ -174,7 +174,8 @@ void __init cf_bootmem_alloc(void) m68k_memory[0 ].addr = _rambase; m68k_memory[0 ].size = _ramend - _rambase; -memblock_add_node (m68k_memory[0 ].addr, m68k_memory[0 ].size,0 ); +memblock_add_node (m68k_memory[0 ].addr, m68k_memory[0 ].size,0 , +MEMBLOCK_NONE );/* compute total pages in system */ num_pages =PFN_DOWN (_ramend - _rambase);
arch/m68k/mm/motorola.c renamed from arch/m68k/mm/motorola.c~memblock-allow-to-specify-flags-with-memblock_add_node +4 -2
@@ -410,7 +410,8 @@ void __init paging_init(void) min_addr = m68k_memory[0 ].addr; max_addr = min_addr + m68k_memory[0 ].size; -memblock_add_node (m68k_memory[0 ].addr, m68k_memory[0 ].size,0 ); +memblock_add_node (m68k_memory[0 ].addr, m68k_memory[0 ].size,0 , +MEMBLOCK_NONE );for (i =1 ; i < m68k_num_memory;) {if (m68k_memory[i].addr < min_addr) { printk("Ignoring memory chunk at 0x%lx:0x%lx before the first chunk\n",
@@ -421,7 +422,8 @@ void __init paging_init(void) (m68k_num_memory - i) * sizeof(struct m68k_mem_info));continue ; } -memblock_add_node (m68k_memory[i].addr, m68k_memory[i].size, i); +memblock_add_node (m68k_memory[i].addr, m68k_memory[i].size, i, +MEMBLOCK_NONE ); addr = m68k_memory[i].addr + m68k_memory[i].size;if (addr > max_addr) max_addr = addr;
arch/mips/loongson64/init.c renamed from arch/mips/loongson64/init.c~memblock-allow-to-specify-flags-with-memblock_add_node +3 -1
@@ -77,7 +77,9 @@ void __init szmem(unsigned int node) (u32)node_id, mem_type, mem_start, mem_size);pr_info (" start_pfn:0x%llx, end_pfn:0x%llx, num_physpages:0x%lx\n" , start_pfn, end_pfn, num_physpages); -memblock_add_node (PFN_PHYS (start_pfn),PFN_PHYS (node_psize), node); +memblock_add_node (PFN_PHYS (start_pfn), +PFN_PHYS (node_psize), node, +MEMBLOCK_NONE );break ;case SYSTEM_RAM_RESERVED : pr_info("Node%d: mem_type:%d, mem_start:0x%llx, mem_size:0x%llx MB\n",
arch/mips/sgi-ip27/ip27-memory.c renamed from arch/mips/sgi-ip27/ip27-memory.c~memblock-allow-to-specify-flags-with-memblock_add_node +2 -1
@@ -341,7 +341,8 @@ static void __init szmem(void)continue ; }memblock_add_node (PFN_PHYS (slot_getbasepfn (node, slot)), -PFN_PHYS (slot_psize), node); +PFN_PHYS (slot_psize), node, +MEMBLOCK_NONE ); } } }
arch/s390/kernel/setup.c renamed from arch/s390/kernel/setup.c~memblock-allow-to-specify-flags-with-memblock_add_node +2 -1
@@ -593,7 +593,8 @@ static void __init setup_resources(void)* part of the System RAM resource. */ if (crashk_res.end) { -memblock_add_node (crashk_res.start,resource_size (&crashk_res),0 ); +memblock_add_node (crashk_res.start,resource_size (&crashk_res), +0 ,MEMBLOCK_NONE );memblock_reserve (crashk_res.start,resource_size (&crashk_res));insert_resource (&iomem_resource, &crashk_res); }
include/linux/memblock.h renamed from include/linux/memblock.h~memblock-allow-to-specify-flags-with-memblock_add_node +2 -1
@@ -104,7 +104,8 @@ static inline void memblock_discard(void#endif void memblock_allow_resize (void ); -int memblock_add_node (phys_addr_t base,phys_addr_t size,int nid); +int memblock_add_node (phys_addr_t base,phys_addr_t size,int nid, +enum memblock_flags flags);int memblock_add (phys_addr_t base,phys_addr_t size);int memblock_remove (phys_addr_t base,phys_addr_t size);int memblock_phys_free (phys_addr_t base,phys_addr_t size);
include/linux/mm.h renamed from include/linux/mm.h~memblock-allow-to-specify-flags-with-memblock_add_node +1 -1
@@ -2425,7 +2425,7 @@ static inline unsigned long get_num_phys* unsigned long max_zone_pfns[MAX_NR_ZONES] = {max_dma, max_normal_pfn, * max_highmem_pfn}; * for_each_valid_physical_page_range() -* memblock_add_node(base, size, nid) +* memblock_add_node(base, size, nid, MEMBLOCK_NONE) * free_area_init(max_zone_pfns); */ void free_area_init (unsigned long *max_zone_pfn);
mm/memblock.c renamed from mm/memblock.c~memblock-allow-to-specify-flags-with-memblock_add_node +5 -4
@@ -655,6 +655,7 @@ repeat:* @base: base address of the new region * @size: size of the new region * @nid: nid of the new region +* @flags: flags of the new region * * Add new memblock region [@base, @base + @size) to the "memory" * type. See memblock_add_range() description for mode details
@@ -663,14 +664,14 @@ repeat:* 0 on success, -errno on failure. */ int __init_memblock memblock_add_node(phys_addr_t base, phys_addr_t size, -int nid) +int nid,enum memblock_flags flags) {phys_addr_t end = base + size -1 ; -memblock_dbg ("%s: [%pa-%pa] nid=%d %pS\n" , __func__, - &base, &end, nid, (void *)_RET_IP_); +memblock_dbg ("%s: [%pa-%pa] nid=%d flags=%x %pS\n" , __func__, + &base, &end, nid, flags, (void *)_RET_IP_); -return memblock_add_range (&memblock.memory, base, size, nid,0 ); +return memblock_add_range (&memblock.memory, base, size, nid, flags); }/**
mm/memory_hotplug.c renamed from mm/memory_hotplug.c~memblock-allow-to-specify-flags-with-memblock_add_node +1 -1
@@ -1370,7 +1370,7 @@ int __ref add_memory_resource(int nid, smem_hotplug_begin ();if (IS_ENABLED (CONFIG_ARCH_KEEP_MEMBLOCK )) { - ret =memblock_add_node (start, size, nid); + ret =memblock_add_node (start, size, nid,MEMBLOCK_NONE );if (ret) goto error_mem_hotplug_end; }
_
Andrew Morton
maintainerPATCH 195/262 memblock: add MEMBLOCK_DRIVER_MANAGED to mimic IORESOURCE_SYSRAM_DRIVER_MANAGED
In reply to Andrew MortonFrom: David Hildenbrand <[email protected]>
Subject: memblock: add MEMBLOCK_DRIVER_MANAGED to mimic IORESOURCE_SYSRAM_DRIVER_MANAGED
Let's add a flag that corresponds to IORESOURCE_SYSRAM_DRIVER_MANAGED, indicating that we're dealing with a memory region that is never indicated in the firmware-provided memory map, but always detected and added by a driver.
Similar to MEMBLOCK_HOTPLUG, most infrastructure has to treat such memory regions like ordinary MEMBLOCK_NONE memory regions -- for example, when selecting memory regions to add to the vmcore for dumping in the crashkernel via for_each_mem_range().
However, especially kexec_file is not supposed to select such memblocks via for_each_free_mem_range() / for_each_free_mem_range_reverse() to place kexec images, similar to how we handle IORESOURCE_SYSRAM_DRIVER_MANAGED without CONFIG_ARCH_KEEP_MEMBLOCK.
We'll make sure that memory hotplug code sets the flag where applicable (IORESOURCE_SYSRAM_DRIVER_MANAGED) next. This prepares architectures that need CONFIG_ARCH_KEEP_MEMBLOCK, such as arm64, for virtio-mem support.
Note that kexec *must not* indicate this memory to the second kernel and *must not* place kexec-images on this memory. Let's add a comment to kexec_walk_memblock(), documenting how we handle MEMBLOCK_DRIVER_MANAGED now just like using IORESOURCE_SYSRAM_DRIVER_MANAGED in locate_mem_hole_callback() for kexec_walk_resources().
Also note that MEMBLOCK_HOTPLUG cannot be reused due to different semantics:
MEMBLOCK_HOTPLUG: memory is indicated as "System RAM" in the firmware-provided memory map and added to the system early during boot; kexec *has to* indicate this memory to the second kernel and can place kexec-images on this memory. After memory hotunplug, kexec has to be re-armed. We mostly ignore this flag when "movable_node" is not set on the kernel command line, because then we're told to not care about hotunpluggability of such memory regions.
MEMBLOCK_DRIVER_MANAGED: memory is not indicated as "System RAM" in the firmware-provided memory map; this memory is always detected and added to the system by a driver; memory might not actually be physically hotunpluggable. kexec *must not* indicate this memory to the second kernel and *must not* place kexec-images on this memory.
---
include/linux/memblock.h | 16 ++++++++++++++-- kernel/kexec_file.c | 5 +++++ mm/memblock.c | 4 ++++ 3 files changed, 23 insertions(+), 2 deletions(-)
include/linux/memblock.h renamed from include/linux/memblock.h~memblock-add-memblock_driver_managed-to-mimic-ioresource_sysram_driver_managed +14 -2
@@ -37,12 +37,17 @@ extern unsigned long long max_possible_p* @MEMBLOCK_NOMAP: don't add to kernel direct mapping and treat as * reserved in the memory map; refer to memblock_mark_nomap() description * for further details +* @MEMBLOCK_DRIVER_MANAGED: memory region that is always detected and added +* via a driver, and never indicated in the firmware-provided memory map as +* system RAM. This corresponds to IORESOURCE_SYSRAM_DRIVER_MANAGED in the +* kernel resource tree. */ enum memblock_flags {MEMBLOCK_NONE =0x0 ,/* No special request */ MEMBLOCK_HOTPLUG =0x1 ,/* hotpluggable region */ MEMBLOCK_MIRROR =0x2 ,/* mirrored region */ MEMBLOCK_NOMAP =0x4 ,/* don't add to kernel direct mapping */ +MEMBLOCK_DRIVER_MANAGED =0x8 ,/* always detected via a driver */ };/**
@@ -213,7 +218,8 @@ static inline void __next_physmem_range(*/ #define for_each_mem_range (i, p_start, p_end) \ __for_each_mem_range(i, &memblock.memory, NULL, NUMA_NO_NODE, \ - MEMBLOCK_HOTPLUG, p_start, p_end, NULL) + MEMBLOCK_HOTPLUG | MEMBLOCK_DRIVER_MANAGED, \ + p_start, p_end, NULL)/** * for_each_mem_range_rev - reverse iterate through memblock areas from
@@ -224,7 +230,8 @@ static inline void __next_physmem_range(*/ #define for_each_mem_range_rev (i, p_start, p_end) \ __for_each_mem_range_rev(i, &memblock.memory, NULL, NUMA_NO_NODE, \ - MEMBLOCK_HOTPLUG, p_start, p_end, NULL) + MEMBLOCK_HOTPLUG | MEMBLOCK_DRIVER_MANAGED,\ + p_start, p_end, NULL)/** * for_each_reserved_mem_range - iterate over all reserved memblock areas
@@ -254,6 +261,11 @@ static inline bool memblock_is_nomap(strreturn m->flags &MEMBLOCK_NOMAP ; } +static inline bool memblock_is_driver_managed (struct memblock_region *m) +{ +return m->flags &MEMBLOCK_DRIVER_MANAGED ; +} +int memblock_search_pfn_nid (unsigned long pfn,unsigned long *start_pfn,unsigned long *end_pfn); void __next_mem_pfn_range(int *idx, int nid, unsigned long *out_start_pfn,
kernel/kexec_file.c renamed from kernel/kexec_file.c~memblock-add-memblock_driver_managed-to-mimic-ioresource_sysram_driver_managed +5 -0
@@ -556,6 +556,11 @@ static int kexec_walk_memblock(struct keif (kbuf->image->type ==KEXEC_TYPE_CRASH )return func (&crashk_res, kbuf); +/* +* Using MEMBLOCK_NONE will properly skip MEMBLOCK_DRIVER_MANAGED. See +* IORESOURCE_SYSRAM_DRIVER_MANAGED handling in +* locate_mem_hole_callback(). +*/ if (kbuf->top_down) {for_each_free_mem_range_reverse (i,NUMA_NO_NODE ,MEMBLOCK_NONE , &mstart, &mend,NULL ) {
mm/memblock.c renamed from mm/memblock.c~memblock-add-memblock_driver_managed-to-mimic-ioresource_sysram_driver_managed +4 -0
@@ -982,6 +982,10 @@ static bool should_skip_region(struct meif (!(flags &MEMBLOCK_NOMAP ) &&memblock_is_nomap (m))return true; +/* skip driver-managed memory unless we were asked for it explicitly */ +if (!(flags &MEMBLOCK_DRIVER_MANAGED ) &&memblock_is_driver_managed (m)) +return true; +return false; }
_
Andrew Morton
maintainerPATCH 196/262 mm/memory_hotplug: indicate MEMBLOCK_DRIVER_MANAGED with IORESOURCE_SYSRAM_DRIVER_MANAGED
In reply to Andrew MortonFrom: David Hildenbrand <[email protected]>
Subject: mm/memory_hotplug: indicate MEMBLOCK_DRIVER_MANAGED with IORESOURCE_SYSRAM_DRIVER_MANAGED
Let's communicate driver-managed regions to memblock, to properly teach kexec_file with CONFIG_ARCH_KEEP_MEMBLOCK to not place images on these memory regions.
---
mm/memory_hotplug.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
mm/memory_hotplug.c renamed from mm/memory_hotplug.c~mm-memory_hotplug-indicate-memblock_driver_managed-with-ioresource_sysram_driver_managed +4 -1
@@ -1342,6 +1342,7 @@ bool mhp_supports_memmap_on_memory(unsigint __ref add_memory_resource (int nid,struct resource *res,mhp_t mhp_flags) {struct mhp_params params = { .pgprot =pgprot_mhp (PAGE_KERNEL ) }; +enum memblock_flags memblock_flags =MEMBLOCK_NONE ;struct vmem_altmap mhp_altmap = {};struct memory_group *group =NULL ;u64 start, size;
@@ -1370,7 +1371,9 @@ int __ref add_memory_resource(int nid, smem_hotplug_begin ();if (IS_ENABLED (CONFIG_ARCH_KEEP_MEMBLOCK )) { - ret =memblock_add_node (start, size, nid,MEMBLOCK_NONE ); +if (res->flags &IORESOURCE_SYSRAM_DRIVER_MANAGED ) + memblock_flags =MEMBLOCK_DRIVER_MANAGED ; + ret =memblock_add_node (start, size, nid, memblock_flags);if (ret) goto error_mem_hotplug_end; }
_
Andrew Morton
maintainerPATCH 197/262 mm/rmap.c: avoid double faults migrating device private pages
In reply to Andrew MortonFrom: Alistair Popple <[email protected]>
Subject: mm/rmap.c: avoid double faults migrating device private pages
During migration special page table entries are installed for each page being migrated. These entries store the pfn and associated permissions of ptes mapping the page being migarted.
Device-private pages use special swap pte entries to distinguish read-only vs. writeable pages which the migration code checks when creating migration entries. Normally this follows a fast path in migrate_vma_collect_pmd() which correctly copies the permissions of device-private pages over to migration entries when migrating pages back to the CPU.
However the slow-path falls back to using try_to_migrate() which unconditionally creates read-only migration entries for device-private pages. This leads to unnecessary double faults on the CPU as the new pages are always mapped read-only even when they could be mapped writeable. Fix this by correctly copying device-private permissions in try_to_migrate_one().
---
mm/rmap.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
mm/rmap.c renamed from mm/rmap.c~mm-rmapc-avoid-double-faults-migrating-device-private-pages +6 -2
@@ -1807,6 +1807,7 @@ static bool try_to_migrate_one(struct paupdate_hiwater_rss (mm);if (is_zone_device_page (page)) { +unsigned long pfn =page_to_pfn (page);swp_entry_t entry;pte_t swp_pte;
@@ -1815,8 +1816,11 @@ static bool try_to_migrate_one(struct pa* pte. do_swap_page() will wait until the migration * pte is removed and then restart fault handling. */ - entry =make_readable_migration_entry ( -page_to_pfn (page)); + entry =pte_to_swp_entry (pteval); +if (is_writable_device_private_entry (entry)) + entry =make_writable_migration_entry (pfn); +else + entry =make_readable_migration_entry (pfn); swp_pte =swp_entry_to_pte (entry);/*
_
Andrew Morton
maintainerPATCH 198/262 mm/zsmalloc.c: close race window between zs_pool_dec_isolated() and zs_unregister_migration()
In reply to Andrew MortonFrom: Miaohe Lin <[email protected]>
Subject: mm/zsmalloc.c: close race window between zs_pool_dec_isolated() and zs_unregister_migration()
There is one possible race window between zs_pool_dec_isolated() and zs_unregister_migration() because wait_for_isolated_drain() checks the isolated count without holding class->lock and there is no order inside zs_pool_dec_isolated(). Thus the below race window could be possible:
zs_pool_dec_isolated zs_unregister_migration
check pool->destroying != 0
pool->destroying = true; smp_mb(); wait_for_isolated_drain() wait for pool->isolated_pages == 0
atomic_long_dec(&pool->isolated_pages);
atomic_long_read(&pool->isolated_pages) == 0
Since we observe the pool->destroying (false) before atomic_long_dec() for pool->isolated_pages, waking pool->migration_wait up is missed.
Fix this by ensure checking pool->destroying happens after the atomic_long_dec(&pool->isolated_pages).
---
mm/zsmalloc.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
mm/zsmalloc.c renamed from mm/zsmalloc.c~mm-zsmallocc-close-race-window-between-zs_pool_dec_isolated-and-zs_unregister_migration +4 -3
@@ -1830,10 +1830,11 @@ static inline void zs_pool_dec_isolated(VM_BUG_ON (atomic_long_read (&pool->isolated_pages) <=0 );atomic_long_dec (&pool->isolated_pages);/* -* There's no possibility of racing, since wait_for_isolated_drain() -* checks the isolated count under &class->lock after enqueuing -* on migration_wait. +* Checking pool->destroying must happen after atomic_long_dec() +* for pool->isolated_pages above. Paired with the smp_mb() in +* zs_unregister_migration(). */ +smp_mb__after_atomic ();if (atomic_long_read (&pool->isolated_pages) ==0 && pool->destroying)wake_up_all (&pool->migration_wait); }
_
Andrew Morton
maintainerPATCH 199/262 mm/highmem: remove deprecated kmap_atomic
In reply to Andrew MortonFrom: Ira Weiny <[email protected]>
Subject: mm/highmem: remove deprecated kmap_atomic
kmap_atomic() is being deprecated in favor of kmap_local_page().
Replace the uses of kmap_atomic() within the highmem code.
On profiling clear_huge_page() using ftrace an improvement of 62% was observed on the below setup.
Setup:-
Below data has been collected on Qualcomm's SM7250 SoC THP enabled (kernel v4.19.113) with only CPU-0(Cortex-A55) and CPU-7(Cortex-A76) switched on and set to max frequency, also DDR set to perf governor.
FTRACE Data:-
Base data:-
Number of iterations: 48
Mean of allocation time: 349.5 us
std deviation: 74.5 us
v4 data:-
Number of iterations: 48
Mean of allocation time: 131 us
std deviation: 32.7 us
The following simple userspace experiment to allocate 100MB(BUF_SZ) of pages and writing to it gave us a good insight, we observed an improvement of 42% in allocation and writing timings.
-------------------------------------------------------------
Test code snippet
-------------------------------------------------------------
clock_start();
buf = malloc(BUF_SZ); /* Allocate 100 MB of memory */
for(i=0; i < BUF_SZ_PAGES; i++)
{
*((int *)(buf + (i*PAGE_SIZE))) = 1;
}
clock_end();-------------------------------------------------------------
Malloc test timings for 100MB anon allocation:-
Base data:-
Number of iterations: 100
Mean of allocation time: 31831 us
std deviation: 4286 us
v4 data:-
Number of iterations: 100
Mean of allocation time: 18193 us
std deviation: 4915 us
---
include/linux/highmem.h | 28 ++++++++++++++-------------- mm/highmem.c | 6 +++--- 2 files changed, 17 insertions(+), 17 deletions(-)
include/linux/highmem.h renamed from include/linux/highmem.h~mm-highmem-remove-deprecated-kmap_atomic +14 -14
@@ -143,9 +143,9 @@ static inline void invalidate_kernel_vma#ifndef clear_user_highpagestatic inline void clear_user_highpage (struct page *page,unsigned long vaddr) { -void *addr =kmap_atomic (page); +void *addr =kmap_local_page (page);clear_user_page (addr, vaddr, page); -kunmap_atomic (addr); +kunmap_local (addr); }#endif
@@ -177,9 +177,9 @@ alloc_zeroed_user_highpage_movable(strucstatic inline void clear_highpage (struct page *page) { -void *kaddr =kmap_atomic (page); +void *kaddr =kmap_local_page (page);clear_page (kaddr); -kunmap_atomic (kaddr); +kunmap_local (kaddr); }#ifndef __HAVE_ARCH_TAG_CLEAR_HIGHPAGE
@@ -202,7 +202,7 @@ static inline void zero_user_segments(st unsigned start1, unsigned end1, unsigned start2, unsigned end2) { - void *kaddr = kmap_atomic(page); + void *kaddr = kmap_local_page(page);unsigned int i;BUG_ON (end1 >page_size (page) || end2 >page_size (page));
@@ -213,7 +213,7 @@ static inline void zero_user_segments(stif (end2 > start2)memset (kaddr + start2,0 , end2 - start2); -kunmap_atomic (kaddr); +kunmap_local (kaddr);for (i =0 ; i <compound_nr (page); i++)flush_dcache_page (page + i); }
@@ -238,11 +238,11 @@ static inline void copy_user_highpage(st {char *vfrom, *vto; - vfrom =kmap_atomic (from); - vto =kmap_atomic (to); + vfrom =kmap_local_page (from); + vto =kmap_local_page (to);copy_user_page (vto, vfrom, vaddr, to); -kunmap_atomic (vto); -kunmap_atomic (vfrom); +kunmap_local (vto); +kunmap_local (vfrom); }#endif
@@ -253,11 +253,11 @@ static inline void copy_highpage(struct {char *vfrom, *vto; - vfrom =kmap_atomic (from); - vto =kmap_atomic (to); + vfrom =kmap_local_page (from); + vto =kmap_local_page (to);copy_page (vto, vfrom); -kunmap_atomic (vto); -kunmap_atomic (vfrom); +kunmap_local (vto); +kunmap_local (vfrom); }#endif
mm/highmem.c renamed from mm/highmem.c~mm-highmem-remove-deprecated-kmap_atomic +3 -3
@@ -383,7 +383,7 @@ void zero_user_segments(struct page *pagunsigned this_end =min_t (unsigned, end1,PAGE_SIZE );if (end1 > start1) { - kaddr =kmap_atomic (page + i); + kaddr =kmap_local_page (page + i);memset (kaddr + start1,0 , this_end - start1); } end1 -= this_end;
@@ -398,7 +398,7 @@ void zero_user_segments(struct page *pagif (end2 > start2) {if (!kaddr) - kaddr =kmap_atomic (page + i); + kaddr =kmap_local_page (page + i);memset (kaddr + start2,0 , this_end - start2); } end2 -= this_end;
@@ -406,7 +406,7 @@ void zero_user_segments(struct page *pag }if (kaddr) { -kunmap_atomic (kaddr); +kunmap_local (kaddr);flush_dcache_page (page + i); }
_
Andrew Morton
maintainerPATCH 200/262 zram_drv: allow reclaim on bio_alloc
In reply to Andrew MortonFrom: Jaewon Kim <[email protected]>
Subject: zram_drv: allow reclaim on bio_alloc
The read_from_bdev_async is not called on atomic context. So GFP_NOIO is available rather than GFP_ATOMIC. If there were reclaimable pages with GFP_NOIO, we can avoid allocation failure and page fault failure.
---
drivers/block/zram/zram_drv.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/block/zram/zram_drv.c renamed from drivers/block/zram/zram_drv.c~zram_drv-allow-reclaim-on-bio_alloc +1 -1
@@ -587,7 +587,7 @@ static int read_from_bdev_async(struct z {struct bio *bio; - bio =bio_alloc (GFP_ATOMIC ,1 ); + bio =bio_alloc (GFP_NOIO ,1 );if (!bio)return -ENOMEM ;
_
Andrew Morton
maintainerPATCH 201/262 zram: off by one in read_block_state()
In reply to Andrew MortonFrom: Dan Carpenter <[email protected]>
Subject: zram: off by one in read_block_state()
snprintf() returns the number of bytes it would have printed if there were space. But it does not count the NUL terminator. So that means that if "count == copied" then this has already overflowed by one character.
This bug likely isn't super harmful in real life.
---
drivers/block/zram/zram_drv.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/block/zram/zram_drv.c renamed from drivers/block/zram/zram_drv.c~zram-off-by-one-in-read_block_state +1 -1
@@ -910,7 +910,7 @@ static ssize_t read_block_state(struct fzram_test_flag (zram, index,ZRAM_HUGE ) ?'h' :'.' , zram_test_flag(zram, index, ZRAM_IDLE) ? 'i' : '.'); -if (count < copied) { +if (count <= copied) {zram_slot_unlock (zram, index);break ; }
_
Andrew Morton
maintainerPATCH 202/262 zram: introduce an aged idle interface
In reply to Andrew MortonFrom: Brian Geffon <[email protected]>
Subject: zram: introduce an aged idle interface
This change introduces an aged idle interface to the existing idle sysfs file for zram.
When CONFIG_ZRAM_MEMORY_TRACKING is enabled the idle file now also accepts an integer argument. This integer is the age (in seconds) of pages to mark as idle. The idle file still supports 'all' as it always has. This new approach allows for much more control over which pages get marked as idle.
---
Documentation/admin-guide/blockdev/zram.rst | 8 ++ drivers/block/zram/zram_drv.c | 62 +++++++++++++----- 2 files changed, 54 insertions(+), 16 deletions(-)
Documentation/admin-guide/blockdev/zram.rst renamed from Documentation/admin-guide/blockdev/zram.rst~zram-introduce-an-aged-idle-interface +8 -0
@@ -328,6 +328,14 @@ as idle:: From now on, any pages on zram are idle pages. The idle mark will be removed until someone requests access of the block. IOW, unless there is access request, those pages are still idle pages. +Additionally, when CONFIG_ZRAM_MEMORY_TRACKING is enabled pages can be +marked as idle based on how long (in seconds) it's been since they were +last accessed:: + + echo 86400 > /sys/block/zramX/idle + +In this example all pages which haven't been accessed in more than 86400 +seconds (one day) will be marked idle. Admin can request writeback of those idle pages at right timing via::
drivers/block/zram/zram_drv.c renamed from drivers/block/zram/zram_drv.c~zram-introduce-an-aged-idle-interface +46 -16
82 lines not on this page · raw message
_
Andrew Morton
maintainerPATCH 203/262 mm: remove HARDENED_USERCOPY_FALLBACK
In reply to Andrew MortonFrom: Stephen Kitt <[email protected]>
Subject: mm: remove HARDENED_USERCOPY_FALLBACK
This has served its purpose and is no longer used. All usercopy violations appear to have been handled by now, any remaining instances (or new bugs) will cause copies to be rejected.
This isn't a direct revert of commit 2d891fbc3bb6 ("usercopy: Allow strict enforcement of whitelists"); since usercopy_fallback is effectively 0, the fallback handling is removed too.
This also removes the usercopy_fallback module parameter on slab_common.
---
arch/powerpc/configs/skiroot_defconfig | 1 - include/linux/slab.h | 2 -- mm/slab.c | 13 ------------- mm/slab_common.c | 8 -------- mm/slub.c | 14 -------------- security/Kconfig | 14 -------------- 6 files changed, 52 deletions(-)
arch/powerpc/configs/skiroot_defconfig renamed from arch/powerpc/configs/skiroot_defconfig~mm-remove-hardened_usercopy_fallback +0 -1
@@ -275,7 +275,6 @@ CONFIG_NLS_UTF8=y CONFIG_ENCRYPTED_KEYS=y CONFIG_SECURITY=y CONFIG_HARDENED_USERCOPY=y -# CONFIG_HARDENED_USERCOPY_FALLBACK is not set CONFIG_HARDENED_USERCOPY_PAGESPAN=y CONFIG_FORTIFY_SOURCE=y CONFIG_SECURITY_LOCKDOWN_LSM=y
include/linux/slab.h renamed from include/linux/slab.h~mm-remove-hardened_usercopy_fallback +0 -2
@@ -142,8 +142,6 @@ struct mem_cgroup;void __init kmem_cache_init (void );bool slab_is_available (void ); -extern bool usercopy_fallback; -struct kmem_cache *kmem_cache_create (const char *name,unsigned int size,unsigned int align,slab_flags_t flags,void (*ctor)(void *));
mm/slab.c renamed from mm/slab.c~mm-remove-hardened_usercopy_fallback +0 -13
@@ -4204,19 +4204,6 @@ void __check_heap_object(const void *ptr n <= cachep->useroffset - offset + cachep->usersize) return; -/* -* If the copy is still within the allocated object, produce -* a warning instead of rejecting the copy. This is intended -* to be a temporary method to find any missing usercopy -* whitelists. -*/ -if (usercopy_fallback && - offset <= cachep->object_size && - n <= cachep->object_size - offset) { -usercopy_warn ("SLAB object" , cachep->name, to_user, offset, n); -return ; - } - usercopy_abort("SLAB object", cachep->name, to_user, offset, n); }#endif /* CONFIG_HARDENED_USERCOPY */
mm/slab_common.c renamed from mm/slab_common.c~mm-remove-hardened_usercopy_fallback +0 -8
@@ -37,14 +37,6 @@ LIST_HEAD(slab_caches);DEFINE_MUTEX (slab_mutex);struct kmem_cache *kmem_cache; -#ifdef CONFIG_HARDENED_USERCOPY -bool usercopy_fallback__ro_after_init = -IS_ENABLED (CONFIG_HARDENED_USERCOPY_FALLBACK ); -module_param (usercopy_fallback, bool,0400 ); -MODULE_PARM_DESC (usercopy_fallback, -"WARN instead of reject usercopy whitelist violations" ); -#endif -static LIST_HEAD (slab_caches_to_rcu_destroy);static void slab_caches_to_rcu_destroy_workfn (struct work_struct *work); static DECLARE_WORK(slab_caches_to_rcu_destroy_work,
mm/slub.c renamed from mm/slub.c~mm-remove-hardened_usercopy_fallback +0 -14
@@ -4489,7 +4489,6 @@ void __check_heap_object(const void *ptr {struct kmem_cache *s;unsigned int offset; -size_t object_size;bool is_kfence =is_kfence_address (ptr); ptr =kasan_reset_tag (ptr);
@@ -4522,19 +4521,6 @@ void __check_heap_object(const void *ptr n <= s->useroffset - offset + s->usersize) return; -/* -* If the copy is still within the allocated object, produce -* a warning instead of rejecting the copy. This is intended -* to be a temporary method to find any missing usercopy -* whitelists. -*/ - object_size =slab_ksize (s); -if (usercopy_fallback && - offset <= object_size && n <= object_size - offset) { -usercopy_warn ("SLUB object" , s->name, to_user, offset, n); -return ; - } - usercopy_abort("SLUB object", s->name, to_user, offset, n); }#endif /* CONFIG_HARDENED_USERCOPY */
security/Kconfig renamed from security/Kconfig~mm-remove-hardened_usercopy_fallback +0 -14
@@ -163,20 +163,6 @@ config HARDENED_USERCOPY or are part of the kernel text. This kills entire classes of heap overflow exploits and similar kernel memory exposures. -config HARDENED_USERCOPY_FALLBACK - bool "Allow usercopy whitelist violations to fallback to object size" - depends on HARDENED_USERCOPY - default y - help - This is a temporary option that allows missing usercopy whitelists - to be discovered via a WARN() to the kernel log, instead of - rejecting the copy, falling back to non-whitelisted hardened - usercopy that checks the slab allocation size instead of the - whitelist size. This option will be removed once it seems like - all missing usercopy whitelists have been identified and fixed. - Booting with "slab_common.usercopy_fallback=Y/N" can change - this setting. - config HARDENED_USERCOPY_PAGESPAN bool "Refuse to copy allocations that span multiple pages" depends on HARDENED_USERCOPY
_
Andrew Morton
maintainerPATCH 204/262 include/linux/mm.h: move nr_free_buffer_pages from swap.h to mm.h
In reply to Andrew MortonFrom: Mianhan Liu <[email protected]>
Subject: include/linux/mm.h: move nr_free_buffer_pages from swap.h to mm.h
nr_free_buffer_pages could be exposed through mm.h instead of swap.h. The advantage of this change is that it can reduce the obsolete includes. For example, net/ipv4/tcp.c wouldn't need swap.h any more since it has already included mm.h. Similarly, after checking all the other files, it comes that tcp.c, udp.c meter.c ,... follow the same rule, so these files can have swap.h removed too.
Moreover, after preprocessing all the files that use nr_free_buffer_pages, it turns out that those files have already included mm.h.Thus, we can move nr_free_buffer_pages from swap.h to mm.h safely. This change will not affect the compilation of other files.
---
drivers/mmc/core/mmc_test.c | 1 - include/linux/mm.h | 2 ++ include/linux/swap.h | 1 - net/ipv4/tcp.c | 1 - net/ipv4/udp.c | 1 - net/netfilter/ipvs/ip_vs_ctl.c | 1 - net/openvswitch/meter.c | 1 - net/sctp/protocol.c | 1 - 8 files changed, 2 insertions(+), 7 deletions(-)
drivers/mmc/core/mmc_test.c renamed from drivers/mmc/core/mmc_test.c~include-linux-mmh-move-nr_free_buffer_pages-from-swaph-to-mmh +0 -1
@@ -10,7 +10,6 @@#include <linux/slab.h> #include <linux/scatterlist.h> -#include <linux/swap.h> /* For nr_free_buffer_pages() */ #include <linux/list.h> #include <linux/debugfs.h>
include/linux/mm.h renamed from include/linux/mm.h~include-linux-mmh-move-nr_free_buffer_pages-from-swaph-to-mmh +2 -0
@@ -875,6 +875,8 @@ void put_pages_list(struct list_head *pavoid split_page (struct page *page,unsigned int order);void copy_huge_page (struct page *dst,struct page *src); +unsigned long nr_free_buffer_pages (void ); +/* * Compound pages have a destructor function. Provide a * prototype for that function and accessor functions.
include/linux/swap.h renamed from include/linux/swap.h~include-linux-mmh-move-nr_free_buffer_pages-from-swaph-to-mmh +0 -1
@@ -335,7 +335,6 @@ void workingset_update_node(struct xa_no/* linux/mm/page_alloc.c */ extern unsigned long totalreserve_pages; -extern unsigned long nr_free_buffer_pages (void );/* Definition of global_zone_page_state not available yet */ #define nr_free_pages () global_zone_page_state(NR_FREE_PAGES)
net/ipv4/tcp.c renamed from net/ipv4/tcp.c~include-linux-mmh-move-nr_free_buffer_pages-from-swaph-to-mmh +0 -1
@@ -260,7 +260,6 @@#include <linux/random.h> #include <linux/memblock.h> #include <linux/highmem.h> -#include <linux/swap.h> #include <linux/cache.h> #include <linux/err.h> #include <linux/time.h>
net/ipv4/udp.c renamed from net/ipv4/udp.c~include-linux-mmh-move-nr_free_buffer_pages-from-swaph-to-mmh +0 -1
@@ -78,7 +78,6 @@#include <asm/ioctls.h> #include <linux/memblock.h> #include <linux/highmem.h> -#include <linux/swap.h> #include <linux/types.h> #include <linux/fcntl.h> #include <linux/module.h>
net/netfilter/ipvs/ip_vs_ctl.c renamed from net/netfilter/ipvs/ip_vs_ctl.c~include-linux-mmh-move-nr_free_buffer_pages-from-swaph-to-mmh +0 -1
@@ -24,7 +24,6 @@#include <linux/sysctl.h> #include <linux/proc_fs.h> #include <linux/workqueue.h> -#include <linux/swap.h> #include <linux/seq_file.h> #include <linux/slab.h>
net/openvswitch/meter.c renamed from net/openvswitch/meter.c~include-linux-mmh-move-nr_free_buffer_pages-from-swaph-to-mmh +0 -1
@@ -12,7 +12,6 @@#include <linux/openvswitch.h> #include <linux/netlink.h> #include <linux/rculist.h> -#include <linux/swap.h> #include <net/netlink.h> #include <net/genetlink.h>
net/sctp/protocol.c renamed from net/sctp/protocol.c~include-linux-mmh-move-nr_free_buffer_pages-from-swaph-to-mmh +0 -1
@@ -33,7 +33,6 @@#include <linux/seq_file.h> #include <linux/memblock.h> #include <linux/highmem.h> -#include <linux/swap.h> #include <linux/slab.h> #include <net/net_namespace.h> #include <net/protocol.h>
_
Andrew Morton
maintainerPATCH 205/262 stacktrace: move filter_irq_stacks() to kernel/stacktrace.c
In reply to Andrew MortonFrom: Marco Elver <[email protected]>
Subject: stacktrace: move filter_irq_stacks() to kernel/stacktrace.c
filter_irq_stacks() has little to do with the stackdepot implementation, except that it is usually used by users (such as KASAN) of stackdepot to reduce the stack trace.
However, filter_irq_stacks() itself is not useful without a stack trace as obtained by stack_trace_save() and friends.
Therefore, move filter_irq_stacks() to kernel/stacktrace.c, so that new users of filter_irq_stacks() do not have to start depending on STACKDEPOT only for filter_irq_stacks().
---
include/linux/stackdepot.h | 2 -- include/linux/stacktrace.h | 1 + kernel/stacktrace.c | 30 ++++++++++++++++++++++++++++++ lib/stackdepot.c | 24 ------------------------ 4 files changed, 31 insertions(+), 26 deletions(-)
include/linux/stackdepot.h renamed from include/linux/stackdepot.h~stacktrace-move-filter_irq_stacks-to-kernel-stacktracec +0 -2
@@ -25,8 +25,6 @@ depot_stack_handle_t stack_depot_save(ununsigned int stack_depot_fetch (depot_stack_handle_t handle,unsigned long **entries); -unsigned int filter_irq_stacks (unsigned long *entries,unsigned int nr_entries); -#ifdef CONFIG_STACKDEPOT int stack_depot_init (void );#else
include/linux/stacktrace.h renamed from include/linux/stacktrace.h~stacktrace-move-filter_irq_stacks-to-kernel-stacktracec +1 -0
@@ -21,6 +21,7 @@ unsigned int stack_trace_save_tsk(structunsigned int stack_trace_save_regs (struct pt_regs *regs,unsigned long *store,unsigned int size,unsigned int skipnr);unsigned int stack_trace_save_user (unsigned long *store,unsigned int size); +unsigned int filter_irq_stacks (unsigned long *entries,unsigned int nr_entries);/* Internal interfaces. Do not use in generic code */ #ifdef CONFIG_ARCH_STACKWALK
kernel/stacktrace.c renamed from kernel/stacktrace.c~stacktrace-move-filter_irq_stacks-to-kernel-stacktracec +30 -0
@@ -13,6 +13,7 @@#include <linux/export.h> #include <linux/kallsyms.h> #include <linux/stacktrace.h> +#include <linux/interrupt.h> /** * stack_trace_print - Print the entries in the stack trace
@@ -373,3 +374,32 @@ unsigned int stack_trace_save_user(unsig#endif /* CONFIG_USER_STACKTRACE_SUPPORT */ #endif /* !CONFIG_ARCH_STACKWALK */ + +static inline bool in_irqentry_text (unsigned long ptr) +{ +return (ptr >= (unsigned long )&__irqentry_text_start && + ptr < (unsigned long )&__irqentry_text_end) || + (ptr >= (unsigned long )&__softirqentry_text_start && + ptr < (unsigned long )&__softirqentry_text_end); +} + +/** +* filter_irq_stacks - Find first IRQ stack entry in trace +* @entries: Pointer to stack trace array +* @nr_entries: Number of entries in the storage array +* +* Return: Number of trace entries until IRQ stack starts. +*/ +unsigned int filter_irq_stacks (unsigned long *entries,unsigned int nr_entries) +{ +unsigned int i; + +for (i =0 ; i < nr_entries; i++) { +if (in_irqentry_text (entries[i])) { +/* Include the irqentry function into the stack. */ +return i +1 ; + } + } +return nr_entries; +} +EXPORT_SYMBOL_GPL (filter_irq_stacks);
lib/stackdepot.c renamed from lib/stackdepot.c~stacktrace-move-filter_irq_stacks-to-kernel-stacktracec +0 -24
@@ -20,7 +20,6 @@*/ #include <linux/gfp.h> -#include <linux/interrupt.h> #include <linux/jhash.h> #include <linux/kernel.h> #include <linux/mm.h>
@@ -371,26 +370,3 @@ depot_stack_handle_t stack_depot_save(unreturn __stack_depot_save (entries, nr_entries, alloc_flags, true); }EXPORT_SYMBOL_GPL (stack_depot_save); - -static inline int in_irqentry_text (unsigned long ptr) -{ -return (ptr >= (unsigned long )&__irqentry_text_start && - ptr < (unsigned long )&__irqentry_text_end) || - (ptr >= (unsigned long )&__softirqentry_text_start && - ptr < (unsigned long )&__softirqentry_text_end); -} - -unsigned int filter_irq_stacks (unsigned long *entries, -unsigned int nr_entries) -{ -unsigned int i; - -for (i =0 ; i < nr_entries; i++) { -if (in_irqentry_text (entries[i])) { -/* Include the irqentry function into the stack. */ -return i +1 ; - } - } -return nr_entries; -} -EXPORT_SYMBOL_GPL (filter_irq_stacks);
_
Andrew Morton
maintainerPATCH 206/262 kfence: count unexpectedly skipped allocations
In reply to Andrew MortonFrom: Marco Elver <[email protected]>
Subject: kfence: count unexpectedly skipped allocations
Maintain a counter to count allocations that are skipped due to being incompatible (oversized, incompatible gfp flags) or no capacity.
This is to compute the fraction of allocations that could not be serviced by KFENCE, which we expect to be rare.
---
mm/kfence/core.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-)
mm/kfence/core.c renamed from mm/kfence/core.c~kfence-count-unexpectedly-skipped-allocations +13 -3
@@ -112,6 +112,8 @@ enum kfence_counter_id {KFENCE_COUNTER_FREES ,KFENCE_COUNTER_ZOMBIES ,KFENCE_COUNTER_BUGS , +KFENCE_COUNTER_SKIP_INCOMPAT , +KFENCE_COUNTER_SKIP_CAPACITY , KFENCE_COUNTER_COUNT, };static atomic_long_t counters[KFENCE_COUNTER_COUNT ];
@@ -121,6 +123,8 @@ static const char *const counter_names[] [KFENCE_COUNTER_FREES] = "total frees", [KFENCE_COUNTER_ZOMBIES] = "zombie allocations", [KFENCE_COUNTER_BUGS] = "total bugs", + [KFENCE_COUNTER_SKIP_INCOMPAT] = "skipped allocations (incompatible)", + [KFENCE_COUNTER_SKIP_CAPACITY ] ="skipped allocations (capacity)" , };static_assert (ARRAY_SIZE (counter_names) ==KFENCE_COUNTER_COUNT );
@@ -271,8 +275,10 @@ static void *kfence_guarded_alloc(structlist_del_init (&meta->list); }raw_spin_unlock_irqrestore (&kfence_freelist_lock, flags); -if (!meta) +if (!meta) { +atomic_long_inc (&counters[KFENCE_COUNTER_SKIP_CAPACITY ]);return NULL ; + }if (unlikely (!raw_spin_trylock_irqsave (&meta->lock, flags))) {/*
@@ -740,8 +746,10 @@ void *__kfence_alloc(struct kmem_cache ** Perform size check before switching kfence_allocation_gate, so that * we don't disable KFENCE without making an allocation. */ -if (size >PAGE_SIZE ) +if (size >PAGE_SIZE ) { +atomic_long_inc (&counters[KFENCE_COUNTER_SKIP_INCOMPAT ]);return NULL ; + }/* * Skip allocations from non-default zones, including DMA. We cannot
@@ -749,8 +757,10 @@ void *__kfence_alloc(struct kmem_cache ** properties (e.g. reside in DMAable memory). */ if ((flags &GFP_ZONEMASK ) || - (s->flags & (SLAB_CACHE_DMA |SLAB_CACHE_DMA32 ))) + (s->flags & (SLAB_CACHE_DMA |SLAB_CACHE_DMA32 ))) { +atomic_long_inc (&counters[KFENCE_COUNTER_SKIP_INCOMPAT ]);return NULL ; + }/* * allocation_gate only needs to become non-zero, so it doesn't make
_
Andrew Morton
maintainerPATCH 207/262 kfence: move saving stack trace of allocations into __kfence_alloc()
In reply to Andrew MortonFrom: Marco Elver <[email protected]>
Subject: kfence: move saving stack trace of allocations into __kfence_alloc()
Move the saving of the stack trace of allocations into __kfence_alloc(), so that the stack entries array can be used outside of kfence_guarded_alloc() and we avoid potentially unwinding the stack multiple times.
---
mm/kfence/core.c | 35 ++++++++++++++++++++++++----------- 1 file changed, 24 insertions(+), 11 deletions(-)
mm/kfence/core.c renamed from mm/kfence/core.c~kfence-move-saving-stack-trace-of-allocations-into-__kfence_alloc +24 -11
@@ -187,19 +187,26 @@ static inline unsigned long metadata_to_* Update the object's metadata state, including updating the alloc/free stacks * depending on the state transition. */ -static noinline void metadata_update_state(struct kfence_metadata *meta, -enum kfence_object_state next) +static noinline void +metadata_update_state (struct kfence_metadata *meta,enum kfence_object_state next, +unsigned long *stack_entries,size_t num_stack_entries) {struct kfence_track *track = next ==KFENCE_OBJECT_FREED ? &meta->free_track : &meta->alloc_track;lockdep_assert_held (&meta->lock); -/* -* Skip over 1 (this) functions; noinline ensures we do not accidentally -* skip over the caller by never inlining. -*/ - track->num_stack_entries =stack_trace_save (track->stack_entries,KFENCE_STACK_DEPTH ,1 ); +if (stack_entries) { +memcpy (track->stack_entries, stack_entries, + num_stack_entries *sizeof (stack_entries[0 ])); + }else { +/* +* Skip over 1 (this) functions; noinline ensures we do not +* accidentally skip over the caller by never inlining. +*/ + num_stack_entries =stack_trace_save (track->stack_entries,KFENCE_STACK_DEPTH ,1 ); + } + track->num_stack_entries = num_stack_entries; track->pid =task_pid_nr (current); track->cpu =raw_smp_processor_id (); track->ts_nsec =local_clock ();/* Same source as printk timestamps. */
@@ -261,7 +268,8 @@ static __always_inline void for_each_can } } -static void *kfence_guarded_alloc (struct kmem_cache *cache,size_t size,gfp_t gfp) +static void *kfence_guarded_alloc (struct kmem_cache *cache,size_t size,gfp_t gfp, +unsigned long *stack_entries,size_t num_stack_entries) {struct kfence_metadata *meta =NULL ;unsigned long flags;
@@ -320,7 +328,7 @@ static void *kfence_guarded_alloc(struct addr = (void *)meta->addr;/* Update remaining metadata. */ -metadata_update_state (meta,KFENCE_OBJECT_ALLOCATED ); +metadata_update_state (meta,KFENCE_OBJECT_ALLOCATED , stack_entries, num_stack_entries);/* Pairs with READ_ONCE() in kfence_shutdown_cache(). */ WRITE_ONCE (meta->cache, cache); meta->size = size;
@@ -400,7 +408,7 @@ static void kfence_guarded_free(void *admemzero_explicit (addr, meta->size);/* Mark the object as freed. */ -metadata_update_state (meta,KFENCE_OBJECT_FREED ); +metadata_update_state (meta,KFENCE_OBJECT_FREED ,NULL ,0 );raw_spin_unlock_irqrestore (&meta->lock, flags);
@@ -742,6 +750,9 @@ void kfence_shutdown_cache(struct kmem_cvoid *__kfence_alloc (struct kmem_cache *s,size_t size,gfp_t flags) { +unsigned long stack_entries[KFENCE_STACK_DEPTH ]; +size_t num_stack_entries; +/* * Perform size check before switching kfence_allocation_gate, so that * we don't disable KFENCE without making an allocation.
@@ -786,7 +797,9 @@ void *__kfence_alloc(struct kmem_cache *if (!READ_ONCE (kfence_enabled))return NULL ; -return kfence_guarded_alloc (s, size, flags); + num_stack_entries =stack_trace_save (stack_entries,KFENCE_STACK_DEPTH ,0 ); + +return kfence_guarded_alloc (s, size, flags, stack_entries, num_stack_entries); }size_t kfence_ksize (const void *addr)
_
Andrew Morton
maintainerPATCH 208/262 kfence: limit currently covered allocations when pool nearly full
In reply to Andrew MortonFrom: Marco Elver <[email protected]>
Subject: kfence: limit currently covered allocations when pool nearly full
One of KFENCE's main design principles is that with increasing uptime, allocation coverage increases sufficiently to detect previously undetected bugs.
We have observed that frequent long-lived allocations of the same source (e.g. pagecache) tend to permanently fill up the KFENCE pool with increasing system uptime, thus breaking the above requirement. The workaround thus far had been increasing the sample interval and/or increasing the KFENCE pool size, but is no reliable solution.
To ensure diverse coverage of allocations, limit currently covered allocations of the same source once pool utilization reaches 75% (configurable via kfence.skip_covered_thresh) or above. The effect is retaining reasonable allocation coverage when the pool is close to full.
A side-effect is that this also limits frequent long-lived allocations of the same source filling up the pool permanently.
Uniqueness of an allocation for coverage purposes is based on its (partial) allocation stack trace (the source). A Counting Bloom filter is used to check if an allocation is covered; if the allocation is currently covered, the allocation is skipped by KFENCE.
Testing was done using:
(a) a synthetic workload that performs frequent long-lived allocations (default config values; sample_interval=1; num_objects=63), and
(b) normal desktop workloads on an otherwise idle machine where the problem was first reported after a few days of uptime (default config values).
In both test cases the sampled allocation rate no longer drops to zero at any point. In the case of (b) we observe (after 2 days uptime) 15% unique allocations in the pool, 77% pool utilization, with 20% "skipped allocations (covered)".
---
mm/kfence/core.c | 109 ++++++++++++++++++++++++++++++++++++++++++- mm/kfence/kfence.h | 2 2 files changed, 109 insertions(+), 2 deletions(-)
mm/kfence/core.c renamed from mm/kfence/core.c~kfence-limit-currently-covered-allocations-when-pool-nearly-full +107 -2
@@ -10,12 +10,15 @@#include <linux/atomic.h> #include <linux/bug.h> #include <linux/debugfs.h> +#include <linux/hash.h> #include <linux/irq_work.h> +#include <linux/jhash.h> #include <linux/kcsan-checks.h> #include <linux/kfence.h> #include <linux/kmemleak.h> #include <linux/list.h> #include <linux/lockdep.h> +#include <linux/log2.h> #include <linux/memblock.h> #include <linux/moduleparam.h> #include <linux/random.h>
@@ -82,6 +85,10 @@ static const struct kernel_param_ops sam };module_param_cb (sample_interval, &sample_interval_param_ops, &kfence_sample_interval,0600 ); +/* Pool usage% threshold when currently covered allocations are skipped. */ +static unsigned long kfence_skip_covered_thresh__read_mostly =75 ; +module_param_named (skip_covered_thresh, kfence_skip_covered_thresh, ulong,0644 ); +/* The pool of pages used for guard pages and objects. */ char *__kfence_pool__ro_after_init ;EXPORT_SYMBOL (__kfence_pool);/* Export for test modules. */
@@ -105,6 +112,32 @@ DEFINE_STATIC_KEY_FALSE(kfence_allocatio/* Gates the allocation, ensuring only one succeeds in a given period. */ atomic_t kfence_allocation_gate =ATOMIC_INIT (1 ); +/* +* A Counting Bloom filter of allocation coverage: limits currently covered +* allocations of the same source filling up the pool. +* +* Assuming a range of 15%-85% unique allocations in the pool at any point in +* time, the below parameters provide a probablity of 0.02-0.33 for false +* positive hits respectively: +* +* P(alloc_traces) = (1 - e^(-HNUM * (alloc_traces / SIZE)) ^ HNUM +*/ +#define ALLOC_COVERED_HNUM 2 +#define ALLOC_COVERED_ORDER (const_ilog2(CONFIG_KFENCE_NUM_OBJECTS) + 2) +#define ALLOC_COVERED_SIZE (1 << ALLOC_COVERED_ORDER) +#define ALLOC_COVERED_HNEXT (h) hash_32(h, ALLOC_COVERED_ORDER) +#define ALLOC_COVERED_MASK (ALLOC_COVERED_SIZE - 1) +static atomic_t alloc_covered[ALLOC_COVERED_SIZE ]; + +/* Stack depth used to determine uniqueness of an allocation. */ +#define UNIQUE_ALLOC_STACK_DEPTH ((size_t)8) + +/* +* Randomness for stack hashes, making the same collisions across reboots and +* different machines less likely. +*/ +static u32 stack_hash_seed__ro_after_init ; +/* Statistics counters for debugfs. */ enum kfence_counter_id {KFENCE_COUNTER_ALLOCATED ,
@@ -114,6 +147,7 @@ enum kfence_counter_id {KFENCE_COUNTER_BUGS ,KFENCE_COUNTER_SKIP_INCOMPAT ,KFENCE_COUNTER_SKIP_CAPACITY , +KFENCE_COUNTER_SKIP_COVERED , KFENCE_COUNTER_COUNT, };static atomic_long_t counters[KFENCE_COUNTER_COUNT ];
@@ -125,11 +159,57 @@ static const char *const counter_names[] [KFENCE_COUNTER_BUGS] = "total bugs", [KFENCE_COUNTER_SKIP_INCOMPAT] = "skipped allocations (incompatible)", [KFENCE_COUNTER_SKIP_CAPACITY] = "skipped allocations (capacity)", + [KFENCE_COUNTER_SKIP_COVERED ] ="skipped allocations (covered)" , };static_assert (ARRAY_SIZE (counter_names) ==KFENCE_COUNTER_COUNT );/* === Internals ============================================================ */ +static inline bool should_skip_covered (void ) +{ +unsigned long thresh = (CONFIG_KFENCE_NUM_OBJECTS * kfence_skip_covered_thresh) /100 ; + +return atomic_long_read (&counters[KFENCE_COUNTER_ALLOCATED ]) > thresh; +} + +static u32 get_alloc_stack_hash (unsigned long *stack_entries,size_t num_entries) +{ + num_entries =min (num_entries,UNIQUE_ALLOC_STACK_DEPTH ); + num_entries =filter_irq_stacks (stack_entries, num_entries); +return jhash (stack_entries, num_entries *sizeof (stack_entries[0 ]), stack_hash_seed); +} + +/* +* Adds (or subtracts) count @val for allocation stack trace hash +* @alloc_stack_hash from Counting Bloom filter. +*/ +static void alloc_covered_add (u32 alloc_stack_hash,int val) +{ +int i; + +for (i =0 ; i <ALLOC_COVERED_HNUM ; i++) { +atomic_add (val, &alloc_covered[alloc_stack_hash &ALLOC_COVERED_MASK ]); + alloc_stack_hash =ALLOC_COVERED_HNEXT (alloc_stack_hash); + } +} + +/* +* Returns true if the allocation stack trace hash @alloc_stack_hash is +* currently contained (non-zero count) in Counting Bloom filter. +*/ +static bool alloc_covered_contains (u32 alloc_stack_hash) +{ +int i; + +for (i =0 ; i <ALLOC_COVERED_HNUM ; i++) { +if (!atomic_read (&alloc_covered[alloc_stack_hash &ALLOC_COVERED_MASK ])) +return false; + alloc_stack_hash =ALLOC_COVERED_HNEXT (alloc_stack_hash); + } + +return true; +} +static bool kfence_protect (unsigned long addr) {return !KFENCE_WARN_ON (!kfence_protect_page (ALIGN_DOWN (addr,PAGE_SIZE ), true));
@@ -269,7 +349,8 @@ static __always_inline void for_each_can }static void *kfence_guarded_alloc (struct kmem_cache *cache,size_t size,gfp_t gfp, -unsigned long *stack_entries,size_t num_stack_entries) +unsigned long *stack_entries,size_t num_stack_entries, +u32 alloc_stack_hash) {struct kfence_metadata *meta =NULL ;unsigned long flags;
@@ -332,6 +413,8 @@ static void *kfence_guarded_alloc(struct/* Pairs with READ_ONCE() in kfence_shutdown_cache(). */ WRITE_ONCE (meta->cache, cache); meta->size = size; + meta->alloc_stack_hash = alloc_stack_hash; +for_each_canary (meta, set_canary_byte);/* Set required struct page fields. */
@@ -344,6 +427,8 @@ static void *kfence_guarded_alloc(structraw_spin_unlock_irqrestore (&meta->lock, flags); +alloc_covered_add (alloc_stack_hash,1 ); +/* Memory initialization. */ /*
@@ -412,6 +497,8 @@ static void kfence_guarded_free(void *adraw_spin_unlock_irqrestore (&meta->lock, flags); +alloc_covered_add (meta->alloc_stack_hash,-1 ); +/* Protect to detect use-after-frees. */ kfence_protect ((unsigned long )addr);
@@ -677,6 +764,7 @@ void __init kfence_init(void)if (!kfence_sample_interval)return ; + stack_hash_seed = (u32 )random_get_entropy ();if (!kfence_init_pool ()) {pr_err ("%s failed\n" , __func__);return ;
@@ -752,6 +840,7 @@ void *__kfence_alloc(struct kmem_cache * {unsigned long stack_entries[KFENCE_STACK_DEPTH ];size_t num_stack_entries; +u32 alloc_stack_hash;/* * Perform size check before switching kfence_allocation_gate, so that
@@ -799,7 +888,23 @@ void *__kfence_alloc(struct kmem_cache * num_stack_entries =stack_trace_save (stack_entries,KFENCE_STACK_DEPTH ,0 ); -return kfence_guarded_alloc (s, size, flags, stack_entries, num_stack_entries); +/* +* Do expensive check for coverage of allocation in slow-path after +* allocation_gate has already become non-zero, even though it might +* mean not making any allocation within a given sample interval. +* +* This ensures reasonable allocation coverage when the pool is almost +* full, including avoiding long-lived allocations of the same source +* filling up the pool (e.g. pagecache allocations). +*/ + alloc_stack_hash =get_alloc_stack_hash (stack_entries, num_stack_entries); +if (should_skip_covered () &&alloc_covered_contains (alloc_stack_hash)) { +atomic_long_inc (&counters[KFENCE_COUNTER_SKIP_COVERED ]); +return NULL ; + } + +return kfence_guarded_alloc (s, size, flags, stack_entries, num_stack_entries, + alloc_stack_hash); }size_t kfence_ksize (const void *addr)
mm/kfence/kfence.h renamed from mm/kfence/kfence.h~kfence-limit-currently-covered-allocations-when-pool-nearly-full +2 -0
@@ -87,6 +87,8 @@ struct kfence_metadata {/* Allocation and free stack information. */ struct kfence_track alloc_track;struct kfence_track free_track; +/* For updating alloc_covered on frees. */ +u32 alloc_stack_hash; };extern struct kfence_metadata kfence_metadata[CONFIG_KFENCE_NUM_OBJECTS ];
_
Andrew Morton
maintainerPATCH 209/262 kfence: add note to documentation about skipping covered allocations
In reply to Andrew MortonFrom: Marco Elver <[email protected]>
Subject: kfence: add note to documentation about skipping covered allocations
Add a note briefly mentioning the new policy about "skipping currently covered allocations if pool close to full." Since this has a notable impact on KFENCE's bug-detection ability on systems with large uptimes, it is worth pointing out the feature.
---
Documentation/dev-tools/kfence.rst | 11 +++++++++++ 1 file changed, 11 insertions(+)
Documentation/dev-tools/kfence.rst renamed from Documentation/dev-tools/kfence.rst~kfence-add-note-to-documentation-about-skipping-covered-allocations +11 -0
@@ -269,6 +269,17 @@ tail of KFENCE's freelist, so that the l first, and the chances of detecting use-after-frees of recently freed objects is increased. +If pool utilization reaches 75% (default) or above, to reduce the risk of the +pool eventually being fully occupied by allocated objects yet ensure diverse +coverage of allocations, KFENCE limits currently covered allocations of the +same source from further filling up the pool. The "source" of an allocation is +based on its partial allocation stack trace. A side-effect is that this also +limits frequent long-lived allocations (e.g. pagecache) of the same source +filling up the pool permanently, which is the most common risk for the pool +becoming full and the sampled allocation rate dropping to zero. The threshold +at which to start limiting currently covered allocations can be configured via +the boot parameter ``kfence.skip_covered_thresh`` (pool usage%). + Interface ---------
_
Andrew Morton
maintainerPATCH 210/262 kfence: test: use kunit_skip() to skip tests
In reply to Andrew MortonFrom: Marco Elver <[email protected]>
Subject: kfence: test: use kunit_skip() to skip tests
Use the new kunit_skip() to skip tests if requirements were not met. It makes it easier to see in KUnit's summary if there were skipped tests.
---
mm/kfence/kfence_test.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-)
mm/kfence/kfence_test.c renamed from mm/kfence/kfence_test.c~kfence-test-use-kunit_skip-to-skip-tests +8 -6
@@ -32,6 +32,11 @@#define arch_kfence_test_address (addr) (addr)#endif +#define KFENCE_TEST_REQUIRES (test, cond) do { \ + if (!(cond)) \ + kunit_skip((test), "Test requires: " #cond); \ +} while (0) +/* Report as observed from console. */ static struct { spinlock_t lock;
@@ -555,8 +560,7 @@ static void test_init_on_free(struct kun };int i; -if (!IS_ENABLED (CONFIG_INIT_ON_FREE_DEFAULT_ON )) -return ; +KFENCE_TEST_REQUIRES (test,IS_ENABLED (CONFIG_INIT_ON_FREE_DEFAULT_ON ));/* Assume it hasn't been disabled on command line. */ setup_test_cache (test, size,0 ,NULL );
@@ -603,10 +607,8 @@ static void test_gfpzero(struct kunit *tchar *buf1, *buf2;int i; -if (CONFIG_KFENCE_SAMPLE_INTERVAL >100 ) { -kunit_warn (test,"skipping ... would take too long\n" ); -return ; - } +/* Skip if we think it'd take too long. */ +KFENCE_TEST_REQUIRES (test,CONFIG_KFENCE_SAMPLE_INTERVAL <=100 );setup_test_cache (test, size,0 ,NULL ); buf1 =test_alloc (test, size,GFP_KERNEL ,ALLOCATE_ANY );
_
Andrew Morton
maintainerPATCH 211/262 kfence: shorten critical sections of alloc/free
In reply to Andrew MortonFrom: Marco Elver <[email protected]>
Subject: kfence: shorten critical sections of alloc/free
Initializing memory and setting/checking the canary bytes is relatively expensive, and doing so in the meta->lock critical sections extends the duration with preemption and interrupts disabled unnecessarily.
Any reads to meta->addr and meta->size in kfence_guarded_alloc() and kfence_guarded_free() don't require locking meta->lock as long as the object is removed from the freelist: only kfence_guarded_alloc() sets meta->addr and meta->size after removing it from the freelist, which requires a preceding kfence_guarded_free() returning it to the list or the initial state.
Therefore move reads to meta->addr and meta->size, including expensive memory initialization using them, out of meta->lock critical sections.
---
mm/kfence/core.c | 38 +++++++++++++++++++++----------------- 1 file changed, 21 insertions(+), 17 deletions(-)
mm/kfence/core.c renamed from mm/kfence/core.c~kfence-shorten-critical-sections-of-alloc-free +21 -17
@@ -309,12 +309,19 @@ static inline bool set_canary_byte(u8 *a/* Check canary byte at @addr. */ static inline bool check_canary_byte (u8 *addr) { +struct kfence_metadata *meta; +unsigned long flags; +if (likely (*addr ==KFENCE_CANARY_PATTERN (addr)))return true;atomic_long_inc (&counters[KFENCE_COUNTER_BUGS ]); -kfence_report_error ((unsigned long )addr, false,NULL ,addr_to_metadata ((unsigned long )addr), -KFENCE_ERROR_CORRUPTION ); + + meta =addr_to_metadata ((unsigned long )addr); +raw_spin_lock_irqsave (&meta->lock, flags); +kfence_report_error ((unsigned long )addr, false,NULL , meta,KFENCE_ERROR_CORRUPTION ); +raw_spin_unlock_irqrestore (&meta->lock, flags); +return false; }
@@ -324,8 +331,6 @@ static __always_inline void for_each_canconst unsigned long pageaddr =ALIGN_DOWN (meta->addr,PAGE_SIZE );unsigned long addr; -lockdep_assert_held (&meta->lock); -/* * We'll iterate over each canary byte per-side until fn() returns * false. However, we'll still iterate over the canary bytes to the
@@ -414,8 +419,9 @@ static void *kfence_guarded_alloc(structWRITE_ONCE (meta->cache, cache); meta->size = size; meta->alloc_stack_hash = alloc_stack_hash; +raw_spin_unlock_irqrestore (&meta->lock, flags); -for_each_canary (meta, set_canary_byte); +alloc_covered_add (alloc_stack_hash,1 );/* Set required struct page fields. */ page =virt_to_page (meta->addr);
@@ -425,11 +431,8 @@ static void *kfence_guarded_alloc(structif (IS_ENABLED (CONFIG_SLAB )) page->s_mem = addr; -raw_spin_unlock_irqrestore (&meta->lock, flags); - -alloc_covered_add (alloc_stack_hash,1 ); -/* Memory initialization. */ +for_each_canary (meta, set_canary_byte);/* * We check slab_want_init_on_alloc() ourselves, rather than letting
@@ -454,6 +457,7 @@ static void kfence_guarded_free(void *ad {struct kcsan_scoped_access assert_page_exclusive;unsigned long flags; +bool init;raw_spin_lock_irqsave (&meta->lock, flags);
@@ -481,6 +485,13 @@ static void kfence_guarded_free(void *ad meta->unprotected_page =0 ; } +/* Mark the object as freed. */ +metadata_update_state (meta,KFENCE_OBJECT_FREED ,NULL ,0 ); + init =slab_want_init_on_free (meta->cache); +raw_spin_unlock_irqrestore (&meta->lock, flags); + +alloc_covered_add (meta->alloc_stack_hash,-1 ); +/* Check canary bytes for memory corruption. */ for_each_canary (meta, check_canary_byte);
@@ -489,16 +500,9 @@ static void kfence_guarded_free(void *ad* data is still there, and after a use-after-free is detected, we * unprotect the page, so the data is still accessible. */ -if (!zombie &&unlikely (slab_want_init_on_free (meta->cache))) +if (!zombie &&unlikely (init))memzero_explicit (addr, meta->size); -/* Mark the object as freed. */ -metadata_update_state (meta,KFENCE_OBJECT_FREED ,NULL ,0 ); - -raw_spin_unlock_irqrestore (&meta->lock, flags); - -alloc_covered_add (meta->alloc_stack_hash,-1 ); -/* Protect to detect use-after-frees. */ kfence_protect ((unsigned long )addr);
_
Andrew Morton
maintainerPATCH 212/262 kfence: always use static branches to guard kfence_alloc()
In reply to Andrew MortonFrom: Marco Elver <[email protected]>
Subject: kfence: always use static branches to guard kfence_alloc()
Regardless of KFENCE mode (CONFIG_KFENCE_STATIC_KEYS: either using static keys to gate allocations, or using a simple dynamic branch), always use a static branch to avoid the dynamic branch in kfence_alloc() if KFENCE was disabled at boot.
For CONFIG_KFENCE_STATIC_KEYS=n, this now avoids the dynamic branch if KFENCE was disabled at boot.
To simplify, also unifies the location where kfence_allocation_gate is read-checked to just be inline in kfence_alloc().
---
include/linux/kfence.h | 21 +++++++++++---------- mm/kfence/core.c | 16 +++++++--------- 2 files changed, 18 insertions(+), 19 deletions(-)
include/linux/kfence.h renamed from include/linux/kfence.h~kfence-always-use-static-branches-to-guard-kfence_alloc +11 -10
@@ -14,6 +14,9 @@#ifdef CONFIG_KFENCE +#include <linux/atomic.h> +#include <linux/static_key.h> +/* * We allocate an even number of pages, as it simplifies calculations to map * address to metadata indices; effectively, the very first page serves as an
@@ -22,13 +25,8 @@#define KFENCE_POOL_SIZE ((CONFIG_KFENCE_NUM_OBJECTS + 1) * 2 * PAGE_SIZE)extern char *__kfence_pool; -#ifdef CONFIG_KFENCE_STATIC_KEYS -#include <linux/static_key.h> DECLARE_STATIC_KEY_FALSE (kfence_allocation_key); -#else -#include <linux/atomic.h> extern atomic_t kfence_allocation_gate; -#endif /** * is_kfence_address() - check if an address belongs to KFENCE pool
@@ -116,13 +114,16 @@ void *__kfence_alloc(struct kmem_cache **/ static __always_inline void *kfence_alloc(struct kmem_cache *s, size_t size, gfp_t flags) { -#ifdef CONFIG_KFENCE_STATIC_KEYS -if (static_branch_unlikely (&kfence_allocation_key)) +#if defined(CONFIG_KFENCE_STATIC_KEYS ) ||CONFIG_KFENCE_SAMPLE_INTERVAL ==0 +if (!static_branch_unlikely (&kfence_allocation_key)) +return NULL ;#else - if (unlikely(!atomic_read(&kfence_allocation_gate))) +if (!static_branch_likely (&kfence_allocation_key)) +return NULL ;#endif -return __kfence_alloc (s, size, flags); -return NULL ; +if (likely (atomic_read (&kfence_allocation_gate))) +return NULL ; +return __kfence_alloc (s, size, flags); }/**
mm/kfence/core.c renamed from mm/kfence/core.c~kfence-always-use-static-branches-to-guard-kfence_alloc +7 -9
@@ -104,10 +104,11 @@ struct kfence_metadata kfence_metadata[Cstatic struct list_head kfence_freelist =LIST_HEAD_INIT (kfence_freelist);static DEFINE_RAW_SPINLOCK (kfence_freelist_lock);/* Lock protecting freelist. */ -#ifdef CONFIG_KFENCE_STATIC_KEYS -/* The static key to set up a KFENCE allocation. */ +/* +* The static key to set up a KFENCE allocation; or if static keys are not used +* to gate allocations, to avoid a load and compare if KFENCE is disabled. +*/ DEFINE_STATIC_KEY_FALSE (kfence_allocation_key); -#endif /* Gates the allocation, ensuring only one succeeds in a given period. */ atomic_t kfence_allocation_gate =ATOMIC_INIT (1 );
@@ -774,6 +775,8 @@ void __init kfence_init(void)return ; } +if (!IS_ENABLED (CONFIG_KFENCE_STATIC_KEYS )) +static_branch_enable (&kfence_allocation_key);WRITE_ONCE (kfence_enabled, true);queue_delayed_work (system_unbound_wq, &kfence_timer,0 ); pr_info("initialized - using %lu bytes for %d objects at 0x%p-0x%p\n", KFENCE_POOL_SIZE,
@@ -866,12 +869,7 @@ void *__kfence_alloc(struct kmem_cache *return NULL ; } -/* -* allocation_gate only needs to become non-zero, so it doesn't make -* sense to continue writing to it and pay the associated contention -* cost, in case we have a large number of concurrent allocations. -*/ -if (atomic_read (&kfence_allocation_gate) ||atomic_inc_return (&kfence_allocation_gate) >1 ) +if (atomic_inc_return (&kfence_allocation_gate) >1 )return NULL ;#ifdef CONFIG_KFENCE_STATIC_KEYS /*
_
Andrew Morton
maintainerPATCH 213/262 kfence: default to dynamic branch instead of static keys mode
In reply to Andrew MortonFrom: Marco Elver <[email protected]>
Subject: kfence: default to dynamic branch instead of static keys mode
We have observed that on very large machines with newer CPUs, the static key/branch switching delay is on the order of milliseconds. This is due to the required broadcast IPIs, which simply does not scale well to hundreds of CPUs (cores). If done too frequently, this can adversely affect tail latencies of various workloads.
One workaround is to increase the sample interval to several seconds, while decreasing sampled allocation coverage, but the problem still exists and could still increase tail latencies.
As already noted in the Kconfig help text, there are trade-offs: at lower sample intervals the dynamic branch results in better performance; however, at very large sample intervals, the static keys mode can result in better performance -- careful benchmarking is recommended.
Our initial benchmarking showed that with large enough sample intervals and workloads stressing the allocator, the static keys mode was slightly better. Evaluating and observing the possible system-wide side-effects of the static-key-switching induced broadcast IPIs, however, was a blind spot (in particular on large machines with 100s of cores).
Therefore, a major downside of the static keys mode is, unfortunately, that it is hard to predict performance on new system architectures and topologies, but also making conclusions about performance of new workloads based on a limited set of benchmarks.
Most distributions will simply select the defaults, while targeting a large variety of different workloads and system architectures. As such, the better default is CONFIG_KFENCE_STATIC_KEYS=n, and re-enabling it is only recommended after careful evaluation.
For reference, on x86-64 the condition in kfence_alloc() generates exactly 2 instructions in the kmem_cache_alloc() fast-path:
| ... | cmpl $0x0,0x1a8021c(%rip) # ffffffff82d560d0 <kfence_allocation_gate> | je ffffffff812d6003 <kmem_cache_alloc+0x243> | ...
which, given kfence_allocation_gate is infrequently modified, should be well predicted by most CPUs.
---
Documentation/dev-tools/kfence.rst | 12 ++++++++---- lib/Kconfig.kfence | 26 +++++++++++++++----------- 2 files changed, 23 insertions(+), 15 deletions(-)
Documentation/dev-tools/kfence.rst renamed from Documentation/dev-tools/kfence.rst~kfence-default-to-dynamic-branch-instead-of-static-keys-mode +8 -4
@@ -231,10 +231,14 @@ Guarded allocations are set up based on of the sample interval, the next allocation through the main allocator (SLAB or SLUB) returns a guarded allocation from the KFENCE object pool (allocation sizes up to PAGE_SIZE are supported). At this point, the timer is reset, and -the next allocation is set up after the expiration of the interval. To "gate" a -KFENCE allocation through the main allocator's fast-path without overhead, -KFENCE relies on static branches via the static keys infrastructure. The static -branch is toggled to redirect the allocation to KFENCE. +the next allocation is set up after the expiration of the interval. + +When using ``CONFIG_KFENCE_STATIC_KEYS=y``, KFENCE allocations are "gated" +through the main allocator's fast-path by relying on static branches via the +static keys infrastructure. The static branch is toggled to redirect the +allocation to KFENCE. Depending on sample interval, target workloads, and +system architecture, this may perform better than the simple dynamic branch. +Careful benchmarking is recommended. KFENCE objects each reside on a dedicated page, at either the left or right page boundaries selected at random. The pages to the left and right of the
lib/Kconfig.kfence renamed from lib/Kconfig.kfence~kfence-default-to-dynamic-branch-instead-of-static-keys-mode +15 -11
@@ -25,17 +25,6 @@ menuconfig KFENCE if KFENCE -config KFENCE_STATIC_KEYS - bool "Use static keys to set up allocations" - default y - depends on JUMP_LABEL # To ensure performance, require jump labels - help - Use static keys (static branches) to set up KFENCE allocations. Using - static keys is normally recommended, because it avoids a dynamic - branch in the allocator's fast path. However, with very low sample - intervals, or on systems that do not support jump labels, a dynamic - branch may still be an acceptable performance trade-off. - config KFENCE_SAMPLE_INTERVAL int "Default sample interval in milliseconds" default 100
@@ -56,6 +45,21 @@ config KFENCE_NUM_OBJECTS pages are required; with one containing the object and two adjacent ones used as guard pages. +config KFENCE_STATIC_KEYS + bool "Use static keys to set up allocations" if EXPERT + depends on JUMP_LABEL + help + Use static keys (static branches) to set up KFENCE allocations. This + option is only recommended when using very large sample intervals, or + performance has carefully been evaluated with this option. + + Using static keys comes with trade-offs that need to be carefully + evaluated given target workloads and system architectures. Notably, + enabling and disabling static keys invoke IPI broadcasts, the latency + and impact of which is much harder to predict than a dynamic branch. + + Say N if you are unsure. + config KFENCE_STRESS_TEST_FAULTS int "Stress testing of fault handling and error reporting" if EXPERT default 0
_
Andrew Morton
maintainerPATCH 214/262 mm/damon: grammar s/works/work/
In reply to Andrew MortonFrom: Geert Uytterhoeven <[email protected]>
Subject: mm/damon: grammar s/works/work/
Correct a singular versus plural grammar mistake in the help text for the DAMON_VADDR config symbol.
---
mm/damon/Kconfig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
mm/damon/Kconfig renamed from mm/damon/Kconfig~mm-damon-grammar-s-works-work +1 -1
@@ -30,7 +30,7 @@ config DAMON_VADDR select PAGE_IDLE_FLAG help This builds the default data access monitoring primitives for DAMON - that works for virtual address spaces. + that work for virtual address spaces. config DAMON_VADDR_KUNIT_TEST bool "Test for DAMON primitives" if !KUNIT_ALL_TESTS
_
Andrew Morton
maintainerPATCH 215/262 Documentation/vm: move user guides to admin-guide/mm/
In reply to Andrew MortonFrom: SeongJae Park <[email protected]>
Subject: Documentation/vm: move user guides to admin-guide/mm/
Most memory management user guide documents are in 'admin-guide/mm/', but two of those are in 'vm/'. This commit moves the two docs into 'admin-guide/mm' for easier documents finding.
---
Documentation/admin-guide/mm/index.rst | 2 ++
.../{vm => admin-guide/mm}/swap_numa.rst | 0
.../{vm => admin-guide/mm}/zswap.rst | 0
Documentation/vm/index.rst | 26 ++++---------------
4 files changed, 7 insertions(+), 21 deletions(-)
rename Documentation/{vm => admin-guide/mm}/swap_numa.rst (100%)
rename Documentation/{vm => admin-guide/mm}/zswap.rst (100%)Documentation/admin-guide/mm/index.rst +2 -0
@@ -37,5 +37,7 @@ the Linux memory management. numaperf pagemap soft-dirty + swap_numa transhuge userfaultfd + zswap
Documentation/admin-guide/mm/swap_numa.rst renamed from Documentation/vm/swap_numa.rst +0 -0
Documentation/admin-guide/mm/zswap.rst renamed from Documentation/vm/zswap.rst +0 -0
Documentation/vm/index.rst +5 -21
@@ -3,27 +3,11 @@ Linux Memory Management Documentation ===================================== This is a collection of documents about the Linux memory management (mm) -subsystem. If you are looking for advice on simply allocating memory, -see the :ref:`memory_allocation`. - -User guides for MM features -=========================== - -The following documents provide guides for controlling and tuning -various features of the Linux memory management - -.. toctree:: - :maxdepth: 1 - - swap_numa - zswap - -Kernel developers MM documentation -================================== - -The below documents describe MM internals with different level of -details ranging from notes and mailing list responses to elaborate -descriptions of data structures and algorithms. +subsystem internals with different level of details ranging from notes and +mailing list responses for elaborating descriptions of data structures and +algorithms. If you are looking for advice on simply allocating memory, see the +:ref:`memory_allocation`. For controlling and tuning guides, see the +:doc:`admin guide <../admin-guide/mm/index>`. .. toctree:: :maxdepth: 1
Signature · 1 line
2.17.1
Andrew Morton
maintainerPATCH 216/262 MAINTAINERS: update SeongJae's email address
In reply to Andrew MortonFrom: SeongJae Park <[email protected]>
Subject: MAINTAINERS: update SeongJae's email address
This commit updates SeongJae's email address in MAINTAINERS file to his preferred one.
---
MAINTAINERS | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
MAINTAINERS renamed from MAINTAINERS~maintainers-update-seongjaes-email-address +1 -1
@@ -5161,7 +5161,7 @@ F: net/ax25/ax25_timer.c F: net/ax25/sysctl_net_ax25.c DATA ACCESS MONITOR -M: SeongJae Park <[email protected]> +M: SeongJae Park <[email protected]> L: [email protected] S: Maintained F: Documentation/admin-guide/mm/damon/
_
Andrew Morton
maintainerPATCH 217/262 docs/vm/damon: remove broken reference
In reply to Andrew MortonFrom: SeongJae Park <[email protected]>
Subject: docs/vm/damon: remove broken reference
Building DAMON documents warns for a reference to nonexisting doc, as below:
$ time make htmldocs
[...]
Documentation/vm/damon/index.rst:24: WARNING: toctree contains reference to nonexisting document 'vm/damon/plans'This commit fixes the warning by removing the wrong reference.
---
Documentation/vm/damon/index.rst | 1 - 1 file changed, 1 deletion(-)
Documentation/vm/damon/index.rst renamed from Documentation/vm/damon/index.rst~docs-vm-damon-remove-broken-reference +0 -1
@@ -27,4 +27,3 @@ workloads and systems. faq design api - plans
_
Andrew Morton
maintainerPATCH 218/262 include/linux/damon.h: fix kernel-doc comments for 'damon_callback'
In reply to Andrew MortonFrom: SeongJae Park <[email protected]>
Subject: include/linux/damon.h: fix kernel-doc comments for 'damon_callback'
A few Kernel-doc comments in 'damon.h' are broken. This commit fixes those.
---
include/linux/damon.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
include/linux/damon.h renamed from include/linux/damon.h~include-linux-damonh-fix-kernel-doc-comments-for-damon_callback +3 -3
@@ -62,7 +62,7 @@ struct damon_target {struct damon_ctx ;/** -* struct damon_primitive Monitoring primitives for given use cases. +* struct damon_primitive - Monitoring primitives for given use cases. * * @init: Initialize primitive-internal data structures. * @update: Update primitive-internal data structures.
@@ -108,8 +108,8 @@ struct damon_primitive {void (*cleanup)(struct damon_ctx *context); }; -/* -* struct damon_callback Monitoring events notification callbacks. +/** +* struct damon_callback - Monitoring events notification callbacks. * * @before_start: Called before starting the monitoring. * @after_sampling: Called after each sampling.
_
Andrew Morton
maintainerPATCH 219/262 mm/damon/core: print kdamond start log in debug mode only
In reply to Andrew MortonFrom: SeongJae Park <[email protected]>
Subject: mm/damon/core: print kdamond start log in debug mode only
Logging of kdamond startup is using 'pr_info()' unnecessarily. This commit makes it to use 'pr_debug()' instead.
---
mm/damon/core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
mm/damon/core.c renamed from mm/damon/core.c~mm-damon-core-print-kdamond-start-log-in-debug-mode-only +1 -1
@@ -653,7 +653,7 @@ static int kdamond_fn(void *data)unsigned long sz_limit =0 ;mutex_lock (&ctx->kdamond_lock); -pr_info ("kdamond (%d) starts\n" , ctx->kdamond->pid); +pr_debug ("kdamond (%d) starts\n" , ctx->kdamond->pid);mutex_unlock (&ctx->kdamond_lock);if (ctx->primitive.init)
_
Andrew Morton
maintainerPATCH 220/262 mm/damon: remove unnecessary do_exit() from kdamond
In reply to Andrew MortonFrom: Changbin Du <[email protected]>
Subject: mm/damon: remove unnecessary do_exit() from kdamond
Just return from the kthread function.
---
mm/damon/core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
mm/damon/core.c renamed from mm/damon/core.c~mm-damon-remove-unnecessary-do_exit-from-kdamond +1 -1
@@ -714,7 +714,7 @@ static int kdamond_fn(void *data) nr_running_ctxs--;mutex_unlock (&damon_lock); -do_exit (0 ); +return 0 ; }#include "core-test.h"
_
Andrew Morton
maintainerPATCH 221/262 mm/damon: needn't hold kdamond_lock to print pid of kdamond
In reply to Andrew MortonFrom: Changbin Du <[email protected]>
Subject: mm/damon: needn't hold kdamond_lock to print pid of kdamond
Just get the pid by 'current->pid'. Meanwhile, to be symmetrical make the 'starts' and 'finishes' logs both use debug level.
---
mm/damon/core.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
mm/damon/core.c renamed from mm/damon/core.c~mm-damon-neednt-hold-kdamond_lock-to-print-pid-of-kdamond +2 -4
@@ -652,9 +652,7 @@ static int kdamond_fn(void *data)unsigned int max_nr_accesses =0 ;unsigned long sz_limit =0 ; -mutex_lock (&ctx->kdamond_lock); -pr_debug ("kdamond (%d) starts\n" , ctx->kdamond->pid); -mutex_unlock (&ctx->kdamond_lock); +pr_debug ("kdamond (%d) starts\n" , current->pid);if (ctx->primitive.init) ctx->primitive.init (ctx);
@@ -705,7 +703,7 @@ static int kdamond_fn(void *data)if (ctx->primitive.cleanup) ctx->primitive.cleanup (ctx); -pr_debug ("kdamond (%d) finishes\n" , ctx->kdamond->pid); +pr_debug ("kdamond (%d) finishes\n" , current->pid);mutex_lock (&ctx->kdamond_lock); ctx->kdamond =NULL ;mutex_unlock (&ctx->kdamond_lock);
_
Andrew Morton
maintainerPATCH 222/262 mm/damon/core: nullify pointer ctx->kdamond with a NULL
In reply to Andrew MortonFrom: Colin Ian King <[email protected]>
Subject: mm/damon/core: nullify pointer ctx->kdamond with a NULL
Currently a plain integer is being used to nullify the pointer ctx->kdamond. Use NULL instead. Cleans up sparse warning:
mm/damon/core.c:317:40: warning: Using plain integer as NULL pointer
---
mm/damon/core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
mm/damon/core.c renamed from mm/damon/core.c~mm-damon-core-nullify-pointer-ctx-kdamond-with-a-null +1 -1
@@ -314,7 +314,7 @@ static int __damon_start(struct damon_ct nr_running_ctxs);if (IS_ERR (ctx->kdamond)) { err =PTR_ERR (ctx->kdamond); - ctx->kdamond =0 ; + ctx->kdamond =NULL ; } }mutex_unlock (&ctx->kdamond_lock);
_
Andrew Morton
maintainerPATCH 223/262 mm/damon/core: account age of target regions
In reply to Andrew MortonFrom: SeongJae Park <[email protected]>
Subject: mm/damon/core: account age of target regions
Patch series "Implement Data Access Monitoring-based Memory Operation Schemes".
Introduction
============
DAMON[1] can be used as a primitive for data access aware memory management optimizations. For that, users who want such optimizations should run DAMON, read the monitoring results, analyze it, plan a new memory management scheme, and apply the new scheme by themselves. Such efforts will be inevitable for some complicated optimizations.
However, in many other cases, the users would simply want the system to apply a memory management action to a memory region of a specific size having a specific access frequency for a specific time. For example, "page out a memory region larger than 100 MiB keeping only rare accesses more than 2 minutes", or "Do not use THP for a memory region larger than 2 MiB rarely accessed for more than 1 seconds".
To make the works easier and non-redundant, this patchset implements a new feature of DAMON, which is called Data Access Monitoring-based Operation Schemes (DAMOS). Using the feature, users can describe the normal schemes in a simple way and ask DAMON to execute those on its own.
[1] https://damonitor.github.io
Evaluations
===========
DAMOS is accurate and useful for memory management optimizations. An experimental DAMON-based operation scheme for THP, 'ethp', removes 76.15% of THP memory overheads while preserving 51.25% of THP speedup. Another experimental DAMON-based 'proactive reclamation' implementation, 'prcl', reduces 93.38% of residential sets and 23.63% of system memory footprint while incurring only 1.22% runtime overhead in the best case (parsec3/freqmine).
NOTE that the experimental THP optimization and proactive reclamation are not for production but only for proof of concepts.
Please refer to the showcase web site's evaluation document[1] for detailed evaluation setup and results.
[1] https://damonitor.github.io/doc/html/v34/vm/damon/eval.html
Long-term Support Trees
-----------------------
For people who want to test DAMON but using LTS kernels, there are another couple of trees based on two latest LTS kernels respectively and containing the 'damon/master' backports.
- For v5.4.y: https://git.kernel.org/sj/h/damon/for-v5.4.y
- For v5.10.y: https://git.kernel.org/sj/h/damon/for-v5.10.y
Sequence Of Patches
===================
The 1st patch accounts age of each region. The 2nd patch implements the core of the DAMON-based operation schemes feature. The 3rd patch makes the default monitoring primitives for virtual address spaces to support the schemes. From this point, the kernel space users can use DAMOS. The 4th patch exports the feature to the user space via the debugfs interface. The 5th patch implements schemes statistics feature for easier tuning of the schemes and runtime access pattern analysis, and the 6th patch adds selftests for these changes. Finally, the 7th patch documents this new feature.
This patch (of 7):
DAMON can be used for data access pattern aware memory management optimizations. For that, users should run DAMON, read the monitoring results, analyze it, plan a new memory management scheme, and apply the new scheme by themselves. It would not be too hard, but still require some level of effort. For complicated cases, this effort is inevitable.
That said, in many cases, users would simply want to apply an actions to a memory region of a specific size having a specific access frequency for a specific time. For example, "page out a memory region larger than 100 MiB but having a low access frequency more than 10 minutes", or "Use THP for a memory region larger than 2 MiB having a high access frequency for more than 2 seconds".
For such optimizations, users will need to first account the age of each region themselves. To reduce such efforts, this commit implements a simple age account of each region in DAMON. For each aggregation step, DAMON compares the access frequency with that from last aggregation and reset the age of the region if the change is significant. Else, the age is incremented. Also, in case of the merge of regions, the region size-weighted average of the ages is set as the age of merged new region.
---
include/linux/damon.h | 10 ++++++++++ mm/damon/core.c | 13 +++++++++++++ 2 files changed, 23 insertions(+)
include/linux/damon.h renamed from include/linux/damon.h~mm-damon-core-account-age-of-target-regions +10 -0
@@ -31,12 +31,22 @@ struct damon_addr_range {* @sampling_addr: Address of the sample for the next access check. * @nr_accesses: Access frequency of this region. * @list: List head for siblings. +* @age: Age of this region. +* +* @age is initially zero, increased for each aggregation interval, and reset +* to zero again if the access frequency is significantly changed. If two +* regions are merged into a new region, both @nr_accesses and @age of the new +* region are set as region size-weighted average of those of the two regions. */ struct damon_region {struct damon_addr_range ar;unsigned long sampling_addr;unsigned int nr_accesses;struct list_head list; + +unsigned int age; +/* private: Internal value for age calculation. */ +unsigned int last_nr_accesses; };/**
mm/damon/core.c renamed from mm/damon/core.c~mm-damon-core-account-age-of-target-regions +13 -0
@@ -45,6 +45,9 @@ struct damon_region *damon_new_region(un region->nr_accesses =0 ;INIT_LIST_HEAD (®ion->list); + region->age =0 ; + region->last_nr_accesses =0 ; +return region; }
@@ -444,6 +447,7 @@ static void kdamond_reset_aggregated(strdamon_for_each_region (r, t) {trace_damon_aggregated (t, r,damon_nr_regions (t)); + r->last_nr_accesses = r->nr_accesses; r->nr_accesses =0 ; } }
@@ -461,6 +465,7 @@ static void damon_merge_two_regions(stru l->nr_accesses = (l->nr_accesses * sz_l + r->nr_accesses * sz_r) / (sz_l + sz_r); + l->age = (l->age * sz_l + r->age * sz_r) / (sz_l + sz_r); l->ar.end = r->ar.end;damon_destroy_region (r, t); }
@@ -480,6 +485,11 @@ static void damon_merge_regions_of(strucstruct damon_region *r, *prev =NULL , *next;damon_for_each_region_safe (r, next, t) { +if (diff_of (r->nr_accesses, r->last_nr_accesses) > thres) + r->age =0 ; +else + r->age++; +if (prev && prev->ar.end == r->ar.start &&diff_of (prev->nr_accesses, r->nr_accesses) <= thres &&sz_damon_region (prev) +sz_damon_region (r) <= sz_limit)
@@ -527,6 +537,9 @@ static void damon_split_region_at(struct r->ar.end = new->ar.start; + new->age = r->age; + new->last_nr_accesses = r->last_nr_accesses; +damon_insert_region (new, r,damon_next_region (r), t); }
_
Andrew Morton
maintainerPATCH 224/262 mm/damon/core: implement DAMON-based Operation Schemes (DAMOS)
In reply to Andrew MortonFrom: SeongJae Park <[email protected]>
Subject: mm/damon/core: implement DAMON-based Operation Schemes (DAMOS)
In many cases, users might use DAMON for simple data access aware memory management optimizations such as applying an operation scheme to a memory region of a specific size having a specific access frequency for a specific time. For example, "page out a memory region larger than 100 MiB but having a low access frequency more than 10 minutes", or "Use THP for a memory region larger than 2 MiB having a high access frequency for more than 2 seconds".
Most simple form of the solution would be doing offline data access pattern profiling using DAMON and modifying the application source code or system configuration based on the profiling results. Or, developing a daemon constructed with two modules (one for access monitoring and the other for applying memory management actions via mlock(), madvise(), sysctl, etc) is imaginable.
To avoid users spending their time for implementation of such simple data access monitoring-based operation schemes, this commit makes DAMON to handle such schemes directly. With this commit, users can simply specify their desired schemes to DAMON. Then, DAMON will automatically apply the schemes to the user-specified target processes.
Each of the schemes is composed with conditions for filtering of the target memory regions and desired memory management action for the target. Specifically, the format is::
<min/max size> <min/max access frequency> <min/max age> <action>
The filtering conditions are size of memory region, number of accesses to the region monitored by DAMON, and the age of the region. The age of region is incremented periodically but reset when its addresses or access frequency has significantly changed or the action of a scheme was applied. For the action, current implementation supports a few of madvise()-like hints, ``WILLNEED``, ``COLD``, ``PAGEOUT``, ``HUGEPAGE``, and ``NOHUGEPAGE``.
Because DAMON supports various address spaces and application of the actions to a monitoring target region is dependent to the type of the target address space, the application code should be implemented by each primitives and registered to the framework. Note that this commit only implements the framework part. Following commit will implement the action applications for virtual address spaces primitives.
---
include/linux/damon.h | 66 ++++++++++++++++++++++++ mm/damon/core.c | 109 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 175 insertions(+)
include/linux/damon.h renamed from include/linux/damon.h~mm-damon-core-implement-damon-based-operation-schemes-damos +66 -0
@@ -69,6 +69,48 @@ struct damon_target {struct list_head list; }; +/** +* enum damos_action - Represents an action of a Data Access Monitoring-based +* Operation Scheme. +* +* @DAMOS_WILLNEED: Call ``madvise()`` for the region with MADV_WILLNEED. +* @DAMOS_COLD: Call ``madvise()`` for the region with MADV_COLD. +* @DAMOS_PAGEOUT: Call ``madvise()`` for the region with MADV_PAGEOUT. +* @DAMOS_HUGEPAGE: Call ``madvise()`` for the region with MADV_HUGEPAGE. +* @DAMOS_NOHUGEPAGE: Call ``madvise()`` for the region with MADV_NOHUGEPAGE. +*/ +enum damos_action { +DAMOS_WILLNEED , +DAMOS_COLD , +DAMOS_PAGEOUT , +DAMOS_HUGEPAGE , +DAMOS_NOHUGEPAGE , +}; + +/** +* struct damos - Represents a Data Access Monitoring-based Operation Scheme. +* @min_sz_region: Minimum size of target regions. +* @max_sz_region: Maximum size of target regions. +* @min_nr_accesses: Minimum ``->nr_accesses`` of target regions. +* @max_nr_accesses: Maximum ``->nr_accesses`` of target regions. +* @min_age_region: Minimum age of target regions. +* @max_age_region: Maximum age of target regions. +* @action: &damo_action to be applied to the target regions. +* @list: List head for siblings. +* +* Note that both the minimums and the maximums are inclusive. +*/ +struct damos { +unsigned long min_sz_region; +unsigned long max_sz_region; +unsigned int min_nr_accesses; +unsigned int max_nr_accesses; +unsigned int min_age_region; +unsigned int max_age_region; +enum damos_action action; +struct list_head list; +}; +struct damon_ctx ;/**
@@ -79,6 +121,7 @@ struct damon_ctx;* @prepare_access_checks: Prepare next access check of target regions. * @check_accesses: Check the accesses to target regions. * @reset_aggregated: Reset aggregated accesses monitoring results. +* @apply_scheme: Apply a DAMON-based operation scheme. * @target_valid: Determine if the target is valid. * @cleanup: Clean up the context. *
@@ -104,6 +147,9 @@ struct damon_ctx;* of its update. The value will be used for regions adjustment threshold. * @reset_aggregated should reset the access monitoring results that aggregated * by @check_accesses. +* @apply_scheme is called from @kdamond when a region for user provided +* DAMON-based operation scheme is found. It should apply the scheme's action +* to the region. This is not used for &DAMON_ARBITRARY_TARGET case. * @target_valid should check whether the target is still valid for the * monitoring. * @cleanup is called from @kdamond just before its termination.
@@ -114,6 +160,8 @@ struct damon_primitive {void (*prepare_access_checks)(struct damon_ctx *context);unsigned int (*check_accesses)(struct damon_ctx *context);void (*reset_aggregated)(struct damon_ctx *context); +int (*apply_scheme)(struct damon_ctx *context,struct damon_target *t, +struct damon_region *r,struct damos *scheme);bool (*target_valid)(void *target);void (*cleanup)(struct damon_ctx *context); };
@@ -192,6 +240,7 @@ struct damon_callback {* @min_nr_regions: The minimum number of adaptive monitoring regions. * @max_nr_regions: The maximum number of adaptive monitoring regions. * @adaptive_targets: Head of monitoring targets (&damon_target) list. +* @schemes: Head of schemes (&damos) list. */ struct damon_ctx {unsigned long sample_interval;
@@ -213,6 +262,7 @@ struct damon_ctx {unsigned long min_nr_regions;unsigned long max_nr_regions;struct list_head adaptive_targets; +struct list_head schemes; };#define damon_next_region (r) \
@@ -233,6 +283,12 @@ struct damon_ctx {#define damon_for_each_target_safe (t, next, ctx) \ list_for_each_entry_safe(t, next, &(ctx)->adaptive_targets, list) +#define damon_for_each_scheme (s, ctx) \ + list_for_each_entry(s, &(ctx)->schemes, list) + +#define damon_for_each_scheme_safe (s, next, ctx) \ + list_for_each_entry_safe(s, next, &(ctx)->schemes, list) +#ifdef CONFIG_DAMON struct damon_region *damon_new_region (unsigned long start,unsigned long end);
@@ -242,6 +298,14 @@ inline void damon_insert_region(struct dvoid damon_add_region (struct damon_region *r,struct damon_target *t);void damon_destroy_region (struct damon_region *r,struct damon_target *t); +struct damos *damon_new_scheme ( +unsigned long min_sz_region,unsigned long max_sz_region, +unsigned int min_nr_accesses,unsigned int max_nr_accesses, +unsigned int min_age_region,unsigned int max_age_region, +enum damos_action action); +void damon_add_scheme (struct damon_ctx *ctx,struct damos *s); +void damon_destroy_scheme (struct damos *s); +struct damon_target *damon_new_target (unsigned long id);void damon_add_target (struct damon_ctx *ctx,struct damon_target *t);void damon_free_target (struct damon_target *t);
@@ -255,6 +319,8 @@ int damon_set_targets(struct damon_ctx *int damon_set_attrs (struct damon_ctx *ctx,unsigned long sample_int,unsigned long aggr_int,unsigned long primitive_upd_int,unsigned long min_nr_reg,unsigned long max_nr_reg); +int damon_set_schemes (struct damon_ctx *ctx, +struct damos **schemes,ssize_t nr_schemes);int damon_nr_running_ctxs (void );int damon_start (struct damon_ctx **ctxs,int nr_ctxs);
mm/damon/core.c renamed from mm/damon/core.c~mm-damon-core-implement-damon-based-operation-schemes-damos +109 -0
146 lines not on this page · raw message
_
Andrew Morton
maintainerPATCH 225/262 mm/damon/vaddr: support DAMON-based Operation Schemes
In reply to Andrew MortonFrom: SeongJae Park <[email protected]>
Subject: mm/damon/vaddr: support DAMON-based Operation Schemes
This commit makes DAMON's default primitives for virtual address spaces to support DAMON-based Operation Schemes (DAMOS) by implementing actions application functions and registering it to the monitoring context. The implementation simply links 'madvise()' for related DAMOS actions. That is, 'madvise(MADV_WILLNEED)' is called for 'WILLNEED' DAMOS action and similar for other actions ('COLD', 'PAGEOUT', 'HUGEPAGE', 'NOHUGEPAGE').
So, the kernel space DAMON users can now use the DAMON-based optimizations with only small amount of code.
---
include/linux/damon.h | 2 + mm/damon/vaddr.c | 56 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+)
include/linux/damon.h renamed from include/linux/damon.h~mm-damon-vaddr-support-damon-based-operation-schemes +2 -0
@@ -337,6 +337,8 @@ void damon_va_prepare_access_checks(struunsigned int damon_va_check_accesses (struct damon_ctx *ctx);bool damon_va_target_valid (void *t);void damon_va_cleanup (struct damon_ctx *ctx); +int damon_va_apply_scheme (struct damon_ctx *context,struct damon_target *t, +struct damon_region *r,struct damos *scheme);void damon_va_set_primitives (struct damon_ctx *ctx);#endif /* CONFIG_DAMON_VADDR */
mm/damon/vaddr.c renamed from mm/damon/vaddr.c~mm-damon-vaddr-support-damon-based-operation-schemes +56 -0
74 lines not on this page · raw message
_