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=-8.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS 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 60FE4C4338F for ; Sun, 15 Aug 2021 10:34:52 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id A82DD60F21 for ; Sun, 15 Aug 2021 10:34:51 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org A82DD60F21 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id 2B6B76B006C; Sun, 15 Aug 2021 06:34:51 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 2668E8D0001; Sun, 15 Aug 2021 06:34:51 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 12EA26B0072; Sun, 15 Aug 2021 06:34:51 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0124.hostedemail.com [216.40.44.124]) by kanga.kvack.org (Postfix) with ESMTP id ECCF56B006C for ; Sun, 15 Aug 2021 06:34:50 -0400 (EDT) Received: from smtpin17.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 7F20916B1E for ; Sun, 15 Aug 2021 10:34:50 +0000 (UTC) X-FDA: 78476956740.17.54F8554 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf23.hostedemail.com (Postfix) with ESMTP id 31A81900B4D3 for ; Sun, 15 Aug 2021 10:34:50 +0000 (UTC) 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> Authentication-Results: imf23.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b="u5Ui/TVG"; spf=none (imf23.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org; dmarc=none X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 31A81900B4D3 X-Stat-Signature: hjiamrxfg9bdjbw5pbbheefa774jpg6q X-HE-Tag: 1629023690-637523 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 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?