Re: [RFC][PATCH 3/4] filemap: implement filemap allocate post callback for page_owner

jeff.xie
2023-11-09T15:46:08Z

November 9, 2023 at 10:09 PM, "Matthew Wilcox" <willy@infradead.org> wrote:

>
> 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.

Thanks, I need to know more about struct folio ;-)

>
> >
> > + 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?

Since the page_owner's result only shows which PID allocated this page, we only need to obtain the address space of the corresponding process for that PID.

--
Jeff Xie