Re: [RFC][PATCH 3/4] filemap: implement filemap allocate post callback for page_owner
From: Matthew Wilcox
Date: Thu Nov 09 2023 - 09:09:21 EST
On Thu, Nov 09, 2023 at 11:25:20AM +0800, Jeff Xie wrote:
> +static int filemap_alloc_post_page_owner(struct folio *folio, struct task_struct *tsk,
> + void *data, char *kbuf, size_t count)
> +{
> + int ret;
> + int mapcount;
> + dev_t s_dev;
> + struct inode *inode;
> + struct vm_area_struct *vma;
> + struct mm_struct *mm;
> + unsigned long virtual_start = 0x0;
> + unsigned long virtual_end = 0x0;
> + struct address_space *mapping = data;
This is just folio->mapping.
> + mapcount = folio_mapcount(folio);
> + if (mapcount && tsk && tsk->mm) {
> + mm = tsk->mm;
> + VMA_ITERATOR(vmi, mm, 0);
> + mmap_read_lock(mm);
> + for_each_vma(vmi, vma) {
> + if (page_mapped_in_vma(&folio->page, vma)) {
> + virtual_start = vma_address(&folio->page, vma);
> + virtual_end = virtual_start + folio_nr_pages(folio) * PAGE_SIZE;
> + break;
> + }
> + }
> + mmap_read_unlock(mm);
> + }
Why not just walk the rmap directly to find out where it's mapped in
any process instead of the one which allocated it?