Unverified Commit 0c8d7c88 authored by openeuler-ci-bot's avatar openeuler-ci-bot Committed by Gitee
Browse files

!6201 v2 mm: some optimization about hugetlb and thp

Merge Pull Request from: @ci-robot 
 
PR sync from: Kefeng Wang <wangkefeng.wang@huawei.com>
https://mailweb.openeuler.org/hyperkitty/list/kernel@openeuler.org/message/ELFG3CUXSVTYSCT4DTYHQOCPEIPQEUQ4/ 
1. hugetlb: remove hugetlb special casing in filemap.c  
2. thp: 
   1) align larger anonymous mappings on THP
   2) batch tlb flush when splitting
   3) try madvise huge for file exec

Baolin Wang (1):
  mm: huge_memory: batch tlb flush when splitting a pte-mapped THP

Fangrui Song (1):
  mm: remove VM_EXEC requirement for THP eligibility

Kefeng Wang (1):
  mm: filemap: try to enable THP for exec mapping

Lance Yang (2):
  mm/khugepaged: bypassing unnecessary scans with MMF_DISABLE_THP check
  mm/khugepaged: keep mm in mm_slot without MMF_DISABLE_THP check

Lorenzo Stoakes (1):
  mm/filemap: clarify filemap_fault() comments for not uptodate case

Rik van Riel (1):
  mm: align larger anonymous mappings on THP boundaries

Ryan Roberts (1):
  mm: thp_get_unmapped_area must honour topdown preference

Sidhartha Kumar (3):
  mm/filemap: remove hugetlb special casing in filemap.c
  mm/hugetlb: have CONFIG_HUGETLB_PAGE select CONFIG_XARRAY_MULTI
  fs/hugetlbfs/inode.c: mm/memory-failure.c: fix hugetlbfs hwpoison
    handling

Yang Shi (3):
  mm: mmap: map MAP_STACK to VM_NOHUGEPAGE
  mm: huge_memory: don't force huge page alignment on 32 bit
  mm: mmap: no need to call khugepaged_enter_vma() for stack


-- 
2.27.0
 
https://gitee.com/openeuler/kernel/issues/I9H84X 
 
Link:https://gitee.com/openeuler/kernel/pulls/6201

 

Reviewed-by: default avatarzhangyi (F) <yi.zhang@huawei.com>
Reviewed-by: default avatarXie XiuQi <xiexiuqi@huawei.com>
Signed-off-by: default avatarXie XiuQi <xiexiuqi@huawei.com>
parents 410b12b8 edeba251
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -202,6 +202,13 @@ PMD-mappable transparent hugepage::

	cat /sys/kernel/mm/transparent_hugepage/hpage_pmd_size

The kernel tries to use huge, PMD-mappable page on read page fault for
file exec mapping if CONFIG_READ_ONLY_THP_FOR_FS enabled. It's possible
to enabled the feature by writing 1 or disablt by writing 0::

	echo 0x0 >/sys/kernel/mm/transparent_hugepage/thp_exec_enabled
	echo 0x1 >/sys/kernel/mm/transparent_hugepage/thp_exec_enabled

