Split a folio to any lower order folios
Subsystems (10)
v2 cover Split a folio to any lower order folios
From: Zi Yan <[email protected]>
Hi all,
File folio supports any order and people would like to support flexible orders for anonymous folio[1] too. Currently, split_huge_page() only splits a huge page to order-0 pages, but splitting to orders higher than 0 is also useful. This patchset adds support for splitting a huge page to any lower order pages and uses it during folio truncate operations.
The patchset is on top of mm-everything-2023-03-27-21-20.
Changelog from v1
===
1. Changed split_page_memcg() and split_page_owner() parameter to use order
2. Used folio_test_pmd_mappable() in place of the equivalent code
Details
===
* Patch 1 changes split_page_memcg() to use order instead of nr_pages
* Patch 2 changes split_page_owner() to use order instead of nr_pages
* Patch 3 and 4 add new_order parameter split_page_memcg() and split_page_owner() and prepare for upcoming changes.
* Patch 5 adds split_huge_page_to_list_to_order() to split a huge page to any lower order. The original split_huge_page_to_list() calls split_huge_page_to_list_to_order() with new_order = 0.
* Patch 6 uses split_huge_page_to_list_to_order() in large pagecache folio truncation instead of split the large folio all the way down to order-0.
* Patch 7 adds a test API to debugfs and test cases in split_huge_page_test selftests.
Comments and/or suggestions are welcome.
[1] https://lore.kernel.org/linux-mm/Y%[email protected]/
Zi Yan (7):
mm/memcg: use order instead of nr in split_page_memcg() mm/page_owner: use order instead of nr in split_page_owner()
mm: memcg: make memcg huge page split support any order split.
mm: page_owner: add support for splitting to any order in split
page_owner.
mm: thp: split huge page to any lower order pages.
mm: truncate: split huge page cache page to a non-zero order if
possible.
mm: huge_memory: enable debugfs to split huge pages to any order.
include/linux/huge_mm.h | 10 +- include/linux/memcontrol.h | 4 +- include/linux/page_owner.h | 10 +- mm/huge_memory.c | 137 ++++++++--- mm/memcontrol.c | 10 +- mm/page_alloc.c | 8 +- mm/page_owner.c | 10 +- mm/truncate.c | 21 +- .../selftests/mm/split_huge_page_test.c | 225 +++++++++++++++++- 9 files changed, 366 insertions(+), 69 deletions(-)
Signature · 1 line
2.39.2
PATCH v2 1/7 mm/memcg: use order instead of nr in split_page_memcg()
From: Zi Yan <[email protected]>
We do not have non power of two pages, using nr is error prone if nr is not power-of-two. Use page order instead.
--- include/linux/memcontrol.h | 4 ++-- mm/huge_memory.c | 3 ++- mm/memcontrol.c | 3 ++- mm/page_alloc.c | 4 ++-- 4 files changed, 8 insertions(+), 6 deletions(-)
include/linux/memcontrol.h +2 -2
@@ -1151,7 +1151,7 @@ static inline void memcg_memory_event_mm(struct mm_struct *mm,rcu_read_unlock (); } -void split_page_memcg (struct page *head,unsigned int nr); +void split_page_memcg (struct page *head,int order); unsigned long mem_cgroup_soft_limit_reclaim(pg_data_t *pgdat, int order, gfp_t gfp_mask,
@@ -1588,7 +1588,7 @@ void count_memcg_event_mm(struct mm_struct *mm, enum vm_event_item idx) { } -static inline void split_page_memcg (struct page *head,unsigned int nr) +static inline void split_page_memcg (struct page *head,int order) { }
mm/huge_memory.c +2 -1
@@ -2512,10 +2512,11 @@ static void __split_huge_page(struct page *page, struct list_head *list,struct address_space *swap_cache =NULL ;unsigned long offset =0 ;unsigned int nr =thp_nr_pages (head); +int order =folio_order (folio);int i;/* complete memcg works before add pages to LRU */ -split_page_memcg (head, nr); +split_page_memcg (head, order);if (PageAnon (head) &&PageSwapCache (head)) {swp_entry_t entry = { .val =page_private (head) };
mm/memcontrol.c +2 -1
@@ -3414,11 +3414,12 @@ void obj_cgroup_uncharge(struct obj_cgroup *objcg, size_t size)/* * Because page_memcg(head) is not set on tails, set it now. */ -void split_page_memcg (struct page *head,unsigned int nr) +void split_page_memcg (struct page *head,int order) {struct folio *folio =page_folio (head);struct mem_cgroup *memcg =folio_memcg (folio);int i; +unsigned int nr =1 << order;if (mem_cgroup_disabled () || !memcg)return ;
mm/page_alloc.c +2 -2
@@ -2781,7 +2781,7 @@ void split_page(struct page *page, unsigned int order)for (i =1 ; i < (1 << order); i++)set_page_refcounted (page + i);split_page_owner (page,1 << order); -split_page_memcg (page,1 << order); +split_page_memcg (page, order); }EXPORT_SYMBOL_GPL (split_page);
@@ -4997,7 +4997,7 @@ static void *make_alloc_exact(unsigned long addr, unsigned int order,struct page *last = page + nr;split_page_owner (page,1 << order); -split_page_memcg (page,1 << order); +split_page_memcg (page, order);while (page < --last)set_page_refcounted (last);
Signature · 1 line
2.39.2
PATCH v2 2/7 mm/page_owner: use order instead of nr in split_page_owner()
In reply to Zi YanFrom: Zi Yan <[email protected]>
We do not have non power of two pages, using nr is error prone if nr is not power-of-two. Use page order instead.
--- include/linux/page_owner.h | 8 ++++---- mm/huge_memory.c | 2 +- mm/page_alloc.c | 4 ++-- mm/page_owner.c | 3 ++- 4 files changed, 9 insertions(+), 8 deletions(-)
include/linux/page_owner.h +4 -4
@@ -11,7 +11,7 @@ extern struct page_ext_operations page_owner_ops;extern void __reset_page_owner (struct page *page,unsigned short order);extern void __set_page_owner (struct page *page,unsigned short order,gfp_t gfp_mask); -extern void __split_page_owner (struct page *page,unsigned int nr); +extern void __split_page_owner (struct page *page,int order);extern void __folio_copy_owner (struct folio *newfolio,struct folio *old);extern void __set_page_owner_migrate_reason (struct page *page,int reason);extern void __dump_page_owner (const struct page *page);
@@ -31,10 +31,10 @@ static inline void set_page_owner(struct page *page,__set_page_owner (page, order, gfp_mask); } -static inline void split_page_owner (struct page *page,unsigned int nr) +static inline void split_page_owner (struct page *page,int order) {if (static_branch_unlikely (&page_owner_inited)) -__split_page_owner (page, nr); +__split_page_owner (page, order); }static inline void folio_copy_owner (struct folio *newfolio,struct folio *old) {
@@ -60,7 +60,7 @@ static inline void set_page_owner(struct page *page, { }static inline void split_page_owner (struct page *page, -unsigned short order) +int order) { }static inline void folio_copy_owner (struct folio *newfolio,struct folio *folio)
mm/huge_memory.c +1 -1
@@ -2557,7 +2557,7 @@ static void __split_huge_page(struct page *page, struct list_head *list,unlock_page_lruvec (lruvec);/* Caller disabled irqs, so they are still disabled here */ -split_page_owner (head, nr); +split_page_owner (head, order);/* See comment in __split_huge_page_tail() */ if (PageAnon (head)) {
mm/page_alloc.c +2 -2
@@ -2780,7 +2780,7 @@ void split_page(struct page *page, unsigned int order)for (i =1 ; i < (1 << order); i++)set_page_refcounted (page + i); -split_page_owner (page,1 << order); +split_page_owner (page, order);split_page_memcg (page, order); }EXPORT_SYMBOL_GPL (split_page);
@@ -4996,7 +4996,7 @@ static void *make_alloc_exact(unsigned long addr, unsigned int order,struct page *page =virt_to_page ((void *)addr);struct page *last = page + nr; -split_page_owner (page,1 << order); +split_page_owner (page, order);split_page_memcg (page, order);while (page < --last)set_page_refcounted (last);
mm/page_owner.c +2 -1
@@ -211,11 +211,12 @@ void __set_page_owner_migrate_reason(struct page *page, int reason)page_ext_put (page_ext); } -void __split_page_owner (struct page *page,unsigned int nr) +void __split_page_owner (struct page *page,int order) {int i;struct page_ext *page_ext =page_ext_get (page);struct page_owner *page_owner; +unsigned int nr =1 << order;if (unlikely (!page_ext))return ;
Signature · 1 line
2.39.2
PATCH v2 3/7 mm: memcg: make memcg huge page split support any order split.
In reply to Zi YanFrom: Zi Yan <[email protected]>
It sets memcg information for the pages after the split. A new parameter new_order is added to tell the order of subpages in the new page, always 0 for now. It prepares for upcoming changes to support split huge page to any lower order.
--- include/linux/memcontrol.h | 4 ++-- mm/huge_memory.c | 2 +- mm/memcontrol.c | 11 ++++++----- mm/page_alloc.c | 4 ++-- 4 files changed, 11 insertions(+), 10 deletions(-)
include/linux/memcontrol.h +2 -2
@@ -1151,7 +1151,7 @@ static inline void memcg_memory_event_mm(struct mm_struct *mm,rcu_read_unlock (); } -void split_page_memcg (struct page *head,int order); +void split_page_memcg (struct page *head,int old_order,int new_order); unsigned long mem_cgroup_soft_limit_reclaim(pg_data_t *pgdat, int order, gfp_t gfp_mask,
@@ -1588,7 +1588,7 @@ void count_memcg_event_mm(struct mm_struct *mm, enum vm_event_item idx) { } -static inline void split_page_memcg (struct page *head,int order) +static inline void split_page_memcg (struct page *head,int old_order,int new_order) { }
mm/huge_memory.c +1 -1
@@ -2516,7 +2516,7 @@ static void __split_huge_page(struct page *page, struct list_head *list,int i;/* complete memcg works before add pages to LRU */ -split_page_memcg (head, order); +split_page_memcg (head, order,0 );if (PageAnon (head) &&PageSwapCache (head)) {swp_entry_t entry = { .val =page_private (head) };
mm/memcontrol.c +6 -5
@@ -3414,23 +3414,24 @@ void obj_cgroup_uncharge(struct obj_cgroup *objcg, size_t size)/* * Because page_memcg(head) is not set on tails, set it now. */ -void split_page_memcg (struct page *head,int order) +void split_page_memcg (struct page *head,int old_order,int new_order) {struct folio *folio =page_folio (head);struct mem_cgroup *memcg =folio_memcg (folio);int i; -unsigned int nr =1 << order; +unsigned int old_nr =1 << old_order; +unsigned int new_nr =1 << new_order;if (mem_cgroup_disabled () || !memcg)return ; -for (i =1 ; i < nr; i++) +for (i = new_nr; i < old_nr; i += new_nr)folio_page (folio, i)->memcg_data = folio->memcg_data;if (folio_memcg_kmem (folio)) -obj_cgroup_get_many (__folio_objcg (folio), nr -1 ); +obj_cgroup_get_many (__folio_objcg (folio), old_nr / new_nr -1 );else -css_get_many (&memcg->css, nr -1 ); +css_get_many (&memcg->css, old_nr / new_nr -1 ); }#ifdef CONFIG_SWAP
mm/page_alloc.c +2 -2
@@ -2781,7 +2781,7 @@ void split_page(struct page *page, unsigned int order)for (i =1 ; i < (1 << order); i++)set_page_refcounted (page + i);split_page_owner (page, order); -split_page_memcg (page, order); +split_page_memcg (page, order,0 ); }EXPORT_SYMBOL_GPL (split_page);
@@ -4997,7 +4997,7 @@ static void *make_alloc_exact(unsigned long addr, unsigned int order,struct page *last = page + nr;split_page_owner (page, order); -split_page_memcg (page, order); +split_page_memcg (page, order,0 );while (page < --last)set_page_refcounted (last);
Signature · 1 line
2.39.2
PATCH v2 4/7 mm: page_owner: add support for splitting to any order in split page_owner.
In reply to Zi YanFrom: Zi Yan <[email protected]>
It adds a new_order parameter to set new page order in page owner. It prepares for upcoming changes to support split huge page to any lower order.
--- include/linux/page_owner.h | 10 +++++----- mm/huge_memory.c | 2 +- mm/page_alloc.c | 4 ++-- mm/page_owner.c | 11 ++++++----- 4 files changed, 14 insertions(+), 13 deletions(-)
include/linux/page_owner.h +5 -5
@@ -11,7 +11,7 @@ extern struct page_ext_operations page_owner_ops;extern void __reset_page_owner (struct page *page,unsigned short order);extern void __set_page_owner (struct page *page,unsigned short order,gfp_t gfp_mask); -extern void __split_page_owner (struct page *page,int order); +extern void __split_page_owner (struct page *page,int old_order,int new_order);extern void __folio_copy_owner (struct folio *newfolio,struct folio *old);extern void __set_page_owner_migrate_reason (struct page *page,int reason);extern void __dump_page_owner (const struct page *page);
@@ -31,10 +31,10 @@ static inline void set_page_owner(struct page *page,__set_page_owner (page, order, gfp_mask); } -static inline void split_page_owner (struct page *page,int order) +static inline void split_page_owner (struct page *page,int old_order,int new_order) {if (static_branch_unlikely (&page_owner_inited)) -__split_page_owner (page, order); +__split_page_owner (page, old_order, new_order); }static inline void folio_copy_owner (struct folio *newfolio,struct folio *old) {
@@ -56,11 +56,11 @@ static inline void reset_page_owner(struct page *page, unsigned short order) { }static inline void set_page_owner (struct page *page, -unsigned int order,gfp_t gfp_mask) +unsigned short order,gfp_t gfp_mask) { }static inline void split_page_owner (struct page *page, -int order) +int old_order,int new_order) { }static inline void folio_copy_owner (struct folio *newfolio,struct folio *folio)
mm/huge_memory.c +1 -1
@@ -2557,7 +2557,7 @@ static void __split_huge_page(struct page *page, struct list_head *list,unlock_page_lruvec (lruvec);/* Caller disabled irqs, so they are still disabled here */ -split_page_owner (head, order); +split_page_owner (head, order,0 );/* See comment in __split_huge_page_tail() */ if (PageAnon (head)) {
mm/page_alloc.c +2 -2
@@ -2780,7 +2780,7 @@ void split_page(struct page *page, unsigned int order)for (i =1 ; i < (1 << order); i++)set_page_refcounted (page + i); -split_page_owner (page, order); +split_page_owner (page, order,0 );split_page_memcg (page, order,0 ); }EXPORT_SYMBOL_GPL (split_page);
@@ -4996,7 +4996,7 @@ static void *make_alloc_exact(unsigned long addr, unsigned int order,struct page *page =virt_to_page ((void *)addr);struct page *last = page + nr; -split_page_owner (page, order); +split_page_owner (page, order,0 );split_page_memcg (page, order,0 );while (page < --last)set_page_refcounted (last);
mm/page_owner.c +6 -5
@@ -211,20 +211,21 @@ void __set_page_owner_migrate_reason(struct page *page, int reason)page_ext_put (page_ext); } -void __split_page_owner (struct page *page,int order) +void __split_page_owner (struct page *page,int old_order,int new_order) {int i;struct page_ext *page_ext =page_ext_get (page);struct page_owner *page_owner; -unsigned int nr =1 << order; +unsigned int old_nr =1 << old_order; +unsigned int new_nr =1 << new_order;if (unlikely (!page_ext))return ; -for (i =0 ; i < nr; i++) { +for (i =0 ; i < old_nr; i += new_nr) { + page_ext =lookup_page_ext (page + i); page_owner =get_page_owner (page_ext); - page_owner->order =0 ; - page_ext =page_ext_next (page_ext); + page_owner->order = new_order; }page_ext_put (page_ext); }
Signature · 1 line
2.39.2
kernel test robot
build botRe: [PATCH v2 4/7] mm: page_owner: add support for splitting to any order in split page_owner.
Thank you for the patch! Yet something to improve:
Hi Zi,
Thank you for the patch! Yet something to improve:
[auto build test ERROR on akpm-mm/mm-everything]
[also build test ERROR on linus/master v6.3-rc4 next-20230329] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Zi-Yan/mm-memcg-use-order-instead-of-nr-in-split_page_memcg/20230329-091809 base: https://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm.git mm-everything patch link: https://lore.kernel.org/r/20230329011712.3242298-5-zi.yan%40sent.com patch subject: [PATCH v2 4/7] mm: page_owner: add support for splitting to any order in split page_owner. config: i386-randconfig-m021 (https://download.01.org/0day-ci/archive/20230329/[email protected]/config) compiler: gcc-11 (Debian 11.3.0-8) 11.3.0
reproduce (this is a W=1 build):
# https://github.com/intel-lab-lkp/linux/commit/6d1831c0e01a1a742e026454fe6e5643e08c5985
git remote add linux-review https://github.com/intel-lab-lkp/linux
git fetch --no-tags linux-review Zi-Yan/mm-memcg-use-order-instead-of-nr-in-split_page_memcg/20230329-091809 git checkout 6d1831c0e01a1a742e026454fe6e5643e08c5985
# save the config file
mkdir build_dir && cp config build_dir/.config
make W=1 O=build_dir ARCH=i386 olddefconfig
make W=1 O=build_dir ARCH=i386 SHELL=/bin/bash
If you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot <[email protected]>
| Link: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All errors (new ones prefixed by >>):
mm/page_owner.c: In function '__split_page_owner':
>> mm/page_owner.c:226:28: error: implicit declaration of function 'lookup_page_ext' [-Werror=implicit-function-declaration]
226 | page_ext = lookup_page_ext(page + i);
| ^~~~~~~~~~~~~~~
mm/page_owner.c:226:26: warning: assignment to 'struct page_ext *' from 'int' makes pointer from integer without a cast [-Wint-conversion]
226 | page_ext = lookup_page_ext(page + i);
| ^cc1: some warnings being treated as errors
vim +/lookup_page_ext +226 mm/page_owner.c
213
214 void __split_page_owner(struct page *page, int old_order, int new_order)
215 {
216 int i;
217 struct page_ext *page_ext = page_ext_get(page);
218 struct page_owner *page_owner;
219 unsigned int old_nr = 1 << old_order;
220 unsigned int new_nr = 1 << new_order;
221
222 if (unlikely(!page_ext))
223 return;
224
225 for (i = 0; i < old_nr; i += new_nr) {
> 226 page_ext = lookup_page_ext(page + i);
227 page_owner = get_page_owner(page_ext);
228 page_owner->order = new_order;
229 }
230 page_ext_put(page_ext);
231 }
232
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests
Zi Yan
reviewerRe: [PATCH v2 4/7] mm: page_owner: add support for splitting to any order in split page_owner.
Quoted 57 lines · kernel test robot
Hi Zi,
Thank you for the patch! Yet something to improve:
[auto build test ERROR on akpm-mm/mm-everything]
[also build test ERROR on linus/master v6.3-rc4 next-20230329] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]url: https://github.com/intel-lab-lkp/linux/commits/Zi-Yan/mm-memcg-use-order-instead-of-nr-in-split_page_memcg/20230329-091809 base: https://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm.git mm-everything patch link: https://lore.kernel.org/r/20230329011712.3242298-5-zi.yan%40sent.com patch subject: [PATCH v2 4/7] mm: page_owner: add support for splitting to any order in split page_owner. config: i386-randconfig-m021 (https://download.01.org/0day-ci/archive/20230329/202303291732.7OqWI96E-lkp-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org/config) compiler: gcc-11 (Debian 11.3.0-8) 11.3.0reproduce (this is a W=1 build):
# https://github.com/intel-lab-lkp/linux/commit/6d1831c0e01a1a742e026454fe6e5643e08c5985
git remote add linux-review https://github.com/intel-lab-lkp/linux
git fetch --no-tags linux-review Zi-Yan/mm-memcg-use-order-instead-of-nr-in-split_page_memcg/20230329-091809 git checkout6d1831c0e01a1a742e026454fe6e5643e08c5985
# save the config file
mkdirbuild_dir&& cp config build_dir/.config
make W=1 O=build_dir ARCH=i386 olddefconfig
make W=1 O=build_dir ARCH=i386 SHELL=/bin/bashIf you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot <[email protected]> | Link: https://lore.kernel.org/oe-kbuild-all/[email protected]/All errors (new ones prefixed by >>):
mm/page_owner.c: In function '__split_page_owner':Quoted 1 line
Quoted 1 line
mm/page_owner.c:226:28: error: implicit declaration of function 'lookup_page_ext' [-Werror=implicit-function-declaration]226 | page_ext = lookup_page_ext(page + i); | ^~~~~~~~~~~~~~~ mm/page_owner.c:226:26: warning: assignment to 'struct page_ext *' from 'int' makes pointer from integer without a cast [-Wint-conversion] 226 | page_ext = lookup_page_ext(page + i); | ^cc1: some warnings being treated as errors
vim +/lookup_page_ext +226
mm/page_owner.c213 214 void __split_page_owner(struct page *page, int old_order, int new_order) 215 { 216 int i; 217 struct page_ext *page_ext = page_ext_get(page); 218 struct page_owner *page_owner; 219 unsigned int old_nr = 1 << old_order; 220 unsigned int new_nr = 1 << new_order; 221 222 if (unlikely(!page_ext)) 223 return; 224 225 for (i = 0; i < old_nr; i += new_nr) {
Quoted 11 lines
Quoted 1 line
226
page_ext=lookup_page_ext(page + i);227 page_owner = get_page_owner(page_ext); 228 page_owner->order = new_order; 229 } 230 page_ext_put(page_ext); 231 } 232Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests
It can be fixed by the patch below. I will fix it in the next version. Thanks.
mm/page_owner.c +1 -1
@@ -223,9 +223,9 @@ void __split_page_owner(struct page *page, int old_order, int new_order)return ;for (i =0 ; i < old_nr; i += new_nr) { - page_ext =lookup_page_ext (page + i); page_owner =get_page_owner (page_ext); page_owner->order = new_order; + page_ext =page_ext_next (page_ext); }page_ext_put (page_ext); }
kernel test robot
build botRe: [PATCH v2 4/7] mm: page_owner: add support for splitting to any order in split page_owner.
In reply to Zi YanThank you for the patch! Yet something to improve:
Hi Zi,
Thank you for the patch! Yet something to improve:
[auto build test ERROR on akpm-mm/mm-everything]
[also build test ERROR on linus/master v6.3-rc4 next-20230329] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Zi-Yan/mm-memcg-use-order-instead-of-nr-in-split_page_memcg/20230329-091809 base: https://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm.git mm-everything patch link: https://lore.kernel.org/r/20230329011712.3242298-5-zi.yan%40sent.com patch subject: [PATCH v2 4/7] mm: page_owner: add support for splitting to any order in split page_owner. config: x86_64-randconfig-a016 (https://download.01.org/0day-ci/archive/20230329/202303292237.pg39cTKv-lkp-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org/config) compiler: clang version 14.0.6 (https://github.com/llvm/llvm-project f28c006a5895fc0e329fe15fead81e37457cb1d1)
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# https://github.com/intel-lab-lkp/linux/commit/6d1831c0e01a1a742e026454fe6e5643e08c5985
git remote add linux-review https://github.com/intel-lab-lkp/linux
git fetch --no-tags linux-review Zi-Yan/mm-memcg-use-order-instead-of-nr-in-split_page_memcg/20230329-091809 git checkout 6d1831c0e01a1a742e026454fe6e5643e08c5985
# save the config file
mkdir build_dir && cp config build_dir/.config
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=x86_64 olddefconfig COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=x86_64 SHELL=/bin/bash
If you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot <[email protected]>
| Link: https://lore.kernel.org/oe-kbuild-all/202303292237.pg39cTKv-lkp-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org/
All error/warnings (new ones prefixed by >>):
>> mm/page_owner.c:226:14: error: implicit declaration of function 'lookup_page_ext' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
page_ext = lookup_page_ext(page + i);
^
>> mm/page_owner.c:226:12: warning: incompatible integer to pointer conversion assigning to 'struct page_ext *' from 'int' [-Wint-conversion]
page_ext = lookup_page_ext(page + i);
^ ~~~~~~~~~~~~~~~~~~~~~~~~~1 warning and 1 error generated.
vim +/lookup_page_ext +226 mm/page_owner.c
213
214 void __split_page_owner(struct page *page, int old_order, int new_order)
215 {
216 int i;
217 struct page_ext *page_ext = page_ext_get(page);
218 struct page_owner *page_owner;
219 unsigned int old_nr = 1 << old_order;
220 unsigned int new_nr = 1 << new_order;
221
222 if (unlikely(!page_ext))
223 return;
224
225 for (i = 0; i < old_nr; i += new_nr) {
> 226 page_ext = lookup_page_ext(page + i);
227 page_owner = get_page_owner(page_ext);
228 page_owner->order = new_order;
229 }
230 page_ext_put(page_ext);
231 }
232
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests
kernel test robot
build botRe: [PATCH v2 4/7] mm: page_owner: add support for splitting to any order in split page_owner.
In reply to Zi YanThank you for the patch! Yet something to improve:
Hi Zi,
Thank you for the patch! Yet something to improve:
[auto build test ERROR on akpm-mm/mm-everything]
[also build test ERROR on linus/master v6.3-rc4 next-20230329] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Zi-Yan/mm-memcg-use-order-instead-of-nr-in-split_page_memcg/20230329-091809 base: https://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm.git mm-everything patch link: https://lore.kernel.org/r/20230329011712.3242298-5-zi.yan%40sent.com patch subject: [PATCH v2 4/7] mm: page_owner: add support for splitting to any order in split page_owner. config: riscv-buildonly-randconfig-r006-20230329 (https://download.01.org/0day-ci/archive/20230330/[email protected]/config) compiler: clang version 17.0.0 (https://github.com/llvm/llvm-project 67409911353323ca5edf2049ef0df54132fa1ca7)
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# install riscv cross compiling tool for clang build
# apt-get install binutils-riscv64-linux-gnu
# https://github.com/intel-lab-lkp/linux/commit/6d1831c0e01a1a742e026454fe6e5643e08c5985
git remote add linux-review https://github.com/intel-lab-lkp/linux
git fetch --no-tags linux-review Zi-Yan/mm-memcg-use-order-instead-of-nr-in-split_page_memcg/20230329-091809 git checkout 6d1831c0e01a1a742e026454fe6e5643e08c5985
# save the config file
mkdir build_dir && cp config build_dir/.config
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=riscv olddefconfig COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=riscv SHELL=/bin/bash
If you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot <[email protected]>
| Link: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All errors (new ones prefixed by >>):
>> mm/page_owner.c:226:14: error: call to undeclared function 'lookup_page_ext'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
page_ext = lookup_page_ext(page + i);
^
>> mm/page_owner.c:226:12: error: incompatible integer to pointer conversion assigning to 'struct page_ext *' from 'int' [-Wint-conversion]
page_ext = lookup_page_ext(page + i);
^ ~~~~~~~~~~~~~~~~~~~~~~~~~2 errors generated.
vim +/lookup_page_ext +226 mm/page_owner.c
213
214 void __split_page_owner(struct page *page, int old_order, int new_order)
215 {
216 int i;
217 struct page_ext *page_ext = page_ext_get(page);
218 struct page_owner *page_owner;
219 unsigned int old_nr = 1 << old_order;
220 unsigned int new_nr = 1 << new_order;
221
222 if (unlikely(!page_ext))
223 return;
224
225 for (i = 0; i < old_nr; i += new_nr) {
> 226 page_ext = lookup_page_ext(page + i);
227 page_owner = get_page_owner(page_ext);
228 page_owner->order = new_order;
229 }
230 page_ext_put(page_ext);
231 }
232
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests
PATCH v2 5/7 mm: thp: split huge page to any lower order pages.
In reply to Zi YanFrom: Zi Yan <[email protected]>
To split a THP to any lower order pages, we need to reform THPs on subpages at given order and add page refcount based on the new page order. Also we need to reinitialize page_deferred_list after removing the page from the split_queue, otherwise a subsequent split will see list corruption when checking the page_deferred_list again.
It has many uses, like minimizing the number of pages after truncating a huge pagecache page. For anonymous THPs, we can only split them to order-0 like before until we add support for any size anonymous THPs.
--- include/linux/huge_mm.h | 10 ++-- mm/huge_memory.c | 102 +++++++++++++++++++++++++++++----------- 2 files changed, 81 insertions(+), 31 deletions(-)
include/linux/huge_mm.h +6 -4
@@ -147,10 +147,11 @@ void prep_transhuge_page(struct page *page);void free_transhuge_page (struct page *page);bool can_split_folio (struct folio *folio,int *pextra_pins); -int split_huge_page_to_list (struct page *page,struct list_head *list); +int split_huge_page_to_list_to_order (struct page *page,struct list_head *list, +unsigned int new_order);static inline int split_huge_page (struct page *page) { -return split_huge_page_to_list (page,NULL ); +return split_huge_page_to_list_to_order (page,NULL ,0 ); }void deferred_split_folio (struct folio *folio);
@@ -297,7 +298,8 @@ can_split_folio(struct folio *folio, int *pextra_pins)return false; }static inline int -split_huge_page_to_list (struct page *page,struct list_head *list) +split_huge_page_to_list_to_order (struct page *page,struct list_head *list, +unsigned int new_order) {return 0 ; }
@@ -397,7 +399,7 @@ static inline bool thp_migration_supported(void)static inline int split_folio_to_list (struct folio *folio,struct list_head *list) { -return split_huge_page_to_list (&folio->page, list); +return split_huge_page_to_list_to_order (&folio->page, list,0 ); }static inline int split_folio (struct folio *folio)
mm/huge_memory.c +75 -27
234 lines not on this page · raw message
Signature · 1 line
2.39.2
Re: [PATCH v2 5/7] mm: thp: split huge page to any lower order pages.
Quoted 8 lines · Zi Yan
From: Zi Yan <[email protected]>
To split a THP to any lower order pages, we need to reform THPs on subpages at given order and add page refcount based on the new page order. Also we need to reinitialize
page_deferred_listafter removing the page from thesplit_queue, otherwise a subsequent split will see list corruption when checking thepage_deferred_listagain.
Quoted 5 lines
It has many uses, like minimizing the number of pages after truncating a huge pagecache page. For anonymous THPs, we can only split them to order-0 like before until we add support for any size anonymous THPs.
Because I'm currently looking into something that would also not be compatible with order-1 for now:
You should make it clear that order-1 is not supported, like:
"mm: thp: split huge page to any lower order pages (except order 1)"
And clarify in the subject why that is the case.
Signature · 3 lines
Cheers, David / dhildenb
Zi Yan
reviewerRe: [PATCH v2 5/7] mm: thp: split huge page to any lower order pages.
Quoted 15 lines · David Hildenbrand
Quoted 8 lines · Zi Yan
From: Zi Yan <[email protected]>
To split a THP to any lower order pages, we need to reform THPs on subpages at given order and add page refcount based on the new page order. Also we need to reinitialize
page_deferred_listafter removing the page from thesplit_queue, otherwise a subsequent split will see list corruption when checking thepage_deferred_listagain.Quoted 5 lines
It has many uses, like minimizing the number of pages after truncating a huge pagecache page. For anonymous THPs, we can only split them to order-0 like before until we add support for any size anonymous THPs.
Quoted 7 lines
Because I'm currently looking into something that would also not be compatible with order-1 for now:
You should make it clear that order-1 is not supported, like:
"mm: thp: split huge page to any lower order pages (except order 1)"
And clarify in the subject why that is the case.
Sure.
I will add below to the commit message and the comment of split_huge_page_to_list_to_order():
Order-1 folio is not supported because _deferred_list, which is used by partially mapped folios, is stored in subpage 2 and an order-1 folio only has subpage 0 and 1.
PATCH v2 6/7 mm: truncate: split huge page cache page to a non-zero order if possible.
In reply to Zi YanFrom: Zi Yan <[email protected]>
To minimize the number of pages after a huge page truncation, we do not need to split it all the way down to order-0. The huge page has at most three parts, the part before offset, the part to be truncated, the part remaining at the end. Find the greatest common divisor of them to calculate the new page order from it, so we can split the huge page to this order and keep the remaining pages as large and as few as possible.
--- mm/truncate.c | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-)
mm/truncate.c +19 -2
@@ -22,6 +22,7 @@#include <linux/buffer_head.h> /* grr. try_to_release_page */ #include <linux/shmem_fs.h> #include <linux/rmap.h> +#include <linux/gcd.h> #include "internal.h" /*
@@ -211,7 +212,8 @@ int truncate_inode_folio(struct address_space *mapping, struct folio *folio)bool truncate_inode_partial_folio (struct folio *folio,loff_t start,loff_t end) {loff_t pos =folio_pos (folio); -unsigned int offset, length; +unsigned int offset, length, remaining; +unsigned int new_order =folio_order (folio);if (pos < start) offset = start - pos;
@@ -222,6 +224,7 @@ bool truncate_inode_partial_folio(struct folio *folio, loff_t start, loff_t end) length = length - offset; else length = end +1 - pos - offset; + remaining =folio_size (folio) - offset - length;folio_wait_writeback (folio);if (length ==folio_size (folio)) {
@@ -236,11 +239,25 @@ bool truncate_inode_partial_folio(struct folio *folio, loff_t start, loff_t end)*/ folio_zero_range (folio, offset, length); +/* +* Use the greatest common divisor of offset, length, and remaining +* as the smallest page size and compute the new order from it. So we +* can truncate a subpage as large as possible. Round up gcd to +* PAGE_SIZE, otherwise ilog2 can give -1 when gcd/PAGE_SIZE is 0. +*/ + new_order =ilog2 (round_up (gcd (gcd (offset, length), remaining), +PAGE_SIZE ) /PAGE_SIZE ); + +/* order-1 THP not supported, downgrade to order-0 */ +if (new_order ==1 ) + new_order =0 ; + +if (folio_has_private (folio))folio_invalidate (folio, offset, length);if (!folio_test_large (folio))return true; -if (split_folio (folio) ==0 ) +if (split_huge_page_to_list_to_order (&folio->page,NULL , new_order) ==0 )return true;if (folio_test_dirty (folio))return false;
Signature · 1 line
2.39.2
PATCH v2 7/7 mm: huge_memory: enable debugfs to split huge pages to any order.
In reply to Zi YanFrom: Zi Yan <[email protected]>
It is used to test split_huge_page_to_list_to_order for pagecache THPs. Also add test cases for split_huge_page_to_list_to_order via both debugfs, truncating a file, and punching holes in a file.
--- mm/huge_memory.c | 34 ++- .../selftests/mm/split_huge_page_test.c | 225 +++++++++++++++++- 2 files changed, 242 insertions(+), 17 deletions(-)
mm/huge_memory.c +22 -12
@@ -3023,7 +3023,7 @@ static inline bool vma_not_suitable_for_thp_split(struct vm_area_struct *vma) }static int split_huge_pages_pid (int pid,unsigned long vaddr_start, -unsigned long vaddr_end) +unsigned long vaddr_end,unsigned int new_order) {int ret =0 ;struct task_struct *task;
@@ -3085,13 +3085,19 @@ static int split_huge_pages_pid(int pid, unsigned long vaddr_start, goto next; total++; -if (!can_split_folio (page_folio (page),NULL )) +/* +* For folios with private, split_huge_page_to_list_to_order() +* will try to drop it before split and then check if the folio +* can be split or not. So skip the check here. +*/ +if (!folio_test_private (page_folio (page)) && + !can_split_folio (page_folio (page),NULL )) goto next;if (!trylock_page (page)) goto next; -if (!split_huge_page (page)) +if (!split_huge_page_to_list_to_order (page,NULL , new_order)) split++;unlock_page (page);
@@ -3109,7 +3115,7 @@ static int split_huge_pages_pid(int pid, unsigned long vaddr_start, }static int split_huge_pages_in_file (const char *file_path,pgoff_t off_start, -pgoff_t off_end) +pgoff_t off_end,unsigned int new_order) {struct filename *file;struct file *candidate;
@@ -3148,7 +3154,7 @@ static int split_huge_pages_in_file(const char *file_path, pgoff_t off_start,if (!folio_trylock (folio)) goto next; -if (!split_folio (folio)) +if (!split_huge_page_to_list_to_order (&folio->page,NULL , new_order)) split++;folio_unlock (folio);
@@ -3173,10 +3179,14 @@ static ssize_t split_huge_pages_write(struct file *file, const char __user *buf, {static DEFINE_MUTEX (split_debug_mutex);ssize_t ret; -/* hold pid, start_vaddr, end_vaddr or file_path, off_start, off_end */ +/* +* hold pid, start_vaddr, end_vaddr, new_order or +* file_path, off_start, off_end, new_order +*/ char input_buf[MAX_INPUT_BUF_SZ ];int pid;unsigned long vaddr_start, vaddr_end; +unsigned int new_order =0 ; ret =mutex_lock_interruptible (&split_debug_mutex);if (ret)
@@ -3205,29 +3215,29 @@ static ssize_t split_huge_pages_write(struct file *file, const char __user *buf, goto out; } - ret =sscanf (buf,"0x%lx,0x%lx" , &off_start, &off_end); -if (ret !=2 ) { + ret =sscanf (buf,"0x%lx,0x%lx,%d" , &off_start, &off_end, &new_order); +if (ret !=2 && ret !=3 ) { ret = -EINVAL ; goto out; } - ret =split_huge_pages_in_file (file_path, off_start, off_end); + ret =split_huge_pages_in_file (file_path, off_start, off_end, new_order);if (!ret) ret = input_len; goto out; } - ret =sscanf (input_buf,"%d,0x%lx,0x%lx" , &pid, &vaddr_start, &vaddr_end); + ret =sscanf (input_buf,"%d,0x%lx,0x%lx,%d" , &pid, &vaddr_start, &vaddr_end, &new_order);if (ret ==1 && pid ==1 ) {split_huge_pages_all (); ret =strlen (input_buf); goto out; - }else if (ret !=3 ) { + }else if (ret !=3 && ret !=4 ) { ret = -EINVAL ; goto out; } - ret =split_huge_pages_pid (pid, vaddr_start, vaddr_end); + ret =split_huge_pages_pid (pid, vaddr_start, vaddr_end, new_order);if (!ret) ret =strlen (input_buf); out:
tools/testing/selftests/mm/split_huge_page_test.c +220 -5
277 lines not on this page · raw message
Signature · 1 line
2.39.2