linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Shakeel Butt <shakeel.butt@linux.dev>
To: Vlastimil Babka <vbabka@suse.cz>
Cc: Jingxiang Zeng <linuszeng@tencent.com>,
	linux-mm@kvack.org,  akpm@linux-foundation.org,
	hannes@cmpxchg.org, mhocko@kernel.org, roman.gushchin@linux.dev,
	 muchun.song@linux.dev, chengming.zhou@linux.dev,
	kasong@tencent.com,  kernel test robot <lkp@intel.com>
Subject: Re: [PATCH] mm/list_lru: make the case where mlru is NULL as unlikely
Date: Fri, 28 Feb 2025 10:48:12 -0800	[thread overview]
Message-ID: <lvuudvfogvdz7ybzuwy2j4oivxce5vlgltnzuguk52sqmwy7cu@wpkzyv3zdfne> (raw)
In-Reply-To: <c2b440f7-2b72-415b-887c-4effb9357b47@suse.cz>

On Fri, Feb 28, 2025 at 05:33:28PM +0100, Vlastimil Babka wrote:
> On 2/28/25 17:30, Vlastimil Babka wrote:
> > On 2/25/25 17:23, Shakeel Butt wrote:
> >> On Tue, Feb 25, 2025 at 11:30:20PM +0800, Jingxiang Zeng wrote:
> >>>  mm/list_lru.c | 2 +-
> >>>  1 file changed, 1 insertion(+), 1 deletion(-)
> >>> 
> >>> diff --git a/mm/list_lru.c b/mm/list_lru.c
> >>> index 064d2018e265..e7e13513ff8e 100644
> >>> --- a/mm/list_lru.c
> >>> +++ b/mm/list_lru.c
> >>> @@ -552,7 +552,7 @@ static int memcg_list_lru_alloc(struct mem_cgroup *memcg, struct list_lru *lru)
> >>>  			}
> >>>  			xas_unlock_irqrestore(&xas, flags);
> >>>  		} while (xas_nomem(&xas, GFP_KERNEL));
> >>> -		if (mlru)
> >>> +		if (unlikely(mlru))
> >>>  			kfree(mlru);
> >> 
> >> The report is saying not to check at all. So, just remove the check and
> >> simply call kfree(mlru) as it handles the NULL check efficiently.
> > 
> > BTW, if it's unlikely to be !NULL then it's not really efficient to call
> > kfree() unconditionally as it's a function call and those are more expensive
> > than inline check (especially with spectre mitigations).

Thanks, that warning gave me the impression that unconditional kfree() is
always better.

> 
> OTOH making kfree() do the check inline would bloat all callers, and most of
> them are likely !NULL.
> We could perhaps have a kfree_unlikely() variant doing an inline
> "if unlikely(obj) kfree()" if enough places do it.
> 

This makes sense.


      reply	other threads:[~2025-02-28 18:48 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-02-25 15:30 Jingxiang Zeng
2025-02-25 16:23 ` Shakeel Butt
2025-02-26  1:11   ` Johannes Weiner
2025-02-26  2:09     ` jingxiang zeng
2025-02-26 21:08     ` Shakeel Butt
2025-02-27  8:03       ` jingxiang zeng
2025-02-28 16:30   ` Vlastimil Babka
2025-02-28 16:33     ` Vlastimil Babka
2025-02-28 18:48       ` Shakeel Butt [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=lvuudvfogvdz7ybzuwy2j4oivxce5vlgltnzuguk52sqmwy7cu@wpkzyv3zdfne \
    --to=shakeel.butt@linux.dev \
    --cc=akpm@linux-foundation.org \
    --cc=chengming.zhou@linux.dev \
    --cc=hannes@cmpxchg.org \
    --cc=kasong@tencent.com \
    --cc=linuszeng@tencent.com \
    --cc=linux-mm@kvack.org \
    --cc=lkp@intel.com \
    --cc=mhocko@kernel.org \
    --cc=muchun.song@linux.dev \
    --cc=roman.gushchin@linux.dev \
    --cc=vbabka@suse.cz \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox