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=-10.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS 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 D4B21C432BE for ; Sun, 15 Aug 2021 10:34:56 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 96B5461106 for ; Sun, 15 Aug 2021 10:34:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237148AbhHOKfW (ORCPT ); Sun, 15 Aug 2021 06:35:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58660 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232507AbhHOKfV (ORCPT ); Sun, 15 Aug 2021 06:35:21 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 03370C061764 for ; Sun, 15 Aug 2021 03:34:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=wIy2WCEKV0r/vK8gf5Lm8U+9ngWtzGQMVcf+08uX0S8=; b=u5Ui/TVGjleiTx0wcq91U6h9kf 0drv5HLXOhVm/5HuuMAT4gmWuG1+BTXoydypQha32TY7000OlbvNGEXiON61CdyZGoiXJVrw5tCQI OSCIwfr0HKTunkKAc1knmPU3uAmu/xWm1FIwLvQfQ9wzow7qu748ZX7QqBm+pQe2z5joe2a1o7Nle HNcSRzUaC54R3ycIloH9e1I4Vd7/wf2WRz/xE6UO8H07fsTWfSGpZyvjy+6bkfNyZ7oPvVNKSZjUI eX2rFc4GVnTQoYk9S5IqLVufoVs+hdBAxkAnNxAogDGvUcgAmGcnMt3Ev2ElC8BLWdPE6pu1g3yd5 syYftYlg==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1mFDT8-0003Tw-Pf; Sun, 15 Aug 2021 10:34:23 +0000 Date: Sun, 15 Aug 2021 11:34:18 +0100 From: Matthew Wilcox To: Baolin Wang Cc: akpm@linux-foundation.org, apopple@nvidia.com, shy828301@gmail.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v2 1/4] mm: migrate: Move the page count validation to the proper place Message-ID: References: <644a666e1e177c57a39a4c37c6e2ca64052b9d7e.1629008158.git.baolin.wang@linux.alibaba.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <644a666e1e177c57a39a4c37c6e2ca64052b9d7e.1629008158.git.baolin.wang@linux.alibaba.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sun, Aug 15, 2021 at 02:23:03PM +0800, Baolin Wang wrote: > We've got the expected count for anonymous page or file page by > expected_page_refs() at the beginning of migrate_page_move_mapping(), > thus we should move the page count validation a little forward to > reduce duplicated code. > > Moreover the i_pages lock is not used to guarantee the page refcount > safety in migrate_page_move_mapping(), so we can move the getting page > count out of the i_pages lock. Since now the migration page has > established a migration pte under the page lock now, with the page > refcount freezing validation, to ensure that the page references > meet the migration requirement. I remain unconvinced by this. Looking at folio_migrate_mapping() a little more deeply, I don't understand why we first check folio_ref_count() and then attempt to free the refcount. Why not just try to freeze it directly? ie instead of your patch, this: +++ b/mm/migrate.c @@ -403,13 +403,8 @@ int folio_migrate_mapping(struct address_space *mapping, newzone = folio_zone(newfolio); xas_lock_irq(&xas); - if (folio_ref_count(folio) != expected_count || - xas_load(&xas) != folio) { - xas_unlock_irq(&xas); - return -EAGAIN; - } - - if (!folio_ref_freeze(folio, expected_count)) { + if (xas_load(&xas) != folio || + !folio_ref_freeze(folio, expected_count)) { xas_unlock_irq(&xas); return -EAGAIN; } And since we've got the lock on the page, how can somebody else be removing it from the page cache? I think that xas_load() can be removed too. So even more simply, +++ b/mm/migrate.c @@ -403,12 +403,6 @@ int folio_migrate_mapping(struct address_space *mapping, newzone = folio_zone(newfolio); xas_lock_irq(&xas); - if (folio_ref_count(folio) != expected_count || - xas_load(&xas) != folio) { - xas_unlock_irq(&xas); - return -EAGAIN; - } - if (!folio_ref_freeze(folio, expected_count)) { xas_unlock_irq(&xas); return -EAGAIN; but I'm not really set up to test page migration. Does your test suite test migrating file-backed pages?