linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Johannes Weiner <hannes@cmpxchg.org>
To: Nhat Pham <nphamcs@gmail.com>
Cc: akpm@linux-foundation.org, kernel-team@meta.com,
	linux-mm@kvack.org, linux-kernel@vger.kernel.org,
	stable@vger.kernel.org, yosryahmed@google.com,
	Yu Zhao <yuzhao@google.com>
Subject: Re: [PATCH v2] workingset: ensure memcg is valid for recency check
Date: Fri, 18 Aug 2023 10:12:51 -0400	[thread overview]
Message-ID: <20230818141251.GB138967@cmpxchg.org> (raw)
In-Reply-To: <20230817190126.3155299-1-nphamcs@gmail.com>

On Thu, Aug 17, 2023 at 12:01:26PM -0700, Nhat Pham wrote:
>  static bool lru_gen_test_recent(void *shadow, bool file, struct lruvec **lruvec,
>  				unsigned long *token, bool *workingset)
>  {
> -	int memcg_id;
>  	unsigned long min_seq;
>  	struct mem_cgroup *memcg;
>  	struct pglist_data *pgdat;
>  
> -	unpack_shadow(shadow, &memcg_id, &pgdat, token, workingset);
> +	unpack_shadow(shadow, &memcg, &pgdat, token, workingset);
> +	if (!mem_cgroup_disabled() && !memcg)
> +		return false;
>  
> -	memcg = mem_cgroup_from_id(memcg_id);
>  	*lruvec = mem_cgroup_lruvec(memcg, pgdat);
> +	mem_cgroup_put(memcg);
>  
>  	min_seq = READ_ONCE((*lruvec)->lrugen.min_seq[file]);
>  	return (*token >> LRU_REFS_WIDTH) == (min_seq & (EVICTION_MASK >> LRU_REFS_WIDTH));

This isn't quite right. lruvec's lifetime is bound to the memcg, so
the put has to happen after the code is done accessing it.

lru_gen_refault() is still using the eviction lruvec after the recency
test - but only if eviction_lruvec == refault_lruvec. This gives me
pause, because they're frequently different. This is a common setup:

root - slice - service 1
            `- service 2

where slice has the limit and will be the cause of evictions, whereas
the service groups have the actual pages and see the refaults.

workingset_eviction() and workingset_refault() will do recency
evaluation against slice, and refault accounting against service X.

MGLRU will use service X to determine recency, which 1) will not
properly activate when one service is thrashing while the other is
dominating the memory allowance of slice, and 2) will not detect
refaults of pages shared between the services.

Maybe it's time to fix this first and bring the two codebases in
unison. Then the recency test and eviction group lifetime can be
encapsulated in test_recent(), and _refault() can just use
folio_memcg() to do the activation and accounting against.


      parent reply	other threads:[~2023-08-18 14:12 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-08-17 16:47 [PATCH] " Nhat Pham
2023-08-17 17:39 ` Yosry Ahmed
2023-08-17 18:13   ` Nhat Pham
2023-08-17 18:24     ` Yosry Ahmed
2023-08-17 19:01 ` [PATCH v2] " Nhat Pham
2023-08-17 20:50   ` Yosry Ahmed
2023-08-17 22:43     ` Nhat Pham
2023-08-17 22:49       ` Yosry Ahmed
2023-08-17 23:12         ` Yu Zhao
2023-08-18 13:49           ` Johannes Weiner
2023-08-18 14:56             ` Yosry Ahmed
2023-08-18 16:23               ` Nhat Pham
2023-08-18 16:30                 ` Yosry Ahmed
2023-08-18 17:35               ` Johannes Weiner
2023-08-18 17:45                 ` Yosry Ahmed
2023-08-18 18:35                   ` Johannes Weiner
2023-08-18 18:44                     ` Yosry Ahmed
2023-08-18 21:35                       ` Shakeel Butt
2023-08-18 21:51                         ` Yu Zhao
2023-08-18 21:59                           ` Yosry Ahmed
2023-08-18 22:29                         ` Johannes Weiner
2023-08-18 22:19                       ` Johannes Weiner
2023-08-18 22:26                         ` Yosry Ahmed
2023-08-18  0:37         ` Nhat Pham
2023-08-18  3:26   ` kernel test robot
2023-08-18  3:36   ` kernel test robot
2023-08-18 14:12   ` Johannes Weiner [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=20230818141251.GB138967@cmpxchg.org \
    --to=hannes@cmpxchg.org \
    --cc=akpm@linux-foundation.org \
    --cc=kernel-team@meta.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=nphamcs@gmail.com \
    --cc=stable@vger.kernel.org \
    --cc=yosryahmed@google.com \
    --cc=yuzhao@google.com \
    /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