From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C1EE3C433DB for ; Tue, 12 Jan 2021 11:36:52 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 90F20224BD for ; Tue, 12 Jan 2021 11:36:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729990AbhALLgM (ORCPT ); Tue, 12 Jan 2021 06:36:12 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55964 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729831AbhALLgJ (ORCPT ); Tue, 12 Jan 2021 06:36:09 -0500 Received: from mail-pl1-x631.google.com (mail-pl1-x631.google.com [IPv6:2607:f8b0:4864:20::631]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6822FC061575 for ; Tue, 12 Jan 2021 03:35:29 -0800 (PST) Received: by mail-pl1-x631.google.com with SMTP id be12so1265849plb.4 for ; Tue, 12 Jan 2021 03:35:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=4QLLdsmjlUXD8ZcmN6OfppjkNNypBTtU+sGe4+bM98Y=; b=HatddMj3Nb+5ix0xm5HiDy9AAbfoiZeBVH4pXzG70aFjUn13J/ansi0iyM9h8zgV9B 5Jf0XMRvh3nkOq9KyGKbPR9eoqf95+ZUlAvzEA3z6qDQ89RR8dDxqarfbXvIs6oemqQU itw2ayQ2h9cb49gWKsJiTJ04zZ28AXwMtTfDU1Fm72BzYX6Hew1QaLZsg6Exah+G2qdN b0WfiVOlqbIH+UHi4ObUPbDppUuAM3Pkh1Ihs4FfMW9uQt6BFKkTFpSiBKKk9wFz5qWU O9u4nl2hEGA9taENgivAmW3tKE69I7DMk5p2NOP8p2RVSkvFcGkVVb0ERZqqwaTFfAed zXwg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=4QLLdsmjlUXD8ZcmN6OfppjkNNypBTtU+sGe4+bM98Y=; b=VynYDjbsWeJaUmS1EULYX8Ol0A7Q9/+JMDYx0vin8yRVwMA9lcS136rN0EmEwJInSd gaKncff+3xwppYzQqrJD10iQHVdvRooczCw3wMtvVIaip9LzN9xtKoKCyHY2k2yBMRV1 wcSUHX9UkTBjue+6oIia0bFX255rXQ94utY730svfytOoE0Jd9pgI1h5RlzPL3vn1+Zl g8i4qcQxuDlNGi1u1VHvSZHqUxTjS8NhxBl92yx2OmR166F3ob76vyFiaIep3ZipOALt 27/BdTMhMCkT61A0/ZkpEMc0F//qqXQkuQZTTQI2BdgmJhBr4HfJsHReWB4R6KYV0NA+ D++A== X-Gm-Message-State: AOAM531RE9VlMyOFvdeWZn30Hztwo+DclzmmNguwVF30c6W/ws8F6Nca uQ1AdvlRmadMNlNkAEX1MKC7GA+eaxC8/D8iAuORvA== X-Google-Smtp-Source: ABdhPJxx1CVCheR6Stp3vqmoxoihh85LIgzCfQUCw04RbIpBz5X+OfH/Fs4Vj4t2NU/KXdMU/qKfpjoBThxmeHzrUyw= X-Received: by 2002:a17:90a:5405:: with SMTP id z5mr4290338pjh.13.1610451329003; Tue, 12 Jan 2021 03:35:29 -0800 (PST) MIME-Version: 1.0 References: <20210110124017.86750-1-songmuchun@bytedance.com> <20210110124017.86750-5-songmuchun@bytedance.com> <20210112083335.GH22493@dhcp22.suse.cz> <20210112100602.GL22493@dhcp22.suse.cz> <20210112111158.GM22493@dhcp22.suse.cz> In-Reply-To: <20210112111158.GM22493@dhcp22.suse.cz> From: Muchun Song Date: Tue, 12 Jan 2021 19:34:45 +0800 Message-ID: Subject: Re: [External] Re: [PATCH v3 4/6] mm: hugetlb: add return -EAGAIN for dissolve_free_huge_page To: Michal Hocko Cc: Mike Kravetz , Andrew Morton , Naoya Horiguchi , Andi Kleen , Linux Memory Management List , LKML Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Jan 12, 2021 at 7:12 PM Michal Hocko wrote: > > On Tue 12-01-21 18:49:17, Muchun Song wrote: > > On Tue, Jan 12, 2021 at 6:06 PM Michal Hocko wrote: > > > > > > On Tue 12-01-21 17:51:05, Muchun Song wrote: > > > > On Tue, Jan 12, 2021 at 4:33 PM Michal Hocko wrote: > > > > > > > > > > On Mon 11-01-21 17:20:51, Mike Kravetz wrote: > > > > > > On 1/10/21 4:40 AM, Muchun Song wrote: > > > > > > > There is a race between dissolve_free_huge_page() and put_page(), > > > > > > > and the race window is quite small. Theoretically, we should return > > > > > > > -EBUSY when we encounter this race. In fact, we have a chance to > > > > > > > successfully dissolve the page if we do a retry. Because the race > > > > > > > window is quite small. If we seize this opportunity, it is an > > > > > > > optimization for increasing the success rate of dissolving page. > > > > > > > > > > > > > > If we free a HugeTLB page from a non-task context, it is deferred > > > > > > > through a workqueue. In this case, we need to flush the work. > > > > > > > > > > > > > > The dissolve_free_huge_page() can be called from memory hotplug, > > > > > > > the caller aims to free the HugeTLB page to the buddy allocator > > > > > > > so that the caller can unplug the page successfully. > > > > > > > > > > > > > > Signed-off-by: Muchun Song > > > > > > > --- > > > > > > > mm/hugetlb.c | 26 +++++++++++++++++++++----- > > > > > > > 1 file changed, 21 insertions(+), 5 deletions(-) > > > > > > > > > > > > I am unsure about the need for this patch. The code is OK, there are no > > > > > > issues with the code. > > > > > > > > > > > > As mentioned in the commit message, this is an optimization and could > > > > > > potentially cause a memory offline operation to succeed instead of fail. > > > > > > However, we are very unlikely to ever exercise this code. Adding an > > > > > > optimization that is unlikely to be exercised is certainly questionable. > > > > > > > > > > > > Memory offline is the only code that could benefit from this optimization. > > > > > > As someone with more memory offline user experience, what is your opinion > > > > > > Michal? > > > > > > > > > > I am not a great fun of optimizations without any data to back them up. > > > > > I do not see any sign this code has been actually tested and the > > > > > condition triggered. > > > > > > > > This race is quite small. I only trigger this only once on my server. > > > > And then the kernel panic. So I sent this patch series to fix some > > > > bugs. > > > > > > Memory hotplug shouldn't panic when this race happens. Are you sure you > > > have seen a race that is directly related to this patch? > > > > I mean the panic is fixed by: > > > > [PATCH v3 3/6] mm: hugetlb: fix a race between freeing and dissolving the page > > OK, so the answer is that this is not really triggered by any real life > problem. Can you actually trigger it intentionally? > > > > > > Besides that I have requested to have an explanation of why blocking on > > > > > the WQ is safe and that hasn't happened. > > > > > > > > I have seen all the caller of dissolve_free_huge_page, some caller is under > > > > page lock (via lock_page). Others are also under a sleep context. > > > > > > > > So I think that blocking on the WQ is safe. Right? > > > > > > I have requested to explicitly write your thinking why this is safe so > > > that we can double check it. Dependency on a work queue progress is much > > > more complex than any other locks because there is no guarantee that WQ > > > will make forward progress (all workers might be stuck, new workers not > > > able to be created etc.). > > > > OK. I know about your concern. How about setting the page as temporary > > when hitting this race? > > > > int dissolve_free_huge_page(struct page *page) > > { > > @@ -1793,8 +1794,10 @@ int dissolve_free_huge_page(struct page *page) > > * We should make sure that the page is already on the free list > > * when it is dissolved. > > */ > > - if (unlikely(!PageHugeFreed(head))) > > + if (unlikely(!PageHugeFreed(head))) { > > + SetPageHugeTemporary(page) > > goto out; > > + } > > > > Setting the page as temporary and just return -EBUSY (do not flush > > the work). __free_huge_page() will free it to the buddy allocator later. > > Can we stop these subtle hacks please? Temporary page is meant to > represent unaccounted temporary page for migration. This has nothing to > do with it. Sure. Can drop this patch. > -- > Michal Hocko > SUSE Labs From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 342B4C433DB for ; Tue, 12 Jan 2021 11:35:32 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 9510F22CBE for ; Tue, 12 Jan 2021 11:35:31 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 9510F22CBE Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=bytedance.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 1C3016B02A2; Tue, 12 Jan 2021 06:35:31 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 174866B02A3; Tue, 12 Jan 2021 06:35:31 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 062378D0090; Tue, 12 Jan 2021 06:35:30 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0122.hostedemail.com [216.40.44.122]) by kanga.kvack.org (Postfix) with ESMTP id E2BC36B02A2 for ; Tue, 12 Jan 2021 06:35:30 -0500 (EST) Received: from smtpin15.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id A6313824805A for ; Tue, 12 Jan 2021 11:35:30 +0000 (UTC) X-FDA: 77696917620.15.basin08_241822227515 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin15.hostedemail.com (Postfix) with ESMTP id 845ED1814B0C7 for ; Tue, 12 Jan 2021 11:35:30 +0000 (UTC) X-HE-Tag: basin08_241822227515 X-Filterd-Recvd-Size: 8002 Received: from mail-pl1-f175.google.com (mail-pl1-f175.google.com [209.85.214.175]) by imf25.hostedemail.com (Postfix) with ESMTP for ; Tue, 12 Jan 2021 11:35:29 +0000 (UTC) Received: by mail-pl1-f175.google.com with SMTP id d4so442387plh.5 for ; Tue, 12 Jan 2021 03:35:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=4QLLdsmjlUXD8ZcmN6OfppjkNNypBTtU+sGe4+bM98Y=; b=HatddMj3Nb+5ix0xm5HiDy9AAbfoiZeBVH4pXzG70aFjUn13J/ansi0iyM9h8zgV9B 5Jf0XMRvh3nkOq9KyGKbPR9eoqf95+ZUlAvzEA3z6qDQ89RR8dDxqarfbXvIs6oemqQU itw2ayQ2h9cb49gWKsJiTJ04zZ28AXwMtTfDU1Fm72BzYX6Hew1QaLZsg6Exah+G2qdN b0WfiVOlqbIH+UHi4ObUPbDppUuAM3Pkh1Ihs4FfMW9uQt6BFKkTFpSiBKKk9wFz5qWU O9u4nl2hEGA9taENgivAmW3tKE69I7DMk5p2NOP8p2RVSkvFcGkVVb0ERZqqwaTFfAed zXwg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=4QLLdsmjlUXD8ZcmN6OfppjkNNypBTtU+sGe4+bM98Y=; b=arkiWcaMKqmhQfDt+ywKlH6FuXACoKGvIx2HTWW8xQoDIXMQCKpOR+EmV8ctHkDL0N 41uBubYjpHPlO74m1I9pJqw2jfBT7aEih/GCSWXnwP1/5hj7BthREiFSHc5r2KIeiBbT hoEF7v8M4L9QfF5olf8RhWJ0f7UHYiL7dgvjDF99Oeb+j9TG1JNq+zKM7J5FDaDgRpHi r4ZryBVf1iEcpW7cT1uT3VbzLQEkhcXgu/gge0eKaFl6g1ymvx9BIecL6Ha2bCoyHWlW rz4WB8yurg0HSzwK72ovavjGVkcBnhs0g2Qgto8HpZNyGXXPboT6HqP5s+DbGCiYj4PZ EiMQ== X-Gm-Message-State: AOAM530FvQLhG6RyXi9QeaVA0GOL2+JTC/pu5/hOBlMku0ls7ZafZ0ll Ra5Y/OyMixhiT5gBuNgmkBA+QTPN2eot9Ar7yFxhkA== X-Google-Smtp-Source: ABdhPJxx1CVCheR6Stp3vqmoxoihh85LIgzCfQUCw04RbIpBz5X+OfH/Fs4Vj4t2NU/KXdMU/qKfpjoBThxmeHzrUyw= X-Received: by 2002:a17:90a:5405:: with SMTP id z5mr4290338pjh.13.1610451329003; Tue, 12 Jan 2021 03:35:29 -0800 (PST) MIME-Version: 1.0 References: <20210110124017.86750-1-songmuchun@bytedance.com> <20210110124017.86750-5-songmuchun@bytedance.com> <20210112083335.GH22493@dhcp22.suse.cz> <20210112100602.GL22493@dhcp22.suse.cz> <20210112111158.GM22493@dhcp22.suse.cz> In-Reply-To: <20210112111158.GM22493@dhcp22.suse.cz> From: Muchun Song Date: Tue, 12 Jan 2021 19:34:45 +0800 Message-ID: Subject: Re: [External] Re: [PATCH v3 4/6] mm: hugetlb: add return -EAGAIN for dissolve_free_huge_page To: Michal Hocko Cc: Mike Kravetz , Andrew Morton , Naoya Horiguchi , Andi Kleen , Linux Memory Management List , LKML Content-Type: text/plain; charset="UTF-8" X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Tue, Jan 12, 2021 at 7:12 PM Michal Hocko wrote: > > On Tue 12-01-21 18:49:17, Muchun Song wrote: > > On Tue, Jan 12, 2021 at 6:06 PM Michal Hocko wrote: > > > > > > On Tue 12-01-21 17:51:05, Muchun Song wrote: > > > > On Tue, Jan 12, 2021 at 4:33 PM Michal Hocko wrote: > > > > > > > > > > On Mon 11-01-21 17:20:51, Mike Kravetz wrote: > > > > > > On 1/10/21 4:40 AM, Muchun Song wrote: > > > > > > > There is a race between dissolve_free_huge_page() and put_page(), > > > > > > > and the race window is quite small. Theoretically, we should return > > > > > > > -EBUSY when we encounter this race. In fact, we have a chance to > > > > > > > successfully dissolve the page if we do a retry. Because the race > > > > > > > window is quite small. If we seize this opportunity, it is an > > > > > > > optimization for increasing the success rate of dissolving page. > > > > > > > > > > > > > > If we free a HugeTLB page from a non-task context, it is deferred > > > > > > > through a workqueue. In this case, we need to flush the work. > > > > > > > > > > > > > > The dissolve_free_huge_page() can be called from memory hotplug, > > > > > > > the caller aims to free the HugeTLB page to the buddy allocator > > > > > > > so that the caller can unplug the page successfully. > > > > > > > > > > > > > > Signed-off-by: Muchun Song > > > > > > > --- > > > > > > > mm/hugetlb.c | 26 +++++++++++++++++++++----- > > > > > > > 1 file changed, 21 insertions(+), 5 deletions(-) > > > > > > > > > > > > I am unsure about the need for this patch. The code is OK, there are no > > > > > > issues with the code. > > > > > > > > > > > > As mentioned in the commit message, this is an optimization and could > > > > > > potentially cause a memory offline operation to succeed instead of fail. > > > > > > However, we are very unlikely to ever exercise this code. Adding an > > > > > > optimization that is unlikely to be exercised is certainly questionable. > > > > > > > > > > > > Memory offline is the only code that could benefit from this optimization. > > > > > > As someone with more memory offline user experience, what is your opinion > > > > > > Michal? > > > > > > > > > > I am not a great fun of optimizations without any data to back them up. > > > > > I do not see any sign this code has been actually tested and the > > > > > condition triggered. > > > > > > > > This race is quite small. I only trigger this only once on my server. > > > > And then the kernel panic. So I sent this patch series to fix some > > > > bugs. > > > > > > Memory hotplug shouldn't panic when this race happens. Are you sure you > > > have seen a race that is directly related to this patch? > > > > I mean the panic is fixed by: > > > > [PATCH v3 3/6] mm: hugetlb: fix a race between freeing and dissolving the page > > OK, so the answer is that this is not really triggered by any real life > problem. Can you actually trigger it intentionally? > > > > > > Besides that I have requested to have an explanation of why blocking on > > > > > the WQ is safe and that hasn't happened. > > > > > > > > I have seen all the caller of dissolve_free_huge_page, some caller is under > > > > page lock (via lock_page). Others are also under a sleep context. > > > > > > > > So I think that blocking on the WQ is safe. Right? > > > > > > I have requested to explicitly write your thinking why this is safe so > > > that we can double check it. Dependency on a work queue progress is much > > > more complex than any other locks because there is no guarantee that WQ > > > will make forward progress (all workers might be stuck, new workers not > > > able to be created etc.). > > > > OK. I know about your concern. How about setting the page as temporary > > when hitting this race? > > > > int dissolve_free_huge_page(struct page *page) > > { > > @@ -1793,8 +1794,10 @@ int dissolve_free_huge_page(struct page *page) > > * We should make sure that the page is already on the free list > > * when it is dissolved. > > */ > > - if (unlikely(!PageHugeFreed(head))) > > + if (unlikely(!PageHugeFreed(head))) { > > + SetPageHugeTemporary(page) > > goto out; > > + } > > > > Setting the page as temporary and just return -EBUSY (do not flush > > the work). __free_huge_page() will free it to the buddy allocator later. > > Can we stop these subtle hacks please? Temporary page is meant to > represent unaccounted temporary page for migration. This has nothing to > do with it. Sure. Can drop this patch. > -- > Michal Hocko > SUSE Labs