ext4: support of huge pages
Subsystems (19)
v6 cover ext4: support of huge pages
Here's respin of my huge ext4 patchset on top v4.10-rc/5 + my recent patchset that fixes rmap-related THP bugs. That patchset also bring required for huge-ext4 page_mkclean() changes.
Please review and consider applying.
I don't see any xfstests regressions with huge pages enabled. Patch with new configurations for xfstests-bld is below.
The basics are the same as with tmpfs[1] which is in Linus' tree now and ext4 built on top of it. The main difference is that we need to handle read out from and write-back to backing storage.
As with other THPs, the implementation is build around compound pages:
a naturally aligned collection of pages that memory management subsystem [in most cases] treat as a single entity:
- head page (the first subpage) on LRU represents whole huge page;
- head page's flags represent state of whole huge page (with few
exceptions);
- mm can't migrate subpages of the compound page individually;
For THP, we use PMD-sized huge pages.
Head page links buffer heads for whole huge page. Dirty/writeback/etc. tracking happens on per-hugepage level as all subpages share the same page flags.
lock_page() on any subpage would lock whole hugepage for the same reason.
On radix-tree, a huge page represented as a multi-order entry of the same order (HPAGE_PMD_ORDER). This allows us to track dirty/writeback on radix-tree tags with the same granularity as on struct page.
On IO via syscalls, we are still limited by copying upto PAGE_SIZE per iteration. The limitation here comes from how copy_page_to_iter() and copy_page_from_iter() work wrt. highmem: it can only handle one small page a time.
On write side, we also have problem with assuming small pages: write length and offset within page calculated before we know if small or huge page is allocated. It's not easy to fix. Looks like it would require change in ->write_begin() interface to accept len > PAGE_SIZE.
On split_huge_page() we need to free buffers before splitting the page. Page buffers takes additional pin on the page and can be a vector to mess with the page during split. We want to avoid this.
If try_to_free_buffers() fails, split_huge_page() would return -EBUSY.
Readahead doesn't play with huge pages well: 128k max readahead window, assumption on page size, PageReadahead() to track hit/miss. I've got it to allocate huge pages, but it doesn't provide any readahead as such. I don't know how to do this right. It's not clear at this point if we really need readahead with huge pages. I guess it's good enough for now.
Shadow entries ignored on allocation -- recently evicted page is not promoted to active list. Not sure if current workingset logic is adequate for huge pages. On eviction, we split the huge page and setup 4k shadow entries as usual.
Unlike tmpfs, ext4 makes use of tags in radix-tree. The approach I used for tmpfs -- 512 entries in radix-tree per-hugepages -- doesn't work well if we want to have coherent view on tags. So the first patch converts tmpfs to use multi-order entries in radix-tree. The same infrastructure used for ext4.
Encryption doesn't handle huge pages yet. To avoid regressions we just disable huge pages for the inode if it has EXT4_INODE_ENCRYPT.
Tested with 4k, 1k, encryption and bigalloc. All with and without huge=always. I think it's reasonable coverage.
The patchset is also in git:
git://git.kernel.org/pub/scm/linux/kernel/git/kas/linux.git hugeext4/v6
[1] http://lkml.kernel.org/r/1465222029-45942-1-git-send-email-kirill.shutemov@linux.intel.com
Changes since v5:
- Rebased;
- Reserve larger jounral transaction for huge pages (pointed by Jan);
Changes since v4:
- Rebase onto updated radix-tree interface;
- Change interface to page cache lookups wrt. multi-order entries;
- Do not mess with BIO_MAX_PAGES: ext4_mpage_readpages() now uses
block_read_full_page() for THP read out;
- Fix work with memcg enabled;
- Drop bogus VM_BUG_ON() from wp_huge_pmd();
Changes since v3:
- account huge page to dirty/writeback/reclaimable/etc. according to its size. It fixes background writback.
- move code that adds huge page to radix-tree to
page_cache_tree_insert() (Jan);
- make ramdisk work with huge pages;
- fix unaccont of shadow entries (Jan);
- use try_to_release_page() instead of try_to_free_buffers() in
split_huge_page() (Jan);
- make thp_get_unmapped_area() respect S_HUGE_MODE;
- use huge-page aligned address to zap page range in wp_huge_pmd();
- use ext4_kvmalloc in ext4_mpage_readpages() instead of
kmalloc() (Andreas);Changes since v2:
- fix intermittent crash in generic/299;
- typo (condition inversion) in do_generic_file_read(),
reported by Jitendra;
TODO:
- on IO via syscalls, copy more than PAGE_SIZE per iteration to/from
userspace;
- readahead ?;
- wire up madvise()/fadvise();
- encryption with huge pages;
- reclaim of file huge pages can be optimized -- split_huge_page() is not
required for pages with backing storage;Quoted 1 line
From
f523dd3aad026f5a3f8cbabc0ec69958a0618f6bMon Sep 17 00:00:00 2001
From: "Kirill A. Shutemov" <[email protected]>
Date: Fri, 12 Aug 2016 19:44:30 +0300
Subject: [PATCH] Add few more configurations to test ext4 with huge pages
Four new configurations: huge_4k, huge_1k, huge_bigalloc, huge_encrypt.
--- .../test-appliance/files/root/fs/ext4/cfg/all.list | 4 ++++ .../test-appliance/files/root/fs/ext4/cfg/huge_1k | 6 ++++++ .../test-appliance/files/root/fs/ext4/cfg/huge_4k | 6 ++++++ .../test-appliance/files/root/fs/ext4/cfg/huge_bigalloc | 14 ++++++++++++++ .../files/root/fs/ext4/cfg/huge_bigalloc.exclude | 7 +++++++ .../test-appliance/files/root/fs/ext4/cfg/huge_encrypt | 5 +++++ .../files/root/fs/ext4/cfg/huge_encrypt.exclude | 16 ++++++++++++++++ kvm-xfstests/util/parse_cli | 1 + 8 files changed, 59 insertions(+) create mode 100644 kvm-xfstests/test-appliance/files/root/fs/ext4/cfg/huge_1k create mode 100644 kvm-xfstests/test-appliance/files/root/fs/ext4/cfg/huge_4k create mode 100644 kvm-xfstests/test-appliance/files/root/fs/ext4/cfg/huge_bigalloc create mode 100644 kvm-xfstests/test-appliance/files/root/fs/ext4/cfg/huge_bigalloc.exclude create mode 100644 kvm-xfstests/test-appliance/files/root/fs/ext4/cfg/huge_encrypt create mode 100644 kvm-xfstests/test-appliance/files/root/fs/ext4/cfg/huge_encrypt.exclude
kvm-xfstests/test-appliance/files/root/fs/ext4/cfg/all.list +4 -0
@@ -9,3 +9,7 @@ dioread_nolock data_journal bigalloc bigalloc_1k +huge_4k +huge_1k +huge_bigalloc +huge_encrypt
kvm-xfstests/test-appliance/files/root/fs/ext4/cfg/huge_1k new file +6 -0
@@ -0,0 +1,6 @@ +export FS=ext4 +export TEST_DEV=$SM_TST_DEV +export TEST_DIR=$SM_TST_MNT +export MKFS_OPTIONS="-q -b 1024" +export EXT_MOUNT_OPTIONS="huge=always" +TESTNAME="Ext4 1k block with huge pages"
kvm-xfstests/test-appliance/files/root/fs/ext4/cfg/huge_4k new file +6 -0
@@ -0,0 +1,6 @@ +export FS=ext4 +export TEST_DEV=$PRI_TST_DEV +export TEST_DIR=$PRI_TST_MNT +export MKFS_OPTIONS="-q" +export EXT_MOUNT_OPTIONS="huge=always" +TESTNAME="Ext4 4k block with huge pages"
kvm-xfstests/test-appliance/files/root/fs/ext4/cfg/huge_bigalloc new file +14 -0
@@ -0,0 +1,14 @@ +SIZE=large +export MKFS_OPTIONS="-O bigalloc" +export EXT_MOUNT_OPTIONS="huge=always" + +# Until we can teach xfstests the difference between cluster size and +# block size, avoid collapse_range, insert_range, and zero_range since +# these will fail due the fact that these operations require +# cluster-aligned ranges. +export FSX_AVOID="-C -I -z" +export FSSTRESS_AVOID="-f collapse=0 -f insert=0 -f zero=0" +export XFS_IO_AVOID="fcollapse finsert zero" + +TESTNAME="Ext4 4k block w/bigalloc" +
kvm-xfstests/test-appliance/files/root/fs/ext4/cfg/huge_bigalloc.exclude new file +7 -0
@@ -0,0 +1,7 @@ +# bigalloc does not support on-line defrag +ext4/301 +ext4/302 +ext4/303 +ext4/304 +ext4/307 +ext4/308
kvm-xfstests/test-appliance/files/root/fs/ext4/cfg/huge_encrypt new file +5 -0
@@ -0,0 +1,5 @@ +SIZE=small +export MKFS_OPTIONS="" +export EXT_MOUNT_OPTIONS="test_dummy_encryption,huge=always" +REQUIRE_FEATURE=encryption +TESTNAME="Ext4 encryption"
kvm-xfstests/test-appliance/files/root/fs/ext4/cfg/huge_encrypt.exclude new file +16 -0
@@ -0,0 +1,16 @@ +ext4/004 # dump/restore doesn't handle quotas + +# encryption doesn't play well with quota +generic/082 +generic/219 +generic/230 +generic/231 +generic/232 +generic/233 +generic/235 +generic/270 + +# generic/204 tests ENOSPC handling; it doesn't correctly +# anticipate the external extended attribute required when +# using a 1k block size +generic/204
kvm-xfstests/util/parse_cli +1 -0
@@ -36,6 +36,7 @@ print_help () echo "Common file system configurations are:" echo " 4k 1k ext3 nojournal ext3conv metacsum dioread_nolock " echo " data_journal bigalloc bigalloc_1k inline" + echo " huge_4k huge_1k huge_bigalloc huge_encrypt" echo "" echo "xfstest names have the form: ext4/NNN generic/NNN shared/NNN" echo ""
Signature · 86 lines
2.9.3
Kirill A. Shutemov (36):
mm, shmem: swich huge tmpfs to multi-order radix-tree entries
Revert "radix-tree: implement radix_tree_maybe_preload_order()"
page-flags: relax page flag policy for few flags
mm, rmap: account file thp pages
thp: try to free page's buffers before attempt split
thp: handle write-protection faults for file THP
filemap: allocate huge page in page_cache_read(), if allowed
filemap: handle huge pages in do_generic_file_read()
filemap: allocate huge page in pagecache_get_page(), if allowed
filemap: handle huge pages in filemap_fdatawait_range()
HACK: readahead: alloc huge pages, if allowed
brd: make it handle huge pages
mm: make write_cache_pages() work on huge pages
thp: introduce hpage_size() and hpage_mask()
thp: do not threat slab pages as huge in hpage_{nr_pages,size,mask}
thp: make thp_get_unmapped_area() respect S_HUGE_MODE
fs: make block_read_full_page() be able to read huge page
fs: make block_write_{begin,end}() be able to handle huge pages
fs: make block_page_mkwrite() aware about huge pages
truncate: make truncate_inode_pages_range() aware about huge pages
truncate: make invalidate_inode_pages2_range() aware about huge pages
mm: account huge pages to dirty, writaback, reclaimable, etc.
ext4: make ext4_mpage_readpages() hugepage-aware
ext4: make ext4_writepage() work on huge pages
ext4: handle huge pages in ext4_page_mkwrite()
ext4: handle huge pages in __ext4_block_zero_page_range()
ext4: make ext4_block_write_begin() aware about huge pages
ext4: handle huge pages in ext4_da_write_end()
ext4: make ext4_da_page_release_reservation() aware about huge pages
ext4: handle writeback with huge pages
ext4: make EXT4_IOC_MOVE_EXT work with huge pages
ext4: fix SEEK_DATA/SEEK_HOLE for huge pages
ext4: make fallocate() operations work with huge pages
ext4: reserve larger jounral transaction for huge pages
mm, fs, ext4: expand use of page_mapping() and page_to_pgoff()
ext4, vfs: add huge= mount option
Naoya Horiguchi (1):
mm, hugetlb: switch hugetlbfs to multi-order radix-tree entries
drivers/base/node.c | 6 +
drivers/block/brd.c | 17 +-
fs/buffer.c | 106 ++++++-----
fs/ext4/ext4.h | 5 +
fs/ext4/ext4_jbd2.h | 16 +-
fs/ext4/extents.c | 10 +-
fs/ext4/file.c | 18 +-
fs/ext4/inode.c | 207 +++++++++++++-------
fs/ext4/move_extent.c | 12 +-
fs/ext4/page-io.c | 11 +-
fs/ext4/readpage.c | 2 +-
fs/ext4/super.c | 24 +++
fs/fs-writeback.c | 10 +-
fs/hugetlbfs/inode.c | 22 +--
fs/proc/meminfo.c | 4 +
fs/proc/task_mmu.c | 5 +-
include/linux/backing-dev.h | 10 +
include/linux/buffer_head.h | 10 +-
include/linux/fs.h | 5 +
include/linux/huge_mm.h | 18 +-
include/linux/memcontrol.h | 22 +--
include/linux/mm.h | 10 +-
include/linux/mmzone.h | 2 +
include/linux/page-flags.h | 12 +-
include/linux/pagemap.h | 54 +++---
include/linux/radix-tree.h | 1 -
lib/radix-tree.c | 74 --------
mm/filemap.c | 447 ++++++++++++++++++++++++++++----------------
mm/huge_memory.c | 74 ++++++--
mm/hugetlb.c | 19 +-
mm/khugepaged.c | 26 +--
mm/memory.c | 12 +-
mm/migrate.c | 1 +
mm/page-writeback.c | 99 ++++++----
mm/page_alloc.c | 5 +
mm/readahead.c | 17 +-
mm/rmap.c | 16 +-
mm/shmem.c | 117 +++++-------
mm/truncate.c | 137 ++++++++++----
mm/vmstat.c | 2 +
40 files changed, 1036 insertions(+), 629 deletions(-)
--
2.11.0PATCH v6 1/37 mm, shmem: swich huge tmpfs to multi-order radix-tree entries
We would need to use multi-order radix-tree entires for ext4 and other filesystems to have coherent view on tags (dirty/towrite) in the tree.
This patch converts huge tmpfs implementation to multi-order entries, so we will be able to use the same code patch for all filesystems.
We also change interface for page-cache lookup function:
- functions that lookup for pages[1] would return subpages of THP
relevant for requested indexes;
- functions that lookup for entries[2] would return one entry per-THP and index will point to index of head page (basically, round down to HPAGE_PMD_NR);
This would provide balanced exposure of multi-order entires to the rest of the kernel.
[1] find_get_pages(), pagecache_get_page(), pagevec_lookup(), etc.
[2] find_get_entry(), find_get_entries(), pagevec_lookup_entries(), etc.
--- include/linux/pagemap.h | 9 ++ mm/filemap.c | 236 ++++++++++++++++++++++++++---------------------- mm/huge_memory.c | 48 +++++++--- mm/khugepaged.c | 26 ++---- mm/shmem.c | 117 ++++++++++-------------- mm/truncate.c | 15 ++- 6 files changed, 235 insertions(+), 216 deletions(-)
include/linux/pagemap.h +9 -0
@@ -332,6 +332,15 @@ static inline struct page *grab_cache_page_nowait(struct address_space *mapping, mapping_gfp_mask(mapping)); } +static inline struct page *find_subpage (struct page *page,pgoff_t offset) +{ +VM_BUG_ON_PAGE (PageTail (page), page); +VM_BUG_ON_PAGE (page->index > offset, page); +VM_BUG_ON_PAGE (page->index + (1 <<compound_order (page)) < offset, + page); +return page - page->index + offset; +} +struct page *find_get_entry (struct address_space *mapping,pgoff_t offset);struct page *find_lock_entry (struct address_space *mapping,pgoff_t offset); unsigned find_get_entries(struct address_space *mapping, pgoff_t start,
mm/filemap.c +127 -109
487 lines not on this page · raw message
mm/huge_memory.c +36 -12
98 lines not on this page · raw message
mm/khugepaged.c +8 -18
@@ -1350,10 +1350,8 @@ static void collapse_shmem(struct mm_struct *mm,break ; } nr_none += n; -for (; index <min (iter.index, end); index++) { -radix_tree_insert (&mapping->page_tree, index, - new_page + (index %HPAGE_PMD_NR )); - } +for (; index <min (iter.index, end); index++) +radix_tree_insert (&mapping->page_tree, index, new_page);/* We are done. */ if (index >= end)
@@ -1425,8 +1423,7 @@ static void collapse_shmem(struct mm_struct *mm,list_add_tail (&page->lru, &pagelist);/* Finally, replace with the new page. */ -radix_tree_replace_slot (&mapping->page_tree, slot, - new_page + (index %HPAGE_PMD_NR )); +radix_tree_replace_slot (&mapping->page_tree, slot, new_page); slot =radix_tree_iter_resume (slot, &iter); index++;
@@ -1444,24 +1441,17 @@ static void collapse_shmem(struct mm_struct *mm,break ; } -/* -* Handle hole in radix tree at the end of the range. -* This code only triggers if there's nothing in radix tree -* beyond 'end'. -*/ -if (result ==SCAN_SUCCEED && index < end) { +if (result ==SCAN_SUCCEED ) {int n = end - index; -if (!shmem_charge (mapping->host, n)) { +if (n && !shmem_charge (mapping->host, n)) { result =SCAN_FAIL ; goto tree_locked; } - -for (; index < end; index++) { -radix_tree_insert (&mapping->page_tree, index, - new_page + (index %HPAGE_PMD_NR )); - } nr_none += n; + +radix_tree_join (&mapping->page_tree, start, +HPAGE_PMD_ORDER , new_page); } tree_locked:
mm/shmem.c +49 -68
205 lines not on this page · raw message
mm/truncate.c +6 -9
@@ -524,16 +524,13 @@ unsigned long invalidate_mapping_pages(struct address_space *mapping,WARN_ON (page_to_index (page) != index); -/* Middle of THP: skip */ -if (PageTransTail (page)) { +/* Is 'start' or 'end' in the middle of THP ? */ +if (PageTransHuge (page) && + (start > index || + (index ==round_down (end,HPAGE_PMD_NR )))) { +/* skip */ unlock_page (page);continue ; - }else if (PageTransHuge (page)) { - index +=HPAGE_PMD_NR -1 ; - i +=HPAGE_PMD_NR -1 ; -/* 'end' is in the middle of THP */ -if (index ==round_down (end,HPAGE_PMD_NR )) -continue ; } ret =invalidate_inode_page (page);
@@ -547,9 +544,9 @@ unsigned long invalidate_mapping_pages(struct address_space *mapping, count += ret; }pagevec_remove_exceptionals (&pvec); + index += pvec.nr ?hpage_nr_pages (pvec.pages[pvec.nr -1 ]) :1 ;pagevec_release (&pvec);cond_resched (); - index++; }return count; }
Signature · 1 line
2.11.0
PATCH v6 2/37 Revert "radix-tree: implement radix_tree_maybe_preload_order()"
In reply to Kirill A. ShutemovThis reverts commit 356e1c23292a4f63cfdf1daf0e0ddada51f32de8.
After conversion of huge tmpfs to multi-order entries, we don't need this anymore.
--- include/linux/radix-tree.h | 1 - lib/radix-tree.c | 74 ---------------------------------------------- 2 files changed, 75 deletions(-)
include/linux/radix-tree.h +0 -1
@@ -322,7 +322,6 @@ unsigned int radix_tree_gang_lookup_slot(struct radix_tree_root *root, unsigned long first_index, unsigned int max_items);int radix_tree_preload (gfp_t gfp_mask);int radix_tree_maybe_preload (gfp_t gfp_mask); -int radix_tree_maybe_preload_order (gfp_t gfp_mask,int order);void radix_tree_init (void );void *radix_tree_tag_set (struct radix_tree_root *root,unsigned long index,unsigned int tag);
lib/radix-tree.c +0 -74
98 lines not on this page · raw message
Signature · 1 line
2.11.0
PATCH v6 3/37 page-flags: relax page flag policy for few flags
In reply to Kirill A. ShutemovThese flags are in use for filesystems with backing storage: PG_error, PG_writeback and PG_readahead.
--- include/linux/page-flags.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
include/linux/page-flags.h +5 -5
@@ -263,7 +263,7 @@ static inline int TestClearPage##uname(struct page *page) { return 0; } __PAGEFLAG(Locked, locked, PF_NO_TAIL) PAGEFLAG(Waiters, waiters, PF_ONLY_HEAD) __CLEARPAGEFLAG(Waiters, waiters, PF_ONLY_HEAD) -PAGEFLAG(Error, error, PF_NO_COMPOUND) TESTCLEARFLAG(Error, error, PF_NO_COMPOUND) +PAGEFLAG(Error, error, PF_NO_TAIL) TESTCLEARFLAG(Error, error, PF_NO_TAIL) PAGEFLAG(Referenced, referenced, PF_HEAD) TESTCLEARFLAG(Referenced, referenced, PF_HEAD)__SETPAGEFLAG (Referenced, referenced,PF_HEAD )
@@ -303,15 +303,15 @@ PAGEFLAG(OwnerPriv1, owner_priv_1, PF_ANY)* Only test-and-set exist for PG_writeback. The unconditional operators are * risky: they bypass page accounting. */ -TESTPAGEFLAG(Writeback, writeback, PF_NO_COMPOUND) - TESTSCFLAG(Writeback, writeback, PF_NO_COMPOUND) +TESTPAGEFLAG(Writeback, writeback, PF_NO_TAIL) + TESTSCFLAG(Writeback, writeback, PF_NO_TAIL)PAGEFLAG (MappedToDisk, mappedtodisk,PF_NO_TAIL ) /* PG_readahead is only used for reads; PG_reclaim is only for writes */ PAGEFLAG(Reclaim, reclaim, PF_NO_TAIL) TESTCLEARFLAG(Reclaim, reclaim, PF_NO_TAIL) -PAGEFLAG(Readahead, reclaim, PF_NO_COMPOUND) - TESTCLEARFLAG(Readahead, reclaim, PF_NO_COMPOUND) +PAGEFLAG(Readahead, reclaim, PF_NO_TAIL) + TESTCLEARFLAG(Readahead, reclaim, PF_NO_TAIL)#ifdef CONFIG_HIGHMEM /*
Signature · 1 line
2.11.0
PATCH v6 4/37 mm, rmap: account file thp pages
In reply to Kirill A. ShutemovLet's add FileHugePages and FilePmdMapped fields into meminfo and smaps. It indicates how many times we allocate and map file THP.
--- drivers/base/node.c | 6 ++++++ fs/proc/meminfo.c | 4 ++++ fs/proc/task_mmu.c | 5 ++++- include/linux/mmzone.h | 2 ++ mm/filemap.c | 3 ++- mm/huge_memory.c | 5 ++++- mm/page_alloc.c | 5 +++++ mm/rmap.c | 12 ++++++++---- mm/vmstat.c | 2 ++ 9 files changed, 37 insertions(+), 7 deletions(-)
drivers/base/node.c +6 -0
@@ -116,6 +116,8 @@ static ssize_t node_read_meminfo(struct device *dev,"Node %d AnonHugePages: %8lu kB\n" "Node %d ShmemHugePages: %8lu kB\n" "Node %d ShmemPmdMapped: %8lu kB\n" +"Node %d FileHugePages: %8lu kB\n" +"Node %d FilePmdMapped: %8lu kB\n" #endif , nid, K(node_page_state(pgdat, NR_FILE_DIRTY)),
@@ -139,6 +141,10 @@ static ssize_t node_read_meminfo(struct device *dev, nid,K (node_page_state (pgdat,NR_SHMEM_THPS ) *HPAGE_PMD_NR ), nid,K (node_page_state (pgdat,NR_SHMEM_PMDMAPPED ) * +HPAGE_PMD_NR ), + nid,K (node_page_state (pgdat,NR_FILE_THPS ) * +HPAGE_PMD_NR ), + nid,K (node_page_state (pgdat,NR_FILE_PMDMAPPED ) * HPAGE_PMD_NR));#else nid, K(sum_zone_node_page_state(nid, NR_SLAB_UNRECLAIMABLE)));
fs/proc/meminfo.c +4 -0
@@ -146,6 +146,10 @@ static int meminfo_proc_show(struct seq_file *m, void *v) global_node_page_state(NR_SHMEM_THPS) * HPAGE_PMD_NR);show_val_kb (m,"ShmemPmdMapped: " ,global_node_page_state (NR_SHMEM_PMDMAPPED ) *HPAGE_PMD_NR ); +show_val_kb (m,"FileHugePages: " , +global_node_page_state (NR_FILE_THPS ) *HPAGE_PMD_NR ); +show_val_kb (m,"FilePmdMapped: " , +global_node_page_state (NR_FILE_PMDMAPPED ) *HPAGE_PMD_NR );#endif #ifdef CONFIG_CMA
fs/proc/task_mmu.c +4 -1
@@ -442,6 +442,7 @@ struct mem_size_stats {unsigned long anonymous;unsigned long anonymous_thp;unsigned long shmem_thp; +unsigned long file_thp;unsigned long swap;unsigned long shared_hugetlb;unsigned long private_hugetlb;
@@ -577,7 +578,7 @@ static void smaps_pmd_entry(pmd_t *pmd, unsigned long addr, else if (is_zone_device_page(page))/* pass */ ; else - VM_BUG_ON_PAGE(1, page); + mss->file_thp += HPAGE_PMD_SIZE; smaps_account(mss, page, true, pmd_young(*pmd), pmd_dirty(*pmd)); }#else
@@ -772,6 +773,7 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)"Anonymous: %8lu kB\n" "AnonHugePages: %8lu kB\n" "ShmemPmdMapped: %8lu kB\n" +"FilePmdMapped: %8lu kB\n" "Shared_Hugetlb: %8lu kB\n" "Private_Hugetlb: %7lu kB\n" "Swap: %8lu kB\n"
@@ -790,6 +792,7 @@ static int show_smap(struct seq_file *m, void *v, int is_pid) mss.anonymous >>10 , mss.anonymous_thp >>10 , mss.shmem_thp >>10 , + mss.file_thp >>10 , mss.shared_hugetlb >>10 , mss.private_hugetlb >>10 , mss.swap >> 10,
include/linux/mmzone.h +2 -0
@@ -163,6 +163,8 @@ enum node_stat_item {NR_SHMEM ,/* shmem pages (included tmpfs/GEM pages) */ NR_SHMEM_THPS ,NR_SHMEM_PMDMAPPED , +NR_FILE_THPS , +NR_FILE_PMDMAPPED ,NR_ANON_THPS ,NR_UNSTABLE_NFS ,/* NFS unstable pages */ NR_VMSCAN_WRITE,
mm/filemap.c +2 -1
@@ -240,7 +240,8 @@ void __delete_from_page_cache(struct page *page, void *shadow)if (PageTransHuge (page))__dec_node_page_state (page,NR_SHMEM_THPS ); }else { -VM_BUG_ON_PAGE (PageTransHuge (page) && !PageHuge (page), page); +if (PageTransHuge (page) && !PageHuge (page)) +__dec_node_page_state (page,NR_FILE_THPS ); }/*
mm/huge_memory.c +4 -1
@@ -1942,7 +1942,10 @@ static void __split_huge_page(struct page *page, struct list_head *list,struct radix_tree_iter iter;void **slot; -__dec_node_page_state (head,NR_SHMEM_THPS ); +if (PageSwapBacked (page)) +__dec_node_page_state (page,NR_SHMEM_THPS ); +else +__dec_node_page_state (page,NR_FILE_THPS );radix_tree_split (&mapping->page_tree, head->index,0 ); radix_tree_for_each_slot(slot, &mapping->page_tree, &iter,
mm/page_alloc.c +5 -0
@@ -4337,6 +4337,8 @@ void show_free_areas(unsigned int filter)#ifdef CONFIG_TRANSPARENT_HUGEPAGE " shmem_thp: %lukB" " shmem_pmdmapped: %lukB" +" file_thp: %lukB" +" file_pmdmapped: %lukB" " anon_thp: %lukB"#endif " writeback_tmp:%lukB"
@@ -4359,6 +4361,9 @@ void show_free_areas(unsigned int filter)K (node_page_state (pgdat,NR_SHMEM_THPS ) *HPAGE_PMD_NR ),K (node_page_state (pgdat,NR_SHMEM_PMDMAPPED ) *HPAGE_PMD_NR ), +K (node_page_state (pgdat,NR_FILE_THPS ) *HPAGE_PMD_NR ), +K (node_page_state (pgdat,NR_FILE_PMDMAPPED ) + *HPAGE_PMD_NR ),K (node_page_state (pgdat,NR_ANON_THPS ) *HPAGE_PMD_NR ), #endif K(node_page_state(pgdat, NR_SHMEM)),
mm/rmap.c +8 -4
@@ -1138,8 +1138,10 @@ void page_add_file_rmap(struct page *page, bool compound) }if (!atomic_inc_and_test (compound_mapcount_ptr (page))) goto out; -VM_BUG_ON_PAGE (!PageSwapBacked (page), page); -__inc_node_page_state (page,NR_SHMEM_PMDMAPPED ); +if (PageSwapBacked (page)) +__inc_node_page_state (page,NR_SHMEM_PMDMAPPED ); +else +__inc_node_page_state (page,NR_FILE_PMDMAPPED ); }else {if (PageTransCompound (page) &&page_mapping (page)) {VM_WARN_ON_ONCE (!PageLocked (page));
@@ -1179,8 +1181,10 @@ static void page_remove_file_rmap(struct page *page, bool compound) }if (!atomic_add_negative (-1 ,compound_mapcount_ptr (page))) goto out; -VM_BUG_ON_PAGE (!PageSwapBacked (page), page); -__dec_node_page_state (page,NR_SHMEM_PMDMAPPED ); +if (PageSwapBacked (page)) +__dec_node_page_state (page,NR_SHMEM_PMDMAPPED ); +else +__dec_node_page_state (page,NR_FILE_PMDMAPPED ); }else {if (!atomic_add_negative (-1 , &page->_mapcount)) goto out;
mm/vmstat.c +2 -0
@@ -967,6 +967,8 @@ const char * const vmstat_text[] = {"nr_shmem" ,"nr_shmem_hugepages" ,"nr_shmem_pmdmapped" , +"nr_file_hugepaged" , +"nr_file_pmdmapped" ,"nr_anon_transparent_hugepages" ,"nr_unstable" , "nr_vmscan_write",
Signature · 1 line
2.11.0
PATCH v6 5/37 thp: try to free page's buffers before attempt split
In reply to Kirill A. ShutemovWe want page to be isolated from the rest of the system before splitting it. We rely on page count to be 2 for file pages to make sure nobody uses the page: one pin to caller, one to radix-tree.
Filesystems with backing storage can have page count increased if it has buffers.
Let's try to free them, before attempt split. And remove one guarding VM_BUG_ON_PAGE().
--- include/linux/buffer_head.h | 1 + mm/huge_memory.c | 19 ++++++++++++++++++- 2 files changed, 19 insertions(+), 1 deletion(-)
include/linux/buffer_head.h +1 -0
@@ -400,6 +400,7 @@ extern int __set_page_dirty_buffers(struct page *page);#else /* CONFIG_BLOCK */ static inline void buffer_init (void ) {} +static inline int page_has_buffers (struct page *page) {return 0 ; }static inline int try_to_free_buffers (struct page *page) {return 1 ; }static inline int inode_has_buffers (struct inode *inode) {return 0 ; }static inline void invalidate_inode_buffers (struct inode *inode) {}
mm/huge_memory.c +18 -1
@@ -30,6 +30,7 @@#include <linux/userfaultfd_k.h> #include <linux/page_idle.h> #include <linux/shmem_fs.h> +#include <linux/buffer_head.h> #include <asm/tlb.h> #include <asm/pgalloc.h>
@@ -2117,7 +2118,6 @@ int split_huge_page_to_list(struct page *page, struct list_head *list)VM_BUG_ON_PAGE (is_huge_zero_page (page), page);VM_BUG_ON_PAGE (!PageLocked (page), page); -VM_BUG_ON_PAGE (!PageSwapBacked (page), page);VM_BUG_ON_PAGE (!PageCompound (page), page);if (PageAnon (head)) {
@@ -2146,6 +2146,23 @@ int split_huge_page_to_list(struct page *page, struct list_head *list) goto out; } +/* Try to free buffers before attempt split */ +if (!PageSwapBacked (head) &&PagePrivate (page)) { +/* +* We cannot trigger writeback from here due possible +* recursion if triggered from vmscan, only wait. +* +* Caller can trigger writeback it on its own, if safe. +*/ +wait_on_page_writeback (head); + +if (page_has_buffers (head) && !try_to_release_page (head, +GFP_KERNEL )) { + ret = -EBUSY ; + goto out; + } + } +/* Addidional pin from radix tree */ extra_pins =1 ; anon_vma =NULL ;
Signature · 1 line
2.11.0
PATCH v6 6/37 thp: handle write-protection faults for file THP
In reply to Kirill A. ShutemovFor filesystems that wants to be write-notified (has mkwrite), we will encount write-protection faults for huge PMDs in shared mappings.
The easiest way to handle them is to clear the PMD and let it refault as wriable.
--- mm/memory.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-)
mm/memory.c +9 -1
@@ -3488,8 +3488,16 @@ static int wp_huge_pmd(struct vm_fault *vmf, pmd_t orig_pmd)return vmf->vma->vm_ops->pmd_fault (vmf->vma, vmf->address, vmf->pmd, vmf->flags); +if (vmf->vma->vm_flags &VM_SHARED ) { +/* Clear PMD */ +zap_page_range_single (vmf->vma, vmf->address &HPAGE_PMD_MASK , +HPAGE_PMD_SIZE ,NULL ); + +/* Refault to establish writable PMD */ +return 0 ; + } +/* COW handled on pte level: split pmd */ -VM_BUG_ON_VMA (vmf->vma->vm_flags &VM_SHARED , vmf->vma);__split_huge_pmd (vmf->vma, vmf->pmd, vmf->address, false,NULL );return VM_FAULT_FALLBACK ;
Signature · 1 line
2.11.0
PATCH v6 7/37 filemap: allocate huge page in page_cache_read(), if allowed
In reply to Kirill A. ShutemovThis patch adds basic functionality to put huge page into page cache.
At the moment we only put huge pages into radix-tree if the range covered by the huge page is empty.
We ignore shadow entires for now, just remove them from the tree before inserting huge page.
Later we can add logic to accumulate information from shadow entires to return to caller (average eviction time?).
--- include/linux/fs.h | 5 ++ include/linux/pagemap.h | 21 ++++++- mm/filemap.c | 155 ++++++++++++++++++++++++++++++++++++++---------- 3 files changed, 147 insertions(+), 34 deletions(-)
include/linux/fs.h +5 -0
@@ -1806,6 +1806,11 @@ struct super_operations {#else #define S_DAX 0/* Make all the DAX code disappear */ #endif +#define S_HUGE_MODE 0xc000 +#define S_HUGE_NEVER 0x0000 +#define S_HUGE_ALWAYS 0x4000 +#define S_HUGE_WITHIN_SIZE 0x8000 +#define S_HUGE_ADVISE 0xc000/* * Note that nosuid etc flags are inode-specific: setting some file-system
include/linux/pagemap.h +18 -3
@@ -201,14 +201,20 @@ static inline int page_cache_add_speculative(struct page *page, int count) }#ifdef CONFIG_NUMA -extern struct page *__page_cache_alloc (gfp_t gfp); +extern struct page *__page_cache_alloc_order (gfp_t gfp,unsigned int order);#else -static inline struct page *__page_cache_alloc (gfp_t gfp) +static inline struct page *__page_cache_alloc_order (gfp_t gfp, +unsigned int order) { -return alloc_pages (gfp,0 ); +return alloc_pages (gfp, order); }#endif +static inline struct page *__page_cache_alloc (gfp_t gfp) +{ +return __page_cache_alloc_order (gfp,0 ); +} +static inline struct page *page_cache_alloc (struct address_space *x) {return __page_cache_alloc (mapping_gfp_mask (x));
@@ -225,6 +231,15 @@ static inline gfp_t readahead_gfp_mask(struct address_space *x) __GFP_COLD | __GFP_NORETRY | __GFP_NOWARN; } +extern bool __page_cache_allow_huge (struct address_space *x,pgoff_t offset); +static inline bool page_cache_allow_huge (struct address_space *x, +pgoff_t offset) +{ +if (!IS_ENABLED (CONFIG_TRANSPARENT_HUGEPAGE )) +return false; +return __page_cache_allow_huge (x, offset); +} +typedef int filler_t (void *,struct page *); pgoff_t page_cache_next_hole(struct address_space *mapping,
mm/filemap.c +124 -31
244 lines not on this page · raw message
Signature · 1 line
2.11.0
PATCH v6 8/37 filemap: handle huge pages in do_generic_file_read()
In reply to Kirill A. ShutemovMost of work happans on head page. Only when we need to do copy data to userspace we find relevant subpage.
We are still limited by PAGE_SIZE per iteration. Lifting this limitation would require some more work.
--- mm/filemap.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
mm/filemap.c +4 -1
@@ -1886,6 +1886,7 @@ static ssize_t do_generic_file_read(struct file *filp, loff_t *ppos,if (unlikely (page ==NULL )) goto no_cached_page; } + page =compound_head (page);if (PageReadahead (page)) { page_cache_async_readahead(mapping, ra, filp, page,
@@ -1967,7 +1968,8 @@ static ssize_t do_generic_file_read(struct file *filp, loff_t *ppos,* now we can copy it to user space... */ - ret =copy_page_to_iter (page, offset, nr, iter); + ret =copy_page_to_iter (page + index - page->index, offset, + nr, iter); offset += ret; index += offset >>PAGE_SHIFT ; offset &= ~PAGE_MASK ;
@@ -2385,6 +2387,7 @@ int filemap_fault(struct vm_area_struct *vma, struct vm_fault *vmf)* because there really aren't any performance issues here * and we need to check for errors. */ + page =compound_head (page);ClearPageError (page); error = mapping->a_ops->readpage (file, page);if (!error) {
Signature · 1 line
2.11.0
PATCH v6 9/37 filemap: allocate huge page in pagecache_get_page(), if allowed
In reply to Kirill A. ShutemovWrite path allocate pages using pagecache_get_page(). We should be able to allocate huge pages there, if it's allowed. As usually, fallback to small pages, if failed.
--- mm/filemap.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-)
mm/filemap.c +15 -2
@@ -1374,13 +1374,16 @@ struct page *pagecache_get_page(struct address_space *mapping, pgoff_t offset, no_page:if (!page && (fgp_flags &FGP_CREAT )) { +pgoff_t hoffset;int err;if ((fgp_flags &FGP_WRITE ) &&mapping_cap_account_dirty (mapping)) gfp_mask |= __GFP_WRITE;if (fgp_flags &FGP_NOFS ) gfp_mask &= ~__GFP_FS; - page =__page_cache_alloc (gfp_mask); + page =page_cache_alloc_huge (mapping, offset, gfp_mask); +no_huge:if (!page) + page =__page_cache_alloc (gfp_mask);if (!page)return NULL ;
@@ -1391,9 +1394,19 @@ struct page *pagecache_get_page(struct address_space *mapping, pgoff_t offset,if (fgp_flags &FGP_ACCESSED )__SetPageReferenced (page); - err =add_to_page_cache_lru (page, mapping, offset, +if (PageTransHuge (page)) + hoffset =round_down (offset,HPAGE_PMD_NR ); +else + hoffset = offset; + + err =add_to_page_cache_lru (page, mapping, hoffset, gfp_mask &GFP_RECLAIM_MASK );if (unlikely (err)) { +if (PageTransHuge (page)) { +put_page (page); + page =NULL ; + goto no_huge; + }put_page (page); page =NULL ;if (err == -EEXIST )
Signature · 1 line
2.11.0
PATCH v6 10/37 filemap: handle huge pages in filemap_fdatawait_range()
In reply to Kirill A. ShutemovWe writeback whole huge page a time.
--- mm/filemap.c | 5 +++++ 1 file changed, 5 insertions(+)
mm/filemap.c +5 -0
@@ -405,9 +405,14 @@ static int __filemap_fdatawait_range(struct address_space *mapping,if (page->index > end)continue ; + page =compound_head (page);wait_on_page_writeback (page);if (TestClearPageError (page)) ret = -EIO ; +if (PageTransHuge (page)) { + index = page->index +HPAGE_PMD_NR ; + i += index - pvec.pages[i]->index -1 ; + } }pagevec_release (&pvec);cond_resched ();
Signature · 7 lines
2.11.0 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH v6 11/37 HACK: readahead: alloc huge pages, if allowed
In reply to Kirill A. ShutemovMost page cache allocation happens via readahead (sync or async), so if we want to have significant number of huge pages in page cache we need to find a ways to allocate them from readahead.
Unfortunately, huge pages doesn't fit into current readahead design:
128 max readahead window, assumption on page size, PageReadahead() to track hit/miss.
I haven't found a ways to get it right yet.
This patch just allocates huge page if allowed, but doesn't really provide any readahead if huge page is allocated. We read out 2M a time and I would expect spikes in latancy without readahead.
Therefore HACK.
Having that said, I don't think it should prevent huge page support to be applied. Future will show if lacking readahead is a big deal with huge pages in page cache.
Any suggestions are welcome.
--- mm/readahead.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-)
mm/readahead.c +16 -1
@@ -174,6 +174,21 @@ int __do_page_cache_readahead(struct address_space *mapping, struct file *filp,if (page_offset > end_index)break ; +if (IS_ENABLED (CONFIG_TRANSPARENT_HUGE_PAGECACHE ) && + (!page_idx || !(page_offset %HPAGE_PMD_NR )) && +page_cache_allow_huge (mapping, page_offset)) { + page =__page_cache_alloc_order (gfp_mask | __GFP_COMP, +HPAGE_PMD_ORDER ); +if (page) { +prep_transhuge_page (page); + page->index =round_down (page_offset, +HPAGE_PMD_NR ); +list_add (&page->lru, &page_pool); + ret++; + goto start_io; + } + } +rcu_read_lock (); page =radix_tree_lookup (&mapping->page_tree, page_offset);rcu_read_unlock ();
@@ -189,7 +204,7 @@ int __do_page_cache_readahead(struct address_space *mapping, struct file *filp,SetPageReadahead (page); ret++; } - +start_io:/* * Now start the IO. We ignore I/O errors - if the page is not * uptodate then the caller will launch readpage again, and
Signature · 1 line
2.11.0
PATCH v6 12/37 brd: make it handle huge pages
In reply to Kirill A. ShutemovDo not assume length of bio segment is never larger than PAGE_SIZE. With huge pages it's HPAGE_PMD_SIZE (2M on x86-64).
--- drivers/block/brd.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-)
drivers/block/brd.c +12 -5
@@ -202,12 +202,15 @@ static int copy_to_brd_setup(struct brd_device *brd, sector_t sector, size_t n)size_t copy; copy =min_t (size_t, n,PAGE_SIZE - offset); + n -= copy;if (!brd_insert_page (brd, sector))return -ENOSPC ; -if (copy < n) { +while (n) { sector += copy >>SECTOR_SHIFT ;if (!brd_insert_page (brd, sector))return -ENOSPC ; + copy =min_t (size_t, n,PAGE_SIZE ); + n -= copy; }return 0 ; }
@@ -242,6 +245,7 @@ static void copy_to_brd(struct brd_device *brd, const void *src,size_t copy; copy =min_t (size_t, n,PAGE_SIZE - offset); + n -= copy; page =brd_lookup_page (brd, sector);BUG_ON (!page);
@@ -249,10 +253,11 @@ static void copy_to_brd(struct brd_device *brd, const void *src,memcpy (dst + offset, src, copy);kunmap_atomic (dst); -if (copy < n) { +while (n) { src += copy; sector += copy >>SECTOR_SHIFT ; - copy = n - copy; + copy =min_t (size_t, n,PAGE_SIZE ); + n -= copy; page =brd_lookup_page (brd, sector);BUG_ON (!page);
@@ -274,6 +279,7 @@ static void copy_from_brd(void *dst, struct brd_device *brd,size_t copy; copy =min_t (size_t, n,PAGE_SIZE - offset); + n -= copy; page =brd_lookup_page (brd, sector);if (page) { src =kmap_atomic (page);
@@ -282,10 +288,11 @@ static void copy_from_brd(void *dst, struct brd_device *brd, }else memset (dst,0 , copy); -if (copy < n) { +while (n) { dst += copy; sector += copy >>SECTOR_SHIFT ; - copy = n - copy; + copy =min_t (size_t, n,PAGE_SIZE ); + n -= copy; page =brd_lookup_page (brd, sector);if (page) { src =kmap_atomic (page);
Signature · 1 line
2.11.0
PATCH v6 13/37 mm: make write_cache_pages() work on huge pages
In reply to Kirill A. ShutemovWe writeback whole huge page a time. Let's adjust iteration this way.
--- include/linux/mm.h | 1 + include/linux/pagemap.h | 1 + mm/page-writeback.c | 17 ++++++++++++----- 3 files changed, 14 insertions(+), 5 deletions(-)
include/linux/mm.h +1 -0
@@ -1045,6 +1045,7 @@ extern pgoff_t __page_file_index(struct page *page);*/ static inline pgoff_t page_index (struct page *page) { + page =compound_head (page);if (unlikely (PageSwapCache (page)))return __page_file_index (page);return page->index;
include/linux/pagemap.h +1 -0
@@ -545,6 +545,7 @@ static inline int wait_on_page_locked_killable(struct page *page)*/ static inline void wait_on_page_writeback (struct page *page) { + page =compound_head (page);if (PageWriteback (page))wait_on_page_bit (page, PG_writeback); }
mm/page-writeback.c +12 -5
@@ -2209,7 +2209,7 @@ int write_cache_pages(struct address_space *mapping,* mapping. However, page->index will not change * because we have a reference on the page. */ -if (page->index > end) { +if (page_to_pgoff (page) > end) {/* * can't be range_cyclic (1st pass) because * end == -1 in that case.
@@ -2218,7 +2218,12 @@ int write_cache_pages(struct address_space *mapping,break ; } - done_index = page->index; + done_index =page_to_pgoff (page); +if (PageTransCompound (page)) { + index =round_up (index +1 ,HPAGE_PMD_NR ); + i +=HPAGE_PMD_NR - + done_index %HPAGE_PMD_NR -1 ; + }lock_page (page);
@@ -2230,7 +2235,7 @@ int write_cache_pages(struct address_space *mapping,* even if there is now a new, dirty page at the same * pagecache address. */ -if (unlikely (page->mapping != mapping)) { +if (unlikely (page_mapping (page) != mapping)) { continue_unlock:unlock_page (page);continue ;
@@ -2268,7 +2273,8 @@ int write_cache_pages(struct address_space *mapping,* not be suitable for data integrity * writeout). */ - done_index = page->index +1 ; + done_index =compound_head (page)->index + +hpage_nr_pages (page); done =1 ;break ; }
@@ -2280,7 +2286,8 @@ int write_cache_pages(struct address_space *mapping,* keep going until we have written all the pages * we tagged for writeback prior to entering this loop. */ -if (--wbc->nr_to_write <=0 && + wbc->nr_to_write -=hpage_nr_pages (page); +if (wbc->nr_to_write <=0 && wbc->sync_mode ==WB_SYNC_NONE ) { done =1 ;break ;
Signature · 1 line
2.11.0
PATCH v6 14/37 thp: introduce hpage_size() and hpage_mask()
In reply to Kirill A. ShutemovIntroduce new helpers which return size/mask of the page:
HPAGE_PMD_SIZE/HPAGE_PMD_MASK if the page is PageTransHuge() and PAGE_SIZE/PAGE_MASK otherwise.
--- include/linux/huge_mm.h | 16 ++++++++++++++++ 1 file changed, 16 insertions(+)
include/linux/huge_mm.h +16 -0
@@ -142,6 +142,20 @@ static inline int hpage_nr_pages(struct page *page)return 1 ; } +static inline int hpage_size (struct page *page) +{ +if (unlikely (PageTransHuge (page))) +return HPAGE_PMD_SIZE ; +return PAGE_SIZE ; +} + +static inline unsigned long hpage_mask (struct page *page) +{ +if (unlikely (PageTransHuge (page))) +return HPAGE_PMD_MASK ; +return PAGE_MASK ; +} +extern int do_huge_pmd_numa_page (struct vm_fault *vmf,pmd_t orig_pmd);extern struct page *huge_zero_page;
@@ -167,6 +181,8 @@ void mm_put_huge_zero_page(struct mm_struct *mm);#define HPAGE_PMD_SIZE ({ BUILD_BUG(); 0; })#define hpage_nr_pages (x) 1 +#define hpage_size (x) PAGE_SIZE +#define hpage_mask (x) PAGE_MASK#define transparent_hugepage_enabled (__vma) 0
Signature · 1 line
2.11.0
PATCH v6 15/37 thp: do not threat slab pages as huge in hpage_{nr_pages,size,mask}
In reply to Kirill A. ShutemovSlab pages can be compound, but we shouldn't threat them as THP for pupose of hpage_* helpers, otherwise it would lead to confusing results.
For instance, ext4 uses slab pages for journal pages and we shouldn't confuse them with THPs. The easiest way is to exclude them in hpage_* helpers.
--- include/linux/huge_mm.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
include/linux/huge_mm.h +3 -3
@@ -137,21 +137,21 @@ static inline spinlock_t *pmd_trans_huge_lock(pmd_t *pmd, }static inline int hpage_nr_pages (struct page *page) { -if (unlikely (PageTransHuge (page))) +if (unlikely (!PageSlab (page) &&PageTransHuge (page)))return HPAGE_PMD_NR ;return 1 ; }static inline int hpage_size (struct page *page) { -if (unlikely (PageTransHuge (page))) +if (unlikely (!PageSlab (page) &&PageTransHuge (page)))return HPAGE_PMD_SIZE ;return PAGE_SIZE ; }static inline unsigned long hpage_mask (struct page *page) { -if (unlikely (PageTransHuge (page))) +if (unlikely (!PageSlab (page) &&PageTransHuge (page)))return HPAGE_PMD_MASK ;return PAGE_MASK ; }
Signature · 7 lines
2.11.0 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH v6 16/37 thp: make thp_get_unmapped_area() respect S_HUGE_MODE
In reply to Kirill A. ShutemovWe want mmap(NULL) to return PMD-aligned address if the inode can have huge pages in page cache.
--- mm/huge_memory.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
mm/huge_memory.c +3 -1
@@ -528,10 +528,12 @@ unsigned long thp_get_unmapped_area(struct file *filp, unsigned long addr, unsigned long len, unsigned long pgoff, unsigned long flags) { loff_t off = (loff_t)pgoff << PAGE_SHIFT; +struct inode *inode = filp->f_mapping->host;if (addr) goto out; -if (!IS_DAX (filp->f_mapping->host) || !IS_ENABLED (CONFIG_FS_DAX_PMD )) +if ((inode->i_flags &S_HUGE_MODE ) ==S_HUGE_NEVER && + (!IS_DAX (inode) || !IS_ENABLED (CONFIG_FS_DAX_PMD ))) goto out; addr =__thp_get_unmapped_area (filp, len, off, flags,PMD_SIZE );
Signature · 1 line
2.11.0
PATCH v6 17/37 fs: make block_read_full_page() be able to read huge page
In reply to Kirill A. ShutemovThe approach is straight-forward: for compound pages we read out whole huge page.
For huge page we cannot have array of buffer head pointers on stack -- it's 4096 pointers on x86-64 -- 'arr' is allocated with kmalloc() for huge pages.
--- fs/buffer.c | 22 +++++++++++++++++----- include/linux/buffer_head.h | 9 +++++---- include/linux/page-flags.h | 2 +- 3 files changed, 23 insertions(+), 10 deletions(-)
fs/buffer.c +17 -5
@@ -871,7 +871,7 @@ struct buffer_head *alloc_page_buffers(struct page *page, unsigned long size, try_again: head =NULL ; - offset =PAGE_SIZE ; + offset =hpage_size (page);while ((offset -= size) >=0 ) { bh =alloc_buffer_head (GFP_NOFS );if (!bh)
@@ -1466,7 +1466,7 @@ void set_bh_page(struct buffer_head *bh, struct page *page, unsigned long offset) { bh->b_page = page; -BUG_ON (offset >=PAGE_SIZE ); +BUG_ON (offset >=hpage_size (page));if (PageHighMem (page))/* * This catches illegal uses and preserves the offset:
@@ -2280,11 +2280,13 @@ int block_read_full_page(struct page *page, get_block_t *get_block) {struct inode *inode = page->mapping->host;sector_t iblock, lblock; -struct buffer_head *bh, *head, *arr[MAX_BUF_PER_PAGE ]; +struct buffer_head *arr_on_stack[MAX_BUF_PER_PAGE ]; +struct buffer_head *bh, *head, **arr = arr_on_stack;unsigned int blocksize, bbits;int nr, i;int fully_mapped =1 ; +VM_BUG_ON_PAGE (PageTail (page), page); head =create_page_buffers (page, inode,0 ); blocksize = head->b_size; bbits =block_size_bits (blocksize);
@@ -2295,6 +2297,11 @@ int block_read_full_page(struct page *page, get_block_t *get_block) nr =0 ; i =0 ; +if (PageTransHuge (page)) { + arr =kmalloc (sizeof (struct buffer_head *) *HPAGE_PMD_NR * +MAX_BUF_PER_PAGE ,GFP_NOFS ); + } + do { if (buffer_uptodate(bh)) continue;
@@ -2310,7 +2317,9 @@ int block_read_full_page(struct page *page, get_block_t *get_block)SetPageError (page); }if (!buffer_mapped (bh)) { -zero_user (page, i * blocksize, blocksize); +zero_user (page + (i * blocksize /PAGE_SIZE ), + i * blocksize %PAGE_SIZE , + blocksize);if (!err)set_buffer_uptodate (bh);continue ;
@@ -2336,7 +2345,7 @@ int block_read_full_page(struct page *page, get_block_t *get_block)if (!PageError (page))SetPageUptodate (page);unlock_page (page); -return 0 ; + goto out; }/* Stage two: lock the buffers */
@@ -2358,6 +2367,9 @@ int block_read_full_page(struct page *page, get_block_t *get_block)else submit_bh (REQ_OP_READ ,0 , bh); } +out: +if (arr != arr_on_stack) +kfree (arr);return 0 ; }EXPORT_SYMBOL (block_read_full_page);
include/linux/buffer_head.h +5 -4
@@ -131,13 +131,14 @@ BUFFER_FNS(Meta, meta) BUFFER_FNS(Prio, prio) BUFFER_FNS(Defer_Completion, defer_completion) -#define bh_offset (bh) ((unsigned long)(bh)->b_data & ~PAGE_MASK) +#define bh_offset (bh) ((unsigned long)(bh)->b_data & ~hpage_mask(bh->b_page))/* If we *know* page->private refers to buffer_heads */ -#define page_buffers (page) \ +#define page_buffers (__page) \ ({ \ - BUG_ON(!PagePrivate(page)); \ - ((struct buffer_head *)page_private(page)); \ + struct page *p = compound_head(__page); \ + BUG_ON(!PagePrivate(p)); \ + ((struct buffer_head *)page_private(p)); \ })#define page_has_buffers (page) PagePrivate(page)
include/linux/page-flags.h +1 -1
@@ -746,7 +746,7 @@ static inline void ClearPageSlabPfmemalloc(struct page *page)*/ static inline int page_has_private (struct page *page) { -return !!(page->flags &PAGE_FLAGS_PRIVATE ); +return !!(compound_head (page)->flags &PAGE_FLAGS_PRIVATE ); }#undef PF_ANY
Signature · 1 line
2.11.0
PATCH v6 18/37 fs: make block_write_{begin,end}() be able to handle huge pages
In reply to Kirill A. ShutemovIt's more or less straight-forward.
Most changes are around getting offset/len withing page right and zero out desired part of the page.
--- fs/buffer.c | 70 +++++++++++++++++++++++++++++++++++-------------------------- 1 file changed, 40 insertions(+), 30 deletions(-)
fs/buffer.c +40 -30
@@ -1902,6 +1902,7 @@ void page_zero_new_buffers(struct page *page, unsigned from, unsigned to) {unsigned int block_start, block_end;struct buffer_head *head, *bh; +bool uptodate =PageUptodate (page);BUG_ON (!PageLocked (page));if (!page_has_buffers (page))
@@ -1912,21 +1913,21 @@ void page_zero_new_buffers(struct page *page, unsigned from, unsigned to) do { block_end = block_start + bh->b_size; - if (buffer_new(bh)) { - if (block_end > from && block_start < to) { - if (!PageUptodate(page)) { - unsigned start, size; + if (buffer_new(bh) && block_end > from && block_start < to) { + if (!uptodate) { + unsigned start, size; - start = max(from, block_start); - size = min(to, block_end) - start; + start = max(from, block_start); + size = min(to, block_end) - start; - zero_user(page, start, size); - set_buffer_uptodate(bh); - } - - clear_buffer_new(bh); - mark_buffer_dirty(bh); + zero_user(page + block_start / PAGE_SIZE, + start % PAGE_SIZE, + size); + set_buffer_uptodate(bh); } + + clear_buffer_new(bh); + mark_buffer_dirty(bh); } block_start = block_end;
@@ -1992,18 +1993,21 @@ iomap_to_bh(struct inode *inode, sector_t block, struct buffer_head *bh,int __block_write_begin_int (struct page *page,loff_t pos,unsigned len,get_block_t *get_block,struct iomap *iomap) { -unsigned from = pos & (PAGE_SIZE -1 ); -unsigned to = from + len; -struct inode *inode = page->mapping->host; +unsigned from, to; +struct inode *inode =page_mapping (page)->host;unsigned block_start, block_end;sector_t block;int err =0 ;unsigned blocksize, bbits;struct buffer_head *bh, *head, *wait[2 ], **wait_bh=wait; +bool uptodate =PageUptodate (page); + page =compound_head (page); + from = pos & ~hpage_mask (page); + to = from + len;BUG_ON (!PageLocked (page)); -BUG_ON (from >PAGE_SIZE ); -BUG_ON (to >PAGE_SIZE ); +BUG_ON (from >hpage_size (page)); +BUG_ON (to >hpage_size (page));BUG_ON (from > to); head =create_page_buffers (page, inode,0 );
@@ -2016,10 +2020,8 @@ int __block_write_begin_int(struct page *page, loff_t pos, unsigned len, block++, block_start=block_end, bh = bh->b_this_page) { block_end = block_start + blocksize;if (block_end <= from || block_start >= to) { -if (PageUptodate (page)) { -if (!buffer_uptodate (bh)) -set_buffer_uptodate (bh); - } +if (uptodate && !buffer_uptodate (bh)) +set_buffer_uptodate (bh);continue ; }if (buffer_new (bh))
@@ -2036,23 +2038,28 @@ int __block_write_begin_int(struct page *page, loff_t pos, unsigned len,if (buffer_new (bh)) {clean_bdev_bh_alias (bh); -if (PageUptodate (page)) { +if (uptodate) {clear_buffer_new (bh);set_buffer_uptodate (bh);mark_buffer_dirty (bh);continue ; } -if (block_end > to || block_start < from) -zero_user_segments (page, - to, block_end, - block_start, from); +if (block_end > to || block_start < from) { +BUG_ON (to - from >PAGE_SIZE ); +zero_user_segments (page + + block_start /PAGE_SIZE , + to %PAGE_SIZE , + (block_start %PAGE_SIZE ) + blocksize, + block_start %PAGE_SIZE , + from %PAGE_SIZE ); + }continue ; } } -if (PageUptodate (page)) { +if (uptodate) {if (!buffer_uptodate (bh))set_buffer_uptodate (bh); -continue ; +continue ; } if (!buffer_uptodate(bh) && !buffer_delay(bh) && !buffer_unwritten(bh) &&
@@ -2089,6 +2096,7 @@ static int __block_commit_write(struct inode *inode, struct page *page,unsigned blocksize;struct buffer_head *bh, *head; +VM_BUG_ON_PAGE (PageTail (page), page); bh = head =page_buffers (page); blocksize = bh->b_size;
@@ -2102,7 +2110,8 @@ static int __block_commit_write(struct inode *inode, struct page *page,set_buffer_uptodate (bh);mark_buffer_dirty (bh); } -clear_buffer_new (bh); +if (buffer_new (bh)) +clear_buffer_new (bh); block_start = block_end; bh = bh->b_this_page;
@@ -2155,7 +2164,8 @@ int block_write_end(struct file *file, struct address_space *mapping,struct inode *inode = mapping->host;unsigned start; - start = pos & (PAGE_SIZE -1 ); + page =compound_head (page); + start = pos & ~hpage_mask (page);if (unlikely (copied < len)) {/*
Signature · 1 line
2.11.0
PATCH v6 19/37 fs: make block_page_mkwrite() aware about huge pages
In reply to Kirill A. ShutemovAdjust check on whether part of the page beyond file size and apply compound_head() and page_mapping() where appropriate.
--- fs/buffer.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
fs/buffer.c +5 -5
@@ -2544,7 +2544,7 @@ EXPORT_SYMBOL(block_commit_write);int block_page_mkwrite (struct vm_area_struct *vma,struct vm_fault *vmf,get_block_t get_block) { -struct page *page = vmf->page; +struct page *page =compound_head (vmf->page);struct inode *inode =file_inode (vma->vm_file);unsigned long end;loff_t size;
@@ -2552,7 +2552,7 @@ int block_page_mkwrite(struct vm_area_struct *vma, struct vm_fault *vmf,lock_page (page); size =i_size_read (inode); -if ((page->mapping != inode->i_mapping) || +if ((page_mapping (page) != inode->i_mapping) || (page_offset (page) > size)) {/* We overload EFAULT to mean page got truncated */ ret = -EFAULT ;
@@ -2560,10 +2560,10 @@ int block_page_mkwrite(struct vm_area_struct *vma, struct vm_fault *vmf, }/* page is wholly or partially inside EOF */ -if (((page->index +1 ) <<PAGE_SHIFT ) > size) - end = size & ~PAGE_MASK ; +if (((page->index +hpage_nr_pages (page)) <<PAGE_SHIFT ) > size) + end = size & ~hpage_mask (page);else - end =PAGE_SIZE ; + end =hpage_size (page); ret =__block_write_begin (page,0 , end, get_block);if (!ret)
Signature · 1 line
2.11.0
PATCH v6 20/37 truncate: make truncate_inode_pages_range() aware about huge pages
In reply to Kirill A. ShutemovAs with shmem_undo_range(), truncate_inode_pages_range() removes huge pages, if it fully within range.
Partial truncate of huge pages zero out this part of THP.
Unlike with shmem, it doesn't prevent us having holes in the middle of huge page we still can skip writeback not touched buffers.
With memory-mapped IO we would loose holes in some cases when we have THP in page cache, since we cannot track access on 4k level in this case.
--- fs/buffer.c | 2 +- include/linux/mm.h | 9 +++++- mm/truncate.c | 86 ++++++++++++++++++++++++++++++++++++++++++++---------- 3 files changed, 80 insertions(+), 17 deletions(-)
fs/buffer.c +1 -1
@@ -1534,7 +1534,7 @@ void block_invalidatepage(struct page *page, unsigned int offset,/* * Check for overflow */ -BUG_ON (stop >PAGE_SIZE || stop < length); +BUG_ON (stop >hpage_size (page) || stop < length); head =page_buffers (page); bh = head;
include/linux/mm.h +8 -1
@@ -1328,8 +1328,15 @@ int get_kernel_page(unsigned long start, int write, struct page **pages);struct page *get_dump_page (unsigned long addr);extern int try_to_release_page (struct page * page,gfp_t gfp_mask); -extern void do_invalidatepage (struct page *page,unsigned int offset, +extern void __do_invalidatepage (struct page *page,unsigned int offset,unsigned int length); +static inline void do_invalidatepage (struct page *page,unsigned int offset, +unsigned int length) +{ +if (page_has_private (page)) +__do_invalidatepage (page, offset, length); +} +int __set_page_dirty_nobuffers (struct page *page);int __set_page_dirty_no_writeback (struct page *page);
mm/truncate.c +71 -15
149 lines not on this page · raw message
Signature · 7 lines
2.11.0 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH v6 21/37 truncate: make invalidate_inode_pages2_range() aware about huge pages
In reply to Kirill A. ShutemovFor huge pages we need to unmap whole range covered by the huge page.
--- mm/truncate.c | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-)
mm/truncate.c +14 -9
@@ -703,27 +703,32 @@ int invalidate_inode_pages2_range(struct address_space *mapping,continue ; }wait_on_page_writeback (page); +if (page_mapped (page)) { +loff_t begin, len; + + begin = index <<PAGE_SHIFT ;if (!did_range_unmap) {/* * Zap the rest of the file in one hit. */ + len = (loff_t)(1 + end - index) << +PAGE_SHIFT ; +if (len <hpage_size (page)) + len =hpage_size (page);unmap_mapping_range (mapping, - (loff_t )index <<PAGE_SHIFT , - (loff_t)(1 + end - index) - <<PAGE_SHIFT , -0 ); + begin, len,0 ); did_range_unmap =1 ; }else {/* * Just zap this page */ -unmap_mapping_range (mapping, - (loff_t )index <<PAGE_SHIFT , -PAGE_SIZE ,0 ); + len =hpage_size (page); +unmap_mapping_range (mapping, begin, + len,0 ); } } -BUG_ON (page_mapped (page)); +VM_BUG_ON_PAGE (page_mapped (page), page); ret2 =do_launder_page (mapping, page);if (ret2 ==0 ) {if (!invalidate_complete_page2 (mapping, page))
@@ -734,9 +739,9 @@ int invalidate_inode_pages2_range(struct address_space *mapping,unlock_page (page); }pagevec_remove_exceptionals (&pvec); + index += pvec.nr ?hpage_nr_pages (pvec.pages[pvec.nr -1 ]) :1 ;pagevec_release (&pvec);cond_resched (); - index++; }cleancache_invalidate_inode (mapping);return ret;
Signature · 7 lines
2.11.0 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH v6 22/37 mm, hugetlb: switch hugetlbfs to multi-order radix-tree entries
In reply to Kirill A. ShutemovFrom: Naoya Horiguchi <[email protected]>
Currently, hugetlb pages are linked to page cache on the basis of hugepage offset (derived from vma_hugecache_offset()) for historical reason, which doesn't match to the generic usage of page cache and requires some routines to covert page offset <=> hugepage offset in common path. This patch adjusts code for multi-order radix-tree to avoid the situation.
Main change is on the behavior of page->index for hugetlbfs. Before this patch, it represented hugepage offset, but with this patch it represents page offset. So index-related code have to be updated.
Note that hugetlb_fault_mutex_hash() and reservation region handling are still working with hugepage offset.
--- fs/hugetlbfs/inode.c | 22 ++++++++++------------ include/linux/pagemap.h | 23 +++-------------------- mm/filemap.c | 12 +++++------- mm/hugetlb.c | 19 ++++++------------- mm/truncate.c | 8 ++++---- 5 files changed, 28 insertions(+), 56 deletions(-)
fs/hugetlbfs/inode.c +10 -12
@@ -388,8 +388,8 @@ 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 start = lstart >>PAGE_SHIFT ; +const pgoff_t end = lend >>PAGE_SHIFT ;struct vm_area_struct pseudo_vma;struct pagevec pvec;pgoff_t next;
@@ -446,8 +446,7 @@ static void remove_inode_hugepages(struct inode *inode, loff_t lstart,i_mmap_lock_write (mapping);hugetlb_vmdelete_list (&mapping->i_mmap, - next *pages_per_huge_page (h), - (next +1 ) *pages_per_huge_page (h)); + next, next +1 );i_mmap_unlock_write (mapping); }
@@ -466,7 +465,8 @@ static void remove_inode_hugepages(struct inode *inode, loff_t lstart, freed++;if (!truncate_op) {if (unlikely (hugetlb_unreserve_pages (inode, - next, next +1 ,1 ))) + (next) <<huge_page_order (h), + (next +1 ) <<huge_page_order (h),1 )))hugetlb_fix_reserve_counts (inode); }
@@ -550,8 +550,6 @@ static long hugetlbfs_fallocate(struct file *file, int mode, loff_t offset,struct hstate *h =hstate_inode (inode);struct vm_area_struct pseudo_vma;struct mm_struct *mm = current->mm; -loff_t hpage_size =huge_page_size (h); -unsigned long hpage_shift =huge_page_shift (h);pgoff_t start, index, end;int error;u32 hash;
@@ -567,8 +565,8 @@ static long hugetlbfs_fallocate(struct file *file, int mode, loff_t offset,* For this range, start is rounded down and end is rounded up * as well as being converted to page offsets. */ - start = offset >> hpage_shift; - end = (offset + len + hpage_size -1 ) >> hpage_shift; + start = offset >>PAGE_SHIFT ; + end = (offset + len +huge_page_size (h) -1 ) >>PAGE_SHIFT ;inode_lock (inode);
@@ -586,7 +584,7 @@ static long hugetlbfs_fallocate(struct file *file, int mode, loff_t offset, pseudo_vma.vm_flags = (VM_HUGETLB |VM_MAYSHARE |VM_SHARED ); pseudo_vma.vm_file = file; -for (index = start; index < end; index++) { +for (index = start; index < end; index +=pages_per_huge_page (h)) {/* * This is supposed to be the vaddr where the page is being * faulted in, but we have no vaddr here.
@@ -607,10 +605,10 @@ static long hugetlbfs_fallocate(struct file *file, int mode, loff_t offset, }/* Set numa allocation policy based on index */ -hugetlb_set_vma_policy (&pseudo_vma, inode, index); +hugetlb_set_vma_policy (&pseudo_vma, inode, index >>huge_page_order (h));/* addr is the offset within the file (zero based) */ - addr = index * hpage_size; + addr = index <<PAGE_SHIFT & ~huge_page_mask (h);/* mutex taken here, fault path and hole punch */ hash = hugetlb_fault_mutex_hash(h, mm, &pseudo_vma, mapping,
include/linux/pagemap.h +3 -20
@@ -398,10 +398,9 @@ static inline struct page *read_mapping_page(struct address_space *mapping, }/* -* Get index of the page with in radix-tree -* (TODO: remove once hugetlb pages will have ->index in PAGE_SIZE) +* Get the offset in PAGE_SIZE. */ -static inline pgoff_t page_to_index (struct page *page) +static inline pgoff_t page_to_pgoff (struct page *page) {pgoff_t pgoff;
@@ -418,18 +417,6 @@ static inline pgoff_t page_to_index(struct page *page) }/* -* Get the offset in PAGE_SIZE. -* (TODO: hugepage should have ->index in PAGE_SIZE) -*/ -static inline pgoff_t page_to_pgoff (struct page *page) -{ -if (unlikely (PageHeadHuge (page))) -return page->index <<compound_order (page); - -return page_to_index (page); -} - -/* * Return byte-offset into filesystem object for page. */ static inline loff_t page_offset (struct page *page)
@@ -442,15 +429,11 @@ static inline loff_t page_file_offset(struct page *page)return ((loff_t )page_index (page)) <<PAGE_SHIFT ; } -extern pgoff_t linear_hugepage_index (struct vm_area_struct *vma, -unsigned long address); -static inline pgoff_t linear_page_index (struct vm_area_struct *vma,unsigned long address) {pgoff_t pgoff; -if (unlikely (is_vm_hugetlb_page (vma))) -return linear_hugepage_index (vma, address); + pgoff = (address - vma->vm_start) >>PAGE_SHIFT ; pgoff += vma->vm_pgoff;return pgoff;
mm/filemap.c +5 -7
@@ -165,10 +165,7 @@ static void page_cache_tree_delete(struct address_space *mapping, {struct radix_tree_node *node;void **slot; -int nr; - -/* hugetlb pages are represented by one entry in the radix tree */ - nr =PageHuge (page) ?1 :hpage_nr_pages (page); +int nr =hpage_nr_pages (page);VM_BUG_ON_PAGE (!PageLocked (page), page);VM_BUG_ON_PAGE (PageTail (page), page);
@@ -1557,16 +1554,17 @@ unsigned find_get_pages(struct address_space *mapping, pgoff_t start, }/* For multi-order entries, find relevant subpage */ -if (PageTransHuge (page)) { +if (PageCompound (page)) {VM_BUG_ON (index - page->index <0 ); -VM_BUG_ON (index - page->index >=HPAGE_PMD_NR ); +VM_BUG_ON (index - page->index >= +1 <<compound_order (page)); page += index - page->index; } pages[ret] = page;if (++ret == nr_pages)break ; -if (!PageTransCompound (page)) +if (PageHuge (page) || !PageTransCompound (page))continue ; for (refs = 0; ret < nr_pages && (index + 1) % HPAGE_PMD_NR;
mm/hugetlb.c +6 -13
@@ -622,13 +622,6 @@ static pgoff_t vma_hugecache_offset(struct hstate *h, (vma->vm_pgoff >>huge_page_order (h)); } -pgoff_t linear_hugepage_index (struct vm_area_struct *vma, -unsigned long address) -{ -return vma_hugecache_offset (hstate_vma (vma), vma, address); -} -EXPORT_SYMBOL_GPL (linear_hugepage_index); -/* * Return the size of the pages allocated when backing a VMA. In the majority * cases this will be same size as used by the page table entries.
@@ -3605,7 +3598,7 @@ static struct page *hugetlbfs_pagecache_page(struct hstate *h,pgoff_t idx; mapping = vma->vm_file->f_mapping; - idx =vma_hugecache_offset (h, vma, address); + idx =linear_page_index (vma, address);return find_lock_page (mapping, idx); }
@@ -3622,7 +3615,7 @@ static bool hugetlbfs_pagecache_present(struct hstate *h,struct page *page; mapping = vma->vm_file->f_mapping; - idx =vma_hugecache_offset (h, vma, address); + idx =linear_page_index (vma, address); page =find_get_page (mapping, idx);if (page)
@@ -3677,7 +3670,7 @@ static int hugetlb_no_page(struct mm_struct *mm, struct vm_area_struct *vma, retry: page =find_lock_page (mapping, idx);if (!page) { - size =i_size_read (mapping->host) >>huge_page_shift (h); + size =i_size_read (mapping->host) >>PAGE_SHIFT ;if (idx >= size) goto out; page =alloc_huge_page (vma, address,0 );
@@ -3738,7 +3731,7 @@ static int hugetlb_no_page(struct mm_struct *mm, struct vm_area_struct *vma, } ptl =huge_pte_lock (h, mm, ptep); - size =i_size_read (mapping->host) >>huge_page_shift (h); + size =i_size_read (mapping->host) >>PAGE_SHIFT ;if (idx >= size) goto backout;
@@ -3786,7 +3779,7 @@ u32 hugetlb_fault_mutex_hash(struct hstate *h, struct mm_struct *mm,if (vma->vm_flags &VM_SHARED ) { key[0 ] = (unsigned long ) mapping; - key[1 ] = idx; + key[1 ] = idx >>huge_page_order (h); }else { key[0 ] = (unsigned long ) mm; key[1 ] = address >>huge_page_shift (h);
@@ -3842,7 +3835,7 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma, } mapping = vma->vm_file->f_mapping; - idx =vma_hugecache_offset (h, vma, address); + idx =linear_page_index (vma, address);/* * Serialize hugepage allocation and instantiation, so that we don't
mm/truncate.c +4 -4
@@ -310,7 +310,7 @@ void truncate_inode_pages_range(struct address_space *mapping,if (!trylock_page (page))continue ; -WARN_ON (page_to_index (page) != index); +WARN_ON (page_to_pgoff (page) != index);if (PageWriteback (page)) {unlock_page (page);continue ;
@@ -427,7 +427,7 @@ restart: cond_resched(); }lock_page (page); -WARN_ON (page_to_index (page) != index); +WARN_ON (page_to_pgoff (page) != index);wait_on_page_writeback (page);if (PageTransHuge (page)) {
@@ -578,7 +578,7 @@ unsigned long invalidate_mapping_pages(struct address_space *mapping,if (!trylock_page (page))continue ; -WARN_ON (page_to_index (page) != index); +WARN_ON (page_to_pgoff (page) != index);/* Is 'start' or 'end' in the middle of THP ? */ if (PageTransHuge(page) &&
@@ -697,7 +697,7 @@ int invalidate_inode_pages2_range(struct address_space *mapping, }lock_page (page); -WARN_ON (page_to_index (page) != index); +WARN_ON (page_to_pgoff (page) != index);if (page->mapping != mapping) {unlock_page (page);continue ;
Signature · 1 line
2.11.0
PATCH v6 23/37 mm: account huge pages to dirty, writaback, reclaimable, etc.
In reply to Kirill A. ShutemovWe need to account huge pages according to its size to get background writaback work properly.
--- fs/fs-writeback.c | 10 +++--- include/linux/backing-dev.h | 10 ++++++ include/linux/memcontrol.h | 22 ++----------- mm/migrate.c | 1 + mm/page-writeback.c | 80 +++++++++++++++++++++++++++++---------------- mm/rmap.c | 4 +-- 6 files changed, 74 insertions(+), 53 deletions(-)
fs/fs-writeback.c +6 -4
@@ -366,8 +366,9 @@ static void inode_switch_wbs_work_fn(struct work_struct *work)struct page *page =radix_tree_deref_slot_protected (slot, &mapping->tree_lock);if (likely (page) &&PageDirty (page)) { -__dec_wb_stat (old_wb,WB_RECLAIMABLE ); -__inc_wb_stat (new_wb,WB_RECLAIMABLE ); +int nr =hpage_nr_pages (page); +__add_wb_stat (old_wb,WB_RECLAIMABLE , -nr); +__add_wb_stat (new_wb,WB_RECLAIMABLE , nr); } }
@@ -376,9 +377,10 @@ static void inode_switch_wbs_work_fn(struct work_struct *work)struct page *page =radix_tree_deref_slot_protected (slot, &mapping->tree_lock);if (likely (page)) { +int nr =hpage_nr_pages (page);WARN_ON_ONCE (!PageWriteback (page)); -__dec_wb_stat (old_wb,WB_WRITEBACK ); -__inc_wb_stat (new_wb,WB_WRITEBACK ); +__add_wb_stat (old_wb,WB_WRITEBACK , -nr); +__add_wb_stat (new_wb,WB_WRITEBACK , nr); } }
include/linux/backing-dev.h +10 -0
@@ -61,6 +61,16 @@ static inline void __add_wb_stat(struct bdi_writeback *wb,__percpu_counter_add (&wb->stat[item], amount,WB_STAT_BATCH ); } +static inline void add_wb_stat (struct bdi_writeback *wb, +enum wb_stat_item item,s64 amount) +{ +unsigned long flags; + +local_irq_save (flags); +__add_wb_stat (wb, item, amount); +local_irq_restore (flags); +} +static inline void __inc_wb_stat (struct bdi_writeback *wb,enum wb_stat_item item) {
include/linux/memcontrol.h +3 -19
@@ -29,6 +29,7 @@#include <linux/mmzone.h> #include <linux/writeback.h> #include <linux/page-flags.h> +#include <linux/mm.h> struct mem_cgroup ;struct page ;
@@ -517,18 +518,6 @@ static inline void mem_cgroup_update_page_stat(struct page *page,this_cpu_add (page->mem_cgroup->stat->count[idx], val); } -static inline void mem_cgroup_inc_page_stat (struct page *page, -enum mem_cgroup_stat_index idx) -{ -mem_cgroup_update_page_stat (page, idx,1 ); -} - -static inline void mem_cgroup_dec_page_stat (struct page *page, -enum mem_cgroup_stat_index idx) -{ -mem_cgroup_update_page_stat (page, idx,-1 ); -} -unsigned long mem_cgroup_soft_limit_reclaim (pg_data_t *pgdat,int order,gfp_t gfp_mask,unsigned long *total_scanned);
@@ -739,13 +728,8 @@ static inline bool mem_cgroup_oom_synchronize(bool wait)return false; } -static inline void mem_cgroup_inc_page_stat (struct page *page, -enum mem_cgroup_stat_index idx) -{ -} - -static inline void mem_cgroup_dec_page_stat (struct page *page, -enum mem_cgroup_stat_index idx) +static inline void mem_cgroup_update_page_stat (struct page *page, +enum mem_cgroup_stat_index idx,int val) { }
mm/migrate.c +1 -0
@@ -485,6 +485,7 @@ int migrate_page_move_mapping(struct address_space *mapping,* are mapped to swap space. */ if (newzone != oldzone) { +BUG_ON (PageTransHuge (page));__dec_node_state (oldzone->zone_pgdat,NR_FILE_PAGES );__inc_node_state (newzone->zone_pgdat,NR_FILE_PAGES );if (PageSwapBacked (page) && !PageSwapCache (page)) {
mm/page-writeback.c +52 -28
125 lines not on this page · raw message
mm/rmap.c +2 -2
@@ -1154,7 +1154,7 @@ void page_add_file_rmap(struct page *page, bool compound) goto out; }__mod_node_page_state (page_pgdat (page),NR_FILE_MAPPED , nr); -mem_cgroup_inc_page_stat (page,MEM_CGROUP_STAT_FILE_MAPPED ); +mem_cgroup_update_page_stat (page,MEM_CGROUP_STAT_FILE_MAPPED , nr); out:unlock_page_memcg (page); }
@@ -1196,7 +1196,7 @@ static void page_remove_file_rmap(struct page *page, bool compound)* pte lock(a spinlock) is held, which implies preemption disabled. */ __mod_node_page_state (page_pgdat (page),NR_FILE_MAPPED , -nr); -mem_cgroup_dec_page_stat (page,MEM_CGROUP_STAT_FILE_MAPPED ); +mem_cgroup_update_page_stat (page,MEM_CGROUP_STAT_FILE_MAPPED , -nr);if (unlikely (PageMlocked (page)))clear_page_mlock (page);
Signature · 1 line
2.11.0
PATCH v6 24/37 ext4: make ext4_mpage_readpages() hugepage-aware
In reply to Kirill A. ShutemovAs BIO_MAX_PAGES is smaller (on x86) than HPAGE_PMD_NR, we cannot use the optimization ext4_mpage_readpages() provides.
So, for huge pages, we fallback directly to block_read_full_page().
This should be re-visited once we get multipage bvec upstream.
--- fs/ext4/readpage.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/ext4/readpage.c +1 -1
@@ -134,7 +134,7 @@ int ext4_mpage_readpages(struct address_space *mapping, goto next_page; } -if (page_has_buffers (page)) +if (page_has_buffers (page) ||PageTransHuge (page)) goto confused; block_in_file = (sector_t )page->index << (PAGE_SHIFT - blkbits);
Signature · 1 line
2.11.0
PATCH v6 25/37 ext4: make ext4_writepage() work on huge pages
In reply to Kirill A. ShutemovChange ext4_writepage() and underlying ext4_bio_write_page().
It basically removes assumption on page size, infer it from struct page instead.
--- fs/ext4/inode.c | 10 +++++----- fs/ext4/page-io.c | 11 +++++++++-- 2 files changed, 14 insertions(+), 7 deletions(-)
fs/ext4/inode.c +5 -5
@@ -2036,10 +2036,10 @@ static int ext4_writepage(struct page *page,trace_ext4_writepage (page); size =i_size_read (inode); -if (page->index == size >>PAGE_SHIFT ) - len = size & ~PAGE_MASK ; -else - len =PAGE_SIZE ; + + len =hpage_size (page); +if (page->index +hpage_nr_pages (page) -1 == size >>PAGE_SHIFT ) + len = size & ~hpage_mask (page); page_bufs =page_buffers (page);/*
@@ -2063,7 +2063,7 @@ static int ext4_writepage(struct page *page, ext4_bh_delay_or_unwritten)) {redirty_page_for_writepage (wbc, page);if ((current->flags &PF_MEMALLOC ) || - (inode->i_sb->s_blocksize ==PAGE_SIZE )) { + (inode->i_sb->s_blocksize ==hpage_size (page))) {/* * For memory cleaning there's no point in writing only * some buffers. So just bail out. Warn if we came here
fs/ext4/page-io.c +9 -2
@@ -413,6 +413,7 @@ int ext4_bio_write_page(struct ext4_io_submit *io,BUG_ON (!PageLocked (page));BUG_ON (PageWriteback (page)); +BUG_ON (PageTail (page));if (keep_towrite)set_page_writeback_keepwrite (page);
@@ -429,8 +430,14 @@ int ext4_bio_write_page(struct ext4_io_submit *io,* the page size, the remaining memory is zeroed when mapped, and * writes to that region are not written out to the file." */ -if (len <PAGE_SIZE ) -zero_user_segment (page, len,PAGE_SIZE ); +if (len <hpage_size (page)) { + page += len /PAGE_SIZE ; +if (len %PAGE_SIZE ) +zero_user_segment (page, len %PAGE_SIZE ,PAGE_SIZE ); +while (page +1 ==compound_head (page)) +clear_highpage (++page); + page =compound_head (page); + }/* * In the first loop we prepare and mark buffers to submit. We have to * mark all buffers in the page before submitting so that
Signature · 7 lines
2.11.0 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH v6 26/37 ext4: handle huge pages in ext4_page_mkwrite()
In reply to Kirill A. ShutemovTrivial: remove assumption on page size.
--- fs/ext4/inode.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-)
fs/ext4/inode.c +7 -6
@@ -5778,7 +5778,7 @@ static int ext4_bh_unmapped(handle_t *handle, struct buffer_head *bh)int ext4_page_mkwrite (struct vm_area_struct *vma,struct vm_fault *vmf) { -struct page *page = vmf->page; +struct page *page =compound_head (vmf->page);loff_t size;unsigned long len;int ret;
@@ -5814,10 +5814,10 @@ int ext4_page_mkwrite(struct vm_area_struct *vma, struct vm_fault *vmf) goto out; } -if (page->index == size >>PAGE_SHIFT ) - len = size & ~PAGE_MASK ; -else - len =PAGE_SIZE ; + len =hpage_size (page); +if (page->index +hpage_nr_pages (page) -1 == size >>PAGE_SHIFT ) + len = size & ~hpage_mask (page); +/* * Return if we have all the buffers mapped. This avoids the need to do * journal_start/journal_stop which can block and take a long time
@@ -5848,7 +5848,8 @@ int ext4_page_mkwrite(struct vm_area_struct *vma, struct vm_fault *vmf) ret =block_page_mkwrite (vma, vmf, get_block);if (!ret &&ext4_should_journal_data (inode)) {if (ext4_walk_page_buffers (handle,page_buffers (page),0 , -PAGE_SIZE ,NULL , do_journal_get_write_access)) { +hpage_size (page),NULL , + do_journal_get_write_access)) {unlock_page (page); ret =VM_FAULT_SIGBUS ;ext4_journal_stop (handle);
Signature · 1 line
2.11.0
PATCH v6 27/37 ext4: handle huge pages in __ext4_block_zero_page_range()
In reply to Kirill A. ShutemovAs the function handles zeroing range only within one block, the required changes are trivial, just remove assuption on page size.
--- fs/ext4/inode.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
fs/ext4/inode.c +5 -2
@@ -3785,7 +3785,7 @@ static int __ext4_block_zero_page_range(handle_t *handle, struct address_space *mapping, loff_t from, loff_t length) { ext4_fsblk_t index = from >> PAGE_SHIFT; -unsigned offset = from & (PAGE_SIZE -1 ); +unsigned offset;unsigned blocksize, pos;ext4_lblk_t iblock;struct inode *inode = mapping->host;
@@ -3798,6 +3798,9 @@ static int __ext4_block_zero_page_range(handle_t *handle,if (!page)return -ENOMEM ; + page =compound_head (page); + offset = from & ~hpage_mask (page); + blocksize = inode->i_sb->s_blocksize; iblock = index << (PAGE_SHIFT - inode->i_sb->s_blocksize_bits);
@@ -3853,7 +3856,7 @@ static int __ext4_block_zero_page_range(handle_t *handle,if (err) goto unlock; } -zero_user (page, offset, length); +zero_user (page + offset /PAGE_SIZE , offset %PAGE_SIZE , length);BUFFER_TRACE (bh,"zeroed end of block" );if (ext4_should_journal_data (inode)) {
Signature · 1 line
2.11.0
PATCH v6 28/37 ext4: make ext4_block_write_begin() aware about huge pages
In reply to Kirill A. ShutemovIt simply matches changes to __block_write_begin_int().
--- fs/ext4/inode.c | 35 +++++++++++++++++++++-------------- 1 file changed, 21 insertions(+), 14 deletions(-)
fs/ext4/inode.c +21 -14
@@ -1093,9 +1093,8 @@ int do_journal_get_write_access(handle_t *handle,static int ext4_block_write_begin (struct page *page,loff_t pos,unsigned len,get_block_t *get_block) { -unsigned from = pos & (PAGE_SIZE -1 ); -unsigned to = from + len; -struct inode *inode = page->mapping->host; +unsigned from, to; +struct inode *inode =page_mapping (page)->host;unsigned block_start, block_end;sector_t block;int err =0 ;
@@ -1103,10 +1102,14 @@ static int ext4_block_write_begin(struct page *page, loff_t pos, unsigned len,unsigned bbits;struct buffer_head *bh, *head, *wait[2 ], **wait_bh = wait;bool decrypt = false; +bool uptodate =PageUptodate (page); + page =compound_head (page); + from = pos & ~hpage_mask (page); + to = from + len;BUG_ON (!PageLocked (page)); -BUG_ON (from >PAGE_SIZE ); -BUG_ON (to >PAGE_SIZE ); +BUG_ON (from >hpage_size (page)); +BUG_ON (to >hpage_size (page));BUG_ON (from > to);if (!page_has_buffers (page))
@@ -1119,10 +1122,8 @@ static int ext4_block_write_begin(struct page *page, loff_t pos, unsigned len, block++, block_start = block_end, bh = bh->b_this_page) { block_end = block_start + blocksize;if (block_end <= from || block_start >= to) { -if (PageUptodate (page)) { -if (!buffer_uptodate (bh)) -set_buffer_uptodate (bh); - } +if (uptodate && !buffer_uptodate (bh)) +set_buffer_uptodate (bh);continue ; }if (buffer_new (bh))
@@ -1134,19 +1135,25 @@ static int ext4_block_write_begin(struct page *page, loff_t pos, unsigned len,break ;if (buffer_new (bh)) {clean_bdev_bh_alias (bh); -if (PageUptodate (page)) { +if (uptodate) {clear_buffer_new (bh);set_buffer_uptodate (bh);mark_buffer_dirty (bh);continue ; } -if (block_end > to || block_start < from) -zero_user_segments (page, to, block_end, - block_start, from); +if (block_end > to || block_start < from) { +BUG_ON (to - from >PAGE_SIZE ); +zero_user_segments (page + + block_start /PAGE_SIZE , + to %PAGE_SIZE , + (block_start %PAGE_SIZE ) + blocksize, + block_start %PAGE_SIZE , + from %PAGE_SIZE ); + }continue ; } } -if (PageUptodate (page)) { +if (uptodate) {if (!buffer_uptodate (bh))set_buffer_uptodate (bh);continue ;
Signature · 1 line
2.11.0
PATCH v6 29/37 ext4: handle huge pages in ext4_da_write_end()
In reply to Kirill A. ShutemovCall ext4_da_should_update_i_disksize() for head page with offset relative to head page.
--- fs/ext4/inode.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
fs/ext4/inode.c +3 -4
@@ -3019,7 +3019,6 @@ static int ext4_da_write_end(struct file *file,int ret =0 , ret2;handle_t *handle =ext4_journal_current_handle ();loff_t new_i_size; -unsigned long start, end;int write_mode = (int )(unsigned long )fsdata;if (write_mode ==FALL_BACK_TO_NONDELALLOC )
@@ -3027,8 +3026,6 @@ static int ext4_da_write_end(struct file *file, len, copied, page, fsdata);trace_ext4_da_write_end (inode, pos, len, copied); - start = pos & (PAGE_SIZE -1 ); - end = start + copied -1 ;/* * generic_write_end() will run mark_inode_dirty() if i_size
@@ -3037,8 +3034,10 @@ static int ext4_da_write_end(struct file *file,*/ new_i_size = pos + copied;if (copied && new_i_size >EXT4_I (inode)->i_disksize) { +struct page *head =compound_head (page); +unsigned long end = (pos & ~hpage_mask (head)) + copied -1 ;if (ext4_has_inline_data (inode) || -ext4_da_should_update_i_disksize (page, end)) { +ext4_da_should_update_i_disksize (head, end)) {ext4_update_i_disksize (inode, new_i_size);/* We need to mark inode dirty even if * new_i_size is less that inode->i_size
Signature · 1 line
2.11.0
PATCH v6 30/37 ext4: make ext4_da_page_release_reservation() aware about huge pages
In reply to Kirill A. ShutemovFor huge pages 'stop' must be within HPAGE_PMD_SIZE. Let's use hpage_size() in the BUG_ON().
We also need to change how we calculate lblk for cluster deallocation.
--- fs/ext4/inode.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
fs/ext4/inode.c +3 -2
@@ -1571,7 +1571,7 @@ static void ext4_da_page_release_reservation(struct page *page,int num_clusters;ext4_fsblk_t lblk; -BUG_ON (stop >PAGE_SIZE || stop < length); +BUG_ON (stop >hpage_size (page) || stop < length); head =page_buffers (page); bh = head;
@@ -1606,7 +1606,8 @@ static void ext4_da_page_release_reservation(struct page *page,* need to release the reserved space for that cluster. */ num_clusters =EXT4_NUM_B2C (sbi, to_release);while (num_clusters >0 ) { - lblk = (page->index << (PAGE_SHIFT - inode->i_blkbits)) + + lblk = ((page->index + offset /PAGE_SIZE ) << + (PAGE_SHIFT - inode->i_blkbits)) + ((num_clusters -1 ) << sbi->s_cluster_bits);if (sbi->s_cluster_ratio ==1 || !ext4_find_delalloc_cluster (inode, lblk))
Signature · 1 line
2.11.0
PATCH v6 31/37 ext4: handle writeback with huge pages
In reply to Kirill A. ShutemovModify mpage_map_and_submit_buffers() and mpage_release_unused_pages() to deal with huge pages.
Mostly result of try-and-error. Critical view would be appreciated.
--- fs/ext4/inode.c | 61 ++++++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 43 insertions(+), 18 deletions(-)
fs/ext4/inode.c +43 -18
@@ -1665,20 +1665,32 @@ static void mpage_release_unused_pages(struct mpage_da_data *mpd,if (nr_pages ==0 )break ;for (i =0 ; i < nr_pages; i++) { -struct page *page = pvec.pages[i]; +struct page *page =compound_head (pvec.pages[i]); +if (page->index > end)break ;BUG_ON (!PageLocked (page));BUG_ON (PageWriteback (page));if (invalidate) { +unsigned long offset, len; + + offset = (index %hpage_nr_pages (page)); + len = min_t(unsigned long, end - page->index, +hpage_nr_pages (page)); +if (page_mapped (page))clear_page_dirty_for_io (page); -block_invalidatepage (page,0 ,PAGE_SIZE ); +block_invalidatepage (page, offset <<PAGE_SHIFT , + len <<PAGE_SHIFT );ClearPageUptodate (page); }unlock_page (page); +if (PageTransHuge (page)) +break ; } - index = pvec.pages[nr_pages -1 ]->index +1 ; + index =page_to_pgoff (pvec.pages[nr_pages -1 ]) +1 ; +if (PageTransCompound (pvec.pages[nr_pages -1 ])) + index =round_up (index,HPAGE_PMD_NR );pagevec_release (&pvec); } }
@@ -2112,16 +2124,16 @@ static int mpage_submit_page(struct mpage_da_data *mpd, struct page *page)loff_t size =i_size_read (mpd->inode);int err; -BUG_ON (page->index != mpd->first_page); -if (page->index == size >>PAGE_SHIFT ) - len = size & ~PAGE_MASK ; -else - len =PAGE_SIZE ; + page =compound_head (page); + len =hpage_size (page); +if (page->index +hpage_nr_pages (page) -1 == size >>PAGE_SHIFT ) + len = size & ~hpage_mask (page); +clear_page_dirty_for_io (page); err =ext4_bio_write_page (&mpd->io_submit, page, len, mpd->wbc, false);if (!err) - mpd->wbc->nr_to_write--; - mpd->first_page++; + mpd->wbc->nr_to_write -=hpage_nr_pages (page); + mpd->first_page =round_up (mpd->first_page +1 ,hpage_nr_pages (page));return err; }
@@ -2269,12 +2281,16 @@ static int mpage_map_and_submit_buffers(struct mpage_da_data *mpd)break ;for (i =0 ; i < nr_pages; i++) {struct page *page = pvec.pages[i]; +unsigned long diff; -if (page->index > end) +if (page_to_pgoff (page) > end)break ;/* Up to 'end' pages must be contiguous */ -BUG_ON (page->index != start); +BUG_ON (page_to_pgoff (page) != start); + diff = (page -compound_head (page)) << bpp_bits; bh = head =page_buffers (page); +while (diff--) + bh = bh->b_this_page; do { if (lblk < mpd->map.m_lblk) continue;
@@ -2311,7 +2327,10 @@ static int mpage_map_and_submit_buffers(struct mpage_da_data *mpd)* supports blocksize < pagesize as we will try to * convert potentially unmapped parts of inode. */ - mpd->io_submit.io_end->size +=PAGE_SIZE ; +if (PageTransCompound (page)) + mpd->io_submit.io_end->size +=HPAGE_PMD_SIZE ; +else + mpd->io_submit.io_end->size +=PAGE_SIZE ;/* Page fully mapped - let IO run! */ err =mpage_submit_page (mpd, page);if (err <0 ) {
@@ -2319,6 +2338,10 @@ static int mpage_map_and_submit_buffers(struct mpage_da_data *mpd)return err; } start++; +if (PageTransCompound (page)) { + start =round_up (start,HPAGE_PMD_NR ); +break ; + } }pagevec_release (&pvec); }
@@ -2555,7 +2578,7 @@ static int mpage_prepare_extent_to_map(struct mpage_da_data *mpd)* mapping. However, page->index will not change * because we have a reference on the page. */ -if (page->index > end) +if (page_to_pgoff (page) > end) goto out;/*
@@ -2570,7 +2593,7 @@ static int mpage_prepare_extent_to_map(struct mpage_da_data *mpd) goto out;/* If we can't merge this page, we are done. */ -if (mpd->map.m_len >0 && mpd->next_page != page->index) +if (mpd->map.m_len >0 && mpd->next_page !=page_to_pgoff (page)) goto out;lock_page (page);
@@ -2584,7 +2607,7 @@ static int mpage_prepare_extent_to_map(struct mpage_da_data *mpd)if (!PageDirty (page) || (PageWriteback (page) && (mpd->wbc->sync_mode ==WB_SYNC_NONE )) || -unlikely (page->mapping != mapping)) { +unlikely (page_mapping (page) != mapping)) {unlock_page (page);continue ; }
@@ -2593,8 +2616,10 @@ static int mpage_prepare_extent_to_map(struct mpage_da_data *mpd)BUG_ON (PageWriteback (page));if (mpd->map.m_len ==0 ) - mpd->first_page = page->index; - mpd->next_page = page->index +1 ; + mpd->first_page =page_to_pgoff (page); + page =compound_head (page); + mpd->next_page =round_up (page->index +1 , +hpage_nr_pages (page));/* Add all dirty buffers to mpd */ lblk = ((ext4_lblk_t )page->index) << (PAGE_SHIFT - blkbits);
Signature · 1 line
2.11.0
PATCH v6 32/37 ext4: make EXT4_IOC_MOVE_EXT work with huge pages
In reply to Kirill A. ShutemovAdjust how we find relevant block within page and how we clear the required part of the page.
--- fs/ext4/move_extent.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-)
fs/ext4/move_extent.c +9 -3
@@ -210,7 +210,9 @@ mext_page_mkuptodate(struct page *page, unsigned from, unsigned to)return err; }if (!buffer_mapped (bh)) { -zero_user (page, block_start, blocksize); +zero_user (page + block_start /PAGE_SIZE , + block_start %PAGE_SIZE , + blocksize);set_buffer_uptodate (bh);continue ; }
@@ -267,10 +269,11 @@ move_extent_per_page(struct file *o_filp, struct inode *donor_inode,unsigned int tmp_data_size, data_size, replaced_size;int i, err2, jblocks, retries =0 ;int replaced_count =0 ; -int from = data_offset_in_page << orig_inode->i_blkbits; +int from;int blocks_per_page =PAGE_SIZE >> orig_inode->i_blkbits;struct super_block *sb = orig_inode->i_sb;struct buffer_head *bh =NULL ; +int diff;/* * It needs twice the amount of ordinary journal buffers because
@@ -355,6 +358,9 @@ move_extent_per_page(struct file *o_filp, struct inode *donor_inode, goto unlock_pages; } data_copy: + diff = (pagep[0 ] -compound_head (pagep[0 ])) * blocks_per_page; + from = (data_offset_in_page + diff) << orig_inode->i_blkbits; + pagep[0 ] =compound_head (pagep[0 ]); *err =mext_page_mkuptodate (pagep[0 ], from, from + replaced_size);if (*err) goto unlock_pages;
@@ -384,7 +390,7 @@ move_extent_per_page(struct file *o_filp, struct inode *donor_inode,if (!page_has_buffers (pagep[0 ]))create_empty_buffers (pagep[0 ],1 << orig_inode->i_blkbits,0 ); bh =page_buffers (pagep[0 ]); -for (i =0 ; i < data_offset_in_page; i++) +for (i =0 ; i < data_offset_in_page + diff; i++) bh = bh->b_this_page;for (i =0 ; i < block_len_in_page; i++) { *err =ext4_get_block (orig_inode, orig_blk_offset + i, bh,0 );
Signature · 1 line
2.11.0
PATCH v6 33/37 ext4: fix SEEK_DATA/SEEK_HOLE for huge pages
In reply to Kirill A. Shutemovext4_find_unwritten_pgoff() needs few tweaks to work with huge pages. Mostly trivial page_mapping()/page_to_pgoff() and adjustment to how we find relevant block.
--- fs/ext4/file.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-)
fs/ext4/file.c +14 -4
@@ -519,7 +519,7 @@ static int ext4_find_unwritten_pgoff(struct inode *inode,* range, it will be a hole. */ if (lastoff < endoff && whence ==SEEK_HOLE && - page->index > end) { +page_to_pgoff (page) > end) { found =1 ; *offset = lastoff; goto out;
@@ -527,7 +527,7 @@ static int ext4_find_unwritten_pgoff(struct inode *inode,lock_page (page); -if (unlikely (page->mapping != inode->i_mapping)) { +if (unlikely (page_mapping (page) != inode->i_mapping)) {unlock_page (page);continue ; }
@@ -538,8 +538,12 @@ static int ext4_find_unwritten_pgoff(struct inode *inode, }if (page_has_buffers (page)) { +int diff; lastoff =page_offset (page); bh = head =page_buffers (page); + diff = (page -compound_head (page)) << inode->i_blkbits; +while (diff--) + bh = bh->b_this_page; do { if (buffer_uptodate(bh) || buffer_unwritten(bh)) {
@@ -560,8 +564,12 @@ static int ext4_find_unwritten_pgoff(struct inode *inode, }while (bh != head); } - lastoff =page_offset (page) +PAGE_SIZE ; + lastoff =page_offset (page) +hpage_size (page);unlock_page (page); +if (PageTransCompound (page)) { + i++; +break ; + } }/*
@@ -574,7 +582,9 @@ static int ext4_find_unwritten_pgoff(struct inode *inode,break ; } - index = pvec.pages[i -1 ]->index +1 ; + index =page_to_pgoff (pvec.pages[i -1 ]) +1 ; +if (PageTransCompound (pvec.pages[i -1 ])) + index =round_up (index,HPAGE_PMD_NR );pagevec_release (&pvec); }while (index <= end);
Signature · 1 line
2.11.0
PATCH v6 34/37 ext4: make fallocate() operations work with huge pages
In reply to Kirill A. Shutemov__ext4_block_zero_page_range() adjusted to calculate starting iblock correctry for huge pages.
ext4_{collapse,insert}_range() requires page cache invalidation. We need the invalidation to be aligning to huge page border if huge pages are possible in page cache.
--- fs/ext4/extents.c | 10 ++++++++-- fs/ext4/inode.c | 3 +-- 2 files changed, 9 insertions(+), 4 deletions(-)
fs/ext4/extents.c +8 -2
@@ -5501,7 +5501,10 @@ int ext4_collapse_range(struct inode *inode, loff_t offset, loff_t len)* Need to round down offset to be aligned with page size boundary * for page size > block size. */ - ioffset =round_down (offset,PAGE_SIZE ); +if (IS_ENABLED (CONFIG_TRANSPARENT_HUGE_PAGECACHE )) + ioffset =round_down (offset,HPAGE_PMD_SIZE ); +else + ioffset =round_down (offset,PAGE_SIZE );/* * Write tail of the last page before removed range since it will get * removed from the page cache below.
@@ -5650,7 +5653,10 @@ int ext4_insert_range(struct inode *inode, loff_t offset, loff_t len)* Need to round down to align start offset to page size boundary * for page size > block size. */ - ioffset =round_down (offset,PAGE_SIZE ); +if (IS_ENABLED (CONFIG_TRANSPARENT_HUGE_PAGECACHE )) + ioffset =round_down (offset,HPAGE_PMD_SIZE ); +else + ioffset =round_down (offset,PAGE_SIZE );/* Write out all dirty pages */ ret =filemap_write_and_wait_range (inode->i_mapping, ioffset,LLONG_MAX );
fs/ext4/inode.c +1 -2
@@ -3816,7 +3816,6 @@ void ext4_set_aops(struct inode *inode)static int __ext4_block_zero_page_range (handle_t *handle,struct address_space *mapping,loff_t from,loff_t length) { -ext4_fsblk_t index = from >>PAGE_SHIFT ;unsigned offset;unsigned blocksize, pos;ext4_lblk_t iblock;
@@ -3835,7 +3834,7 @@ static int __ext4_block_zero_page_range(handle_t *handle, blocksize = inode->i_sb->s_blocksize; - iblock = index << (PAGE_SHIFT - inode->i_sb->s_blocksize_bits); + iblock = page->index << (PAGE_SHIFT - inode->i_sb->s_blocksize_bits);if (!page_has_buffers (page))create_empty_buffers (page, blocksize,0 );
Signature · 1 line
2.11.0
PATCH v6 35/37 ext4: reserve larger jounral transaction for huge pages
In reply to Kirill A. ShutemovIf huge pages enabled, in worst case with 2048 blocks underlying a page, each possibly in a different block group we have much more metadata to commit.
Let's update estimates accordingly.
I was not able to trigger bad situation without the patch as it's hard to construct very fragmented filesystem, but hopefully this change would be enough to address the concern.
--- fs/ext4/ext4_jbd2.h | 16 +++++++++++++--- fs/ext4/inode.c | 34 +++++++++++++++++++++++++++------- 2 files changed, 40 insertions(+), 10 deletions(-)
fs/ext4/ext4_jbd2.h +13 -3
@@ -353,11 +353,21 @@ static inline int ext4_journal_restart(handle_t *handle, int nblocks)return 0 ; } +static inline int __ext4_journal_blocks_per_page (struct inode *inode,bool thp) +{ +int bpp =0 ; +if (EXT4_JOURNAL (inode) !=NULL ) { + bpp =jbd2_journal_blocks_per_page (inode); +if (thp) + bpp <<=HPAGE_PMD_ORDER ; + } +return bpp; +} +static inline int ext4_journal_blocks_per_page (struct inode *inode) { -if (EXT4_JOURNAL (inode) !=NULL ) -return jbd2_journal_blocks_per_page (inode); -return 0 ; +return __ext4_journal_blocks_per_page (inode, + (inode->i_flags &S_HUGE_MODE ) !=S_HUGE_NEVER ); }static inline int ext4_journal_force_commit (journal_t *journal)
fs/ext4/inode.c +27 -7
@@ -141,6 +141,7 @@ static int __ext4_journalled_writepage(struct page *page, unsigned int len);static int ext4_bh_delay_or_unwritten (handle_t *handle,struct buffer_head *bh);static int ext4_meta_trans_blocks (struct inode *inode,int lblocks,int pextents); +static int __ext4_writepage_trans_blocks (struct inode *inode,int bpp);/* * Test whether an inode is a fast symlink.
@@ -4496,6 +4497,21 @@ void ext4_set_inode_flags(struct inode *inode) !ext4_should_journal_data(inode) && !ext4_has_inline_data(inode) && !ext4_encrypted_inode(inode)) new_fl |=S_DAX ; + +if ((new_fl &S_HUGE_MODE ) !=S_HUGE_NEVER && +EXT4_JOURNAL (inode) !=NULL ) { +int bpp =__ext4_journal_blocks_per_page (inode, true); +int credits =__ext4_writepage_trans_blocks (inode, bpp); + +if (EXT4_JOURNAL (inode)->j_max_transaction_buffers < credits) { +pr_warn_once ("EXT4-fs (%s): " +"journal is too small for huge pages. " +"Disable huge pages support.\n" , + inode->i_sb->s_id); + new_fl &= ~S_HUGE_MODE ; + } + } +inode_set_flags (inode, new_fl,S_SYNC |S_APPEND |S_IMMUTABLE |S_NOATIME |S_DIRSYNC |S_DAX ); }
@@ -5471,6 +5487,16 @@ static int ext4_meta_trans_blocks(struct inode *inode, int lblocks,return ret; } +static int __ext4_writepage_trans_blocks (struct inode *inode,int bpp) +{ +int ret =ext4_meta_trans_blocks (inode, bpp, bpp); + +/* Account for data blocks for journalled mode */ +if (ext4_should_journal_data (inode)) + ret += bpp; +return ret; +} +/* * Calculate the total number of credits to reserve to fit * the modification of a single pages into a single transaction,
@@ -5484,14 +5510,8 @@ static int ext4_meta_trans_blocks(struct inode *inode, int lblocks,int ext4_writepage_trans_blocks (struct inode *inode) {int bpp =ext4_journal_blocks_per_page (inode); -int ret; - - ret =ext4_meta_trans_blocks (inode, bpp, bpp); -/* Account for data blocks for journalled mode */ -if (ext4_should_journal_data (inode)) - ret += bpp; -return ret; +return __ext4_writepage_trans_blocks (inode, bpp); }/*
Signature · 1 line
2.11.0
PATCH v6 36/37 mm, fs, ext4: expand use of page_mapping() and page_to_pgoff()
In reply to Kirill A. ShutemovWith huge pages in page cache we see tail pages in more code paths. This patch replaces direct access to struct page fields with macros which can handle tail pages properly.
--- fs/buffer.c | 2 +- fs/ext4/inode.c | 4 ++-- mm/filemap.c | 24 +++++++++++++----------- mm/memory.c | 2 +- mm/page-writeback.c | 2 +- mm/truncate.c | 5 +++-- 6 files changed, 21 insertions(+), 18 deletions(-)
fs/buffer.c +1 -1
@@ -631,7 +631,7 @@ static void __set_page_dirty(struct page *page, struct address_space *mapping,unsigned long flags;spin_lock_irqsave (&mapping->tree_lock, flags); -if (page->mapping) {/* Race with truncate? */ +if (page_mapping (page)) {/* Race with truncate? */ WARN_ON_ONCE (warn && !PageUptodate (page));account_page_dirtied (page, mapping); radix_tree_tag_set(&mapping->page_tree,
fs/ext4/inode.c +2 -2
@@ -1237,7 +1237,7 @@ static int ext4_write_begin(struct file *file, struct address_space *mapping, }lock_page (page); -if (page->mapping != mapping) { +if (page_mapping (page) != mapping) {/* The page got truncated from under us */ unlock_page (page);put_page (page);
@@ -2975,7 +2975,7 @@ static int ext4_da_write_begin(struct file *file, struct address_space *mapping, }lock_page (page); -if (page->mapping != mapping) { +if (page_mapping (page) != mapping) {/* The page got truncated from under us */ unlock_page (page);put_page (page);
mm/filemap.c +13 -11
@@ -399,7 +399,7 @@ static int __filemap_fdatawait_range(struct address_space *mapping,struct page *page = pvec.pages[i];/* until radix tree lookup accepts end_index */ -if (page->index > end) +if (page_to_pgoff (page) > end)continue ; page =compound_head (page);
@@ -1364,7 +1364,7 @@ struct page *pagecache_get_page(struct address_space *mapping, pgoff_t offset, }/* Has the page been truncated? */ -if (unlikely (page->mapping != mapping)) { +if (unlikely (page_mapping (page) != mapping)) {unlock_page (page);put_page (page); goto repeat;
@@ -1641,7 +1641,8 @@ unsigned find_get_pages_contig(struct address_space *mapping, pgoff_t start,* otherwise we can get both false positives and false * negatives, which is just confusing to the caller. */ -if (page->mapping ==NULL ||page_to_pgoff (page) != index) { +if (page_mapping (page) ==NULL || +page_to_pgoff (page) != index) {put_page (page);break ; }
@@ -1929,7 +1930,7 @@ static ssize_t do_generic_file_read(struct file *filp, loff_t *ppos,if (!trylock_page (page)) goto page_not_up_to_date;/* Did it get truncated before we got the lock? */ -if (!page->mapping) +if (!page_mapping (page)) goto page_not_up_to_date_locked;if (!mapping->a_ops->is_partially_uptodate (page, offset, iter->count))
@@ -2009,7 +2010,7 @@ static ssize_t do_generic_file_read(struct file *filp, loff_t *ppos, page_not_up_to_date_locked:/* Did it get truncated before we got the lock? */ -if (!page->mapping) { +if (!page_mapping (page)) {unlock_page (page);put_page (page);continue ;
@@ -2045,7 +2046,7 @@ static ssize_t do_generic_file_read(struct file *filp, loff_t *ppos,if (unlikely (error)) goto readpage_error;if (!PageUptodate (page)) { -if (page->mapping ==NULL ) { +if (page_mapping (page) ==NULL ) {/* * invalidate_mapping_pages got it */
@@ -2344,12 +2345,12 @@ int filemap_fault(struct vm_area_struct *vma, struct vm_fault *vmf) }/* Did it get truncated? */ -if (unlikely (page->mapping != mapping)) { +if (unlikely (page_mapping (page) != mapping)) {unlock_page (page);put_page (page); goto retry_find; } -VM_BUG_ON_PAGE (page->index != offset, page); +VM_BUG_ON_PAGE (page_to_pgoff (page) != offset, page);/* * We have a locked page in the page cache, now we need to check
@@ -2525,7 +2526,7 @@ int filemap_page_mkwrite(struct vm_area_struct *vma, struct vm_fault *vmf)sb_start_pagefault (inode->i_sb);file_update_time (vma->vm_file);lock_page (page); -if (page->mapping != inode->i_mapping) { +if (page_mapping (page) != inode->i_mapping) {unlock_page (page); ret =VM_FAULT_NOPAGE ; goto out;
@@ -2674,7 +2675,7 @@ static struct page *do_read_cache_page(struct address_space *mapping,lock_page (page);/* Case c or d, restart the operation */ -if (!page->mapping) { +if (!page_mapping (page)) {unlock_page (page);put_page (page); goto repeat;
@@ -3130,12 +3131,13 @@ EXPORT_SYMBOL(generic_file_write_iter);*/ int try_to_release_page (struct page *page,gfp_t gfp_mask) { -struct address_space *const mapping = page->mapping; +struct address_space *const mapping =page_mapping (page);BUG_ON (!PageLocked (page));if (PageWriteback (page))return 0 ; + page =compound_head (page);if (mapping && mapping->a_ops->releasepage)return mapping->a_ops->releasepage (page, gfp_mask);return try_to_free_buffers (page);
mm/memory.c +1 -1
@@ -2049,7 +2049,7 @@ static int do_page_mkwrite(struct vm_fault *vmf)return ret;if (unlikely (!(ret &VM_FAULT_LOCKED ))) {lock_page (page); -if (!page->mapping) { +if (!page_mapping (page)) {unlock_page (page);return 0 ;/* retry */ }
mm/page-writeback.c +1 -1
@@ -2869,7 +2869,7 @@ EXPORT_SYMBOL(mapping_tagged);*/ void wait_for_stable_page (struct page *page) { -if (bdi_cap_stable_pages_required (inode_to_bdi (page->mapping->host))) +if (bdi_cap_stable_pages_required (inode_to_bdi (page_mapping (page)->host)))wait_on_page_writeback (page); }EXPORT_SYMBOL_GPL (wait_for_stable_page);
mm/truncate.c +3 -2
@@ -620,6 +620,7 @@ invalidate_complete_page2(struct address_space *mapping, struct page *page) {unsigned long flags; + page =compound_head (page);if (page->mapping != mapping)return 0 ;
@@ -648,7 +649,7 @@ static int do_launder_page(struct address_space *mapping, struct page *page) {if (!PageDirty (page))return 0 ; -if (page->mapping != mapping || mapping->a_ops->launder_page ==NULL ) +if (page_mapping (page) != mapping || mapping->a_ops->launder_page ==NULL )return 0 ;return mapping->a_ops->launder_page (page); }
@@ -698,7 +699,7 @@ int invalidate_inode_pages2_range(struct address_space *mapping,lock_page (page);WARN_ON (page_to_pgoff (page) != index); -if (page->mapping != mapping) { +if (page_mapping (page) != mapping) {unlock_page (page);continue ; }
Signature · 1 line
2.11.0
PATCH v6 37/37 ext4, vfs: add huge= mount option
In reply to Kirill A. ShutemovThe same four values as in tmpfs case.
Encyption code is not yet ready to handle huge page, so we disable huge pages support if the inode has EXT4_INODE_ENCRYPT.
--- fs/ext4/ext4.h | 5 +++++ fs/ext4/inode.c | 32 +++++++++++++++++++++++--------- fs/ext4/super.c | 24 ++++++++++++++++++++++++ 3 files changed, 52 insertions(+), 9 deletions(-)
fs/ext4/ext4.h +5 -0
@@ -1134,6 +1134,11 @@ struct ext4_inode_info {#define EXT4_MOUNT_DIOREAD_NOLOCK 0x400000/* Enable support for dio read nolocking */ #define EXT4_MOUNT_JOURNAL_CHECKSUM 0x800000/* Journal checksums */ #define EXT4_MOUNT_JOURNAL_ASYNC_COMMIT 0x1000000/* Journal Async Commit */ +#define EXT4_MOUNT_HUGE_MODE 0x6000000/* Huge support mode: */ +#define EXT4_MOUNT_HUGE_NEVER 0x0000000 +#define EXT4_MOUNT_HUGE_ALWAYS 0x2000000 +#define EXT4_MOUNT_HUGE_WITHIN_SIZE 0x4000000 +#define EXT4_MOUNT_HUGE_ADVISE 0x6000000#define EXT4_MOUNT_DELALLOC 0x8000000/* Delalloc support */ #define EXT4_MOUNT_DATA_ERR_ABORT 0x10000000/* Abort on file data write */ #define EXT4_MOUNT_BLOCK_VALIDITY 0x20000000/* Block validity checking */
fs/ext4/inode.c +23 -9
@@ -4481,7 +4481,7 @@ int ext4_get_inode_loc(struct inode *inode, struct ext4_iloc *iloc)void ext4_set_inode_flags (struct inode *inode) {unsigned int flags =EXT4_I (inode)->i_flags; -unsigned int new_fl =0 ; +unsigned int mask, new_fl =0 ;if (flags &EXT4_SYNC_FL ) new_fl |=S_SYNC ;
@@ -4493,11 +4493,25 @@ void ext4_set_inode_flags(struct inode *inode) new_fl |=S_NOATIME ;if (flags &EXT4_DIRSYNC_FL ) new_fl |=S_DIRSYNC ; -if (test_opt (inode->i_sb,DAX ) &&S_ISREG (inode->i_mode) && - !ext4_should_journal_data (inode) && !ext4_has_inline_data (inode) && - !ext4_encrypted_inode (inode)) - new_fl |=S_DAX ; - +if (S_ISREG (inode->i_mode) && !ext4_encrypted_inode (inode)) { +if (test_opt (inode->i_sb,DAX ) && + !ext4_should_journal_data (inode) && + !ext4_has_inline_data (inode)) + new_fl |=S_DAX ; +switch (test_opt (inode->i_sb,HUGE_MODE )) { +case EXT4_MOUNT_HUGE_NEVER : +break ; +case EXT4_MOUNT_HUGE_ALWAYS : + new_fl |=S_HUGE_ALWAYS ; +break ; +case EXT4_MOUNT_HUGE_WITHIN_SIZE : + new_fl |=S_HUGE_WITHIN_SIZE ; +break ; +case EXT4_MOUNT_HUGE_ADVISE : + new_fl |=S_HUGE_ADVISE ; +break ; + } + }if ((new_fl &S_HUGE_MODE ) !=S_HUGE_NEVER &&EXT4_JOURNAL (inode) !=NULL ) {int bpp =__ext4_journal_blocks_per_page (inode, true);
@@ -4511,9 +4525,9 @@ void ext4_set_inode_flags(struct inode *inode) new_fl &= ~S_HUGE_MODE ; } } - -inode_set_flags (inode, new_fl, -S_SYNC |S_APPEND |S_IMMUTABLE |S_NOATIME |S_DIRSYNC |S_DAX ); + mask =S_SYNC |S_APPEND |S_IMMUTABLE |S_NOATIME | +S_DIRSYNC |S_DAX |S_HUGE_MODE ; +inode_set_flags (inode, new_fl, mask); }/* Propagate flags from i_flags to EXT4_I(inode)->i_flags */
fs/ext4/super.c +24 -0
@@ -1296,6 +1296,7 @@ enum { Opt_dioread_nolock, Opt_dioread_lock, Opt_discard, Opt_nodiscard, Opt_init_itable, Opt_noinit_itable, Opt_max_dir_size_kb, Opt_nojournal_checksum, + Opt_huge_never, Opt_huge_always, Opt_huge_within_size, Opt_huge_advise, }; static const match_table_t tokens = {
@@ -1376,6 +1377,10 @@ static const match_table_t tokens = { {Opt_init_itable, "init_itable"}, {Opt_noinit_itable, "noinit_itable"}, {Opt_max_dir_size_kb, "max_dir_size_kb=%u"}, + {Opt_huge_never, "huge=never"}, + {Opt_huge_always, "huge=always"}, + {Opt_huge_within_size, "huge=within_size"}, + {Opt_huge_advise, "huge=advise"}, {Opt_test_dummy_encryption, "test_dummy_encryption"}, {Opt_removed, "check=none"}, /* mount option from ext2/3 */ {Opt_removed, "nocheck"}, /* mount option from ext2/3 */
@@ -1494,6 +1499,11 @@ static int clear_qf_name(struct super_block *sb, int qtype)#define MOPT_NO_EXT3 0x0200#define MOPT_EXT4_ONLY (MOPT_NO_EXT2 | MOPT_NO_EXT3)#define MOPT_STRING 0x0400 +#ifdef CONFIG_TRANSPARENT_HUGE_PAGECACHE +#define MOPT_HUGE 0x1000 +#else +#define MOPT_HUGE MOPT_NOSUPPORT +#endif static const struct mount_opts { int token;
@@ -1581,6 +1591,10 @@ static const struct mount_opts { {Opt_jqfmt_vfsv0, QFMT_VFS_V0, MOPT_QFMT}, {Opt_jqfmt_vfsv1, QFMT_VFS_V1, MOPT_QFMT}, {Opt_max_dir_size_kb, 0, MOPT_GTE0}, + {Opt_huge_never, EXT4_MOUNT_HUGE_NEVER, MOPT_HUGE}, + {Opt_huge_always, EXT4_MOUNT_HUGE_ALWAYS, MOPT_HUGE}, + {Opt_huge_within_size, EXT4_MOUNT_HUGE_WITHIN_SIZE, MOPT_HUGE}, + {Opt_huge_advise, EXT4_MOUNT_HUGE_ADVISE, MOPT_HUGE}, {Opt_test_dummy_encryption, 0, MOPT_GTE0}, {Opt_err, 0, 0} };
@@ -1662,6 +1676,16 @@ static int handle_mount_opt(struct super_block *sb, char *opt, int token, }else return -1 ; } +if (MOPT_HUGE !=MOPT_NOSUPPORT && m->flags &MOPT_HUGE ) { + sbi->s_mount_opt &= ~EXT4_MOUNT_HUGE_MODE ; + sbi->s_mount_opt |= m->mount_opt; +if (m->mount_opt) { +ext4_msg (sb,KERN_WARNING ,"Warning: " +"Support of huge pages is EXPERIMENTAL," +" use at your own risk" ); + } +return 1 ; + }if (m->flags &MOPT_CLEAR_ERR )clear_opt (sb,ERRORS_MASK );if (token == Opt_noquota &&sb_any_quota_loaded (sb)) {
Signature · 7 lines
2.11.0 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Matthew Wilcox
maintainerRe: [PATCHv6 02/37] Revert "radix-tree: implement radix_tree_maybe_preload_order()"
In reply to Kirill A. ShutemovQuoted 4 lines · Kirill A. Shutemov
This reverts commit
356e1c23292a4f63cfdf1daf0e0ddada51f32de8.After conversion of huge tmpfs to multi-order entries, we don't need this anymore.
Yay! Reviewed-by: Matthew Wilcox <[email protected]>
Matthew Wilcox
maintainerRe: [PATCHv6 06/37] thp: handle write-protection faults for file THP
In reply to Kirill A. ShutemovQuoted 5 lines · Kirill A. Shutemov
For filesystems that wants to be write-notified (has mkwrite), we will encount write-protection faults for huge PMDs in shared mappings.
The easiest way to handle them is to clear the PMD and let it refault as wriable.
... of course, the filesystem could implement ->pmd_fault, and then it wouldn't hit this case ...
Re: [PATCHv6 06/37] thp: handle write-protection faults for file THP
Quoted 9 lines · Matthew Wilcox
Quoted 5 lines · Kirill A. Shutemov
For filesystems that wants to be write-notified (has mkwrite), we will encount write-protection faults for huge PMDs in shared mappings.
The easiest way to handle them is to clear the PMD and let it refault as wriable.
... of course, the filesystem could implement ->pmd_fault, and then it wouldn't hit this case ...
I would rather get rid of ->pmd_fault/->huge_fault :)
->fault should be flexible enough to provide for all of them...
Signature · 7 lines
Kirill A. Shutemov -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Matthew Wilcox
maintainerRe: [PATCHv6 01/37] mm, shmem: swich huge tmpfs to multi-order radix-tree entries
In reply to Kirill A. Shutemovinclude/linux/pagemap.h static inline struct page *grab_cache_page_nowait(struct address_space *mapping, · line 342
Quoted 13 lines · Kirill A. Shutemov
+++
b/include/linux/pagemap.hinclude/linux/pagemap.h +8
-0@@ -332,6 +332,15 @@ static inline struct page *grab_cache_page_nowait(struct address_space *mapping, mapping_gfp_mask(mapping)); } +static inline struct page *find_subpage (struct page *page,pgoff_t offset) +{ +VM_BUG_ON_PAGE (PageTail (page), page); +VM_BUG_ON_PAGE (page->index > offset, page); +VM_BUG_ON_PAGE (page->index + (1 <<compound_order (page)) < offset, + page); +return page - page->index + offset; +}
What would you think to:
static inline void check_page_index(struct page *page, pgoff_t offset)
{
VM_BUG_ON_PAGE(PageTail(page), page);
VM_BUG_ON_PAGE(page->index > offset, page);
VM_BUG_ON_PAGE(page->index + (1 << compound_order(page)) <= offset,
page);
}(I think I fixed an off-by-one error up there ... if index + (1 << order) == offset, this is also a bug, right? because offset would then refer to the next page, not this page)
static inline struct page *find_subpage(struct page *page, pgoff_t offset)
{
check_page_index(page, offset);
return page + (offset - page->index);
}... then you can use check_page_index down ...
mm/filemap.c struct page *find_lock_entry(struct address_space *mapping, pgoff_t offset) · line 1253
Quoted 5 lines
mm/filemap.c +0
-1@@ -1250,7 +1233,6 @@ struct page *find_lock_entry(struct address_space *mapping, pgoff_t offset)put_page (page); goto repeat; } -VM_BUG_ON_PAGE (page_to_pgoff (page) != offset, page);
... here?
mm/filemap.c unsigned find_get_pages(struct address_space *mapping, pgoff_t start, · line 1459
Quoted 10 lines
mm/filemap.c +6
-0@@ -1472,25 +1451,35 @@ unsigned find_get_pages(struct address_space *mapping, pgoff_t start, goto repeat; } +/* For multi-order entries, find relevant subpage */ +if (PageTransHuge (page)) { +VM_BUG_ON (index - page->index <0 ); +VM_BUG_ON (index - page->index >=HPAGE_PMD_NR ); + page += index - page->index; + }
Use find_subpage() here?
mm/filemap.c unsigned find_get_pages(struct address_space *mapping, pgoff_t start, · line 1482
Quoted 13 lines
mm/filemap.c +10
-0pages[ret] = page;if (++ret == nr_pages)break ; +if (!PageTransCompound (page)) +continue ; +for (refs =0 ; ret < nr_pages && + (index +1 ) %HPAGE_PMD_NR ; + ret++, refs++, index++) + pages[ret] = ++page; +if (refs) +page_ref_add (compound_head (page), refs); +if (ret == nr_pages) +break ;
Can we avoid referencing huge pages specifically in the page cache? I'd like us to get to the point where we can put arbitrary compound pages into the page cache. For example, I think this can be written as:
if (!PageCompound(page))
continue;
for (refs = 0; ret < nr_pages; refs++, index++) {
if (index > page->index + (1 << compound_order(page)))
break;
pages[ret++] = ++page;
}
if (refs)
page_ref_add(compound_head(page), refs);
if (ret == nr_pages)
break;Quoted 15 lines
mm/filemap.c +10
-0@@ -1541,19 +1533,12 @@ unsigned find_get_pages_contig(struct address_space *mapping, pgoff_t index, +/* For multi-order entries, find relevant subpage */ +if (PageTransHuge (page)) { +VM_BUG_ON (index - page->index <0 ); +VM_BUG_ON (index - page->index >=HPAGE_PMD_NR ); + page += index - page->index; + } + pages[ret] = page;if (++ret == nr_pages)break ; +if (!PageTransCompound (page)) +continue ; + for (refs = 0; ret < nr_pages &&
mm/filemap.c unsigned find_get_pages_contig(struct address_space *mapping, pgoff_t index, · line 1577
Quoted 10 lines
mm/filemap.c +7
-0+ (index +1 ) %HPAGE_PMD_NR ; + ret++, refs++, index++) + pages[ret] = ++page; +if (refs) +page_ref_add (compound_head (page), refs); +if (ret == nr_pages) +break ; }rcu_read_unlock ();return ret;
Ugh, the same code again. Hmm ... we only need to modify 'ret' as a result of this ... so could we split it out like this?
static unsigned populate_pages(struct page **pages, unsigned i, unsigned max,
struct page *page)
{
unsigned refs = 0;
for (;;) {
pages[i++] = page;
if (i == max)
break;
if (PageHead(page + 1))
break;
page++;
refs++;
}
if (refs)
page_ref_add(compound_head(page), refs);
return i;
}Quoted 5 lines
mm/filemap.c +2
-0+unsigned find_get_pages_tag(struct address_space *mapping, pgoff_t *indexp, int tag, unsigned int nr_pages, struct page **pages) break; +if (!PageTransCompound (page))
mm/filemap.c unsigned find_get_pages(struct address_space *mapping, pgoff_t start, · line 1483
Quoted 10 lines
mm/filemap.c +9
-0+continue ; +for (refs =0 ; ret < nr_pages && + (index +1 ) %HPAGE_PMD_NR ; + ret++, refs++, index++) + pages[ret] = ++page; +if (refs) +page_ref_add (compound_head (page), refs); +if (ret == nr_pages) +break ; }
... and again!
mm/filemap.c void filemap_map_pages(struct vm_fault *vmf, · line 2345
Quoted 10 lines
mm/filemap.c +7
-0@@ -2326,25 +2337,26 @@ void filemap_map_pages(struct vm_fault *vmf, +/* For multi-order entries, find relevant subpage */ +if (PageTransHuge (page)) { +VM_BUG_ON (index - page->index <0 ); +VM_BUG_ON (index - page->index >=HPAGE_PMD_NR ); + page += index - page->index; + } + if (!PageUptodate(page) || PageReadahead(page) ||
Readahead is PF_NO_COMPOUND ... so I don't see why this works?
mm/filemap.c void filemap_map_pages(struct vm_fault *vmf, · line 2399
Quoted 12 lines
mm/filemap.c +6
-1@@ -2378,8 +2390,14 @@ void filemap_map_pages(struct vm_fault *vmf,/* Huge page is mapped? No need to proceed. */ if (pmd_trans_huge (*vmf->pmd))break ; -if (iter.index == end_pgoff) +if (index == end_pgoff)break ; +if (page &&PageTransCompound (page) && + (index & (HPAGE_PMD_NR -1 )) != +HPAGE_PMD_NR -1 ) { + index++; + goto repeat;
Do we really have to go all the way back to the beginning of the loop? It'd be nice to be able to insert all of the relevant PTEs in a shorter loop here. We'd need to bump the reference count N more times, and I think we do need to check HWPoison for each subpage.
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Matthew Wilcox
maintainerRe: [PATCHv6 03/37] page-flags: relax page flag policy for few flags
In reply to Kirill A. ShutemovQuoted 2 lines · Kirill A. Shutemov
These flags are in use for filesystems with backing storage:
PG_error,PG_writebackandPG_readahead.
Oh ;-) Then I amend my comment on patch 1 to be "patch 3 needs to go ahead of patch 1" ;-)
Quoted 46 lines
Signed-off-by Kirill A. Shutemov <[email protected]>--- include/linux/page-flags.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)include/linux/page-flags.h +5
-5@@ -263,7 +263,7 @@ static inline int TestClearPage##uname(struct page *page) { return 0; } __PAGEFLAG(Locked, locked, PF_NO_TAIL) PAGEFLAG(Waiters, waiters, PF_ONLY_HEAD) __CLEARPAGEFLAG(Waiters, waiters, PF_ONLY_HEAD) -PAGEFLAG(Error, error, PF_NO_COMPOUND) TESTCLEARFLAG(Error, error, PF_NO_COMPOUND) +PAGEFLAG(Error, error, PF_NO_TAIL) TESTCLEARFLAG(Error, error, PF_NO_TAIL) PAGEFLAG(Referenced, referenced, PF_HEAD) TESTCLEARFLAG(Referenced, referenced, PF_HEAD)__SETPAGEFLAG (Referenced, referenced,PF_HEAD )@@ -303,15 +303,15 @@ PAGEFLAG(OwnerPriv1, owner_priv_1, PF_ANY)* Only test-and-set exist for PG_writeback. The unconditional operators are * risky: they bypass page accounting. */ -TESTPAGEFLAG(Writeback, writeback, PF_NO_COMPOUND) - TESTSCFLAG(Writeback, writeback, PF_NO_COMPOUND) +TESTPAGEFLAG(Writeback, writeback, PF_NO_TAIL) + TESTSCFLAG(Writeback, writeback, PF_NO_TAIL)PAGEFLAG (MappedToDisk, mappedtodisk,PF_NO_TAIL ) /* PG_readahead is only used for reads; PG_reclaim is only for writes */ PAGEFLAG(Reclaim, reclaim, PF_NO_TAIL) TESTCLEARFLAG(Reclaim, reclaim, PF_NO_TAIL) -PAGEFLAG(Readahead, reclaim, PF_NO_COMPOUND) - TESTCLEARFLAG(Readahead, reclaim, PF_NO_COMPOUND) +PAGEFLAG(Readahead, reclaim, PF_NO_TAIL) + TESTCLEARFLAG(Readahead, reclaim, PF_NO_TAIL)#ifdef CONFIG_HIGHMEM /* Signature · 7 lines
2.11.0 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCHv6 01/37] mm, shmem: swich huge tmpfs to multi-order radix-tree entries
In reply to Matthew WilcoxQuoted 25 lines · Matthew Wilcox
include/linux/pagemap.h static inline struct page *grab_cache_page_nowait(struct address_space *mapping, · line 342
Quoted 13 lines · Kirill A. Shutemov
+++
b/include/linux/pagemap.hinclude/linux/pagemap.h +8
-0@@ -332,6 +332,15 @@ static inline struct page *grab_cache_page_nowait(struct address_space *mapping, mapping_gfp_mask(mapping)); } +static inline struct page *find_subpage (struct page *page,pgoff_t offset) +{ +VM_BUG_ON_PAGE (PageTail (page), page); +VM_BUG_ON_PAGE (page->index > offset, page); +VM_BUG_ON_PAGE (page->index + (1 <<compound_order (page)) < offset, + page); +return page - page->index + offset; +}What would you think to:
static inline void
check_page_index(struct page *page, pgoff_t offset){ VM_BUG_ON_PAGE(PageTail(page), page); VM_BUG_ON_PAGE(page->index > offset, page); VM_BUG_ON_PAGE(page->index + (1 << compound_order(page)) <= offset, page); }
Quoted 3 lines
(I think I fixed an off-by-one error up there ... if index + (1 << order) == offset, this is also a bug, right? because offset would then refer to the next page, not this page)
Right, thanks.
Quoted 8 lines
static inline struct page *find_subpage(struct page *page,
pgoff_toffset){ check_page_index(page, offset); return page + (offset - page->index); }... then you can use
check_page_indexdown ...
Okay, makes sense.
Quoted 8 lines
mm/filemap.c struct page *find_lock_entry(struct address_space *mapping, pgoff_t offset) · line 1253
Quoted 6 lines
mm/filemap.c +0
-1@@ -1250,7 +1233,6 @@ struct page *find_lock_entry(struct address_space *mapping, pgoff_t offset)put_page (page); goto repeat; } -VM_BUG_ON_PAGE (page_to_pgoff (page) != offset, page);... here?
Ok.
Quoted 4 lines
Quoted 4 lines
mm/filemap.c +0
-0@@ -1472,25 +1451,35 @@ unsigned find_get_pages(struct address_space *mapping, pgoff_t start, goto repeat; }
Quoted 8 lines
mm/filemap.c unsigned find_get_pages(struct address_space *mapping, pgoff_t start, · line 1468
Quoted 6 lines
mm/filemap.c +6
-0+/* For multi-order entries, find relevant subpage */ +if (PageTransHuge (page)) { +VM_BUG_ON (index - page->index <0 ); +VM_BUG_ON (index - page->index >=HPAGE_PMD_NR ); + page += index - page->index; + }Use
find_subpage()here?
Ok.
Quoted 18 lines
mm/filemap.c unsigned find_get_pages(struct address_space *mapping, pgoff_t start, · line 1482
Quoted 13 lines
mm/filemap.c +10
-0pages[ret] = page;if (++ret == nr_pages)break ; +if (!PageTransCompound (page)) +continue ; +for (refs =0 ; ret < nr_pages && + (index +1 ) %HPAGE_PMD_NR ; + ret++, refs++, index++) + pages[ret] = ++page; +if (refs) +page_ref_add (compound_head (page), refs); +if (ret == nr_pages) +break ;Can we avoid referencing huge pages specifically in the page cache? I'd like us to get to the point where we can put arbitrary compound pages into the page cache. For example, I think this can be written as:
Quoted 11 lines
if (!PageCompound(page))
continue;
for (refs = 0; ret < nr_pages; refs++, index++) {
if (index > page->index + (1 << compound_order(page)))
break;
pages[ret++] = ++page;
}
if (refs)
page_ref_add(compound_head(page), refs);
if (ret == nr_pages)
break;That's slightly more costly, but I guess that's fine.
Quoted 31 lines
Quoted 15 lines
mm/filemap.c +10
-0@@ -1541,19 +1533,12 @@ unsigned find_get_pages_contig(struct address_space *mapping, pgoff_t index, +/* For multi-order entries, find relevant subpage */ +if (PageTransHuge (page)) { +VM_BUG_ON (index - page->index <0 ); +VM_BUG_ON (index - page->index >=HPAGE_PMD_NR ); + page += index - page->index; + } + pages[ret] = page;if (++ret == nr_pages)break ; +if (!PageTransCompound (page)) +continue ; + for (refs = 0; ret < nr_pages &&mm/filemap.c unsigned find_get_pages_contig(struct address_space *mapping, pgoff_t index, · line 1577
Quoted 10 lines
mm/filemap.c +7
-0+ (index +1 ) %HPAGE_PMD_NR ; + ret++, refs++, index++) + pages[ret] = ++page; +if (refs) +page_ref_add (compound_head (page), refs); +if (ret == nr_pages) +break ; }rcu_read_unlock ();return ret;Ugh, the same code again. Hmm ... we only need to modify 'ret' as a result of this ... so could we split it out like this?
static unsigned populate_pages(struct page **pages, unsigned i, unsigned max,
struct page *page)
Quoted 8 lines
{
unsigned refs = 0;
for (;;) {
pages[i++] = page;
if (i == max)
break;
if (PageHead(page + 1))
break;Hm? PageHead()? No. The next page can head or small.
I *guess* we can get away with !PageTail(page + 1)...
Quoted 26 lines
page++; refs++; } if (refs) page_ref_add(compound_head(page), refs); return i; }Quoted 5 lines
mm/filemap.c +2
-0+unsigned find_get_pages_tag(struct address_space *mapping, pgoff_t *indexp, int tag, unsigned int nr_pages, struct page **pages) break; +if (!PageTransCompound (page))mm/filemap.c unsigned find_get_pages(struct address_space *mapping, pgoff_t start, · line 1483
Quoted 10 lines
mm/filemap.c +9
-0+continue ; +for (refs =0 ; ret < nr_pages && + (index +1 ) %HPAGE_PMD_NR ; + ret++, refs++, index++) + pages[ret] = ++page; +if (refs) +page_ref_add (compound_head (page), refs); +if (ret == nr_pages) +break ; }... and again!
Quoted 12 lines
mm/filemap.c void filemap_map_pages(struct vm_fault *vmf, · line 2345
Quoted 10 lines
mm/filemap.c +7
-0@@ -2326,25 +2337,26 @@ void filemap_map_pages(struct vm_fault *vmf, +/* For multi-order entries, find relevant subpage */ +if (PageTransHuge (page)) { +VM_BUG_ON (index - page->index <0 ); +VM_BUG_ON (index - page->index >=HPAGE_PMD_NR ); + page += index - page->index; + } + if (!PageUptodate(page) || PageReadahead(page) ||Readahead is
PF_NO_COMPOUND... so I don't see why this works?
We wouldn't see pages with readahead flag set/cleared until huge pages support in ext4 is enabled at very end of the patchset.
Quoted 10 lines
Quoted 10 lines
mm/filemap.c +3
-1@@ -2378,8 +2390,14 @@ void filemap_map_pages(struct vm_fault *vmf,/* Huge page is mapped? No need to proceed. */ if (pmd_trans_huge (*vmf->pmd))break ; -if (iter.index == end_pgoff) +if (index == end_pgoff)break ; +if (page &&PageTransCompound (page) && + (index & (HPAGE_PMD_NR - 1)) !=
Quoted 8 lines
mm/filemap.c void filemap_map_pages(struct vm_fault *vmf, · line 2399
Quoted 3 lines
mm/filemap.c +3
-0+ HPAGE_PMD_NR - 1) { + index++; + goto repeat;Do we really have to go all the way back to the beginning of the loop? It'd be nice to be able to insert all of the relevant PTEs in a shorter loop here. We'd need to bump the reference count N more times, and I think we do need to check HWPoison for each subpage.
I'll look into it.
Thanks for review.
Signature · 7 lines
Kirill A. Shutemov -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCHv6 05/37] thp: try to free page's buffers before attempt split
In reply to Kirill A. Shutemovmm/huge_memory.c int split_huge_page_to_list(struct page *page, struct list_head *list) · line 2156
Quoted 12 lines · Kirill A. Shutemov
mm/huge_memory.c +8
-0@@ -2146,6 +2146,23 @@ int split_huge_page_to_list(struct page *page, struct list_head *list) goto out; } +/* Try to free buffers before attempt split */ +if (!PageSwapBacked (head) &&PagePrivate (page)) { +/* +* We cannot trigger writeback from here due possible +* recursion if triggered from vmscan, only wait. +* +* Caller can trigger writeback it on its own, if safe. +*/
It took me a few reads to get this. May I suggest:
/*
* Cannot split a page with buffers. If the caller has
* already started writeback, we can wait for it to finish,
* but we cannot start writeback if we were called from vmscan */
mm/huge_memory.c int split_huge_page_to_list(struct page *page, struct list_head *list) · line 2150
Quoted 1 line
mm/huge_memory.c +1
-0+if (!PageSwapBacked (head) &&PagePrivate (page)) {
Also, it looks weird to test PageSwapBacked of *head* and PagePrivate of *page*. I think it's correct, but it still looks weird.
Re: [PATCHv6 04/37] mm, rmap: account file thp pages
In reply to Kirill A. ShutemovQuoted 4 lines · Kirill A. Shutemov
Let's add FileHugePages and FilePmdMapped fields into meminfo and smaps. It indicates how many times we allocate and map file THP.
Signed-off-by Kirill A. Shutemov <[email protected]>
Re: [PATCHv6 06/37] thp: handle write-protection faults for file THP
In reply to Kirill A. ShutemovQuoted 8 lines · Kirill A. Shutemov
For filesystems that wants to be write-notified (has mkwrite), we will encount write-protection faults for huge PMDs in shared mappings.
The easiest way to handle them is to clear the PMD and let it refault as wriable.
Signed-off-by Kirill A. Shutemov <[email protected]>Reviewed-by Jan Kara <[email protected]>
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCHv6 07/37] filemap: allocate huge page in page_cache_read(), if allowed
In reply to Kirill A. ShutemovQuoted 2 lines · Kirill A. Shutemov
Later we can add logic to accumulate information from shadow entires to return to caller (average eviction time?).
I would say minimum rather than average. That will become the refault time of the entire page, so minimum would probably have us making better decisions?
mm/filemap.c line 128
Quoted 10 lines
mm/filemap.c +7
-1+/* Wipe shadow entires */ +radix_tree_for_each_slot (slot, &mapping->page_tree, &iter, + page->index) { +if (iter.index >= page->index +hpage_nr_pages (page)) +break ; p =radix_tree_deref_slot_protected (slot, &mapping->tree_lock); -if (!radix_tree_exceptional_entry (p)) +if (!p) +continue ;
Just FYI, this can't happen. You're holding the tree lock so nobody else gets to remove things from the tree. radix_tree_for_each_slot() only gives you the full slots; it skips the empty ones for you. I'm OK if you want to leave it in out of an abundance of caution.
mm/filemap.c line 134
Quoted 2 lines
mm/filemap.c +2
-0+__radix_tree_replace (&mapping->page_tree, iter.node, slot,NULL , + workingset_update_node, mapping);
I may add an update_node argument to radix_tree_join at some point, so you can use it here. Or maybe we don't need to do that, and what you have here works just fine.
Quoted 1 line
mapping->nrexceptional--;
... because adjusting the exceptional count is going to be a pain.
mm/filemap.c line 153
Quoted 5 lines
mm/filemap.c +5
-0+ error =__radix_tree_insert (&mapping->page_tree, + page->index,compound_order (page), page); +/* This shouldn't happen */ +if (WARN_ON_ONCE (error)) +return error;
A lesser man would have just ignored the return value from __radix_tree_insert. I salute you.
Quoted 28 lines
mm/filemap.c +15
-3@@ -2078,18 +2155,34 @@ static int page_cache_read(struct file *file, pgoff_t offset, gfp_t gfp_mask) {struct address_space *mapping = file->f_mapping;struct page *page; +pgoff_t hoffset;int ret; do { - page = __page_cache_alloc(gfp_mask|__GFP_COLD); + page = page_cache_alloc_huge(mapping, offset, gfp_mask); +no_huge: + if (!page) + page = __page_cache_alloc(gfp_mask|__GFP_COLD); if (!page) return -ENOMEM; - ret = add_to_page_cache_lru(page, mapping, offset, gfp_mask & GFP_KERNEL); - if (ret == 0) + if (PageTransHuge(page)) + hoffset = round_down(offset, HPAGE_PMD_NR); + else + hoffset = offset; + + ret = add_to_page_cache_lru(page, mapping, hoffset, + gfp_mask & GFP_KERNEL); + + if (ret == -EEXIST && PageTransHuge(page)) { + put_page(page);
mm/filemap.c static int page_cache_read(struct file *file, pgoff_t offset, gfp_t gfp_mask) · line 2187
Quoted 10 lines
mm/filemap.c +5
-1+ page =NULL ; + goto no_huge; + }else if (ret ==0 ) { ret = mapping->a_ops->readpage (file, page); - else if (ret == -EEXIST) + }else if (ret == -EEXIST ) { ret =0 ;/* losing race to add is OK */ + }put_page (page);
If the filesystem returns AOP_TRUNCATED_PAGE, you'll go round this loop again trying the huge page again, even if the huge page didn't work the first time. I would tend to think that if the huge page failed the first time, we shouldn't try it again, so I propose this:
struct address_space *mapping = file->f_mapping;
struct page *page;
pgoff_t index;
int ret;
bool try_huge = true;
do {
if (try_huge) {
page = page_cache_alloc_huge(gfp_mask|__GFP_COLD);
if (page)
index = round_down(offset, HPAGE_PMD_NR);
else
try_huge = false;
}
if (!try_huge) {
page = __page_cache_alloc(gfp_mask|__GFP_COLD);
index = offset;
}
if (!page)
return -ENOMEM;
ret = add_to_page_cache_lru(page, mapping, index,
gfp_mask & GFP_KERNEL);
if (ret < 0) {
if (try_huge) {
try_huge = false;
ret = AOP_TRUNCATED_PAGE;
} else if (ret == -EEXIST)
ret = 0; /* losing race to add is OK */
} else {
ret = mapping->a_ops->readpage(file, page);
}
put_page(page);
} while (ret == AOP_TRUNCATED_PAGE);But ... maybe it's OK to retry the huge page. I mean, not many filesystems return AOP_TRUNCATED_PAGE, and they only do so rarely.
Anyway, I'm fine with the patch going in as-is. I just wanted to type out my review notes.
Matthew Wilcox
maintainerRe: [PATCHv6 08/37] filemap: handle huge pages in do_generic_file_read()
In reply to Kirill A. Shutemovmm/filemap.c static ssize_t do_generic_file_read(struct file *filp, loff_t *ppos, · line 1889
Quoted 6 lines · Kirill A. Shutemov
+++
b/mm/filemap.cmm/filemap.c +1
-0@@ -1886,6 +1886,7 @@ static ssize_t do_generic_file_read(struct file *filp, loff_t *ppos,if (unlikely (page ==NULL )) goto no_cached_page; } + page =compound_head (page);
We got this page from find_get_page(), which gets it from pagecache_get_page(), which gets it from find_get_entry() ... which (unless I'm lost in your patch series) returns the head page. So this line is redundant, right?
But then down in filemap_fault, we have:
VM_BUG_ON_PAGE(page->index != offset, page);
... again, maybe I'm lost somewhere in your patch series, but I don't see anywhere you remove that line (or modify it). So are you not testing with VM debugging enabled, or are you not doing a test which includes mapping a file with huge pages, reading from it (to get the page in cache), then faulting on an address that is not in the first 4kB of that 2MB?
Re: [PATCHv6 09/37] filemap: allocate huge page in pagecache_get_page(), if allowed
In reply to Kirill A. ShutemovQuoted 5 lines · Kirill A. Shutemov
Write path allocate pages using
pagecache_get_page(). We should be able to allocate huge pages there, if it's allowed. As usually, fallback to small pages, if failed.Signed-off-by Kirill A. Shutemov <[email protected]>
Matthew Wilcox
maintainerRe: [PATCHv6 10/37] filemap: handle huge pages in filemap_fdatawait_range()
In reply to Kirill A. Shutemovmm/filemap.c static int __filemap_fdatawait_range(struct address_space *mapping, · line 416
Quoted 13 lines · Kirill A. Shutemov
mm/filemap.c +5
-0@@ -405,9 +405,14 @@ static int __filemap_fdatawait_range(struct address_space *mapping,if (page->index > end)continue ; + page =compound_head (page);wait_on_page_writeback (page);if (TestClearPageError (page)) ret = -EIO ; +if (PageTransHuge (page)) { + index = page->index +HPAGE_PMD_NR ; + i += index - pvec.pages[i]->index -1 ; + } }
I'm really not sure about your decision to have some interfaces expose subpages and other expose huge pages. I think I'd be happier to see all the existing interfaces made to continue exposing subpages, then start adding in new interfaces and converting users one at a time to use them. For example here, we'd add find_get_huge_pages_tag(), then pagevec_lookup_huge_tag(), and switch this function from calling pagevec_lookup_tag() to calling pagevec_lookup_huge_tag() ... then this function is done; there's no messing around with calling compound_head or PageTransHuge.
My dream is that eventually all callers will be able to cope with getting a compound page back from the page cache and we can delete the versions that return subpages, and rename the 'huge_' variations.
Matthew Wilcox
maintainerRe: [PATCHv6 11/37] HACK: readahead: alloc huge pages, if allowed
In reply to Kirill A. ShutemovQuoted 14 lines · Kirill A. Shutemov
Most page cache allocation happens via readahead (sync or async), so if we want to have significant number of huge pages in page cache we need to find a ways to allocate them from readahead.
Unfortunately, huge pages doesn't fit into current readahead design:
128 max readahead window, assumption on page size,PageReadahead()to track hit/miss.I haven't found a ways to get it right yet.
This patch just allocates huge page if allowed, but doesn't really provide any readahead if huge page is allocated. We read out 2M a time and I would expect spikes in latancy without readahead.
Quoted 7 lines
Therefore HACK.
Having that said, I don't think it should prevent huge page support to be applied. Future will show if lacking readahead is a big deal with huge pages in page cache.
Any suggestions are welcome.
Well ... what if we made readahead 2 hugepages in size for inodes which are using huge pages? That's only 8x our current readahead window, and if you're asking for hugepages, you're accepting that IOs are going to be larger, and you probably have the kind of storage system which can handle doing larger IOs.
Re: [PATCHv6 11/37] HACK: readahead: alloc huge pages, if allowed
Quoted 22 lines · Matthew Wilcox
Quoted 20 lines · Kirill A. Shutemov
Most page cache allocation happens via readahead (sync or async), so if we want to have significant number of huge pages in page cache we need to find a ways to allocate them from readahead.
Unfortunately, huge pages doesn't fit into current readahead design:
128 max readahead window, assumption on page size,PageReadahead()to track hit/miss.I haven't found a ways to get it right yet.
This patch just allocates huge page if allowed, but doesn't really provide any readahead if huge page is allocated. We read out 2M a time and I would expect spikes in latancy without readahead.
Therefore HACK.
Having that said, I don't think it should prevent huge page support to be applied. Future will show if lacking readahead is a big deal with huge pages in page cache.
Quoted 7 lines
Quoted 1 line
Any suggestions are welcome.
Well ... what if we made readahead 2 hugepages in size for inodes which are using huge pages? That's only 8x our current readahead window, and if you're asking for hugepages, you're accepting that IOs are going to be larger, and you probably have the kind of storage system which can handle doing larger IOs.
It would be nice if the bdi had a parameter for the maximum readahead size. Currently, readahead is capped at 2MB chunks by force_page_cache_readahead() even if bdi->ra_pages and bdi->io_pages are much larger.
It should be up to the filesystem to decide how large the readahead chunks are rather than imposing some policy in the MM code. For high-speed (network) storage access it is better to have at least 4MB read chunks, for RAID storage it is desirable to have stripe-aligned readahead to avoid read inflation when verifying the parity. Any fixed size will eventually be inadequate as disks and filesystems change, so it may as well be a per-bdi tunable that can be set by the filesystem as needed, or possibly with a mount option if needed.
Cheers, Andreas
Matthew Wilcox
maintainerRe: [PATCHv6 11/37] HACK: readahead: alloc huge pages, if allowed
Quoted 11 lines · Andreas Dilger
Quoted 5 lines · Matthew Wilcox
Well ... what if we made readahead 2 hugepages in size for inodes which are using huge pages? That's only 8x our current readahead window, and if you're asking for hugepages, you're accepting that IOs are going to be larger, and you probably have the kind of storage system which can handle doing larger IOs.
It would be nice if the bdi had a parameter for the maximum readahead size. Currently, readahead is capped at 2MB chunks by
force_page_cache_readahead()even ifbdi->ra_pagesandbdi->io_pagesare much larger.
Quoted 7 lines
It should be up to the filesystem to decide how large the readahead chunks are rather than imposing some policy in the MM code. For high-speed (network) storage access it is better to have at least 4MB read chunks, for RAID storage it is desirable to have stripe-aligned readahead to avoid read inflation when verifying the parity. Any fixed size will eventually be inadequate as disks and filesystems change, so it may as well be a per-bdi tunable that can be set by the filesystem as needed, or possibly with a mount option if needed.
I think the filesystem should provide a hint, but ultimately it needs to be up to the MM to decide how far to readahead. The filesystem doesn't (and shouldn't) have the global view into how much memory is available for readahead, nor should it be tracking how well this app is being served by readahead.
That 2MB chunk restriction is allegedly there "so that we don't pin too much memory at once". Maybe that should be scaled with the amount of memory in the system (pinning 2MB of a 256MB system is a bit different from pinning 2MB of a 1TB memory system).
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Matthew Wilcox
maintainerRe: [PATCHv6 12/37] brd: make it handle huge pages
In reply to Kirill A. ShutemovQuoted 2 lines · Kirill A. Shutemov
Do not assume length of bio segment is never larger than
PAGE_SIZE. With huge pages it'sHPAGE_PMD_SIZE(2M on x86-64).
I don't think we even need hugepages for BRD to be buggy. I think there are already places which allocate compound pages (not in highmem, obviously ...) and put them in biovecs. So this is pure and simple a bugfix.
That said, I find the current code in brd a bit inelegant, and I don't think this patch helps... indeed, I think it's buggy:
Quoted 5 lines
(quoted diff) +1
-0@@ -202,12 +202,15 @@ static int copy_to_brd_setup(struct brd_device *brd, sector_t sector, size_t n) size_t copy; copy = min_t(size_t, n, PAGE_SIZE - offset); + n -= copy;
Review static int copy_to_brd_setup(struct brd_device *brd, sector_t sector, size_t n) · line 214
Quoted 10 lines
(quoted diff) +3
-1if (!brd_insert_page(brd, sector)) return -ENOSPC; - if (copy < n) { + while (n) { sector += copy >> SECTOR_SHIFT; if (!brd_insert_page(brd, sector)) return -ENOSPC; + copy = min_t(size_t, n, PAGE_SIZE); + n -= copy; }
We're decrementing 'n' to 0, then testing it, so we never fill in the last page ... right?
Anyway, here's my effort. Untested.
drivers/block/brd.c +28 -33
@@ -202,12 +202,14 @@ static int copy_to_brd_setup(struct brd_device *brd, sector_t sector, size_t n)size_t copy; copy =min_t (size_t, n,PAGE_SIZE - offset); -if (!brd_insert_page (brd, sector)) -return -ENOSPC ; -if (copy < n) { - sector += copy >>SECTOR_SHIFT ; +for (;;) {if (!brd_insert_page (brd, sector))return -ENOSPC ; + n -= copy; +if (!n) +break ; + sector += copy >>SECTOR_SHIFT ; + copy =min_t (size_t, n,PAGE_SIZE ); }return 0 ; }
@@ -239,26 +241,23 @@ static void copy_to_brd(struct brd_device *brd, const void *src,struct page *page;void *dst;unsigned int offset = (sector & (PAGE_SECTORS -1 )) <<SECTOR_SHIFT ; -size_t copy; +size_t copy =min_t (size_t, n,PAGE_SIZE - offset); - copy =min_t (size_t, n,PAGE_SIZE - offset); - page =brd_lookup_page (brd, sector); -BUG_ON (!page); - - dst =kmap_atomic (page); -memcpy (dst + offset, src, copy); -kunmap_atomic (dst); - -if (copy < n) { - src += copy; - sector += copy >>SECTOR_SHIFT ; - copy = n - copy; +for (;;) { page =brd_lookup_page (brd, sector);BUG_ON (!page); dst =kmap_atomic (page); -memcpy (dst, src, copy); +memcpy (dst + offset, src, copy);kunmap_atomic (dst); + + n -= copy; +if (!n) +break ; + src += copy; + sector += copy >>SECTOR_SHIFT ; + offset =0 ; + copy =min_t (size_t, n,PAGE_SIZE ); } }
@@ -271,28 +270,24 @@ static void copy_from_brd(void *dst, struct brd_device *brd,struct page *page;void *src;unsigned int offset = (sector & (PAGE_SECTORS -1 )) <<SECTOR_SHIFT ; -size_t copy; +size_t copy =min_t (size_t, n,PAGE_SIZE - offset); - copy =min_t (size_t, n,PAGE_SIZE - offset); - page =brd_lookup_page (brd, sector); -if (page) { - src =kmap_atomic (page); -memcpy (dst, src + offset, copy); -kunmap_atomic (src); - }else -memset (dst,0 , copy); - -if (copy < n) { - dst += copy; - sector += copy >>SECTOR_SHIFT ; - copy = n - copy; +for (;;) { page =brd_lookup_page (brd, sector);if (page) { src =kmap_atomic (page); -memcpy (dst, src, copy); +memcpy (dst, src + offset, copy);kunmap_atomic (src); }else memset (dst,0 , copy); + + n -= copy; +if (!n) +break ; + dst += copy; + sector += copy >>SECTOR_SHIFT ; + offset =0 ; + copy =min_t (size_t, n,PAGE_SIZE ); } }
Matthew Wilcox
maintainerRe: [PATCHv6 13/37] mm: make write_cache_pages() work on huge pages
In reply to Kirill A. ShutemovQuoted 3 lines · Kirill A. Shutemov
We writeback whole huge page a time. Let's adjust iteration this way.
Signed-off-by Kirill A. Shutemov <[email protected]>
I think a lot of the complexity in this patch is from pagevec_lookup_tag giving you subpages rather than head pages...
mm/page-writeback.c int write_cache_pages(struct address_space *mapping, · line 2280
Quoted 10 lines
mm/page-writeback.c +2
-1@@ -2268,7 +2273,8 @@ int write_cache_pages(struct address_space *mapping,* not be suitable for data integrity * writeout). */ - done_index = page->index +1 ; + done_index =compound_head (page)->index + +hpage_nr_pages (page); done =1 ;break ; }
you'd still need this line, but it'd only be:
done_index = page->index + (1 << compound_order(page));
I think we want:
#define nr_pages(page) (1 << compound_order(page))
because we seem to be repeating that idiom quite a lot in these patches.
done_index = page->index + nr_pages(page);
Still doesn't quite fit on one line, but it's closer, and it's the ridiculous indentation in that function that's the real problem.
Re: [PATCHv6 16/37] thp: make thp_get_unmapped_area() respect S_HUGE_MODE
In reply to Kirill A. ShutemovQuoted 4 lines · Kirill A. Shutemov
We want mmap(NULL) to return PMD-aligned address if the inode can have huge pages in page cache.
Signed-off-by Kirill A. Shutemov <[email protected]>
Re: [PATCHv6 17/37] fs: make block_read_full_page() be able to read huge page
In reply to Kirill A. ShutemovQuoted 2 lines · Kirill A. Shutemov
The approach is straight-forward: for compound pages we read out whole huge page.
Ouch. bufferheads must die ;-)
Quoted 5 lines
For huge page we cannot have array of buffer head pointers on stack -- it's 4096 pointers on x86-64 -- 'arr' is allocated with
kmalloc()for huge pages.Signed-off-by Kirill A. Shutemov <[email protected]>
Matthew Wilcox
maintainerRe: [PATCHv6 15/37] thp: do not threat slab pages as huge in hpage_{nr_pages,size,mask}
In reply to Kirill A. ShutemovQuoted 6 lines · Kirill A. Shutemov
Slab pages can be compound, but we shouldn't threat them as THP for pupose of hpage_* helpers, otherwise it would lead to confusing results.
For instance, ext4 uses slab pages for journal pages and we shouldn't confuse them with THPs. The easiest way is to exclude them in hpage_* helpers.
Well ... I think we should just deal with compound pages instead of just huge or regular. So I'm deferring comment on this patch.
Quoted 41 lines
Signed-off-by Kirill A. Shutemov <[email protected]>--- include/linux/huge_mm.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)include/linux/huge_mm.h +3
-3@@ -137,21 +137,21 @@ static inline spinlock_t *pmd_trans_huge_lock(pmd_t *pmd, }static inline int hpage_nr_pages (struct page *page) { -if (unlikely (PageTransHuge (page))) +if (unlikely (!PageSlab (page) &&PageTransHuge (page)))return HPAGE_PMD_NR ;return 1 ; }static inline int hpage_size (struct page *page) { -if (unlikely (PageTransHuge (page))) +if (unlikely (!PageSlab (page) &&PageTransHuge (page)))return HPAGE_PMD_SIZE ;return PAGE_SIZE ; }static inline unsigned long hpage_mask (struct page *page) { -if (unlikely (PageTransHuge (page))) +if (unlikely (!PageSlab (page) &&PageTransHuge (page)))return HPAGE_PMD_MASK ;return PAGE_MASK ; }Signature · 6 lines
2.11.0 -- To unsubscribe from this list: send the line "unsubscribe linux-fsdevel" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCHv6 01/37] mm, shmem: swich huge tmpfs to multi-order radix-tree entries
In reply to Kirill A. ShutemovQuoted 1 line · Kirill A. Shutemov
I'll look into it.
I ended up with this (I'll test it more later):
void filemap_map_pages(struct vm_fault *vmf,
pgoff_t start_pgoff, pgoff_t end_pgoff)
{
struct radix_tree_iter iter;
void **slot;
struct file *file = vmf->vma->vm_file;
struct address_space *mapping = file->f_mapping;
pgoff_t last_pgoff = start_pgoff;
loff_t size;
struct page *page;
bool mapped;
rcu_read_lock();
radix_tree_for_each_slot(slot, &mapping->page_tree, &iter,
start_pgoff) {
unsigned long index = iter.index;
if (index < start_pgoff)
index = start_pgoff;
if (index > end_pgoff)
break;
repeat:
page = radix_tree_deref_slot(slot);
if (unlikely(!page))
continue;
if (radix_tree_exception(page)) {
if (radix_tree_deref_retry(page))
slot = radix_tree_iter_retry(&iter);
continue;
}
if (!page_cache_get_speculative(page))
goto repeat;
/* Has the page moved? */
if (unlikely(page != *slot)) {
put_page(page);
goto repeat;
}
/* For multi-order entries, find relevant subpage */
page = find_subpage(page, index);
if (!PageUptodate(page) || PageReadahead(page))
goto skip;
if (!trylock_page(page))
goto skip;
if (page_mapping(page) != mapping || !PageUptodate(page))
goto skip_unlock;
size = round_up(i_size_read(mapping->host), PAGE_SIZE);
if (compound_head(page)->index >= size >> PAGE_SHIFT)
goto skip_unlock;
if (file->f_ra.mmap_miss > 0)
file->f_ra.mmap_miss--;
map_next_subpage:
if (PageHWPoison(page))
goto next;
vmf->address += (index - last_pgoff) << PAGE_SHIFT;
if (vmf->pte)
vmf->pte += index - last_pgoff;
last_pgoff = index;
mapped = !alloc_set_pte(vmf, NULL, page);
/* Huge page is mapped or last index? No need to proceed. */
if (pmd_trans_huge(*vmf->pmd) ||
index == end_pgoff) {
unlock_page(page);
break;
}
next:
if (page && PageCompound(page)) {
/* Last subpage handled? */
if ((index & (compound_nr_pages(page) - 1)) ==
compound_nr_pages(page) - 1)
goto skip_unlock;
index++;
page++;
/*
* One page reference goes to page table mapping.
* Need additional reference, if last alloc_set_pte()
* succeed.
*/
if (mapped)
get_page(page);
goto map_next_subpage;
}
skip_unlock:
unlock_page(page);
skip:
iter.index = compound_head(page)->index +
compound_nr_pages(page) - 1;
/* Only give up reference if alloc_set_pte() failed. */
if (!mapped)
put_page(page);
}
rcu_read_unlock();
}Signature · 7 lines
Kirill A. Shutemov -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCHv6 03/37] page-flags: relax page flag policy for few flags
In reply to Matthew WilcoxQuoted 6 lines · Matthew Wilcox
Quoted 2 lines · Kirill A. Shutemov
These flags are in use for filesystems with backing storage:
PG_error,PG_writebackandPG_readahead.Oh ;-) Then I amend my comment on patch 1 to be "patch 3 needs to go ahead of patch 1" ;-)
It doesn't really matter as long as both before patch 37 :P
Signature · 7 lines
Kirill A. Shutemov -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCHv6 05/37] thp: try to free page's buffers before attempt split
In reply to Matthew WilcoxQuoted 16 lines · Matthew Wilcox
mm/huge_memory.c int split_huge_page_to_list(struct page *page, struct list_head *list) · line 2156
Quoted 12 lines · Kirill A. Shutemov
mm/huge_memory.c +8
-0@@ -2146,6 +2146,23 @@ int split_huge_page_to_list(struct page *page, struct list_head *list) goto out; } +/* Try to free buffers before attempt split */ +if (!PageSwapBacked (head) &&PagePrivate (page)) { +/* +* We cannot trigger writeback from here due possible +* recursion if triggered from vmscan, only wait. +* +* Caller can trigger writeback it on its own, if safe. +*/ It took me a few reads to get this. May I suggest:
Quoted 5 lines
/*
* Cannot split a page with buffers. If the caller has
* already started writeback, we can wait for it to finish,
* but we cannot start writeback if we were called from vmscan */
Yeah, that's better.
Quoted 4 lines
mm/huge_memory.c int split_huge_page_to_list(struct page *page, struct list_head *list) · line 2150
Quoted 1 line
mm/huge_memory.c +1
-0+if (!PageSwapBacked (head) &&PagePrivate (page)) {Also, it looks weird to test PageSwapBacked of *head* and PagePrivate of *page*. I think it's correct, but it still looks weird.
I'll change this.
Quoted 1 line
Reviewed-by Matthew Wilcox <[email protected]>
Thanks!
Signature · 1 line
Kirill A. Shutemov
Re: [PATCHv6 07/37] filemap: allocate huge page in page_cache_read(), if allowed
In reply to Matthew WilcoxQuoted 7 lines · Matthew Wilcox
Quoted 2 lines · Kirill A. Shutemov
Later we can add logic to accumulate information from shadow entires to return to caller (average eviction time?).
I would say minimum rather than average. That will become the refault time of the entire page, so minimum would probably have us making better decisions?
Yes, makes sense.
Quoted 6 lines
Quoted 6 lines
mm/filemap.c +5
-0+/* Wipe shadow entires */ +radix_tree_for_each_slot (slot, &mapping->page_tree, &iter, + page->index) { +if (iter.index >= page->index +hpage_nr_pages (page)) +break ;
Quoted 9 lines
mm/filemap.c line 128
Quoted 4 lines
mm/filemap.c +2
-1p =radix_tree_deref_slot_protected (slot, &mapping->tree_lock); -if (!radix_tree_exceptional_entry (p)) +if (!p) +continue ;Just FYI, this can't happen. You're holding the tree lock so nobody else gets to remove things from the tree.
radix_tree_for_each_slot()only gives you the full slots; it skips the empty ones for you. I'm OK if you want to leave it in out of an abundance of caution.
I'll drop it.
Quoted 10 lines
mm/filemap.c line 134
Quoted 2 lines
mm/filemap.c +2
-0+__radix_tree_replace (&mapping->page_tree, iter.node, slot,NULL , + workingset_update_node, mapping);I may add an
update_nodeargument toradix_tree_joinat some point, so you can use it here. Or maybe we don't need to do that, and what you have here works just fine.Quoted 1 line
mapping->nrexceptional--;
... because adjusting the exceptional count is going to be a pain.
Yeah..
Quoted 46 lines
mm/filemap.c line 153
Quoted 5 lines
mm/filemap.c +5
-0+ error =__radix_tree_insert (&mapping->page_tree, + page->index,compound_order (page), page); +/* This shouldn't happen */ +if (WARN_ON_ONCE (error)) +return error;A lesser man would have just ignored the return value from
__radix_tree_insert. I salute you.Quoted 37 lines
mm/filemap.c +20
-4@@ -2078,18 +2155,34 @@ static int page_cache_read(struct file *file, pgoff_t offset, gfp_t gfp_mask) {struct address_space *mapping = file->f_mapping;struct page *page; +pgoff_t hoffset;int ret; do { - page = __page_cache_alloc(gfp_mask|__GFP_COLD); + page = page_cache_alloc_huge(mapping, offset, gfp_mask); +no_huge: + if (!page) + page = __page_cache_alloc(gfp_mask|__GFP_COLD); if (!page) return -ENOMEM; - ret = add_to_page_cache_lru(page, mapping, offset, gfp_mask & GFP_KERNEL); - if (ret == 0) + if (PageTransHuge(page)) + hoffset = round_down(offset, HPAGE_PMD_NR); + else + hoffset = offset; + + ret = add_to_page_cache_lru(page, mapping, hoffset, + gfp_mask & GFP_KERNEL); + + if (ret == -EEXIST && PageTransHuge(page)) { + put_page(page); + page = NULL; + goto no_huge; + } else if (ret == 0) { ret = mapping->a_ops->readpage(file, page); - else if (ret == -EEXIST) + } else if (ret == -EEXIST) { ret = 0; /* losing race to add is OK */ + }
Quoted 6 lines
Review static int page_cache_read(struct file *file, pgoff_t offset, gfp_t gfp_mask) · line 2187
Quoted 1 line
(quoted diff) +0
-0put_page(page);If the filesystem returns
AOP_TRUNCATED_PAGE, you'll go round this loop again trying the huge page again, even if the huge page didn't work the first time. I would tend to think that if the huge page failed the first time, we shouldn't try it again, so I propose this:
AOP_TRUNCATED_PAGE is positive, so I don't see how you avoid try_huge on second iteration. Hm?
Quoted 39 lines
struct address_space *mapping = file->f_mapping;
struct page *page;
pgoff_t index;
int ret;
bool try_huge = true;
do {
if (try_huge) {
page = page_cache_alloc_huge(gfp_mask|__GFP_COLD);
if (page)
index = round_down(offset, HPAGE_PMD_NR);
else
try_huge = false;
}
if (!try_huge) {
page = __page_cache_alloc(gfp_mask|__GFP_COLD);
index = offset;
}
if (!page)
return -ENOMEM;
ret = add_to_page_cache_lru(page, mapping, index,
gfp_mask & GFP_KERNEL);
if (ret < 0) {
if (try_huge) {
try_huge = false;
ret = AOP_TRUNCATED_PAGE;
} else if (ret == -EEXIST)
ret = 0; /* losing race to add is OK */
} else {
ret = mapping->a_ops->readpage(file, page);
}
put_page(page);
} while (ret == AOP_TRUNCATED_PAGE);Quoted 2 lines
But ... maybe it's OK to retry the huge page. I mean, not many filesystems return
AOP_TRUNCATED_PAGE, and they only do so rarely.
What about this:
struct address_space *mapping = file->f_mapping;
struct page *page;
pgoff_t hoffset;
int ret;
bool try_huge = true;
do {
if (try_huge) {
page = page_cache_alloc_huge(mapping, offset, gfp_mask);
hoffset = round_down(offset, HPAGE_PMD_NR);
/* Try to allocate huge page once */
try_huge = false;
}
if (!page) {
page = __page_cache_alloc(gfp_mask|__GFP_COLD);
hoffset = offset;
}
if (!page)
return -ENOMEM;
ret = add_to_page_cache_lru(page, mapping, hoffset,
gfp_mask & GFP_KERNEL);
if (ret == -EEXIST && PageTransHuge(page)) {
/* Retry with small page */
put_page(page);
page = NULL;
continue;
} else if (ret == 0) {
ret = mapping->a_ops->readpage(file, page);
} else if (ret == -EEXIST) {
ret = 0; /* losing race to add is OK */
}
put_page(page);
} while (ret == AOP_TRUNCATED_PAGE);
return ret;Quoted 4 lines
Anyway, I'm fine with the patch going in as-is. I just wanted to type out my review notes.
Reviewed-by Matthew Wilcox <[email protected]>
Thanks!
Signature · 1 line
Kirill A. Shutemov
Re: [PATCHv6 08/37] filemap: handle huge pages in do_generic_file_read()
In reply to Matthew WilcoxQuoted 12 lines · Matthew Wilcox
mm/filemap.c static ssize_t do_generic_file_read(struct file *filp, loff_t *ppos, · line 1889
Quoted 6 lines · Kirill A. Shutemov
+++
b/mm/filemap.cmm/filemap.c +1
-0@@ -1886,6 +1886,7 @@ static ssize_t do_generic_file_read(struct file *filp, loff_t *ppos,if (unlikely (page ==NULL )) goto no_cached_page; } + page =compound_head (page);We got this page from
find_get_page(), which gets it frompagecache_get_page(), which gets it fromfind_get_entry()... which (unless I'm lost in your patch series) returns the head page. So this line is redundant, right?
No. pagecache_get_page() returns subpage. See description of the first patch.
Quoted 6 lines
But then down in
filemap_fault, we have:VM_BUG_ON_PAGE(page->index != offset, page);... again, maybe I'm lost somewhere in your patch series, but I don't see anywhere you remove that line (or modify it).
This should be fine as find_get_page() returns subpage.
Quoted 10 lines
So are you not testing
with VM debugging enabled, or are you not doing a test which includes mapping a file with huge pages, reading from it (to get the page in cache), then faulting on an address that is not in the first 4kB of that 2MB?--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Signature · 1 line
Kirill A. Shutemov
Matthew Wilcox
maintainerRe: [PATCHv6 08/37] filemap: handle huge pages in do_generic_file_read()
Quoted 2 lines · Kirill A. Shutemov
No.
pagecache_get_page()returns subpage. See description of the first patch.
Your description says:
Quoted 9 lines
We also change interface for page-cache lookup function:
- functions that lookup for pages[1] would return subpages of THP
relevant for requested indexes;- functions that lookup for entries[2] would return one entry per-THP and index will point to index of head page (basically, round down to
HPAGE_PMD_NR);
Quoted 5 lines
This would provide balanced exposure of multi-order entires to the rest of the kernel.
[1]
find_get_pages(),pagecache_get_page(),pagevec_lookup(), etc.
[2]find_get_entry(),find_get_entries(),pagevec_lookup_entries(), etc.
I'm saying:
Quoted 3 lines
Quoted 3 lines
We got this page from
find_get_page(), which gets it frompagecache_get_page(), which gets it fromfind_get_entry()... which (unless I'm lost in your patch series) returns the head page.
Am I guilty of debugging documentation rather than code?
Matthew Wilcox
maintainerRe: [PATCHv6 08/37] filemap: handle huge pages in do_generic_file_read()
Quoted 3 lines · Matthew Wilcox
Quoted 2 lines · Kirill A. Shutemov
No.
pagecache_get_page()returns subpage. See description of the first patch.
Oh, I re-read patch 1 and it made sense now. I missed the bit where pagecache_get_page() called page_subpage().
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Matthew Wilcox
maintainerRe: [PATCHv6 08/37] filemap: handle huge pages in do_generic_file_read()
In reply to Kirill A. ShutemovQuoted 5 lines · Kirill A. Shutemov
Most of work happans on head page. Only when we need to do copy data to userspace we find relevant subpage.
We are still limited by
PAGE_SIZEper iteration. Lifting this limitation would require some more work.
Now that I debugged that bit of my brain, here's a more sensible suggestion.
mm/filemap.c static ssize_t do_generic_file_read(struct file *filp, loff_t *ppos, · line 1892
Quoted 8 lines
mm/filemap.c +1
-0@@ -1886,6 +1886,7 @@ static ssize_t do_generic_file_read(struct file *filp, loff_t *ppos,if (unlikely (page ==NULL )) goto no_cached_page; } + page =compound_head (page);if (PageReadahead (page)) { page_cache_async_readahead(mapping, ra, filp, page,
We're going backwards and forwards a lot between subpages and page heads. I'd like to see us do this:
static inline struct page *pagecache_get_page(struct address_space *mapping,
pgoff_t offset, int fgp_flags, gfp_t cache_gfp_mask)
{
struct page *page = pagecache_get_head(mapping, offset, fgp_flags,
cache_gfp_mask);
return page ? find_subpage(page, offset) : NULL;
}static inline struct page *find_get_head(struct address_space *mapping,
pgoff_t offset)
{
return pagecache_get_head(mapping, offset, 0, 0);
}and then we can switch do_generic_file_read() to call find_get_head(), eliminating the conversion back and forth between subpages and head pages.