Linux-mm Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Qi Zheng <qi.zheng@linux.dev>
To: Baolin Wang <baolin.wang@linux.alibaba.com>,
	hughd@google.com, akpm@linux-foundation.org,
	usama.arif@linux.dev, Qi Zheng <zhengqi.arch@bytedance.com>
Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2 2/2] mm: shmem: make unused huge shrinker memcg aware
Date: Wed, 29 Jul 2026 13:59:18 +0800	[thread overview]
Message-ID: <93f5a87d-bf82-4b56-a778-a39d03ba4e3c@linux.dev> (raw)
In-Reply-To: <c169c4ec-adc8-4991-a690-ed5bfb4796a0@linux.alibaba.com>

Hi Baolin,

On 7/29/26 11:29 AM, Baolin Wang wrote:
>>>> @@ -2532,28 +2727,6 @@ static int shmem_get_folio_gfp(struct inode 
>>>> *inode, pgoff_t index,
>>>>   alloced:
>>>>       alloced = true;
>>>> -    if (folio_test_large(folio) &&
>>>> -        DIV_ROUND_UP(i_size_read(inode), PAGE_SIZE) <
>>>> -                    folio_next_index(folio)) {
>>>> -        struct shmem_sb_info *sbinfo = SHMEM_SB(inode->i_sb);
>>>> -        struct shmem_inode_info *info = SHMEM_I(inode);
>>>> -        /*
>>>> -         * Part of the large folio is beyond i_size: subject
>>>> -         * to shrink under memory pressure.
>>>> -         */
>>>> -        spin_lock(&sbinfo->shrinklist_lock);
>>>> -        /*
>>>> -         * _careful to defend against unlocked access to
>>>> -         * ->shrink_list in shmem_unused_huge_shrink()
>>>> -         */
>>>> -        if (list_empty_careful(&info->shrinklist)) {
>>>> -            list_add_tail(&info->shrinklist,
>>>> -                      &sbinfo->shrinklist);
>>>> -            sbinfo->shrinklist_len++;
>>>> -        }
>>>> -        spin_unlock(&sbinfo->shrinklist_lock);
>>>> -    }
>>>
>>> Why move this additional logic down?
>>
>> Because under the following condition:
>>
>>          if (sgp <= SGP_CACHE &&
>>          ((loff_t)index << PAGE_SHIFT) >= i_size_read(inode)) {
>>          error = -EINVAL;
>>          goto unlock;
>>      }
>>
>> we will jump to unlock and remove the folio from page cache.
>>
>> With the new memcg-aware design, shmem_unused_huge_add() takes a memcg
>> reference. If the folio is then removed by the error path, the inode
>> sits on the shrinker list holding a stale memcg reference and pointing
>> at an i_size that no longer matches the folio.
>>
>> So we should ensure the inode is only queued when the folio is fully set
>> up and about to be returned successfully.
> 
> Right. But I think this deserves a separate preparation patch with above 
> explanation, moving the original shrinklist addition logic to after all 
> checks are completed.

Agree, will split this into a separate preparation patch.

Thanks,
Qi




      reply	other threads:[~2026-07-29  5:59 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-21  8:34 [PATCH v2 0/2] make unused huge shrinker memcg aware Qi Zheng
2026-07-21  8:34 ` [PATCH v2 1/2] fs: push nr_cached_objects memcg gating into individual filesystems Qi Zheng
2026-07-21  8:34 ` [PATCH v2 2/2] mm: shmem: make unused huge shrinker memcg aware Qi Zheng
2026-07-21  9:25   ` Qi Zheng
2026-07-27  5:11   ` Baolin Wang
2026-07-28  7:12     ` Qi Zheng
2026-07-29  3:29       ` Baolin Wang
2026-07-29  5:59         ` Qi Zheng [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=93f5a87d-bf82-4b56-a778-a39d03ba4e3c@linux.dev \
    --to=qi.zheng@linux.dev \
    --cc=akpm@linux-foundation.org \
    --cc=baolin.wang@linux.alibaba.com \
    --cc=hughd@google.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=usama.arif@linux.dev \
    --cc=zhengqi.arch@bytedance.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