From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-qk1-f179.google.com (mail-qk1-f179.google.com [209.85.222.179]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1D18D3AB27F for ; Tue, 26 May 2026 20:10:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.179 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779826245; cv=none; b=jXWPla+7mY6YHmNNWaZOD0/AZilABfgf32B7a2/bTetYqdw2QkoKsy03+9/g+sPncFMsjbAskygxlKQ7IM7DypiOKQIZbLgYs99ZyaXELfyZWehjnUCkAFGICc1NXUk9vdn6bprkhQ0mUMTH/pmOuqjhg2UOJ2o41N+LIsOaZlY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779826245; c=relaxed/simple; bh=YMLsVDxtr2b9s0yBcpbvn4Q16I3m7NzRBDVWT0LcopM=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=da+GhU/a0RJiYIOBoeRMjAl/nGXgVbpMB3CR4QTHoq3iPQozvkS41PrsQWDiAFLXNeljia5rTVjwFRO08/ku0B7tgsGcJdnIDGW1UQcJ5Cd1jGPnb0g9xcFXxiDM7AEIwlxzXKs0RysjiSnGUhbEg04Mk8uqdsPsqHFHvNPEOhs= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=cmpxchg.org; spf=pass smtp.mailfrom=cmpxchg.org; dkim=pass (2048-bit key) header.d=cmpxchg.org header.i=@cmpxchg.org header.b=csCuCVQd; arc=none smtp.client-ip=209.85.222.179 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=cmpxchg.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=cmpxchg.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=cmpxchg.org header.i=@cmpxchg.org header.b="csCuCVQd" Received: by mail-qk1-f179.google.com with SMTP id af79cd13be357-914bd98faafso326683385a.0 for ; Tue, 26 May 2026 13:10:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cmpxchg.org; s=google; t=1779826242; x=1780431042; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=4tFZxDP5yKXP0UhVdj6/0NYHpVXbpIOmDxHnncGDOQE=; b=csCuCVQdZ/p9e5RXWPNQy8wc3L0nZjXLDs9OM2xI4PHNFvl/pon53CM9LC7FsFPHji bzvlRyCByOKnh9FIEGMFEEsCc8AfELrHar3+Z+DPME/RMsNLGC6CIDQTpmPSlAL/ggDP +YtPH1dUQPoFUBrHbLweUndNNbCFQYQ3r57gU0rI1D6CLL0jEBJHznfRMypZ5M4EkGzS lIA3LaaZfC54PHdA9nT2Ej+cYJHgCOpwM4I1sXqypzkGHsehru5fbI6Ka8dNMsgPn+Ca JSx0+3KZhYsfcbFjlK5/ezFvqfLdM3D6YzN76d+L8ybkeownFFbOOAb1ya52OTz3565U NPNw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779826242; x=1780431042; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-gg:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=4tFZxDP5yKXP0UhVdj6/0NYHpVXbpIOmDxHnncGDOQE=; b=C8zZ93q9Sz7mTuLdZNyqvOuWdqjHs73BXAS1YPzHwn9KeFhy+lHWfI9JLwpUDIzx/B gcTj4MP6txGa5EYpYoPImuFrtVhobKjc2ek0/JHlFli9yZpN1NzJPlb6INFP6zRrHePv wAMOZOpUFzTM5rh9Qr8WkGDbOoGg02fe690tkgl0PpFgTFcncx9Sb3wgHY3dscIsaPmR aX+XcP4x7vvuQVKDJkPctsTgdomyGXZ9LUtvYj5rIsm1iIEdRthIpdV9mp9Zgw1fDSWL f9IAvG1UjNdVKMHduVuUxWOgjmuQC3ZqFFzixNdWRU4njcuyoEZ+eVAVqNUEGk795LAw 5rBA== X-Forwarded-Encrypted: i=1; AFNElJ91r//tZQz+MRwV0vf4M6BAVC3hrttZ363ivVLkJ4Fg8FrEFUm9bZpYVF+mjLdf/hdrkuh+ZPbXAp+SLDg=@vger.kernel.org X-Gm-Message-State: AOJu0YyseBm3bric5aGSMopOoRcsrOeLMyzsZnZWt6dkwvHR32ckfzHO l6feQhS3tyIL/5PgMbgfOxRm8w/+Gn1yLaPjwiyLDCRAVW62A8wyLnaQnT7+7x1akrQ= X-Gm-Gg: Acq92OGBooEYlt2vGCdls1QxGt2u8Mq96qHNh/699mGJW2P+5BobHCj1nbQEArvvEE0 Ue7xYApyVfEvpTCdYmCUsd4UzWyD6K9oqdmvgE/kDZTJVXAshnakfAj4S+t/5n6ASRdhwcGFjhP LVhUNskj3VQk1YImq/DhGduMZ/mdkf3/K/apVRkzaKXNDi4IRVbnHchLjNAWbkv2zQ2cZxrQhjI 0w//N/Z+mbSF2o1l2wWUCbi+OwFqDIxX0UxuzaAH0rwxLI1+W0BkZ0YI3o6/2dM7M4q8HjzgkX6 zDxhhuvGNlxpY7WFZskeKV2asFqAC/JAJH1J21/7/eYpZeZ2JC/wRZizl2/GrBDxVbOG3r2w+Du 3bMbBKBEy9zgdCoLe41n6xVJYp6seF/WuuKk6iOCVO34zrVXBWhfSGihAyUUd/4X2yUFd2uNl8t dPrMI9tBcuGe9hcDJTELuBsA== X-Received: by 2002:a05:620a:4083:b0:914:afb8:795e with SMTP id af79cd13be357-914b48e7e4emr2837476385a.19.1779826241715; Tue, 26 May 2026 13:10:41 -0700 (PDT) Received: from localhost ([2603:7001:f100:500:365a:60ff:fe62:ff29]) by smtp.gmail.com with ESMTPSA id af79cd13be357-914f8810a50sm310312585a.41.2026.05.26.13.10.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 May 2026 13:10:40 -0700 (PDT) Date: Tue, 26 May 2026 16:10:36 -0400 From: Johannes Weiner To: Usama Arif Cc: Andrew Morton , David Hildenbrand , Lorenzo Stoakes , Shakeel Butt , Michal Hocko , Dave Chinner , Roman Gushchin , Muchun Song , Qi Zheng , Yosry Ahmed , Zi Yan , "Liam R . Howlett" , Kiryl Shutsemau , Vlastimil Babka , Kairui Song , Mikhail Zaslonko , Vasily Gorbik , Baolin Wang , Barry Song , Dev Jain , Lance Yang , Nico Pache , Ryan Roberts , cgroups@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v4 8/8] mm: switch deferred split shrinker to list_lru Message-ID: References: <20260521150330.1955924-9-hannes@cmpxchg.org> <20260526120923.2331056-1-usama.arif@linux.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20260526120923.2331056-1-usama.arif@linux.dev> On Tue, May 26, 2026 at 05:09:22AM -0700, Usama Arif wrote: > On Thu, 21 May 2026 11:02:14 -0400 Johannes Weiner wrote: > > @@ -4446,36 +4377,20 @@ void deferred_split_folio(struct folio *folio, bool partially_mapped) > > count_vm_event(THP_DEFERRED_SPLIT_PAGE); > > count_mthp_stat(folio_order(folio), MTHP_STAT_SPLIT_DEFERRED); > > mod_mthp_stat(folio_order(folio), MTHP_STAT_NR_ANON_PARTIALLY_MAPPED, 1); > > - > > } > > } else { > > /* partially mapped folios cannot become non-partially mapped */ > > VM_WARN_ON_FOLIO(folio_test_partially_mapped(folio), folio); > > } > > - if (list_empty(&folio->_deferred_list)) { > > - struct mem_cgroup *memcg; > > - > > - memcg = folio_split_queue_memcg(folio, ds_queue); > > - list_add_tail(&folio->_deferred_list, &ds_queue->split_queue); > > - ds_queue->split_queue_len++; > > - if (memcg) > > - set_shrinker_bit(memcg, folio_nid(folio), > > - shrinker_id(deferred_split_shrinker)); > > - } > > - split_queue_unlock_irqrestore(ds_queue, flags); > > + __list_lru_add(&deferred_split_lru, lru, &folio->_deferred_list, nid, memcg); > > + list_lru_unlock_irqrestore(lru, &flags); > > + rcu_read_unlock(); > > Can the shrinker bit end up on the wrong memcg here? > > deferred_split_folio() takes the lock via list_lru_lock_irqsave() with > the original folio_memcg() of the folio. If that memcg is dying and > already reparented, lock_list_lru_of_memcg() walks up parent_mem_cgroup() > until it finds a live sublist and locks it (lru), but the memcg local > variable still points at the dying child. > > __list_lru_add() then calls set_shrinker_bit(memcg, ...) with the > original (dying / reparented) memcg, not the parent that actually owns > the locked sublist where the folio was queued. I think you're right. Good catch. This looks like an existing list_lru issue, actually. Even before, list_lru_add() would call lock_list_lru_of_memcg() which might do the hierarchy walk. But then set_shrinker_bit() on the passed in memcg. I'll fix this in list_lru first. It's a likely backport candidate. Then rebase my patches on top. > > @@ -1301,6 +1301,9 @@ static enum scan_result collapse_huge_page(struct mm_struct *mm, unsigned long s > > if (result != SCAN_SUCCEED) > > goto out_nolock; > > > > + if (folio_memcg_alloc_deferred(folio)) > > + goto out_nolock; > > + > > Over here, you will end up reporting success on allocation failure. > > Maybe set result to SCAN_ALLOC_HUGE_PAGE_FAIL? Good point. Sashiko pointed that out as well. I have a follow-up fix. Thanks for taking a look.