From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (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 7376234A3BE for ; Tue, 21 Oct 2025 18:28:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1761071316; cv=none; b=f6NQSePf2qkKDmKdTcNePA4lg9zxeS9QKi0A5jKyJ2eb8liHDiNb/PKE5dnC/hjPIdZhqCObl74wanPgqk76O33W00/4qph1uDTOWlPG2cqrTpEa4Cw2XkkdsK6M7/hPVT6Wqq3jfOuhH3H6W7dPXaxHXmga1/7wfPhasOPT45M= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1761071316; c=relaxed/simple; bh=zax8f3CTswP0OWqYQAc4Do7Qa/kWXv9vp2ys5rDaI10=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=NCGr1ZPqEu5MH5LU67GZ4LWtMTI4iqndtw39jdNqzDYPTriN5IgfkSL7b41OdY39fSO0hGrngjAkTwbZKW44AfEarcBLewvn1oSg7dZeLEH0jDz8i4ICKH5L00xudhG1U5SZrQ7iKv8bM5sDgoOEpQ6+tXuyp5HJO4ZurI19QFA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=fg3wHafk; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="fg3wHafk" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1761071312; 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:autocrypt:autocrypt; bh=p1rUujygHyp+nQsh5XAYAD7qtwFrdj1/nniIVtSG5Cg=; b=fg3wHafkZYdLDJ7ttFAREMWBvt37Pe2Z51GDUCfkP63cB/e3zSWXFf17ji2sBnXn7EnxG0 S8PY+zU2e44uCi1BzFhp92TL8JZlr/5F96otk4DL5GrGA1V71MJv8mlGTePapmdnbzJgCw qwVcatJAtrxyil0+Opub0cN5HzvMi44= Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-222-WK8-6gK9Po-sT1g3-P4DdQ-1; Tue, 21 Oct 2025 14:28:31 -0400 X-MC-Unique: WK8-6gK9Po-sT1g3-P4DdQ-1 X-Mimecast-MFC-AGG-ID: WK8-6gK9Po-sT1g3-P4DdQ_1761071310 Received: by mail-wr1-f69.google.com with SMTP id ffacd0b85a97d-4270a273b6eso3238551f8f.0 for ; Tue, 21 Oct 2025 11:28:30 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1761071310; x=1761676110; h=content-transfer-encoding:in-reply-to:autocrypt:content-language :from:references:cc:to:subject:user-agent:mime-version:date :message-id:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=p1rUujygHyp+nQsh5XAYAD7qtwFrdj1/nniIVtSG5Cg=; b=wk4/z7Pcf5HjhKR50aJQ3NQwJfMPRRQy3U3Uk81lpIX7Vbu8m4u2hdQ8roigrdDNvI rm9JvvHEypApqZDrNiPkMMaCF+0CuG73Lo1Y9WFZJ3RmcuGkKTl9kIaGEYErlGtnhsz/ K1ujvZB5Klwqa016luCgtljAjrJJx/sb6iLgmxk/7hlRRJPvEHTMsEQzL8DdimiDNPPZ WfyWE9Fs5cZ2Wdosxrs76oMrlFZxneQyGQollQWCx9RhkkcEtCWkcyrRVnenEkPVY3hv cGYvglnVa20zYI69n/nDG3jY0aJ0oBclgOWNtjcNCvD28sventHt2LS734zYsB+JEbdL K5yg== X-Forwarded-Encrypted: i=1; AJvYcCXNm4KGMyybg2sMNZHO2NHX2DHrT/2mTbAJ+iWUR7r+5TZOMLnOJdhgzZrkqEalARzzGDof4EcHO5HPU4g=@vger.kernel.org X-Gm-Message-State: AOJu0YzKWnI+1EyqNzNDVfCIPWWQRTY0pkI3k10RD1CJMrA58hkChaGf KK8DgLZuhBavJ02FaoWjw5peAtZ3NwtqG5EwAnCCx0z/kjrNOx63my5o48cMbZ/BwVOxUWJUdH9 TG58RXUomgFFCNuFpkJi5ssmTuKCXDPhVDJE68nyL1U4AV0rHnU/aiMupv2Km8SvNcw== X-Gm-Gg: ASbGncsiNYZbBENOMCzTdrm4OQhraWS6OEp1cjtZTf/UA/rdk5InLJX7tlVOuK+k0Ng Yzk0rwlVypG/R+8C1ds+Jt9zuZSM5dqgZ3U4vSL/2gmg51zoxyNVUaKCk9sUsW7jVgfF7wtLltX 3CpG/tXX390Buvrh/kJhEkMZfoc4Pudj8PxpBYsugC1X1ybcq0lGrTDAQOEozzDIyxSzrfPIat/ h7eaBC0TqwOk/mKB6VhgtgGKS9m6XNKFoNiM4TK3Rwu5SQil3Yx6ymeYafDJfRY5pNalfLY3knx XljleRecb8vZzFRRFhVK+VEZpAXJoJUHuyX9sI0+ssdHew/WacS775NGsh+TDcZzLqv4+mVToo4 cLQaZFUI2kZlZD6jATCTE6md6QDzHSYk= X-Received: by 2002:a05:6000:184f:b0:427:a05:2ff with SMTP id ffacd0b85a97d-4270a050510mr10269752f8f.33.1761071309661; Tue, 21 Oct 2025 11:28:29 -0700 (PDT) X-Google-Smtp-Source: AGHT+IH81g8i/LCi1AuXlZHNIML/iiLnpPkqZNzar/dX2uHH9lLINKzpzMqLwuLZJ7387cttvNJOcA== X-Received: by 2002:a05:6000:184f:b0:427:a05:2ff with SMTP id ffacd0b85a97d-4270a050510mr10269722f8f.33.1761071309148; Tue, 21 Oct 2025 11:28:29 -0700 (PDT) Received: from [192.168.3.141] (p57a1af76.dip0.t-ipconnect.de. [87.161.175.118]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-47494aad668sm23481915e9.2.2025.10.21.11.28.27 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 21 Oct 2025 11:28:28 -0700 (PDT) Message-ID: <595b41b0-428a-4184-9abc-6875309d8cbd@redhat.com> Date: Tue, 21 Oct 2025 20:28:26 +0200 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v2 2/3] mm/memory-failure: improve large block size folio handling. To: Zi Yan Cc: Yang Shi , linmiaohe@huawei.com, jane.chu@oracle.com, kernel@pankajraghav.com, syzbot+e6367ea2fdab6ed46056@syzkaller.appspotmail.com, syzkaller-bugs@googlegroups.com, akpm@linux-foundation.org, mcgrof@kernel.org, nao.horiguchi@gmail.com, Lorenzo Stoakes , Baolin Wang , "Liam R. Howlett" , Nico Pache , Ryan Roberts , Dev Jain , Barry Song , Lance Yang , "Matthew Wilcox (Oracle)" , Wei Yang , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org References: <20251016033452.125479-1-ziy@nvidia.com> <20251016033452.125479-3-ziy@nvidia.com> <5EE26793-2CD4-4776-B13C-AA5984D53C04@nvidia.com> <893332F4-7FE8-4027-8FCC-0972C208E928@nvidia.com> From: David Hildenbrand Content-Language: en-US Autocrypt: addr=david@redh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A0udEBvQ0f9QLNyyy3DZMCQWcwRuj1m73D sq8DEFBdZ5eEkj1dCyx+t/ga6x2rHyc8Sl86oK1tvAkwBNsfKou3v+jP/l14a7DGBvrmlYjO 59o3t6inu6H7pt7OL6u6BQj7DoMAEQEAAcLBfAQYAQgAJgIbDBYhBBvZyq1zXEw6Rg38yk3e EPcA/4NaBQJonNqrBQkmWAihAAoJEE3eEPcA/4NaKtMQALAJ8PzprBEXbXcEXwDKQu+P/vts IfUb1UNMfMV76BicGa5NCZnJNQASDP/+bFg6O3gx5NbhHHPeaWz/VxlOmYHokHodOvtL0WCC 8A5PEP8tOk6029Z+J+xUcMrJClNVFpzVvOpb1lCbhjwAV465Hy+NUSbbUiRxdzNQtLtgZzOV Zw7jxUCs4UUZLQTCuBpFgb15bBxYZ/BL9MbzxPxvfUQIPbnzQMcqtpUs21CMK2PdfCh5c4gS sDci6D5/ZIBw94UQWmGpM/O1ilGXde2ZzzGYl64glmccD8e87OnEgKnH3FbnJnT4iJchtSvx yJNi1+t0+qDti4m88+/9IuPqCKb6Stl+s2dnLtJNrjXBGJtsQG/sRpqsJz5x1/2nPJSRMsx9 5YfqbdrJSOFXDzZ8/r82HgQEtUvlSXNaXCa95ez0UkOG7+bDm2b3s0XahBQeLVCH0mw3RAQg r7xDAYKIrAwfHHmMTnBQDPJwVqxJjVNr7yBic4yfzVWGCGNE4DnOW0vcIeoyhy9vnIa3w1uZ 3iyY2Nsd7JxfKu1PRhCGwXzRw5TlfEsoRI7V9A8isUCoqE2Dzh3FvYHVeX4Us+bRL/oqareJ CIFqgYMyvHj7Q06kTKmauOe4Nf0l0qEkIuIzfoLJ3qr5UyXc2hLtWyT9Ir+lYlX9efqh7mOY qIws/H2t In-Reply-To: <893332F4-7FE8-4027-8FCC-0972C208E928@nvidia.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit On 21.10.25 17:55, Zi Yan wrote: > On 21 Oct 2025, at 11:44, David Hildenbrand wrote: > >> On 21.10.25 03:23, Zi Yan wrote: >>> On 20 Oct 2025, at 19:41, Yang Shi wrote: >>> >>>> On Mon, Oct 20, 2025 at 12:46 PM Zi Yan wrote: >>>>> >>>>> On 17 Oct 2025, at 15:11, Yang Shi wrote: >>>>> >>>>>> On Wed, Oct 15, 2025 at 8:38 PM Zi Yan wrote: >>>>>>> >>>>>>> Large block size (LBS) folios cannot be split to order-0 folios but >>>>>>> min_order_for_folio(). Current split fails directly, but that is not >>>>>>> optimal. Split the folio to min_order_for_folio(), so that, after split, >>>>>>> only the folio containing the poisoned page becomes unusable instead. >>>>>>> >>>>>>> For soft offline, do not split the large folio if it cannot be split to >>>>>>> order-0. Since the folio is still accessible from userspace and premature >>>>>>> split might lead to potential performance loss. >>>>>>> >>>>>>> Suggested-by: Jane Chu >>>>>>> Signed-off-by: Zi Yan >>>>>>> Reviewed-by: Luis Chamberlain >>>>>>> --- >>>>>>> mm/memory-failure.c | 25 +++++++++++++++++++++---- >>>>>>> 1 file changed, 21 insertions(+), 4 deletions(-) >>>>>>> >>>>>>> diff --git a/mm/memory-failure.c b/mm/memory-failure.c >>>>>>> index f698df156bf8..443df9581c24 100644 >>>>>>> --- a/mm/memory-failure.c >>>>>>> +++ b/mm/memory-failure.c >>>>>>> @@ -1656,12 +1656,13 @@ static int identify_page_state(unsigned long pfn, struct page *p, >>>>>>> * there is still more to do, hence the page refcount we took earlier >>>>>>> * is still needed. >>>>>>> */ >>>>>>> -static int try_to_split_thp_page(struct page *page, bool release) >>>>>>> +static int try_to_split_thp_page(struct page *page, unsigned int new_order, >>>>>>> + bool release) >>>>>>> { >>>>>>> int ret; >>>>>>> >>>>>>> lock_page(page); >>>>>>> - ret = split_huge_page(page); >>>>>>> + ret = split_huge_page_to_list_to_order(page, NULL, new_order); >>>>>>> unlock_page(page); >>>>>>> >>>>>>> if (ret && release) >>>>>>> @@ -2280,6 +2281,7 @@ int memory_failure(unsigned long pfn, int flags) >>>>>>> folio_unlock(folio); >>>>>>> >>>>>>> if (folio_test_large(folio)) { >>>>>>> + int new_order = min_order_for_split(folio); >>>>>>> /* >>>>>>> * The flag must be set after the refcount is bumped >>>>>>> * otherwise it may race with THP split. >>>>>>> @@ -2294,7 +2296,14 @@ int memory_failure(unsigned long pfn, int flags) >>>>>>> * page is a valid handlable page. >>>>>>> */ >>>>>>> folio_set_has_hwpoisoned(folio); >>>>>>> - if (try_to_split_thp_page(p, false) < 0) { >>>>>>> + /* >>>>>>> + * If the folio cannot be split to order-0, kill the process, >>>>>>> + * but split the folio anyway to minimize the amount of unusable >>>>>>> + * pages. >>>>>>> + */ >>>>>>> + if (try_to_split_thp_page(p, new_order, false) || new_order) { >>>>>> >>>>>> folio split will clear PG_has_hwpoisoned flag. It is ok for splitting >>>>>> to order-0 folios because the PG_hwpoisoned flag is set on the >>>>>> poisoned page. But if you split the folio to some smaller order large >>>>>> folios, it seems you need to keep PG_has_hwpoisoned flag on the >>>>>> poisoned folio. >>>>> >>>>> OK, this means all pages in a folio with folio_test_has_hwpoisoned() should be >>>>> checked to be able to set after-split folio's flag properly. Current folio >>>>> split code does not do that. I am thinking about whether that causes any >>>>> issue. Probably not, because: >>>>> >>>>> 1. before Patch 1 is applied, large after-split folios are already causing >>>>> a warning in memory_failure(). That kinda masks this issue. >>>>> 2. after Patch 1 is applied, no large after-split folios will appear, >>>>> since the split will fail. >>>> >>>> I'm a little bit confused. Didn't this patch split large folio to >>>> new-order-large-folio (new order is min order)? So this patch had >>>> code: >>>> if (try_to_split_thp_page(p, new_order, false) || new_order) { >>> >>> Yes, but this is Patch 2 in this series. Patch 1 is >>> "mm/huge_memory: do not change split_huge_page*() target order silently." >>> and sent separately as a hotfix[1]. >> >> I'm confused now as well. I'd like to review, will there be a v3 that only contains patch #2+#3? > > Yes. The new V3 will have 3 patches: > 1. a new patch addresses Yang’s concern on setting has_hwpoisoned on after-split > large folios. > 2. patch#2, > 3. patch#3. Okay, I'll wait with the review until you resend :) > > The plan is to send them out once patch 1 is upstreamed. Let me know if you think > it is OK to send them out earlier as Andrew already picked up patch 1. It's in mm/mm-new + mm/mm-unstable, AFAIKT. So sure, send it against one of the tress (I prefer mm-unstable but usually we should target mm-new). > > I also would like to get some feedback on my approach to setting has_hwpoisoned: > > folio's has_hwpoisoned flag needs to be preserved > like what Yang described above. My current plan is to move > folio_clear_has_hwpoisoned(folio) into __split_folio_to_order() and > scan every page in the folio if the folio's has_hwpoisoned is set. Oh, that's nasty indeed ... will have to think about that a bit. Maybe we can keep it simple and always set folio_set_has_hwpoisoned() on all split folios? Essentially turning it into a "maybe_has" semantics. IIUC, the existing folio_stest_has_hwpoisoned users can deal with that? -- Cheers David / dhildenb