mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] mm: mglru: use pte_table_clamped_end() helper to calculate the end
@ 2026-11-12 11:12 Baolin Wang
  2026-11-13  5:01 ` Barry Song
  2026-11-13 17:10 ` kernel test robot
  0 siblings, 2 replies; 4+ messages in thread
From: Baolin Wang @ 2026-11-12 11:12 UTC (permalink / raw)
  To: akpm, david, hannes, kasong
  Cc: baohua, axelrasmussen, yuanchu, weixugc, baoquan.he, qi.zheng,
	shakeel.butt, mhocko, baolin.wang, linux-mm, linux-kernel

Use pte_table_clamped_end() to clamp the range to the PTE table and VMA
boundaries when batch-checking young flags, making the code more readable.

No functional changes intended.

Signed-off-by: Baolin Wang <baolin.wang@linux.alibaba.com>
---
Based on mm/core.git for-next branch.

Note that this was found while reviewing David's series:
https://lore.kernel.org/all/c31cc8a0-c098-4784-a843-f13f51914094@linux.alibaba.com/
---
 mm/vmscan.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/mm/vmscan.c b/mm/vmscan.c
index 5495d9be90e8..804d4188e7b4 100644
--- a/mm/vmscan.c
+++ b/mm/vmscan.c
@@ -4470,7 +4470,7 @@ bool lru_gen_look_around(struct page_vma_mapped_walk *pvmw, unsigned int nr)
 	walk = current->reclaim_state ? current->reclaim_state->mm_walk : NULL;
 
 	start = max(addr & PMD_MASK, vma->vm_start);
-	end = min(addr | ~PMD_MASK, vma->vm_end - 1) + 1;
+	end = pte_table_clamped_end(addr, vma->vm_end);
 
 	if (end - start == PAGE_SIZE)
 		return true;
-- 
2.47.3


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] mm: mglru: use pte_table_clamped_end() helper to calculate the end
  2026-11-12 11:12 [PATCH] mm: mglru: use pte_table_clamped_end() helper to calculate the end Baolin Wang
@ 2026-11-13  5:01 ` Barry Song
  2026-11-13  5:31   ` Baolin Wang
  2026-11-13 17:10 ` kernel test robot
  1 sibling, 1 reply; 4+ messages in thread
From: Barry Song @ 2026-11-13  5:01 UTC (permalink / raw)
  To: Baolin Wang
  Cc: akpm, david, hannes, kasong, axelrasmussen, yuanchu, weixugc,
	baoquan.he, qi.zheng, shakeel.butt, mhocko, linux-mm,
	linux-kernel

On Thu, Nov 12, 2026 at 7:13 PM Baolin Wang
<baolin.wang@linux.alibaba.com> wrote:
>
> Use pte_table_clamped_end() to clamp the range to the PTE table and VMA
> boundaries when batch-checking young flags, making the code more readable.
>
> No functional changes intended.
>
> Signed-off-by: Baolin Wang <baolin.wang@linux.alibaba.com>
> ---
> Based on mm/core.git for-next branch.
>
> Note that this was found while reviewing David's series:
> https://lore.kernel.org/all/c31cc8a0-c098-4784-a843-f13f51914094@linux.alibaba.com/
> ---
>  mm/vmscan.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/mm/vmscan.c b/mm/vmscan.c
> index 5495d9be90e8..804d4188e7b4 100644
> --- a/mm/vmscan.c
> +++ b/mm/vmscan.c
> @@ -4470,7 +4470,7 @@ bool lru_gen_look_around(struct page_vma_mapped_walk *pvmw, unsigned int nr)
>         walk = current->reclaim_state ? current->reclaim_state->mm_walk : NULL;
>
>         start = max(addr & PMD_MASK, vma->vm_start);
> -       end = min(addr | ~PMD_MASK, vma->vm_end - 1) + 1;
> +       end = pte_table_clamped_end(addr, vma->vm_end);


We don't have pte_table_clamped_end() in Andrew's tree yet;
it's part of David's patch:

https://lore.kernel.org/all/20261111-pte_table_clamped_end-v1-1-2dbe339c487a@kernel.org/

So we're not going through Andrew's tree for this patch, right?

>
>         if (end - start == PAGE_SIZE)
>                 return true;
> --
> 2.47.3
>

Thanks,
Barry

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] mm: mglru: use pte_table_clamped_end() helper to calculate the end
  2026-11-13  5:01 ` Barry Song
