From patchwork Sun Jun 18 06:58:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yosry Ahmed X-Patchwork-Id: 13283774 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 1F423EB64D7 for ; Sun, 18 Jun 2023 06:58:31 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id AB3798E0002; Sun, 18 Jun 2023 02:58:30 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A643C6B007D; Sun, 18 Jun 2023 02:58:30 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 92C608E0002; Sun, 18 Jun 2023 02:58:30 -0400 (EDT) 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 8449F6B007B for ; Sun, 18 Jun 2023 02:58:30 -0400 (EDT) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 5585380DA4 for ; Sun, 18 Jun 2023 06:58:30 +0000 (UTC) X-FDA: 80914965180.23.2A862C2 Received: from mail-pg1-f201.google.com (mail-pg1-f201.google.com [209.85.215.201]) by imf23.hostedemail.com (Postfix) with ESMTP id 94D7C14000A for ; Sun, 18 Jun 2023 06:58:28 +0000 (UTC) Authentication-Results: imf23.hostedemail.com; dkim=pass header.d=google.com header.s=20221208 header.b=Jmn08JRk; spf=pass (imf23.hostedemail.com: domain of 3E6uOZAoKCM4I8CBIu16yx08805y.w86527EH-664Fuw4.8B0@flex--yosryahmed.bounces.google.com designates 209.85.215.201 as permitted sender) smtp.mailfrom=3E6uOZAoKCM4I8CBIu16yx08805y.w86527EH-664Fuw4.8B0@flex--yosryahmed.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1687071508; a=rsa-sha256; cv=none; b=cpKMEvpj6p5pbUaMVFebQOVDKjdy3T6XzeUE9fbDZ+XRo22JGxnOGd00mfQi1CNx4QBd4r khnU5pY9uvP2C7IuoTZ3unub/VwAqB8rXiWFza5PIZXQJn6c2L4HQIDBkEXL4x6VyF1nPP nIuNGFBSOcisyP1VXly8sXR21aK1Wew= ARC-Authentication-Results: i=1; imf23.hostedemail.com; dkim=pass header.d=google.com header.s=20221208 header.b=Jmn08JRk; spf=pass (imf23.hostedemail.com: domain of 3E6uOZAoKCM4I8CBIu16yx08805y.w86527EH-664Fuw4.8B0@flex--yosryahmed.bounces.google.com designates 209.85.215.201 as permitted sender) smtp.mailfrom=3E6uOZAoKCM4I8CBIu16yx08805y.w86527EH-664Fuw4.8B0@flex--yosryahmed.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1687071508; 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: references:dkim-signature; bh=h9MkEXCOECVy+F9lVXmcJqM8lpLvl13EAFxuWhnTpvI=; b=G8GXkDwFUPPSI9RFQiKoUnilPihNN0MvSZPSAt5VMEFV78PTSONJQBfONkjeCAO8AxvpN0 8LgyacNnyxH/10+wGQtjw9sZkoTF9xITdyaT0chzO0eWfS61WeU1mBvdjIx69GfnjuTinl D7qh5edLuxc+plHHaiem3TiscqfAeL8= Received: by mail-pg1-f201.google.com with SMTP id 41be03b00d2f7-5488dccfbdfso1947057a12.2 for ; Sat, 17 Jun 2023 23:58:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1687071507; x=1689663507; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=h9MkEXCOECVy+F9lVXmcJqM8lpLvl13EAFxuWhnTpvI=; b=Jmn08JRk9haBdTN7W4jKc018AW8wTh5/Vt4hWrG22Ce5WHHa5gH8+MFIzo5RR/XZDq /W6Qm/trFt2lkCHmg+/8aK4c3BVvqvUZGoipdn0DwQhEJG0zDsVcqfnYXrvXqWqFMSwB cD5AXD9nnEOim2ftXAtIhqlPxnHlllsa63199K3JNAxq5hr4CMKl6vYbDBMBcYoqGoJI TojGOAjg6KS0exeu21OEEbX34hPDKOcGV9jJ6KSr7JDko1JBsl94JVx3mVI4VmF+a4zE hOk3HCxA72ztJwA4CdUKzWKxOVZY+VQuQRRxrmIiJ5l2lm8iS7CGxZY5s5RVjVkMk7B+ 4BIQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687071507; x=1689663507; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=h9MkEXCOECVy+F9lVXmcJqM8lpLvl13EAFxuWhnTpvI=; b=g5YjVD5/vbdHBCHlsnpQjBEEbpylh4qIs6ymHnQWGMGSioNMGa7eAwD9oJ1JvWaXBK mk7lF5uepDDQd4vyTmds5GJMx9n3wxEiMg9F0FVd3aW5qZowjglgkeEKPT/fU1P6YIVi zZVtjV3U8ctR8Y8EUH6bPtYe19w68NC7tbGBuFBU3el8yal2h/NQYuM3GWK2Ir709Xgr yGSiEKClWaPIYMJKG3aHm8NdW76p9fnWfS2IyKVTYFe0l4m++UitZWM5lCeaFO1k8lKE eFb53OoZhpeFWGK/o6MjljkOS7vcX56/GE1HSDZtiE0lcaI2CxJjOYmBD6IFswuKL24Q 7aYw== X-Gm-Message-State: AC+VfDzTvWmoFbnLApIZ6G2RReO6wOqSzZBrUvUdyhI6Z6VjKgWcVWdN wB8DBdET63M3j9kfQ/TQESMlVKSxR7gKkPUT X-Google-Smtp-Source: ACHHUZ5g3uocw1m2bEK5IzJLclvW8dC8mH9S0Bf7aD9hPOQWtWFYCu24N61BbV7x9G/xqeRMh6De5y2vc+vaUIqs X-Received: from yosry.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:2327]) (user=yosryahmed job=sendgmr) by 2002:a63:f106:0:b0:53f:2d21:5a16 with SMTP id f6-20020a63f106000000b0053f2d215a16mr450864pgi.10.1687071507411; Sat, 17 Jun 2023 23:58:27 -0700 (PDT) Date: Sun, 18 Jun 2023 06:58:24 +0000 Mime-Version: 1.0 X-Mailer: git-send-email 2.41.0.162.gfafddb0af9-goog Message-ID: <20230618065824.1365750-1-yosryahmed@google.com> Subject: [RFC PATCH 5/5] Revert "mm/migrate: __unmap_and_move() push good newpage to LRU" From: Yosry Ahmed To: Andrew Morton Cc: 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, Yosry Ahmed X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: 94D7C14000A X-Stat-Signature: 6a5a6k43hbuac6cb6tmegkjtm7bhj8c5 X-Rspam-User: X-HE-Tag: 1687071508-923536 X-HE-Meta: U2FsdGVkX1+wY5zclu01cmLZwctQtElGT3rTT525thZjDx2gcYAOzC1wQ/Sp6IOBrSGIGOyR5wXhg6+R8AVBRIitFvPme+ttr4vsQ9GzHRiIQRjlx1bya+ZhrIJCF9G5Q89TtvhTLQYcQWSKkhbKT8EWENgmmZ3i7C0If+9B8gCwrQbyIuMBWAgCreRQb7HIAZE2iRSAbd340w4oV0Yt6m4vgb0FsK6LDcRa3kKFvWZBWGNPlHzcPi2h4qrbq7YkyeeqPVE8gP2WK8Mjx3iYox0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xALuMy+m4UgQbAuARJR1AF2IVuwv276AsATnzxR7LPOAcADAMR6bkrpWwnpH8XmoU1KeSdC0g2LDxzAE9PYXW+BTpFnoyQYEc91mZyG8RdUuAwjgWhZEj9HO8Ncc7N1Um5q+LiuiM8nGZu0ZaF1X23ZZ/p8AsObCjVZFgr7fvfA6hy2yeJ1mLxhMYZyVTArchiGk/ot3ghASLIcIO3rwRCqFQmSI1qPYqXrdJARRSVyhiKqJuYNWJHGEPMEvWNOSZ1bU1Mf9CrrcRLfhNuCii+h5ysLR6y24XcEINd6QBs/I5xm0asckYvVErzQ+Y86RWUnWFw== 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: 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 Reviewed-by: "Huang, Ying" --- 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_new_page, unsigned long private, if (unlikely(!is_lru)) goto out_unlock_both; - /* - * 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 easiest. - */ - 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_new_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 to + * 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