lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date: Mon, 17 Jun 2024 16:04:20 +0000
From: "Pankaj Raghav (Samsung)" <kernel@...kajraghav.com>
To: Matthew Wilcox <willy@...radead.org>
Cc: david@...morbit.com, djwong@...nel.org, chandan.babu@...cle.com,
	brauner@...nel.org, akpm@...ux-foundation.org, mcgrof@...nel.org,
	linux-mm@...ck.org, hare@...e.de, linux-kernel@...r.kernel.org,
	yang@...amperecomputing.com, Zi Yan <zi.yan@...t.com>,
	linux-xfs@...r.kernel.org, p.raghav@...sung.com,
	linux-fsdevel@...r.kernel.org, hch@....de, gost.dev@...sung.com,
	cl@...amperecomputing.com, john.g.garry@...cle.com
Subject: Re: [PATCH v7 04/11] readahead: allocate folios with
 mapping_min_order in readahead

On Mon, Jun 17, 2024 at 01:32:42PM +0100, Matthew Wilcox wrote:
> On Fri, Jun 14, 2024 at 09:26:02AM +0000, Pankaj Raghav (Samsung) wrote:
> > > Hm, but we don't have a reference on this folio.  So this isn't safe.
> > 
> > That is why I added a check for mapping after read_pages(). You are
> > right, we can make it better.
> 
> That's not enoughh.
> 
> > > > +			if (mapping != folio->mapping)
> > > > +				nr_pages = min_nrpages;
> > > > +
> > > > +			VM_BUG_ON_FOLIO(nr_pages < min_nrpages, folio);
> > > > +			ractl->_index += nr_pages;
> > > 
> > > Why not just:
> > > 			ractl->_index += min_nrpages;
> > 
> > Then we will only move min_nrpages even if the folio we found had a
> > bigger order. Hannes patches (first patch) made sure we move the
> > ractl->index by folio_nr_pages instead of 1 and making this change will
> > defeat the purpose because without mapping order set, min_nrpages will
> > be 1.
> 
> Hannes' patch is wrong.  It's not safe to call folio_nr_pages() unless
> you have a reference to the folio.
> 
> > @@ -266,10 +266,8 @@ void page_cache_ra_unbounded(struct readahead_control *ractl,
> >                          * alignment constraint in the page cache.
> >                          *
> >                          */
> > -                       if (mapping != folio->mapping)
> > -                               nr_pages = min_nrpages;
> > +                       nr_pages = max(folio_nr_pages(folio), (long)min_nrpages);
> 
> No.
> 
> > Now we will still move respecting the min order constraint but if we had
> > a bigger folio and we do have a reference, then we move folio_nr_pages.
> 
> You don't have a reference, so it's never safe.
I am hitting my head now because you have literally mentioned that in
the comment:

	 * next batch.  This page may be the one we would
	 * have intended to mark as Readahead, but we don't
	 * have a stable reference to this page, and it's
	 * not worth getting one just for that.

I will move it by min_nrpages as follows:
>	ractl->_index += min_nrpages;


So the following can still be there from Hannes patch as we have a 
stable reference:

 		ractl->_workingset |= folio_test_workingset(folio);
-		ractl->_nr_pages++;
+		ractl->_nr_pages += folio_nr_pages(folio);
+		i += folio_nr_pages(folio);
 	}
 

Thanks for the clarification.

--
Pankaj

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