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=-3.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS autolearn=no 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 D2639C11F66 for ; Wed, 14 Jul 2021 11:50:08 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 64B70613CF for ; Wed, 14 Jul 2021 11:50:08 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 64B70613CF Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 6F1496B0083; Wed, 14 Jul 2021 07:50:08 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 6A0856B0085; Wed, 14 Jul 2021 07:50:08 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 541D36B0088; Wed, 14 Jul 2021 07:50:08 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0133.hostedemail.com [216.40.44.133]) by kanga.kvack.org (Postfix) with ESMTP id 2CDE36B0083 for ; Wed, 14 Jul 2021 07:50:08 -0400 (EDT) Received: from smtpin35.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 2271C80F63FA for ; Wed, 14 Jul 2021 11:50:07 +0000 (UTC) X-FDA: 78361024854.35.201A753 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf21.hostedemail.com (Postfix) with ESMTP id 6A544D0061C1 for ; Wed, 14 Jul 2021 11:50:06 +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=tmi1aGCU02tV/tT14lWcuB+Jy5Xv5YI9llZbtJNYfEE=; b=pLOe/ifFVz7tyt1jNKOzq+ybQS f7OiCWTvC4JFt8F7TvGA3GErQObr/+sdi3DOUZwuXbN5pMUTirft/5hyBz4QROEAPgOvOdhzCG4PP xrIvVHrr5vhAptoWG71Uww8/zV5DHHaX0SDEDBJO8CrN9y5sXteAqx3+0BWQUdvw6N6U2Ow/9xwXL Pv0M9oVwB+K0j2a6BQmg9YHr/0I9n1PqjxcqwAQWGV8nmXTpcKgnLAFnev3Rmohck7pVApSAPBew+ 7AxeB3uJsfyXfxrvyPrpmG/Fjv3TSv9WJzV2ULhzQ5tI5j2KRk3sLQZialdfB/A8b3btBICob44fu MPeRvbMg==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1m3dNk-002AhM-8V; Wed, 14 Jul 2021 11:48:58 +0000 Date: Wed, 14 Jul 2021 12:48:52 +0100 From: Matthew Wilcox To: Miaohe Lin Cc: Michal Hocko , Yu Zhao , akpm@linux-foundation.org, hannes@cmpxchg.org, vbabka@suse.cz, axboe@kernel.dk, iamjoonsoo.kim@lge.com, alexs@kernel.org, apopple@nvidia.com, minchan@kernel.org, david@redhat.com, shli@fb.com, hillf.zj@alibaba-inc.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH 1/5] mm/vmscan: put the redirtied MADV_FREE pages back to anonymous LRU list Message-ID: References: <20210710100329.49174-1-linmiaohe@huawei.com> <20210710100329.49174-2-linmiaohe@huawei.com> <9409189e-44f7-2608-68af-851629b6d453@huawei.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Authentication-Results: imf21.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b="pLOe/ifF"; spf=none (imf21.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: rspam05 X-Stat-Signature: 4i1yc37nwrgqo1im5qw386w7cb34nm4w X-Rspamd-Queue-Id: 6A544D0061C1 X-HE-Tag: 1626263406-752975 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 Wed, Jul 14, 2021 at 07:36:57PM +0800, Miaohe Lin wrote: > On 2021/7/13 21:34, Matthew Wilcox wrote: > > On Tue, Jul 13, 2021 at 09:13:51PM +0800, Miaohe Lin wrote: > >>>> When the MADV_FREE pages are redirtied before they could be reclaimed, the pages > >>>> should be put back to anonymous LRU list by setting SwapBacked flag, thus the > >>>> pages will be reclaimed in normal swapout way. > >>> > >>> Agreed. But the question is why this needs an explicit handling here > >>> when we already do handle this case when trying to unmap the page. > >> > >> This makes me think more. It seems even the page_ref_freeze call is guaranteed to > >> success as no one can grab the page refcnt after the page is successfully unmapped. > > > > NO! This is wrong. Every page can have its refcount speculatively raised > > (and then lowered). The two prime candidates for this are lockless GUP > > and page cache lookups, but there can be others too. > > > > Many thanks for pointing this out. My overlook! Sorry! > So, it seems lockless GUP can redirty the MADV_FREE page. But is it ok to just release > a redirtied MADV_FREE pages? Because we hold the last reference here and the page will > be freed anyway... I don't see how lockless GUP can redirty the page. It can grab the refcount, thus making the refcount here two. Then the call to freeze here fails and the page stays on the list. But the lockless GUP checks the page is still in the page table (and discovers it isn't, so releases the reference count). Am I missing a path that lets lockless GUP dirty the page?