khugepaged will be automatically started when one or more hugepage
sizes are enabled (either by directly setting "always" or "madvise",
or by setting "inherit" while the top-level enabled is set to "always"
+1 −0
Original line number Diff line number Diff line
@@ -280,6 +280,7 @@ config HUGETLBFS

config HUGETLB_PAGE
	def_bool HUGETLBFS
	select XARRAY_MULTI

config HUGETLB_PAGE_OPTIMIZE_VMEMMAP
	def_bool HUGETLB_PAGE
+19 −18
Original line number Diff line number Diff line
@@ -346,7 +346,7 @@ static ssize_t hugetlbfs_read_iter(struct kiocb *iocb, struct iov_iter *to)
	ssize_t retval = 0;

	while (iov_iter_count(to)) {
		struct page *page;
		struct folio *folio;
		size_t nr, copied, want;

		/* nr is the maximum number of bytes to copy from this page */
@@ -364,18 +364,18 @@ static ssize_t hugetlbfs_read_iter(struct kiocb *iocb, struct iov_iter *to)
		}
		nr = nr - offset;

		/* Find the page */
		page = find_lock_page(mapping, index);
		if (unlikely(page == NULL)) {
		/* Find the folio */
		folio = filemap_lock_hugetlb_folio(h, mapping, index);
		if (IS_ERR(folio)) {
			/*
			 * We have a HOLE, zero out the user-buffer for the
			 * length of the hole or request.
			 */
			copied = iov_iter_zero(nr, to);
		} else {
			unlock_page(page);
			folio_unlock(folio);

			if (!PageHWPoison(page))
			if (!folio_test_hwpoison(folio))
				want = nr;
			else {
				/*
@@ -383,19 +383,19 @@ static ssize_t hugetlbfs_read_iter(struct kiocb *iocb, struct iov_iter *to)
				 * touching the 1st raw HWPOISON subpage after
				 * offset.
				 */
				want = adjust_range_hwpoison(page, offset, nr);
				want = adjust_range_hwpoison(&folio->page, offset, nr);
				if (want == 0) {
					put_page(page);
					folio_put(folio);
					retval = -EIO;
					break;
				}
			}

			/*
			 * We have the page, copy it to user space buffer.
			 * We have the folio, copy it to user space buffer.
			 */
			copied = copy_page_to_iter(page, offset, want, to);
			put_page(page);
			copied = copy_folio_to_iter(folio, offset, want, to);
			folio_put(folio);
		}
		offset += copied;
		retval += copied;
@@ -673,21 +673,20 @@ static void remove_inode_hugepages(struct inode *inode, loff_t lstart,
{
	struct hstate *h = hstate_inode(inode);
	struct address_space *mapping = &inode->i_data;
	const pgoff_t start = lstart >> huge_page_shift(h);
	const pgoff_t end = lend >> huge_page_shift(h);
	const pgoff_t end = lend >> PAGE_SHIFT;
	struct folio_batch fbatch;
	pgoff_t next, index;
	int i, freed = 0;
	bool truncate_op = (lend == LLONG_MAX);

	folio_batch_init(&fbatch);
	next = start;
	next = lstart >> PAGE_SHIFT;
	while (filemap_get_folios(mapping, &next, end - 1, &fbatch)) {
		for (i = 0; i < folio_batch_count(&fbatch); ++i) {
			struct folio *folio = fbatch.folios[i];
			u32 hash = 0;

			index = folio->index;
			index = folio->index >> huge_page_order(h);
			hash = hugetlb_fault_mutex_hash(mapping, index);
			mutex_lock(&hugetlb_fault_mutex_table[hash]);

@@ -705,7 +704,9 @@ static void remove_inode_hugepages(struct inode *inode, loff_t lstart,
	}

	if (truncate_op)
		(void)hugetlb_unreserve_pages(inode, start, LONG_MAX, freed);
		(void)hugetlb_unreserve_pages(inode,
				lstart >> huge_page_shift(h),
				LONG_MAX, freed);
}

static void hugetlbfs_evict_inode(struct inode *inode)
@@ -753,7 +754,7 @@ static void hugetlbfs_zero_partial_page(struct hstate *h,
	pgoff_t idx = start >> huge_page_shift(h);
	struct folio *folio;

	folio = filemap_lock_folio(mapping, idx);
	folio = filemap_lock_hugetlb_folio(h, mapping, idx);
	if (IS_ERR(folio))
		return;

@@ -898,7 +899,7 @@ static long hugetlbfs_fallocate(struct file *file, int mode, loff_t offset,
		mutex_lock(&hugetlb_fault_mutex_table[hash]);

		/* See if already present in mapping to avoid alloc/free */
		folio = filemap_get_folio(mapping, index);
		folio = filemap_get_folio(mapping, index << huge_page_order(h));
		if (!IS_ERR(folio)) {
			folio_put(folio);
			mutex_unlock(&hugetlb_fault_mutex_table[hash]);
+1 −1
Original line number Diff line number Diff line
@@ -50,6 +50,7 @@ enum transparent_hugepage_flag {
	TRANSPARENT_HUGEPAGE_DEFRAG_REQ_MADV_FLAG,
	TRANSPARENT_HUGEPAGE_DEFRAG_KHUGEPAGED_FLAG,
	TRANSPARENT_HUGEPAGE_USE_ZERO_PAGE_FLAG,
	TRANSPARENT_HUGEPAGE_FILE_EXEC_THP_FLAG,
};

struct kobject;
@@ -206,7 +207,6 @@ static inline bool file_thp_enabled(struct vm_area_struct *vma)
	inode = vma->vm_file->f_inode;

	return (IS_ENABLED(CONFIG_READ_ONLY_THP_FOR_FS)) &&
	       (vma->vm_flags & VM_EXEC) &&
	       !inode_is_open_for_write(inode) && S_ISREG(inode->i_mode);
}

+12 −0
Original line number Diff line number Diff line
@@ -901,6 +901,12 @@ static inline unsigned int blocks_per_huge_page(struct hstate *h)
	return huge_page_size(h) / 512;
}

static inline struct folio *filemap_lock_hugetlb_folio(struct hstate *h,
				struct address_space *mapping, pgoff_t idx)
{
	return filemap_lock_folio(mapping, idx << huge_page_order(h));
}

#include <asm/hugetlb.h>

#ifndef is_hugepage_only_range
@@ -1097,6 +1103,12 @@ static inline struct hugepage_subpool *hugetlb_folio_subpool(struct folio *folio
	return NULL;
}

static inline struct folio *filemap_lock_hugetlb_folio(struct hstate *h,
				struct address_space *mapping, pgoff_t idx)
{
	return NULL;
}

static inline int isolate_or_dissolve_huge_page(struct page *page,
						struct list_head *list)
{
Loading