From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out-187.mta1.migadu.com (out-187.mta1.migadu.com [95.215.58.187]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 246D843303B for ; Tue, 21 Jul 2026 09:26:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.187 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784625967; cv=none; b=KXHsay6QNsRjUO176O+eU5vWTkOglvdHpaELGs4kGSr9Dlym37B+NQfmkLwXqDrQEcELHBWdHu7h85oBDwdMsEKFHv2Y1uRtWB8aBqy2S9ji67EODMZC9ToDih8Zylj8yHfahtX0WkHGFWY3Zx4FFy6fRmGvahurX1ZBfoAeLTE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784625967; c=relaxed/simple; bh=8xz8Cg3Db7/oA5HIYcYAL0/XEV3N6GtgXSM/C9eGN5g=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=QlmEExbmY5POKJaTsc3C0z8TLM49b4jw1d548rcqqMxZuZFp9cZcM0duZy9Hc1Aj8dpm5GYxjY1bxeX43ufvuTLpkcg4H5Z86kjqkb+aOjWcvawfJEH4rczuivh0ZiquDGrUxHgt5Uo0fLlM4XuhfzK5BsoTyutVweQUs955OII= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=JGeNhTOH; arc=none smtp.client-ip=95.215.58.187 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="JGeNhTOH" Message-ID: DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1784625962; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=vB+JRQVHlMG5MWvo+GPIUeB91lIMDz4d0A4B5NQYUB4=; b=JGeNhTOH+a/B8Oj13NkMY6wxt3WLgc8dgCHmbJys6SpwisQ/le7wFr9agOxoaW6+Aduta+ tuFCGwosAbVWHQk/vdTBCkc7GdTxl+PBRWiLRQtxtUijnQZ1Vbgjy66bC0j5xgr+HF2A4S 2R6uYsF7mCYhDyDLEpPzu01CNTwjQDM= Date: Tue, 21 Jul 2026 17:25:37 +0800 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Subject: Re: [PATCH v2 2/2] mm: shmem: make unused huge shrinker memcg aware To: hughd@google.com, baolin.wang@linux.alibaba.com, akpm@linux-foundation.org, usama.arif@linux.dev, Qi Zheng Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org References: <889581093179462979dbfb5458620fcca531787b.1784621804.git.zhengqi.arch@bytedance.com> X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Qi Zheng In-Reply-To: <889581093179462979dbfb5458620fcca531787b.1784621804.git.zhengqi.arch@bytedance.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Migadu-Flow: FLOW_OUT sashiko left two review comments about this [1], but they look like false positives. [1]. https://sashiko.dev/#/patchset/cover.1784621804.git.zhengqi.arch%40bytedance.com > > +static bool is_shmem_unused_huge_match(struct folio *folio, > > + struct shrink_control *sc) > > +{ > > + struct mem_cgroup *memcg = NULL; > > + bool match; > > + > > + /* > > + * Only non-root memcg reclaim needs to match the folio charge against > > + * sc->memcg. Skip the folio memcg check for the following cases: > > + * 1. shmem quota reclaim (sc == NULL) > > + * 2. global shrinker reclaim > > + * 3. root memcg reclaim > > + */ > > + if (!sc || !sc->memcg || mem_cgroup_is_root(sc->memcg)) > > + return true; > > + > > + if (folio_nid(folio) != sc->nid) > > + return false; > > + > > + memcg = get_mem_cgroup_from_folio(folio); > > + match = memcg == sc->memcg; > Does this strict equality check fail when a memcg is offlined (reparented)? > When a memcg is offlined (e.g., a container exits), its list_lru items are > reparented to its online parent. During memory pressure, the parent memcg runs > its shrinker, making sc->memcg the parent. However, the folio remains charged > to the offline child memcg. > Consequently, get_mem_cgroup_from_folio() returns the offline child memcg, and > this strict equality check fails. No, get_mem_cgroup_from_folio() should returns parent memcg, not the child memcg. > > +static void shmem_unused_huge_requeue(struct inode *inode, struct folio *folio) > > +{ > > + struct shmem_inode_info *info = SHMEM_I(inode); > > + struct shmem_sb_info *sbinfo = SHMEM_SB(inode->i_sb); > > + struct mem_cgroup *memcg; > > + int nid = folio_nid(folio); > > + > > + memcg = shmem_unused_huge_alloc_lru(sbinfo, folio, GFP_NOWAIT); > > + if (IS_ERR(memcg)) > > + goto drop; > > + > > + spin_lock(&info->lock); > > + /* Requeue the inode to shrinklist */ > > + list_del_init(&info->shrinklist); > > + list_lru_add(&sbinfo->shrinklist, &info->shrinklist, nid, memcg); > > + info->shrinklist_memcg = memcg; > Can this cause a livelock under memory pressure? > Because the memcg match failed in is_shmem_unused_huge_match(), > shmem_unused_huge_shrink() calls this function to place the inode back on the > list. This attempts to requeue it using the offline child memcg. > list_lru_add() transparently routes it back to the parent's list, but > info->shrinklist_memcg records the child memcg. In the next shrinker pass, the > match fails again, creating an infinite requeue loop during reclaim. No, shmem_unused_huge_alloc_lru also returns the parent memcg: shmem_unused_huge_alloc_lru --> get_mem_cgroup_from_folio --> folio_memcg(folio) --> obj_cgroup_memcg(folio_objcg(folio)) --> objcg->memcg /* reparented to the parent memcg */