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 0D430C05027 for ; Mon, 23 Jan 2023 15:48:30 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 96C146B0072; Mon, 23 Jan 2023 10:48:29 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 91C106B0073; Mon, 23 Jan 2023 10:48:29 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 80A606B0074; Mon, 23 Jan 2023 10:48:29 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 728806B0072 for ; Mon, 23 Jan 2023 10:48:29 -0500 (EST) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 31F74160AB1 for ; Mon, 23 Jan 2023 15:48:29 +0000 (UTC) X-FDA: 80386495938.25.8294F70 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf13.hostedemail.com (Postfix) with ESMTP id 11BB620018 for ; Mon, 23 Jan 2023 15:48:26 +0000 (UTC) Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=s7Az+tKo; dmarc=none; spf=none (imf13.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1674488907; h=from:from:sender: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: in-reply-to:in-reply-to:references:references:dkim-signature; bh=KFAbC6/LnUvhZt2KUIpbaDNLUdiCloSuFSNDg9tXQCg=; b=aqZn6yb/OAIlvewp2yuHbPZNxq1NrofjMvf0Orq+uqBmqJ1qBbwzEErvLhWodIlSA1J2Ag mw33ubC8dZkJhDrM6INbbiufn6cHCEjH/LzL6RiB1keFJtVCfUEuVdJ9X+ChdYqJe1/dXX ezcCvysSrOZ/biicc0wYl0bPnim2KUY= ARC-Authentication-Results: i=1; imf13.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=s7Az+tKo; dmarc=none; spf=none (imf13.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1674488907; a=rsa-sha256; cv=none; b=FG5TdNNSsjMO1oqf2Jp3uwX5iR2h6TxMjgDr0fCUd+xv7dSTb3yI2WFSHU5FJ/pB8+e41A RX9HFPpOmYo4ENa3Mi8hwq/6lEpk6ZsSxEn/Qh0MumoLiMfc/WJxlL1pO8S93GfnoWLFKW DIQD0fWd3Jx55Gp2QPq/9qazD3uWfCE= 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=KFAbC6/LnUvhZt2KUIpbaDNLUdiCloSuFSNDg9tXQCg=; b=s7Az+tKooxnLkQ/AMW4/LRGZmh hI6KbpM+sJzFESK7oBd+4KtibzqEg0r7zsWPPKroNyV038yFtHBqNLYmg+kh8Lsbc1hVSZBZTOps3 CRHxyQTGmAUDU84tqz7wTIUe9KA8kZxmR5VwFz9k2x9+X22REj+3dnrHotCr6Tw0sWJUszx47Zus5 3O1CWDPO5qSoJWXj5B06oeLfAgXg2SWeTQEwC7c3wNGambyIkbSQt8iIkAWdav4ql7q6dCo/97FKK KjP+nnVA+0c63lN5Ndo9kILtTMfEQ2+yYQfjbNcLzIV3gsph8S+wRXF4muW5IDtvs9UHK45hJ1V/R IyFoJEZw==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1pJz3W-004L3V-By; Mon, 23 Jan 2023 15:48:22 +0000 Date: Mon, 23 Jan 2023 15:48:22 +0000 From: Matthew Wilcox To: "Vishal Moola (Oracle)" Cc: linux-mm@kvack.org, akpm@linux-foundation.org, sidhartha.kumar@oracle.com, linux-kernel@vger.kernel.org Subject: Re: [PATCH 2/3] mm/migrate: Convert isolate_movable_page() to use folios Message-ID: References: <20230121005622.57808-1-vishal.moola@gmail.com> <20230121005622.57808-3-vishal.moola@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Rspamd-Queue-Id: 11BB620018 X-Rspamd-Server: rspam09 X-Rspam-User: X-Stat-Signature: xttrbdtt1jhjnntrzzxspioy49zdqhys X-HE-Tag: 1674488906-704196 X-HE-Meta: U2FsdGVkX1+vcMgauIoKx4c7elEbGi47rL/LrbqiAKPWJpKspfnjswQ2lPIbIoBIswj8us1ATXjDnPEcLnExTu9fFhlWCawaVuro6TyTyVFoEzNPVXaQiNLLF1nefqFA/DoguHq7EivjuVU9M/lyo45NmF2Da0gKtSXwN9bJ+JM9gPS/1/EPOBx7/QTVms9jqk5BnSeI2ZL99pVB9tdmyDyvcOLUVRIvsY1GDfDaqk/i9oTeDnmqFk9U5koIsSxeADX0jieBTEzf1l4NDotSoQ1OSl/8L8U7RAqz74Ja3te5XHyrnJzd9uY7izrWczyYoYWdWle7YpYrnklnCEbu9WlCeQy+4K4eaJIF3XXbSQshmpK9vQBc8uzCLKxBZda1A5CTXsaMg+Law8gVBqrP4UlVaRm0oLhbUYQNz4NGMyG5oaAhJtTf5CqZw8W4Nogj3kFsUXJYQy3lDUW/j76akoScgi6f3cDXTiH3mhk9PqZObhgdkrLbXeOL0MyfWA/bilKXXjqNwraYryKiVHM6L1oXxQxPluPiboqrwmGt72DlI/AULcc6tO3VgA42kbA5hDDrb4vuP7A6TVVQav9Z1FROubx+Bi1Ve/3oBtHiExYCakVz8e8LuEY+0bNY4vkwZYvlaAse1HYxzxshljFWROWgmQOmEqVN9/Jtz4DyWnvLRKQP013YExD3oFoTljQra+4qkXcFMZCGr1qmq8a+QgQ3jvz6cZCnvYDK9OxC9cC08WvLX7wtq9OkOiYo7PxaHh0oYlcTTRPqolS+xQf4knHlnDiEpssKPHhOhFVmAB+y0GHoaLO8feDqLo5tkHAQivenBTG2+KdHNomS0j3/XwEb8xMjZMxshMYuZbYQ0hW8l2PEgBS3+2hmYc9ZaW84s6K1ILFl8ryP/NsYpUifApO510wwKjLwOzIl6K+TVTARl7B8JGGACQkkVFeULWG25KcwhZkqkmzCmnbMbSP jAvV2iAN ToNn89IPqtU1Qau+lSy0yfAF4PX+7r9hIm/bs7osa4W+MIKaBZ8zhma14TFRg8Skv7uVFXa1ZcFY4VqR4W66RVQJNCQypGjbOLxduEI+hK2+eC1YoJ864qAGrcN6wgoT34+kiP+cHPlGYy3VdeXlgjgulQmn9hfNrthkdGQcYEZyt8WSZrGxzjHh/raXPRqqG3TkcZdZyhHh5a+Q6eYpiBJCg9uTzzosZm4+fnewSSG/IqnoCnkZ97bk+WAqclgB82wAeATdCbNXaXvg= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000172, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Sun, Jan 22, 2023 at 12:46:34PM +0000, Matthew Wilcox wrote: > On Fri, Jan 20, 2023 at 04:56:21PM -0800, Vishal Moola (Oracle) wrote: > > int isolate_movable_page(struct page *page, isolate_mode_t mode) > > { > > + struct folio *folio = page_folio(page); > > const struct movable_operations *mops; > > > > /* > > @@ -71,11 +72,11 @@ int isolate_movable_page(struct page *page, isolate_mode_t mode) > > * the put_page() at the end of this block will take care of > > * release this page, thus avoiding a nasty leakage. > > */ > > - if (unlikely(!get_page_unless_zero(page))) > > + if (unlikely(!folio_try_get(folio))) > > This changes behaviour. Previously when called on a tail page, the > call failed. Now it succeeds, getting a ref on something that at > least was the folio head at some point. > > If you're going to do this, you need to recheck that the page is still > part of the folio after getting the ref (see gup.c for an example). > But I think we should probably maintain the behaviour of failing on > tail pages. > > Maybe something like ... > > if (unlikely(!get_page_unless_zero(page))) > goto out; > /* Refcount is zero on tail pages, so we must have a head */ > folio = (struct folio *)page; I've been thinking about this some more as I don't like doing these kinds of casts (except in the helper functions). What do you think to adding: struct folio *folio_get_nontail_page(struct page *) { if unlikely(!get_page_unless_zero(page)) return NULL; return (struct folio *)page; } and then isolate_movable_page() looks like: struct folio *folio; [...] folio = folio_get_nontail_page(page); if (!folio) goto out; I keep thinking about how this is all going to work when we get to one-pointer-per-page. Telling tail pages from head pages becomes hard. This probably becomes an out-of-line function that looks something like .. struct memdesc *memdesc = READ_ONCE(page->memdesc); struct folio *folio; if (!memdesc_is_folio(memdesc)) return NULL; folio = memdesc_folio(memdesc); if (!folio_try_get(folio)) return NULL; if (READ_ONCE(page->memdesc) != memdesc || folio->pfn != page_pfn(page)) { folio_put(folio); return NULL; } return folio; (note: We need to check that page->memdesc still points to this folio after getting the refcount on it. we could loop around if it fails, but failing the entire get is OK; if memdesc changed then either before this function was called, after this function was called or while this function was called, the refcount on the memdesc it was pointing to was zero)