On Wed, Jan 08, 2025 at 07:41:31PM +0000, Lorenzo Stoakes wrote:
> On Wed, Jan 08, 2025 at 05:32:54PM +0000, Matthew Wilcox wrote:
> > On Wed, Jan 08, 2025 at 04:18:42PM +0000, Lorenzo Stoakes wrote:
> > > @@ -280,7 +269,10 @@ static void fb_deferred_io_work(struct work_struct 
> > > *work)
> > >           struct folio *folio = page_folio(pageref->page);
> > >
> > >           folio_lock(folio);
> > > -         folio_mkclean(folio);
> > > +         rmap_wrprotect_file_page(fbdefio->mapping,
> > > +                                  pageref->offset >> PAGE_SHIFT,
> > > +                                  compound_nr(pageref->page),
> > > +                                  page_to_pfn(pageref->page));
> > >           folio_unlock(folio);
> >
> > Why do we need to lock the folio?  (since this isn't necessarily a
> > folio)  Also, do we need compound_nr() here?  I _think_ for defio,
> > the number of pages allocated per object are fixed, so this should be
> > an fbdefio->nr_pages field?
>
> I'm trying to keep the code as similar as possible to the way it was before,
> even if there are questionable parts.
>
> There is a comment about some timing issue around the locks and so there 
> appears
> to be an assumption about that.

Actually, reading through the code, I think the comment is with regards to
page_mkwrite(), so we should be ok, in fb_deferred_io_track_page():

        /*
         * We want the page to remain locked from ->page_mkwrite until
         * the PTE is marked dirty to avoid mapping_wrprotect_page()
         * being called before the PTE is updated, which would leave
         * the page ignored by defio.
         * Do this by locking the page here and informing the caller
         * about it with VM_FAULT_LOCKED.
         */
        lock_page(pageref->page);

I don't think we need to lock the page (which is managed as kernel memory so
doesn't require it).

So will remove.

>
> As to compound_nr(), we're not write protecting everything, just each 
> invidiual
> page in the list that needs it, so we only want to do one at a time. I 
> strongly
> suspect it's a single base page each time, but for belts + braces I'm doing
> compound_nr().
>
> See below, this is wrong, it should just be '1'.
>
> So this is iterating through a list of pagerefs that can be in any random 
> order.
>
> >
> > (something that's always troubled me about compound_nr() is that it
> > returns 1 for tail pages and the number you actually expect for head
> > pages)
> >
>
> OK I changed this from '1' to compound_nr() out of an (apparently) abundance 
> of
> caution, but I was wrong:
>
> npagerefs = DIV_ROUND_UP(info->fix.smem_len, PAGE_SIZE);
>
> There are page refs for each PAGE_SIZE (i.e. base page size), so there is no 
> way
> anything is compound.
>
> Will switch this to 1.

Reply via email to