@ 2026-11-13  5:31   ` Baolin Wang
  0 siblings, 0 replies; 4+ messages in thread
From: Baolin Wang @ 2026-11-13  5:31 UTC (permalink / raw)
  To: Barry Song
  Cc: akpm, david, hannes, kasong, axelrasmussen, yuanchu, weixugc,
	baoquan.he, qi.zheng, shakeel.butt, mhocko, linux-mm,
	linux-kernel



On 11/13/26 1:01 PM, Barry Song wrote:
> On Thu, Nov 12, 2026 at 7:13 PM Baolin Wang
> <baolin.wang@linux.alibaba.com> wrote:
>>
>> Use pte_table_clamped_end() to clamp the range to the PTE table and VMA
>> boundaries when batch-checking young flags, making the code more readable.
>>
>> No functional changes intended.
>>
>> Signed-off-by: Baolin Wang <baolin.wang@linux.alibaba.com>
>> ---
>> Based on mm/core.git for-next branch.
>>
>> Note that this was found while reviewing David's series:
>> https://lore.kernel.org/all/c31cc8a0-c098-4784-a843-f13f51914094@linux.alibaba.com/
>> ---
>>   mm/vmscan.c | 2 +-
>>   1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/mm/vmscan.c b/mm/vmscan.c
>> index 5495d9be90e8..804d4188e7b4 100644
>> --- a/mm/vmscan.c
>> +++ b/mm/vmscan.c
>> @@ -4470,7 +4470,7 @@ bool lru_gen_look_around(struct page_vma_mapped_walk *pvmw, unsigned int nr)
>>          walk = current->reclaim_state ? current->reclaim_state->mm_walk : NULL;
>>
>>          start = max(addr & PMD_MASK, vma->vm_start);
>> -       end = min(addr | ~PMD_MASK, vma->vm_end - 1) + 1;
>> +       end = pte_table_clamped_end(addr, vma->vm_end);
> 
> 
> We don't have pte_table_clamped_end() in Andrew's tree yet;
> it's part of David's patch:
> 
> https://lore.kernel.org/all/20261111-pte_table_clamped_end-v1-1-2dbe339c487a@kernel.org/
> 
> So we're not going through Andrew's tree for this patch, right?

Yes. I think David will pick up this follow-up.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] mm: mglru: use pte_table_clamped_end() helper to calculate the end
  2026-11-12 11:12 [PATCH] mm: mglru: use pte_table_clamped_end() helper to calculate the end Baolin Wang
  2026-11-13  5:01 ` Barry Song
