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 7B6C0EB64D9 for ; Mon, 19 Jun 2023 04:00:33 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D6C878D0002; Mon, 19 Jun 2023 00:00:32 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id CF4DA8D0001; Mon, 19 Jun 2023 00:00:32 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B96108D0002; Mon, 19 Jun 2023 00:00:32 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id A68648D0001 for ; Mon, 19 Jun 2023 00:00:32 -0400 (EDT) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 62E9C140373 for ; Mon, 19 Jun 2023 04:00:32 +0000 (UTC) X-FDA: 80918145504.08.E9474AB Received: from mail-ed1-f45.google.com (mail-ed1-f45.google.com [209.85.208.45]) by imf16.hostedemail.com (Postfix) with ESMTP id 83831180009 for ; Mon, 19 Jun 2023 04:00:30 +0000 (UTC) Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=google.com header.s=20221208 header.b=liNxIXCO; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf16.hostedemail.com: domain of yosryahmed@google.com designates 209.85.208.45 as permitted sender) smtp.mailfrom=yosryahmed@google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1687147230; 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:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=xj0loivS4oUf7RkNDVjtH35pM6SVj82a3/WxNIXAr94=; b=v5Ua0G3+Z0VWA4nTge6vK2261fwhldnBJ3qbZ7Fj4f8zbE+x6De1Pwf945uLJOciavYgkX aVRtM8uxCpwzRt4Zp566/J4cZYolLzRofy2WgNc2z1YeXF7/bjVFMAVu4J2znzdQTd/A1D JDMTzBwNK4E/nxrffj0asBq+rx9mRFo= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=pass header.d=google.com header.s=20221208 header.b=liNxIXCO; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf16.hostedemail.com: domain of yosryahmed@google.com designates 209.85.208.45 as permitted sender) smtp.mailfrom=yosryahmed@google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1687147230; a=rsa-sha256; cv=none; b=JVHYjXtET+iKl3OYKpFR9944KbmeSNj1NVepMCfRbJppeFoxaC5BUrCw3Te07uiJ8LjB9m UWVkdto9r7NeYrx6WcI7BMsXmzsC3HdFWtpCiImHJQaAMFeZctCSsUnZczTHpXKdjqYE63 nZ/B+bSjzsrHZR3Q1t4PwNGstTzJtVQ= Received: by mail-ed1-f45.google.com with SMTP id 4fb4d7f45d1cf-51a4044b7a1so3712308a12.2 for ; Sun, 18 Jun 2023 21:00:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1687147229; x=1689739229; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=xj0loivS4oUf7RkNDVjtH35pM6SVj82a3/WxNIXAr94=; b=liNxIXCOPgV0NXaraug6RWYcJpcRYj/gogLh22/imSmj/o9B8I42UgxL2hbVFWj0NX kELdD5bdOmOY4wJ3wdTqQb35Q4WWqtrzYnxc/FUU6MvlgO3kzqYNksV5egxh2xUJuBWx FvLXnJOa+5nsy9VOptpTVnpOZDvDKZmSe4kAR1HqqnOLlM+oT7zQg5QJCHVH01E37MoJ R1Qyq1btLvmj2rNuH0oAZZ+O+bTCKstqiEvGIOUuY1QduSDsDR/EMOs8kmQylmQhKq9N 5lngynipHCqoFhfdO2doPxFUKCovaQbqbN9SUD0/jM/8R/7Rc6d5BulHeEqWTqchn0oC BCLg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687147229; x=1689739229; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=xj0loivS4oUf7RkNDVjtH35pM6SVj82a3/WxNIXAr94=; b=hWm5SAtu88WgLRGWLuoPei7Jc+8Ek2dCxz3mfY4Nclqr8uOJgCH7A1+6K6+b0gydEn Bv/na9ZORia2COf9rHAK/we/5LZe4yJddlaT3vD2fFCxNBMehHKLoU65u8vUCRF0P1D6 i8OIyAllIkkTzJ6ffgpMmUtHwq0YpxT5hfkXpbFWdV6WVF6B1ecQAqzuyUTngJxJXg9r obCSYeXVRdSrqwpBebmXSx59br1n+40fCxFyqu0DGIijHbMd1pxv34RLr6GZVX3zH6wd SlEvMju+BMVL1Fq3DF1EnlCAEy9r4b9E7IUSizCGi4QFDrRTv7IFxH7vteE6+KpuSOAK WpFw== X-Gm-Message-State: AC+VfDwDiipIEbMLv13s/3twcbbdbqXvF144uLUMrN6cOtdWwHZRoPgJ nAwNtqy9GKGExktllpkTd72vqnRuYY9vAtdbmi9a5A== X-Google-Smtp-Source: ACHHUZ5AmF5iJZMsMI1kC6TL3hPNZj5ewdCazp5jw+M7S8VBSd7CV2CIuRwo6cjXS2po4KnZwjvWnYnQdHznS39Qu3k= X-Received: by 2002:a17:907:7245:b0:982:a454:6d24 with SMTP id ds5-20020a170907724500b00982a4546d24mr7929914ejc.74.1687147228860; Sun, 18 Jun 2023 21:00:28 -0700 (PDT) MIME-Version: 1.0 References: <20230618065824.1365750-1-yosryahmed@google.com> <87ilbk8b89.fsf@yhuang6-desk2.ccr.corp.intel.com> In-Reply-To: <87ilbk8b89.fsf@yhuang6-desk2.ccr.corp.intel.com> From: Yosry Ahmed Date: Sun, 18 Jun 2023 20:59:52 -0700 Message-ID: Subject: Re: [RFC PATCH 5/5] Revert "mm/migrate: __unmap_and_move() push good newpage to LRU" To: "Huang, Ying" Cc: Andrew Morton , Yu Zhao , "Jan Alexander Steffens (heftig)" , Steven Barrett , Brian Geffon , "T.J. Alumbaugh" , Gaosheng Cui , Suren Baghdasaryan , "Matthew Wilcox (Oracle)" , "Liam R. Howlett" , David Hildenbrand , Jason Gunthorpe , Mathieu Desnoyers , David Howells , Hugh Dickins , Greg Thelen , linux-mm@kvack.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Rspam-User: X-Stat-Signature: gag49cytcndsbr8hini34o7wtjc51a6e X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 83831180009 X-HE-Tag: 1687147230-660984 X-HE-Meta: U2FsdGVkX18N+7KKFy0bNi/0eQt5/Dn2QqcY5y3ENad4QPnB6IL6ScVhQiek9q5RLNZH40VF1o5Ca0DcdvGh1RoV6GzXBKem+3KgNIMBzagHZ8AtQJEwOTOl8/qUDAu5sBYKOs9TpAXXj6977t+svWxAfkDJWs3c5bp5Fu75bqMe1Q82HRAtK6yd+9w6EIsmq8atDBuwVctDx0EcDuzD61kdNGpxPAaqX1uYIKcfAAZ1hGQCZixvByCGJurautWKQSZ5BhimpSRR52+EU/4+jWLUIvBtte1JGeaBQF+/g+K6gvMQK9q+tfpVPqaqPQZGxO11oAVkRfhqsc0EzhJG5dmjXqwSm+VZkqu5bMRzBFddBfvFUegmsBFcJYzT0IFFbPCBJATnPCtTrpt48mV7Wje2onHJlk0UMFk9I6ha77u6jPP+1/DswYDz7vwy7/CQRa1RQcXKiBgmH5SXPxFVaPkQmlvVjfqBGahpdcKRGFWEHpcNkoiYGBvxRxlmhZWBy/fIpa5tnYytlnaNQAnfE+tCaAsc/z7Q9uSU/YcMnQPrsaeOTDzuKlb21eZa1B7rRF48b6HbWywktCbjBzW14TyI7d3sonjvIQmd6cJDJ/K/pE6r3iZ2IzQ+96SCtWIiCtvZG/oiIiOso2CYK6NGZhJLpde+AvL+Wn2VZqdjsk3BIl0OCCktEIInY5Ioelg3pYJYnW8kgYt6NZ+OBcrZZs+impJAm7bg739FkBU9dNgIivgEuEiEbPW4c1cv+pubE2d7NHYxEPFJ/xm0qBkKqsuGDi9KMKm4GuMoLh7YHPIv3BhV2ZFd2G0Qf0LSAxle/s/wWLXlCuyAA8/JPYThHwDsMkLZNfY1r8WMlnzVuLNgZDTBhctflUpzOX/9BYFNo4I6KS/sLwIWIYJ9O5/vsme+AzXQ8GCVCbp5OUX7J5huXaY4DKZjPLKEcBeEf1Yj3VRur4BT3uW5AETzc59 /Tvgfx1Z p4OpJFbO00oD+tZzRDU6437ETpd54rFG23MjYHRx0/jG8eHY8l/cUhFWd9H0pO2dSbSEYQaA8BK4scpH8JRUXMhgGy0Gh2Su17N/2Me1kSEjeFxIc2bIur174fR8WmuVdS6rd1W1OxCJi2oGvPsbCCN++DvzAadkZXJfSxicMvrpymefX86q/u5UVDcudUvKcCLAJWb5yhuenXvPo1kvehhD0VIp/dAXVbq+g6KFYuH+dhmbwhvVW7OqE064F5FfiayM/yNkGZ/kRquP1ihbdQ0gxuI/Zf02kC1x2Nl670GYiMHjAX8vAYrbHh/4mePZ6lF7E 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, Jun 18, 2023 at 7:00=E2=80=AFPM Huang, Ying = wrote: > > Hi, Yosry, > > Yosry Ahmed writes: > > > This reverts commit c3096e6782b733158bf34f6bbb4567808d4e0740. > > > > That commit made sure we immediately add the new page to the LRU before > > remove_migration_ptes() is called in migrate_move_folio() (used to be > > __unmap_and_move() back then), such that the rmap walk will rebuild the > > correct mlock_count for the page again. This was needed because the > > mlock_count was lost when the page is isolated. This is no longer the > > case since mlock_count no longer overlays page->lru. > > > > Revert the commit (the code was foliated afterward the commit, so the > > revert is updated as such). > > > > Signed-off-by: Yosry Ahmed > > --- > > mm/migrate.c | 24 +++++++++--------------- > > 1 file changed, 9 insertions(+), 15 deletions(-) > > > > diff --git a/mm/migrate.c b/mm/migrate.c > > index 01cac26a3127..68f693731865 100644 > > --- a/mm/migrate.c > > +++ b/mm/migrate.c > > @@ -1279,19 +1279,6 @@ static int migrate_folio_move(free_page_t put_ne= w_page, unsigned long private, > > if (unlikely(!is_lru)) > > goto out_unlock_both; > > The patch itself looks good to me! Thanks! > > Reviewed-by: "Huang, Ying" Thanks for taking a look! > > And, it seems that we can remove the above 2 lines and "out_unlock_both" > label now. That can make the code simpler a little. Right? I am not familiar with this code. If we remove the above condition then pages that have is_lru =3D=3D 0 (i.e __PageMovable(src) is true) and page_was_mapped =3D=3D 1 will call remove_migration_ptes(). This wouldn't happen without removing the above 2 lines. If this combination is impossible (is_lru =3D=3D 0 && page_was_mapped =3D=3D 1), then yeah we can remove the above condition. It looks like __SetPageMovable() is only called by zsmalloc, z3fold, and balloon_page_insert(). The former 2 will never have those pages mapped into userspace. I am not familiar with balloon_page_insert(), but my gut feeling is that those are pages used by the driver and are also not mapped into userspace. So I guess we can just remove the condition, but a confirmation for the above would be reassuring :) > > Best Regards, > Huang, Ying > > > - /* > > - * When successful, push dst to LRU immediately: so that if it > > - * turns out to be an mlocked page, remove_migration_ptes() will > > - * automatically build up the correct dst->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 easies= t. > > - */ > > - folio_add_lru(dst); > > - if (page_was_mapped) > > - lru_add_drain(); > > - > > if (page_was_mapped) > > remove_migration_ptes(src, dst, false); > > > > @@ -1301,9 +1288,16 @@ static int migrate_folio_move(free_page_t put_ne= w_page, unsigned long private, > > /* > > * If migration is successful, decrease refcount of dst, > > * which will not free the page because new page owner increased > > - * refcounter. > > + * refcounter. As well, if it is LRU folio, add the folio to LRU > > + * list in here. Use the old state of the isolated source folio t= o > > + * determine if we migrated a LRU folio. dst was already unlocked > > + * and possibly modified by its owner - don't rely on the folio > > + * state. > > */ > > - folio_put(dst); > > + if (unlikely(!is_lru)) > > + folio_put(dst); > > + else > > + folio_putback_lru(dst); > > > > /* > > * A folio that has been migrated has all references removed >