Received: by 2002:ab2:1c04:0:b0:1f7:53ba:1ebe with SMTP id f4csp163982lqg; Fri, 26 Apr 2024 11:37:12 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUwv8xRtpA8rHR4nOpaHLODFzPhyHWcuVkWdiabXRqr5rb4KmBn3TJ2YWe0hWTmtLJ9AWGknpPUNr45SEFStkeEcbRQ/4B7eyMHL9YfVg== X-Google-Smtp-Source: AGHT+IEmIkokSBsVabK13GuB4Vz5WFYKw/ucmvaBBcErTagcadv7qfzxKH2bt7sGaRRviRqGQz2q X-Received: by 2002:a17:90a:f016:b0:2af:6483:a8e0 with SMTP id bt22-20020a17090af01600b002af6483a8e0mr3985766pjb.36.1714156632260; Fri, 26 Apr 2024 11:37:12 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1714156632; cv=pass; d=google.com; s=arc-20160816; b=Q6e3nAHAnef9zZ8k8dqNHPKEpyAhiHhAXo7mOR7sPGUXAMl+FZIZnUz9FNVD7ZU2e0 g8SwfVONpt2J69CsHWCfDgVKXbTIkT9ZI0gLLziovtVvAG5jf9d9BZXY4KlIz5tMExx/ AVee10tJZ4QGXtAXw+rfg5Ll4jN8mdW/iPck1wQX/ZBNDKL31qagkXFSjIE7/N7xccsN Vi9Vo63/CdSTIER52wfV18VW8BqiiChKzFjqH1CxLkUHecQmKtJGxx98/mMpj0yTdLeK 8iYYdaqXNYC7N7PJoYIBFd1yEvngNnEHetL1lL8VDuGK/0Me9hQksqDlFlnUoPifRiTy Xalg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=UUvYm71fjkEqtSxLHnGtOJW9nzuNwvObOROt5Vq5kDE=; fh=naCeMW9u4zsjnL92Usk/DfFONRYTtcAHKz4ayNomlmQ=; b=GHl5eJ8dBAPilJVgC9ImqdcjWVA7cnbyczgsgCc2nUnUspUH0Tp9lOVJtiGddzRFMS IAJKVcTuSgeC0r8W0un1cZMbJoLg0xdIIl5f9drFJVbzZMViRUOFLTFMvtiheFQZ5GNV X0sr1ojTx6+3JwvBSoeTSgfJWyHSJWlIHBZP7th6tK1073mUApQEd9Jhry+JazmhZL11 dB1+DFnGYUZgBRihBA8ZkBTvi4Dc+WLRYJ4K801sxsJTxWw2+EMMr4GY2BTeiJuCb8qY 8VktbBKhCqw8ldXNy1diSJuTFQRpjuUPfSPGVPWUGOFkQYnCVbkucDZfeOmVJLhb6I3I ovSA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=hn9Z4gVI; arc=pass (i=1 dkim=pass dkdomain=infradead.org); spf=pass (google.com: domain of linux-kernel+bounces-160499-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-160499-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id k6-20020a633d06000000b0060e76cfa327si1350070pga.825.2024.04.26.11.37.11 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 Apr 2024 11:37:12 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-160499-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=hn9Z4gVI; arc=pass (i=1 dkim=pass dkdomain=infradead.org); spf=pass (google.com: domain of linux-kernel+bounces-160499-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-160499-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id B5F09B247AE for ; Fri, 26 Apr 2024 17:34:51 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 5B95F15B974; Fri, 26 Apr 2024 17:34:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="hn9Z4gVI" Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 291E8148854 for ; Fri, 26 Apr 2024 17:34:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=90.155.50.34 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714152884; cv=none; b=nSd5QVROJZ7AH2zVVuHQLntYUDYvJAEYi4qIH/TWCHPsA9xWrUUsdj11ZhAd9rv9SAyxzbP6jiLU1q9UxMIiTrqco9pRSYSzFOIJLifxZtLmW+pEg63irSx1liJQMzponXji3S6ouq6PJiCaobRUvMpn69SggPY0LRl+xi1Sm/8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714152884; c=relaxed/simple; bh=mRqrrwqCUQE1blvTPKPlca0CB4j+Sib/FmUAKUGcrYQ=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=jzX8h8pMo8l54M7E2s9uOWPbNcg9pJIq+ymQLkEEqfb072dZE5hq3URWT/TnaN/IYIyRlqotUHxgc8ovFXW0WLTnMCe5RLBvtJ1dkOmdUCPWfHu5D/TAJNxXkWml1z0TiDSTIom4GHCM2zbLONvP5JUo/phyqzEWPvAnsm0dwTU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org; spf=none smtp.mailfrom=infradead.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b=hn9Z4gVI; arc=none smtp.client-ip=90.155.50.34 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=infradead.org 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=UUvYm71fjkEqtSxLHnGtOJW9nzuNwvObOROt5Vq5kDE=; b=hn9Z4gVIqvr6bBM9IEZqJ0TI8o 48x4aZu0SVYcFUsy6Cxy8stS0svKwc8tqPOO+gti0aEyxKfYg/AIm2lxzKawlKfXchIMWCEcUhV1P 8yFxyH+5DuHxjXsLZ9xZ/mmxIe5Am9vCLUJE1G4I4A+BRlDiYf/kYJt5+lD156c4raXEKREk0Sm8b Nu7D1dEbwoxbSzutsI5wCUCB6jOLZganYUzNajBnEVvGMHkNn/7duLouwqKgXHFtbTx51M81kYs5J crh6KuZ7D00yUEbzDbGWLS4WDkZ2bKp8Pp0oZbAdCyTzdrUN3W7eC66kzft0xiy4tSO7DVCJenCDk IatHAwYg==; Received: from willy by casper.infradead.org with local (Exim 4.97.1 #2 (Red Hat Linux)) id 1s0PT2-00000005gwQ-3NQu; Fri, 26 Apr 2024 17:34:36 +0000 Date: Fri, 26 Apr 2024 18:34:36 +0100 From: Matthew Wilcox To: Sidhartha Kumar Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, akpm@linux-foundation.org, linmiaohe@huawei.com, jane.chu@oracle.com, nao.horiguchi@gmail.com, osalvador@suse.de Subject: Re: [PATCH] mm/memory-failure: remove shake_page() Message-ID: References: <20240426171511.122887-1-sidhartha.kumar@oracle.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20240426171511.122887-1-sidhartha.kumar@oracle.com> On Fri, Apr 26, 2024 at 10:15:11AM -0700, Sidhartha Kumar wrote: > Use a folio in get_any_page() to save 5 calls to compound head and > convert the last user of shake_page() to shake_folio(). This allows us > to remove the shake_page() definition. So I didn't do this before because I wasn't convinced it was safe. We don't have a refcount on the folio, so the page might no longer be part of this folio by the time we get the refcount on the folio. I'd really like to see some argumentation for why this is safe. > Signed-off-by: Sidhartha Kumar > --- > mm/memory-failure.c | 20 ++++++++------------ > 1 file changed, 8 insertions(+), 12 deletions(-) > > diff --git a/mm/memory-failure.c b/mm/memory-failure.c > index 16ada4fb02b79..273f6fef29f25 100644 > --- a/mm/memory-failure.c > +++ b/mm/memory-failure.c > @@ -385,11 +385,6 @@ void shake_folio(struct folio *folio) > } > EXPORT_SYMBOL_GPL(shake_folio); > > -static void shake_page(struct page *page) > -{ > - shake_folio(page_folio(page)); > -} > - > static unsigned long dev_pagemap_mapping_shift(struct vm_area_struct *vma, > unsigned long address) > { > @@ -1433,6 +1428,7 @@ static int get_any_page(struct page *p, unsigned long flags) > { > int ret = 0, pass = 0; > bool count_increased = false; > + struct folio *folio = page_folio(p); > > if (flags & MF_COUNT_INCREASED) > count_increased = true; > @@ -1446,7 +1442,7 @@ static int get_any_page(struct page *p, unsigned long flags) > if (pass++ < 3) > goto try_again; > ret = -EBUSY; > - } else if (!PageHuge(p) && !is_free_buddy_page(p)) { > + } else if (!folio_test_hugetlb(folio) && !is_free_buddy_page(p)) { > /* We raced with put_page, retry. */ > if (pass++ < 3) > goto try_again; > @@ -1459,7 +1455,7 @@ static int get_any_page(struct page *p, unsigned long flags) > * page, retry. > */ > if (pass++ < 3) { > - shake_page(p); > + shake_folio(folio); > goto try_again; > } > ret = -EIO; > @@ -1467,7 +1463,7 @@ static int get_any_page(struct page *p, unsigned long flags) > } > } > > - if (PageHuge(p) || HWPoisonHandlable(p, flags)) { > + if (folio_test_hugetlb(folio) || HWPoisonHandlable(p, flags)) { > ret = 1; > } else { > /* > @@ -1475,12 +1471,12 @@ static int get_any_page(struct page *p, unsigned long flags) > * it into something we can handle. > */ > if (pass++ < 3) { > - put_page(p); > - shake_page(p); > + folio_put(folio); > + shake_folio(folio); > count_increased = false; > goto try_again; > } > - put_page(p); > + folio_put(folio); > ret = -EIO; > } > out: > @@ -1643,7 +1639,7 @@ static bool hwpoison_user_mappings(struct folio *folio, struct page *p, > > /* > * try_to_unmap() might put mlocked page in lru cache, so call > - * shake_page() again to ensure that it's flushed. > + * shake_folio() again to ensure that it's flushed. > */ > if (mlocked) > shake_folio(folio); > -- > 2.44.0 >