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: Thu, 1 Feb 2024 10:28:11 +0100
From: Jan Kara <jack@...e.cz>
To: Liu Shixin <liushixin2@...wei.com>
Cc: Alexander Viro <viro@...iv.linux.org.uk>,
	Christian Brauner <brauner@...nel.org>, Jan Kara <jack@...e.cz>,
	Matthew Wilcox <willy@...radead.org>,
	Andrew Morton <akpm@...ux-foundation.org>,
	linux-fsdevel@...r.kernel.org, linux-kernel@...r.kernel.org,
	linux-mm@...ck.org
Subject: Re: [PATCH 1/2] mm/readahead: stop readahead loop if memcg charge
 fails

On Thu 01-02-24 18:08:34, Liu Shixin wrote:
> When a task in memcg readaheads file pages, page_cache_ra_unbounded()
> will try to readahead nr_to_read pages. Even if the new allocated page
> fails to charge, page_cache_ra_unbounded() still tries to readahead
> next page. This leads to too much memory reclaim.
> 
> Stop readahead if mem_cgroup_charge() fails, i.e. add_to_page_cache_lru()
> returns -ENOMEM.
> 
> Signed-off-by: Liu Shixin <liushixin2@...wei.com>
> Signed-off-by: Jinjiang Tu <tujinjiang@...wei.com>

Makes sense. Feel free to add:

Reviewed-by: Jan Kara <jack@...e.cz>

								Honza

> ---
>  mm/readahead.c | 8 ++++++--
>  1 file changed, 6 insertions(+), 2 deletions(-)
> 
> diff --git a/mm/readahead.c b/mm/readahead.c
> index 23620c57c1225..cc4abb67eb223 100644
> --- a/mm/readahead.c
> +++ b/mm/readahead.c
> @@ -228,6 +228,7 @@ void page_cache_ra_unbounded(struct readahead_control *ractl,
>  	 */
>  	for (i = 0; i < nr_to_read; i++) {
>  		struct folio *folio = xa_load(&mapping->i_pages, index + i);
> +		int ret;
>  
>  		if (folio && !xa_is_value(folio)) {
>  			/*
> @@ -247,9 +248,12 @@ void page_cache_ra_unbounded(struct readahead_control *ractl,
>  		folio = filemap_alloc_folio(gfp_mask, 0);
>  		if (!folio)
>  			break;
> -		if (filemap_add_folio(mapping, folio, index + i,
> -					gfp_mask) < 0) {
> +
> +		ret = filemap_add_folio(mapping, folio, index + i, gfp_mask);
> +		if (ret < 0) {
>  			folio_put(folio);
> +			if (ret == -ENOMEM)
> +				break;
>  			read_pages(ractl);
>  			ractl->_index++;
>  			i = ractl->_index + ractl->_nr_pages - index - 1;
> -- 
> 2.25.1
> 
-- 
Jan Kara <jack@...e.com>
SUSE Labs, CR

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