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 B2A9DC433EF for ; Tue, 15 Feb 2022 02:33:22 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 43C5E6B0078; Mon, 14 Feb 2022 21:33:22 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 3EBDD6B007B; Mon, 14 Feb 2022 21:33:22 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 28D0C6B007D; Mon, 14 Feb 2022 21:33:22 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 1CA3C6B0078 for ; Mon, 14 Feb 2022 21:33:22 -0500 (EST) Received: from smtpin06.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id C9723901C2 for ; Tue, 15 Feb 2022 02:33:21 +0000 (UTC) X-FDA: 79143442602.06.DE215DB Received: from mail-qt1-f175.google.com (mail-qt1-f175.google.com [209.85.160.175]) by imf28.hostedemail.com (Postfix) with ESMTP id 63C68C0002 for ; Tue, 15 Feb 2022 02:33:21 +0000 (UTC) Received: by mail-qt1-f175.google.com with SMTP id l14so17265361qtp.7 for ; Mon, 14 Feb 2022 18:33:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:from:to:cc:subject:in-reply-to:message-id:references :mime-version; bh=hA6o7f3VWTxX95Mr0GyMKT1FTGKFiKlNt02jF6v+Tb0=; b=rtEYp0Pul7pel5CuZdN22/B3yxGbnNW3jrMy8534GdcI8lYDHPfs/goTA/UvG5nek9 Wo9HEjPNtZLebFqqkeMWvo5YlcgbC0vQ2MxVDE2fLyPpEN8ztcdUQIVWst7IWcjIJ/TK qfhWX4SVMD1lxSp76cqbh3Kw2Vx1FKnwxo9Bc71WyCwwHGSHBcVckXz6DjlzsyigRq8w aX5VjHhsufzKtYGundL8X2fHKjL7Risp5ebjQ20lyljFgCNyXta2nqn/gPvvEA9jcdxG ENHbUeKNdW4Csx+pHVD+S+m0y/MoXleQ+aI2YObanALTvC1nHb6JKBOsvTKEwz7yzaKJ P2uw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:in-reply-to:message-id :references:mime-version; bh=hA6o7f3VWTxX95Mr0GyMKT1FTGKFiKlNt02jF6v+Tb0=; b=VlU5wD8xg0bDbqI+IC8H+ifHebuAfFmCWVruRSAT3AYtQGE7uV3KOgG9NWXS26xDMx IGU39vxRw6o/oZJC+WBnCxk7QViKy2dSY7EhbObNWovAnpBYiCBGGBdMG9ZtKp5V4SAN +ydZUg9xHXp2cBs/4mSdri//Tq6t3DHcn0yickeSwD5MJEtXKoy4JmiG4cLDe0rqP6Kd hSigFz5lw/xygQec6HnH1N+uJZ3cyENJ3nUftxr9URRqYjnMqubOj2vTALX/i0B6e53f QbE5nx0GFj2pXqMsResjT5m1fNYDLBNkcwmm4NOZSw2ApNS+b8R+QpAeXfuUvuQpmibj 1swQ== X-Gm-Message-State: AOAM531Y9XNOB8kVFhpsJ4wkSz5/5zYLOuPKL8IEDfTBa/28aJ98gfJa B5ykjeTkGDz6JFf6R6fc8niyPA== X-Google-Smtp-Source: ABdhPJzAV7n2bz0VYf1XZvzGWHDRqLhyqek+4Pt0HQtX7UeiNiLfzxn1drhbZ4e+Dmo3KTDseUBAdg== X-Received: by 2002:ac8:4e86:: with SMTP id 6mr1377145qtp.84.1644892400587; Mon, 14 Feb 2022 18:33:20 -0800 (PST) Received: from ripple.attlocal.net (172-10-233-147.lightspeed.sntcca.sbcglobal.net. [172.10.233.147]) by smtp.gmail.com with ESMTPSA id u21sm18424379qtw.80.2022.02.14.18.33.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Feb 2022 18:33:19 -0800 (PST) Date: Mon, 14 Feb 2022 18:33:17 -0800 (PST) From: Hugh Dickins X-X-Sender: hugh@ripple.anvils To: Andrew Morton cc: Michal Hocko , Vlastimil Babka , "Kirill A. Shutemov" , Matthew Wilcox , David Hildenbrand , Alistair Popple , Johannes Weiner , Rik van Riel , Suren Baghdasaryan , Yu Zhao , Greg Thelen , Shakeel Butt , linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH v2 08/13] mm/migrate: __unmap_and_move() push good newpage to LRU In-Reply-To: <55a49083-37f9-3766-1de9-9feea7428ac@google.com> Message-ID: <269eec24-978a-984a-8a85-1d29f36ad343@google.com> References: <55a49083-37f9-3766-1de9-9feea7428ac@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII X-Rspamd-Queue-Id: 63C68C0002 X-Rspam-User: Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=rtEYp0Pu; spf=pass (imf28.hostedemail.com: domain of hughd@google.com designates 209.85.160.175 as permitted sender) smtp.mailfrom=hughd@google.com; dmarc=pass (policy=reject) header.from=google.com X-Stat-Signature: 31b7h738wymze9ujxbfm7i8tjfx9goi8 X-Rspamd-Server: rspam11 X-HE-Tag: 1644892401-961633 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: Compaction, NUMA page movement, THP collapse/split, and memory failure do isolate unevictable pages from their "LRU", losing the record of mlock_count in doing so (isolators are likely to use page->lru for their own private lists, so mlock_count has to be presumed lost). That's unfortunate, and we should put in some work to correct that: one can imagine a function to build up the mlock_count again - but it would require i_mmap_rwsem for read, so be careful where it's called. Or page_referenced_one() and try_to_unmap_one() might do that extra work. But one place that can very easily be improved is page migration's __unmap_and_move(): a small adjustment to where the successful new page is put back on LRU, and its mlock_count (if any) is built back up by remove_migration_ptes(). Signed-off-by: Hugh Dickins Acked-by: Vlastimil Babka --- v2: same as v1. mm/migrate.c | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/mm/migrate.c b/mm/migrate.c index 7c4223ce2500..f4bcf1541b62 100644 --- a/mm/migrate.c +++ b/mm/migrate.c @@ -1032,6 +1032,21 @@ static int __unmap_and_move(struct page *page, struct page *newpage, if (!page_mapped(page)) rc = move_to_new_page(newpage, page, mode); + /* + * When successful, push newpage to LRU immediately: so that if it + * turns out to be an mlocked page, remove_migration_ptes() will + * automatically build up the correct newpage->mlock_count for it. + * + * We would like to do something similar for the old page, when + * unsuccessful, and other cases when a page has been temporarily + * isolated from the unevictable LRU: but this case is the easiest. + */ + if (rc == MIGRATEPAGE_SUCCESS) { + lru_cache_add(newpage); + if (page_was_mapped) + lru_add_drain(); + } + if (page_was_mapped) remove_migration_ptes(page, rc == MIGRATEPAGE_SUCCESS ? newpage : page, false); @@ -1045,20 +1060,12 @@ static int __unmap_and_move(struct page *page, struct page *newpage, unlock_page(page); out: /* - * If migration is successful, decrease refcount of the newpage + * If migration is successful, decrease refcount of the newpage, * which will not free the page because new page owner increased - * refcounter. As well, if it is LRU page, add the page to LRU - * list in here. Use the old state of the isolated source page to - * determine if we migrated a LRU page. newpage was already unlocked - * and possibly modified by its owner - don't rely on the page - * state. + * refcounter. */ - if (rc == MIGRATEPAGE_SUCCESS) { - if (unlikely(!is_lru)) - put_page(newpage); - else - putback_lru_page(newpage); - } + if (rc == MIGRATEPAGE_SUCCESS) + put_page(newpage); return rc; } -- 2.34.1