@ 2026-11-13 17:10 ` kernel test robot
  1 sibling, 0 replies; 4+ messages in thread
From: kernel test robot @ 2026-11-13 17:10 UTC (permalink / raw)
  To: Baolin Wang, akpm, david, hannes, kasong
  Cc: oe-kbuild-all, baohua, axelrasmussen, yuanchu, weixugc,
	baoquan.he, qi.zheng, shakeel.butt, mhocko, baolin.wang,
	linux-mm, linux-kernel

Hi Baolin,

kernel test robot noticed the following build errors:

[auto build test ERROR on akpm-mm/mm-everything]

url:    https://github.com/intel-lab-lkp/linux/commits/Baolin-Wang/mm-mglru-use-pte_table_clamped_end-helper-to-calculate-the-end/20261112-191239
base:   https://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm.git mm-everything
patch link:    https://lore.kernel.org/r/b2386c5da61f9a15e60daa421b033bc1e0bcdd41.1794481498.git.baolin.wang%40linux.alibaba.com
patch subject: [PATCH] mm: mglru: use pte_table_clamped_end() helper to calculate the end
config: x86_64-rhel-9.4-ltp (https://download.01.org/0day-ci/archive/20261114/202611140137.58xBD8xH-lkp@intel.com/config)
compiler: gcc-14 (Debian 14.2.0-19) 14.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20261114/202611140137.58xBD8xH-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202611140137.58xBD8xH-lkp@intel.com/

All errors (new ones prefixed by >>):

   mm/vmscan.c: In function 'lru_gen_look_around':
>> mm/vmscan.c:4343:15: error: implicit declaration of function 'pte_table_clamped_end' [-Wimplicit-function-declaration]
    4343 |         end = pte_table_clamped_end(addr, vma->vm_end);
         |               ^~~~~~~~~~~~~~~~~~~~~


vim +/pte_table_clamped_end +4343 mm/vmscan.c

  4296	
  4297	/******************************************************************************
  4298	 *                          rmap/PT walk feedback
  4299	 ******************************************************************************/
  4300	
  4301	/*
  4302	 * This function exploits spatial locality when shrink_folio_list() walks the
  4303	 * rmap. It scans the adjacent PTEs of a young PTE and promotes hot pages. If
  4304	 * the scan was done cacheline efficiently, it adds the PMD entry pointing to
  4305	 * the PTE table to the Bloom filter. This forms a feedback loop between the
  4306	 * eviction and the aging.
  4307	 */
  4308	bool lru_gen_look_around(struct page_vma_mapped_walk *pvmw, unsigned int nr)
  4309	{
  4310		int i;
  4311		bool dirty;
  4312		unsigned long start;
  4313		unsigned long end;
  4314		struct lru_gen_mm_walk *walk;
  4315		struct folio *last = NULL;
  4316		int young = nr;
  4317		pte_t *pte = pvmw->pte;
  4318		unsigned long addr = pvmw->address;
  4319		struct vm_area_struct *vma = pvmw->vma;
  4320		struct folio *folio = pfn_folio(pvmw->pfn);
  4321		struct mem_cgroup *memcg;
  4322		struct pglist_data *pgdat = folio_pgdat(folio);
  4323		struct lruvec *lruvec;
  4324		struct lru_gen_mm_state *mm_state;
  4325	
  4326		lockdep_assert_held(pvmw->ptl);
  4327		VM_WARN_ON_ONCE_FOLIO(folio_test_lru(folio), folio);
  4328	
  4329		if (!test_and_clear_young_ptes_notify(vma, addr, pte, nr))
  4330			return false;
  4331	
  4332		if (spin_is_contended(pvmw->ptl))
  4333			return true;
  4334	
  4335		/* exclude non-mm-backed VMAs containing anon pages from COW */
  4336		if (!vma_is_mm_backed(vma))
  4337			return true;
  4338	
  4339		/* avoid taking the LRU lock under the PTL when possible */
  4340		walk = current->reclaim_state ? current->reclaim_state->mm_walk : NULL;
  4341	
  4342		start = max(addr & PMD_MASK, vma->vm_start);
> 4343		end = pte_table_clamped_end(addr, vma->vm_end);
  4344	
  4345		if (end - start == PAGE_SIZE)
  4346			return true;
  4347	
  4348		if (end - start > MIN_LRU_BATCH * PAGE_SIZE) {
  4349			if (addr - start < MIN_LRU_BATCH * PAGE_SIZE / 2)
  4350				end = start + MIN_LRU_BATCH * PAGE_SIZE;
  4351			else if (end - addr < MIN_LRU_BATCH * PAGE_SIZE / 2)
  4352				start = end - MIN_LRU_BATCH * PAGE_SIZE;
  4353			else {
  4354				start = addr - MIN_LRU_BATCH * PAGE_SIZE / 2;
  4355				end = addr + MIN_LRU_BATCH * PAGE_SIZE / 2;
  4356			}
  4357		}
  4358	
  4359		memcg = get_mem_cgroup_from_folio(folio);
  4360		lruvec = mem_cgroup_lruvec(memcg, pgdat);
  4361		mm_state = get_mm_state(lruvec);
  4362	
  4363		lazy_mmu_mode_enable();
  4364	
  4365		pte -= (addr - start) / PAGE_SIZE;
  4366	
  4367		for (i = 0, addr = start; addr != end;
  4368		     i += nr, pte += nr, addr += nr * PAGE_SIZE) {
  4369			unsigned long pfn;
  4370			pte_t ptent = ptep_get(pte);
  4371	
  4372			nr = 1;
  4373			pfn = get_pte_pfn(ptent, vma, addr, pgdat);
  4374			if (pfn == -1)
  4375				continue;
  4376	
  4377			folio = get_pfn_folio(pfn, memcg, pgdat);
  4378			if (!folio)
  4379				continue;
  4380	
  4381			if (folio_test_large(folio)) {
  4382				const unsigned int max_nr = (end - addr) >> PAGE_SHIFT;
  4383	
  4384				nr = folio_pte_batch_flags(folio, NULL, pte, &ptent,
  4385							   max_nr, FPB_MERGE_YOUNG_DIRTY);
  4386			}
  4387	
  4388			if (!test_and_clear_young_ptes_notify(vma, addr, pte, nr))
  4389				continue;
  4390	
  4391			if (last != folio) {
  4392				walk_update_folio(walk, vma, lruvec, last, dirty);
  4393	
  4394				last = folio;
  4395				dirty = false;
  4396			}
  4397	
  4398			if (pte_dirty(ptent))
  4399				dirty = true;
  4400	
  4401			young += nr;
  4402		}
  4403	
  4404		walk_update_folio(walk, vma, lruvec, last, dirty);
  4405	
  4406		lazy_mmu_mode_disable();
  4407	
  4408		/* feedback from rmap walkers to page table walkers */
  4409		if (mm_state && suitable_to_scan(i, young))
  4410			update_bloom_filter(mm_state, READ_ONCE(lruvec->lrugen.max_seq),
  4411					    pvmw->pmd);
  4412	
  4413		mem_cgroup_put(memcg);
  4414	
  4415		return true;
  4416	}
  4417	

--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-11-13 17:11 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-12 11:12 [PATCH] mm: mglru: use pte_table_clamped_end() helper to calculate the end Baolin Wang
2026-11-13  5:01 ` Barry Song
2026-11-13  5:31   ` Baolin Wang
2026-11-13 17:10 ` kernel test robot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®