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 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 60A55C4332F for ; Wed, 11 May 2022 15:23:33 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C6FE96B0074; Wed, 11 May 2022 11:23:32 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C1E516B0078; Wed, 11 May 2022 11:23:32 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A72066B007B; Wed, 11 May 2022 11:23:32 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 950106B0074 for ; Wed, 11 May 2022 11:23:32 -0400 (EDT) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 5172532E55 for ; Wed, 11 May 2022 15:23:32 +0000 (UTC) X-FDA: 79453831464.07.150EA4F Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf31.hostedemail.com (Postfix) with ESMTP id DC76520096 for ; Wed, 11 May 2022 15:23:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1652282611; 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; bh=QSwu7xqkqoNLt+H1Fs+CQIumcyQcOiTFfolxhe68oB0=; b=PhxpgV43g8mssBadx8d54pr4XCOH4L/0UtuCbPUmA9nCMrWEBXAvyPe6MAIrzs6PAFmw3N +jSIaTT1q5QzO2vF636/SUYsoJNtZ8ELtxjw5oopRN6hTaWYsURAcnBPB5n650fQNLmAIh 1itQj0IsMff3jIDSkzFXgi+LgsFC840= Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-451-eZu0PLt0NU6y4ArsLN0TLQ-1; Wed, 11 May 2022 11:23:28 -0400 X-MC-Unique: eZu0PLt0NU6y4ArsLN0TLQ-1 Received: by mail-wm1-f72.google.com with SMTP id m186-20020a1c26c3000000b003943e12185dso836783wmm.7 for ; Wed, 11 May 2022 08:23:27 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent :content-language:to:cc:references:from:organization:subject :in-reply-to:content-transfer-encoding; bh=QSwu7xqkqoNLt+H1Fs+CQIumcyQcOiTFfolxhe68oB0=; b=kyzmuo8B2INvA1hhDF9D7g6bFtVW+Li837v1JN0Xa9Sio3X9VvXAZ63VlY/hVLkHcw rFNqX/uMU17XDJBX271pnNK3shotQNBeQ+BkVAOvVkpcWEhxORFXqNC8daQZSEQ7JdXu xrJSthePGZXnKKLAwjdL34cfT/9YcBquBGpUnX3+ntPfu4vLAbeZKakX6LQtgVg9UNDw XkFSNyXrsw7v65v2aSJPvs2D9gZB59jCFjfkGEx222kaYoJ6hcWqaAaDIMlpFWDVuupk 3UVZYWmIqSRedz7FnvCZNkNsia/X7LxIQtEVWvXqE+9+GtI6rVMt8NVPEh9UfWmIwpRf yPHw== X-Gm-Message-State: AOAM5300vg0JLSLQA3THqpKqKnrW4gUz/ozLedR2/fo8LDsxNJCAFFrR hSIbB4id65+N4Tjpp9HR3jcJnF08uH8lCSXaMNvOhUCmVTUAcaCMVsrS20IHHb1LF3XB3Ujz3Rg ftBNSw94D4is= X-Received: by 2002:a05:6000:144e:b0:20c:ab37:70f3 with SMTP id v14-20020a056000144e00b0020cab3770f3mr23119864wrx.682.1652282606802; Wed, 11 May 2022 08:23:26 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzXmrCQHyV0Vzn7S9Pf5AXsxOTUZnIuFnjQeZxtcrP3EcXVkDoAgCyGtUebE34qnyln2EmSPQ== X-Received: by 2002:a05:6000:144e:b0:20c:ab37:70f3 with SMTP id v14-20020a056000144e00b0020cab3770f3mr23119840wrx.682.1652282606497; Wed, 11 May 2022 08:23:26 -0700 (PDT) Received: from ?IPV6:2003:cb:c701:700:2393:b0f4:ef08:bd51? (p200300cbc70107002393b0f4ef08bd51.dip0.t-ipconnect.de. [2003:cb:c701:700:2393:b0f4:ef08:bd51]) by smtp.gmail.com with ESMTPSA id i10-20020a5d630a000000b0020c5253d8d4sm1956738wru.32.2022.05.11.08.23.25 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 11 May 2022 08:23:25 -0700 (PDT) Message-ID: <4cf144a9-fff5-d993-4fcb-7f2dfa6e71bb@redhat.com> Date: Wed, 11 May 2022 17:23:25 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.8.0 To: Miaohe Lin Cc: ying.huang@intel.com, hch@lst.de, dhowells@redhat.com, cl@linux.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, akpm@linux-foundation.org, mike.kravetz@oracle.com, naoya.horiguchi@nec.com References: <20220425132723.34824-1-linmiaohe@huawei.com> <20220425132723.34824-3-linmiaohe@huawei.com> <525298ad-5e6a-2f8d-366d-4dcb7eebd093@redhat.com> From: David Hildenbrand Organization: Red Hat Subject: Re: [PATCH v2 2/4] mm/migration: remove unneeded lock page and PageMovable check In-Reply-To: X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: DC76520096 X-Stat-Signature: 95ya9cq4wew8tu8pzau7wunj6tq5ury7 X-Rspam-User: Authentication-Results: imf31.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=PhxpgV43; spf=none (imf31.hostedemail.com: domain of david@redhat.com has no SPF policy when checking 170.10.129.124) smtp.mailfrom=david@redhat.com; dmarc=pass (policy=none) header.from=redhat.com X-HE-Tag: 1652282589-589238 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 09.05.22 10:51, Miaohe Lin wrote: > On 2022/4/29 18:07, David Hildenbrand wrote: >> On 25.04.22 15:27, Miaohe Lin wrote: >>> When non-lru movable page was freed from under us, __ClearPageMovable must >>> have been done. Even if it's not done, ClearPageIsolated here won't hurt >>> as page will be freed anyway. So we can thus remove unneeded lock page and >>> PageMovable check here. >>> >>> Signed-off-by: Miaohe Lin >>> Reviewed-by: Christoph Hellwig >>> --- >>> mm/migrate.c | 8 ++------ >>> 1 file changed, 2 insertions(+), 6 deletions(-) >>> >>> diff --git a/mm/migrate.c b/mm/migrate.c >>> index b779646665fe..0fc4651b3e39 100644 >>> --- a/mm/migrate.c >>> +++ b/mm/migrate.c >>> @@ -1093,12 +1093,8 @@ static int unmap_and_move(new_page_t get_new_page, >>> /* page was freed from under us. So we are done. */ >>> ClearPageActive(page); >>> ClearPageUnevictable(page); >>> - if (unlikely(__PageMovable(page))) { >>> - lock_page(page); >>> - if (!PageMovable(page)) >>> - ClearPageIsolated(page); >>> - unlock_page(page); >>> - } >>> + if (unlikely(__PageMovable(page))) >>> + ClearPageIsolated(page); >>> goto out; >>> } >> >> Hm, that code+change raises a couple of questions. >> >> We're doing here the same as in putback_movable_pages(). So I guess the >> difference here is that the caller did release the reference while the >> page was isolated, while we don't assume the same in >> putback_movable_pages(). > > Agree. > >> >> >> Shouldn't whoever owned the page have cleared that? IOW, is it even >> valid that we see a movable or isolated page here (WARN/BUG?)? >> >> At least for balloon compaction, I remember that __PageMovable() is >> properly cleared before freeing it via balloon_page_delete(). > > z3fold, zsmalloc will do __ClearPageMovable when the page is going to be released. > So I think we shouldn't see a movable page here: > > void __ClearPageMovable(struct page *page) > { > VM_BUG_ON_PAGE(!PageMovable(page), page); > /* > * Clear registered address_space val with keeping PAGE_MAPPING_MOVABLE > * flag so that VM can catch up released page by driver after isolation. > * With it, VM migration doesn't try to put it back. > */ > page->mapping = (void *)((unsigned long)page->mapping & > PAGE_MAPPING_MOVABLE); > } > > But it seems there is no guarantee for PageIsolated flag. Or am I miss something? At least the code we have now: if (unlikely(__PageMovable(page))) ClearPageIsolated(page); Should be dead code. So PG_isolated could remain set. If PG_isolated is still set, it will get cleared in the buddy when freeing the page via page->flags &= ~PAGE_FLAGS_CHECK_AT_PREP; > >> >> >> Also, I am not sure how reliable that page count check is here: if we'd >> have another speculative reference to the page, we might see >> "page_count(page) > 1" and not take that path, although the previous >> owner released the last reference. > > IIUC, there should not be such speculative reference. The driver should have taken care > of it. How can you prevent any kind of speculative references? See isolate_movable_page() as an example, which grabs a speculative reference to then find out that the page is already isolated by someone else, to then back off. -- Thanks, David / dhildenb