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=-17.6 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_SANE_1 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 928B6C433EF for ; Tue, 7 Sep 2021 01:47:05 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id E89DE6109D for ; Tue, 7 Sep 2021 01:47:04 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org E89DE6109D Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=huawei.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id EA9EA6B0071; Mon, 6 Sep 2021 21:47:03 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E584E6B0072; Mon, 6 Sep 2021 21:47:03 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D46D9900002; Mon, 6 Sep 2021 21:47:03 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0085.hostedemail.com [216.40.44.85]) by kanga.kvack.org (Postfix) with ESMTP id C4F336B0071 for ; Mon, 6 Sep 2021 21:47:03 -0400 (EDT) Received: from smtpin27.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 75EB72AF1D for ; Tue, 7 Sep 2021 01:47:03 +0000 (UTC) X-FDA: 78559089126.27.18E7CAF Received: from szxga08-in.huawei.com (szxga08-in.huawei.com [45.249.212.255]) by imf24.hostedemail.com (Postfix) with ESMTP id 4A7BFB00009F for ; Tue, 7 Sep 2021 01:47:02 +0000 (UTC) Received: from dggeme703-chm.china.huawei.com (unknown [172.30.72.55]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4H3Sm06lzdz1DGpB; Tue, 7 Sep 2021 09:46:08 +0800 (CST) Received: from [10.174.178.100] (10.174.178.100) by dggeme703-chm.china.huawei.com (10.1.199.99) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2308.8; Tue, 7 Sep 2021 09:46:58 +0800 Subject: Re: [PATCH] mm/page_isolation: don't putback unisolated page To: David Hildenbrand , CC: , , , References: <20210904091839.20270-1-linmiaohe@huawei.com> <3b36529f-ab97-ddfe-0407-66f0cd1fd38d@redhat.com> <2d06db75-5c26-8fe2-6883-ac99056a9894@redhat.com> From: Miaohe Lin Message-ID: <57392d12-9a6c-dbb5-3c3e-39ed9ab7c31c@huawei.com> Date: Tue, 7 Sep 2021 09:46:57 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.6.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset="utf-8" Content-Language: en-US X-Originating-IP: [10.174.178.100] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To dggeme703-chm.china.huawei.com (10.1.199.99) X-CFilter-Loop: Reflected Authentication-Results: imf24.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=huawei.com; spf=pass (imf24.hostedemail.com: domain of linmiaohe@huawei.com designates 45.249.212.255 as permitted sender) smtp.mailfrom=linmiaohe@huawei.com X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: 4A7BFB00009F X-Stat-Signature: ubigbrd9ytbox5q4xrgzyezpnwi8kz4a X-HE-Tag: 1630979222-155678 Content-Transfer-Encoding: quoted-printable 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 2021/9/6 20:49, David Hildenbrand wrote: > On 06.09.21 14:45, Miaohe Lin wrote: >> On 2021/9/6 20:11, David Hildenbrand wrote: >>> On 06.09.21 14:02, David Hildenbrand wrote: >>>> On 04.09.21 11:18, Miaohe Lin wrote: >>>>> If __isolate_free_page() failed, due to zone watermark check, the p= age is >>>>> still on the free list. But this page will be put back to free list= again >>>>> via __putback_isolated_page() now. This may trigger page->flags che= cks in >>>>> __free_one_page() if PageReported is set. Or we will corrupt the fr= ee list >>>>> because list_add() will be called for pages already on another list= . >>>>> >>>>> Fixes: 3c605096d315 ("mm/page_alloc: restrict max order of merging = on isolated pageblock") >>>>> Signed-off-by: Miaohe Lin >>>>> --- >>>>> =C2=A0=C2=A0=C2=A0 mm/page_isolation.c | 6 ++---- >>>>> =C2=A0=C2=A0=C2=A0 1 file changed, 2 insertions(+), 4 deletions(-) >>>>> >>>>> diff --git a/mm/page_isolation.c b/mm/page_isolation.c >>>>> index 9bb562d5d194..7d70d772525c 100644 >>>>> --- a/mm/page_isolation.c >>>>> +++ b/mm/page_isolation.c >>>>> @@ -93,10 +93,8 @@ static void unset_migratetype_isolate(struct pag= e *page, unsigned migratetype) >>>>> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0 buddy_pfn =3D __find_buddy_pfn(pfn, order); >>>>> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0 buddy =3D page + (buddy_pfn - pfn); >>>>> =C2=A0=C2=A0=C2=A0 -=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0 if (!is_migrate_isolate_page(buddy)) { >>>>> -=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0 __isolate_free_page(page, order); >>>>> -=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0 isolated_page =3D true; >>>>> -=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= } >>>>> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= if (!is_migrate_isolate_page(buddy)) >>>>> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0 isolated_page =3D !!__isolate_free_page(page, or= der); >>>>> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 = } >>>>> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 } >>>>> =C2=A0=C2=A0=20 >>>> >>>> Thanks! >>>> >>>> Reviewed-by: David Hildenbrand >>>> >>> >>> To make the confusion perfect (sorry) :D I tripple-checked: >>> >>> In unset_migratetype_isolate() we check that is_migrate_isolate_page(= page) holds, otherwise we return. >>> >>> We call __isolate_free_page() only for such pages. >>> >>> __isolate_free_page() won't perform watermark checks on is_migrate_is= olate(). >>> >>> Consequently, __isolate_free_page() should never fail when called fro= m unset_migratetype_isolate() >>> >>> If that's correct then we=C2=A0 could instead maybe add a VM_BUG_ON()= and a comment why this can't fail. >>> >>> >>> Makes sense or am I missing something? >> >> I think you're right. __isolate_free_page() should never fail when cal= led from unset_migratetype_isolate() >> as explained by you. But it might be too fragile to reply on the failu= re conditions of __isolate_free_page(). >> If that changes, VM_BUG_ON() here might trigger unexpectedly. Or am I = just over-worried as failure conditions >> of __isolate_free_page() can hardly change? >=20 > Maybe >=20 > isolated_page =3D !!__isolate_free_page(page, order); > /* > =C2=A0* Isolating a free page in an isolated pageblock is expected to a= lways > =C2=A0* work as watermarks don't apply here. > =C2=A0*/ > VM_BUG_ON(isolated_page); Should this be VM_BUG_ON(!isolated_page) ? >=20 >=20 > VM_BUG_ON() allows us to detect any issues when testing. Combined with = the comment it tells everybody messing with __isolate_free_page() what we= expect in this function. >=20 > In production system, we would handle it gracefully. >=20 Sounds reasonable. Will do it in v2. Many thanks for your suggestion and = effort!