From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-ed1-f50.google.com (mail-ed1-f50.google.com [209.85.208.50]) (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 0864522F755 for ; Sat, 20 Dec 2025 00:47:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.50 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766191648; cv=none; b=GxCAG7xGJ3oRRX0qWtmWN3Tn9yVBmoc2r/1OR10MXNDl0TS76TDyL4ahlYmS57kir5Qa6Al6AUJdVM+UMWgbrQ+l5NTm8hhGWOKAZ77XS3INTOAWJBEUIL0aTcqPAh0LsByK+CO2IHydp60NzRT/vZ3p/1KeZ9gQLVgZCl9eK84= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766191648; c=relaxed/simple; bh=YWHuayNWNXuVU4gRkIiEzc7v6nzrg8c1XJAMEmuDWTU=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=iGsT8TpeyzlWy0vjNdIC1p9shsMI7hEPNorx7zQTGrMxYhXOu2Pd2san1s8ghHYGYKfcTk7A9k0ARSehODNQvt0mqPsagm1XCawjVnfT+TIdqCNf7akmagjxh5FFpNWj9/nPD7tq9X1LmMhukWEFiwSwy7aIflcTSqmG3svpzuA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=UyPm9RsO; arc=none smtp.client-ip=209.85.208.50 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="UyPm9RsO" Received: by mail-ed1-f50.google.com with SMTP id 4fb4d7f45d1cf-64b61f82b5fso2965933a12.0 for ; Fri, 19 Dec 2025 16:47:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1766191645; x=1766796445; darn=vger.kernel.org; h=user-agent:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:reply-to:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=nqGGiBGIBzqIDXbf6caOhs98baOh9Bc0Em5bUFyjY94=; b=UyPm9RsOotEjowTRF7HIeP0wLTrW5BVLzH2T6lYUw4zgFqkWMiCu5oe26HP5vvsAn2 ZEZqZMfm3OvP49xuliBy8GM/2hYS5hC0xsmEINtrTRJuwflBokKs4UKuL+9D4mYB8CMq 4pcoqxkRXV8iZ9keAJFbJ8CEU3ugYL9o8gZoJ3U+BzJvyROKlF6KSiZldUWO9tbBJ7da VVWWSRa6TlsoU+mBIxVvCVtss4WmWovlbiDtyFUSMVbQ3U8L1Yism3SYCplHtMwnFkU4 BtKAHDaL6eSmflKlKZtBaJLH5B6eEEs+ck2hrzvY7cCtAm25ANj/U/ZbykxM4FM4Y6yd uoEw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1766191645; x=1766796445; h=user-agent:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:reply-to:message-id :subject:cc:to:from:date:x-gm-gg:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=nqGGiBGIBzqIDXbf6caOhs98baOh9Bc0Em5bUFyjY94=; b=j7Yp3OorXo2Oe22LLgkYyioCrEdEg5IfOg7tThc2H9MrIBbikFcPrD9xpmNroEw4oo 7WoJXYyFYtuzdBso1vDUEedWbHUvxFH9Ck3S6Ge06oOF/U7ITLNu43hKxHqcwvm3NDTv WCvY/uVK7qLGrrRt4eMllRmkA1aSDIpY0VHlP0jVuyytL7RpliSoT//4kjb6FYRmv/yj UWJEt2As/GjPZ6UrKOE3r6p/xfXlMmb+XnOTzqirCeTfdL7BWHmDkK/Na1JX18Y8Xud1 PLlpmNACjc+xIKXUaq4Vk1KwLUDXOxJ16FrXpkSlkMDxvuGDN+ukhaUucXrLZE9YFMd1 tlqA== X-Forwarded-Encrypted: i=1; AJvYcCUQF7o68jbTDU97LgTqzcBZxrJVPPUD+wUfAQ8MAzVxAZ/4tTNu5nQyx+e3respHGBKua20jX+gsOvRzig=@vger.kernel.org X-Gm-Message-State: AOJu0YyB1S1foKvGcCIofV3/eJ2nbSVArNIDtu3vKPxb4jVVAhl76lG8 knpEqkKTLVt7h8b0B4z05Gc7KALPFf5bNS3LPkfsMsAWwJypXWTt6dzftY3pZMv7 X-Gm-Gg: AY/fxX7205UIeJBEuuG96Xww5s/Xy8JNDbIwUi3odF323aPBcur8z5Pp6fHTxtgmVEo CZ/I6XknuavNOcWLsH2zDWssUwzooAn5zfNCRx68/vrnekbFpm3qfEhpBffjlRd1PEC8kLLTJdF VCCwLOwR9MsUtkQfogKkV6kM9+pRDBevoueXTqEUWjWG2jK2pw3byD5pfX/ebWS7NMKrGiafiiK SbDJLXCTZkEnAEc4UKzrmDs5PZ9+S7f+rYuT8HnRWpEY0u+x4Fwe09PIVwtDU+2o+xR+34L7pkR 3uaRPHvri0B+65F0cX53XhvPND+x3n8VlNVNvHsQbIAgiH0ghwdXyjrAHmc8SFnk3RVUaY+ZUoR oiqikkZLR1W1B9Zv+XJyWHDMBd69xSdzMvtHFm7wTav4MMrjTNKegosMM1oBylUBWtlR1rdzRHP oF7xgeRow87w== X-Google-Smtp-Source: AGHT+IE3zz/T2eYzh/DpdpgtZ2AxbF3wFfdR861oOsjU+UVc6klb7w7mN+3jT1/xcpdOd5OdzJXUhg== X-Received: by 2002:a17:907:72c6:b0:b7a:2ba7:197e with SMTP id a640c23a62f3a-b8036fba99dmr438564366b.29.1766191645250; Fri, 19 Dec 2025 16:47:25 -0800 (PST) Received: from localhost ([185.92.221.13]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-64b9159ac90sm3470027a12.29.2025.12.19.16.47.24 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 19 Dec 2025 16:47:24 -0800 (PST) Date: Sat, 20 Dec 2025 00:47:24 +0000 From: Wei Yang To: Kairui Song Cc: Wei Yang , "David Hildenbrand (Red Hat)" , Zi Yan , Bijan Tabatabai , linux-mm@kvack.org, linux-kernel@vger.kernel.org, akpm@linux-foundation.org, lorenzo.stoakes@oracle.com, Liam.Howlett@oracle.com, vbabka@suse.cz, rppt@kernel.org, surenb@google.com, mhocko@suse.com, shivankg@amd.com, Baolin Wang , Hugh Dickins , Chris Li Subject: Re: [PATCH] mm: Consider non-anon swap cache folios in folio_expected_ref_count() Message-ID: <20251220004724.b4akrh6ljreoyg5j@master> Reply-To: Wei Yang References: <20251216200727.2360228-1-bijan311@gmail.com> <6b4cadb2-6246-48cc-9c76-64ba0a23198b@kernel.org> <0C218C18-916B-4BB0-8B37-AC82503E4AD9@nvidia.com> <20251219002134.uqgtnr43zz7vvvtd@master> 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=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: User-Agent: NeoMutt/20170113 (1.7.2) On Fri, Dec 19, 2025 at 10:35:05AM +0800, Kairui Song wrote: >On Fri, Dec 19, 2025 at 8:21 AM Wei Yang wrote: >> >> On Wed, Dec 17, 2025 at 02:04:16AM +0100, David Hildenbrand (Red Hat) wrote: >> >> > > >> >> > > I am not very familiar with the memory hot-(un)plug or swapping code, so >> >> > > I am not 100% certain if this patch actually solves the root of the >> >> > > problem. I believe the issue is from shmem folios, in which case I believe >> >> > > this patch is correct. However, I couldn't think of an easy way to confirm >> >> > > that the affected folios were from shmem. I guess it could be possible that >> >> > > the root cause could be from some bug where some anonymous pages do not >> >> > > return true to folio_test_anon(). I don't think that's the case, but >> >> > > figured the MM maintainers would have a better idea of what's going on. >> >> >> >> I am not sure about if shmem in swapcache causes the issue, since >> >> the above setup does not involve shmem. +Baolin and Hugh for some insight. >> > >> >We might just push out another unrelated shmem page to swap as we create >> >memory pressure in the system I think. >> > >> >> One trivial question: currently we only put anon/shmem folio in swapcache, >> right? > >For swapout, yes, the entry point to move a folio to swap space is >folio_alloc_swap, only anon and shmem can do that (vmscan.c -> >folio_test_anon && folio_test_swapbacked, and shmem.c). > Thanks for this information. >Swapin is a bit different because of readahead, readahead folios are >not marked as anon / shmem (folio->mapping) until used, they do belong >to anon / shmem though, but we don't add them to the mapping until >that mapping does a swap cache lookup and use the cached folio. > I saw this. So there is some folio which is in swapcache but no sure is anon/shmem yet. >Also maybe worth mentioning, swap cache lookup convention requires the >caller to lock the folio and double check folio still matches the swap >entry before use (folio_matches_swap_entry), folios there are unstable >and could no longer be a valid swap cache folio unless locked. Thanks for this notice, will pay attention to this. -- Wei Yang Help you, Help me