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]
Message-ID: <YkXCWW7ru9Gxyy6G@casper.infradead.org>
Date:   Thu, 31 Mar 2022 16:01:45 +0100
From:   Matthew Wilcox <willy@...radead.org>
To:     Muchun Song <songmuchun@...edance.com>
Cc:     akpm@...ux-foundation.org, hannes@...xchg.org, mhocko@...nel.org,
        vdavydov.dev@...il.com, shakeelb@...gle.com,
        roman.gushchin@...ux.dev, shy828301@...il.com, alexs@...nel.org,
        richard.weiyang@...il.com, david@...morbit.com,
        trond.myklebust@...merspace.com, anna.schumaker@...app.com,
        jaegeuk@...nel.org, chao@...nel.org, kari.argillander@...il.com,
        vbabka@...e.cz, linux-fsdevel@...r.kernel.org,
        linux-kernel@...r.kernel.org, linux-mm@...ck.org,
        linux-nfs@...r.kernel.org, zhengqi.arch@...edance.com,
        duanxiongchun@...edance.com, fam.zheng@...edance.com,
        smuchun@...il.com
Subject: Re: [PATCH v6 12/16] mm: list_lru: replace linear array with xarray

On Mon, Feb 28, 2022 at 08:21:22PM +0800, Muchun Song wrote:
> @@ -586,27 +508,48 @@ int memcg_list_lru_alloc(struct mem_cgroup *memcg, struct list_lru *lru,
>  		}
>  	}
>  
> +	xas_lock_irqsave(&xas, flags);
>  	while (i--) {
> +		int index = READ_ONCE(table[i].memcg->kmemcg_id);
>  		struct list_lru_per_memcg *mlru = table[i].mlru;
>  
> +		xas_set(&xas, index);
> +retry:
> +		if (unlikely(index < 0 || xas_error(&xas) || xas_load(&xas))) {
>  			kfree(mlru);
> +		} else {
> +			xas_store(&xas, mlru);
> +			if (xas_error(&xas) == -ENOMEM) {
> +				xas_unlock_irqrestore(&xas, flags);
> +				if (xas_nomem(&xas, gfp))
> +					xas_set_err(&xas, 0);
> +				xas_lock_irqsave(&xas, flags);
> +				/*
> +				 * The xas lock has been released, this memcg
> +				 * can be reparented before us. So reload
> +				 * memcg id. More details see the comments
> +				 * in memcg_reparent_list_lrus().
> +				 */
> +				index = READ_ONCE(table[i].memcg->kmemcg_id);
> +				if (index < 0)
> +					xas_set_err(&xas, 0);
> +				else if (!xas_error(&xas) && index != xas.xa_index)
> +					xas_set(&xas, index);
> +				goto retry;
> +			}
> +		}
>  	}
> +	/* xas_nomem() is used to free memory instead of memory allocation. */
> +	if (xas.xa_alloc)
> +		xas_nomem(&xas, gfp);
> +	xas_unlock_irqrestore(&xas, flags);
>  	kfree(table);
>  
> +	return xas_error(&xas);
>  }

This is really unidiomatic.  And so much more complicated than it needs
to be.

	while (i--) {
		do {
			int index = READ_ONCE(table[i].memcg->kmemcg_id);
			struct list_lru_per_memcg *mlru = table[i].mlru;

			xas_set(&xas, index);
			xas_lock_irqsave(&xas, flags);
			if (index < 0 || xas_load(&xas))
				xas_set_err(&xas, -EBUSY);
			xas_store(&xas, mlru);
			if (!xas_error(&xas))
				break;
			xas_unlock_irqrestore(&xas, flags);
		} while (xas_nomem(&xas, gfp));

		if (xas_error(&xas))
			kfree(mlru);
	}

	kfree(table);
	return xas_error(&xas);

(you might want to mask out the EBUSY error here)

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