Received: by 2002:ac0:e350:0:0:0:0:0 with SMTP id g16csp221726imn; Wed, 3 Aug 2022 00:49:18 -0700 (PDT) X-Google-Smtp-Source: AGRyM1tKjALHfzI0ivqc0qHHS+/COvHnx+sIfbAzE2sfoJCSLXap86qlJXBqfOEBla5HS6hEeiOo X-Received: by 2002:a63:944:0:b0:41a:3744:6c6 with SMTP id 65-20020a630944000000b0041a374406c6mr20544371pgj.375.1659512958376; Wed, 03 Aug 2022 00:49:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1659512958; cv=none; d=google.com; s=arc-20160816; b=CJxeEfjjgxVTakwjYL26/YtUBB2GUtyoYXbU2rJD38VVnpqgVXpdlxBR7C57AnJyw3 cqUa2S135u7RYm19wvKQ4tGoCXJXQvB4q45kYnBlaQgS6SR6gQPkQ+m9pQaHCvcRMvoB 2tH0Aa50lYWZoSZaLoc91+OfKSH2U12mJaKR5WqBHah8q1hKBVln+C7IvE9heRjVPtl0 f2s9zPL24dVKRgKSUXLRMke0JJvOVWc1yNSL41ysXzSDZzvpnRAgsYZO1lkQYhZcw1pA 8VQqbg/28rx+KFwmYzezGJAeiaTT7MPFszuQXxPVFiYJwujRq4IyGZD5l0cvE2GnLq4z By2w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:to:references:message-id :content-transfer-encoding:cc:date:in-reply-to:from:subject :mime-version:dkim-signature; bh=yZyRNrOtmJn2R9oPRcJXRCnJ2GUbITB77EurprO2OQI=; b=uIYHM8uftWtcLixstPvBQPkVdgqJnVZBPhIn/VbiC3e6bp1gEbWoC8NUv18LNKgNYW cOe2FGqJdh8DySGpVtuiRCudC2PE/36KTzyVolLqfkOO0981/3PJv1dVE5G3y0uD5p5w MoypsWxI+i1Ye06qX9Q0wkxB7QrzSARp09PweoWJMe41Kdcgtq0Y6Af1J1dYlS2g4iil 77NyandAopUiywUUXSvx7Ul3X/TbD6k2j3/tf41+M+5Nk83nmjU63VoPhZHL5PUM3hCB qY2osFlYIQqCymhOvN4P61DBD6gUj+yPhJmTqUggttL8KJYaNsrOOKw0FIyk4WVpvXfp ZuPQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b="Ot1NjR/U"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ot5-20020a17090b3b4500b001f4eed1e26csi1369759pjb.89.2022.08.03.00.49.03; Wed, 03 Aug 2022 00:49:18 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b="Ot1NjR/U"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236006AbiHCHnH (ORCPT + 99 others); Wed, 3 Aug 2022 03:43:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34528 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235863AbiHCHnA (ORCPT ); Wed, 3 Aug 2022 03:43:00 -0400 Received: from mail-pj1-x1030.google.com (mail-pj1-x1030.google.com [IPv6:2607:f8b0:4864:20::1030]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C9EC228E15 for ; Wed, 3 Aug 2022 00:42:58 -0700 (PDT) Received: by mail-pj1-x1030.google.com with SMTP id h21-20020a17090aa89500b001f31a61b91dso1157061pjq.4 for ; Wed, 03 Aug 2022 00:42:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=yZyRNrOtmJn2R9oPRcJXRCnJ2GUbITB77EurprO2OQI=; b=Ot1NjR/UkHIDQeGzZnG3pPKCxE57l/N5qwvNLfad66Bn3n5u8eg7oDqIVa8nEWvc2d CY4qXmToL6CmKvbzgmXCRnFM+soJ44AKdA6qwPV4aVRAoIcIhIOBh474KLF5E1r5J4RK PpphwE2cffnx6mUv5tz/ym9DeWhTjZMIXTGzrZdLErT9kqUbPNeBWtiW551TjPpaEToa ov2nZOxydaj58+HG7z1NocYCfOS5ZpVUp8DZmKlR8YbloLCMHvbVluaKaEcMxm0b6+13 cnIfr+GIULENfKMun0SPEU3cQGCYlF2+TeQ354oHU1KdRVt5b04DC1hB5uI36Ug+esZ+ YFqg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=yZyRNrOtmJn2R9oPRcJXRCnJ2GUbITB77EurprO2OQI=; b=Dgvta4W/aCLHPC55jUwmOFU+99FZeK5u+d0QFCAh9auTBxbJ83HXKTTAYVmQh0hXui vLZA7HG5NZK/FsmcUckASSvkaHQeS/a7ZRu8e3DCLfE0qMN8o58XbyTeBQ/gRtukkQJ1 dXD82nC4wa+4XPo41RbTbvssGSzcqtmttL9sfWJWpaipFQFMdZzcZiJ0Otc0AgqHHRXD MbWxM0qDc8jrBvw1ymhC6IUmEcvRq50jNMXYGS3otf2vqaeXWwYyae8FGFn5Rm0Ays6C vJSBHy4t4FBZJud4QvJQrqeGVWBL7pL9pQ4F1D42+WeB4MvyCqJMM+gACV3Ov3+pjqaD v2Sw== X-Gm-Message-State: ACgBeo38YLxUUPW2p20ZHJGAgvHJXbV3As2sfMqmlfCN1yz98tz/usAI dLsOPNBlhvUQKE1ocO3zfZ4= X-Received: by 2002:a17:902:cec1:b0:16d:c4f2:66c5 with SMTP id d1-20020a170902cec100b0016dc4f266c5mr24747092plg.20.1659512577878; Wed, 03 Aug 2022 00:42:57 -0700 (PDT) Received: from smtpclient.apple (c-24-6-216-183.hsd1.ca.comcast.net. [24.6.216.183]) by smtp.gmail.com with ESMTPSA id q30-20020a631f5e000000b0041c6541383dsm2536258pgm.60.2022.08.03.00.42.56 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 03 Aug 2022 00:42:56 -0700 (PDT) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3696.120.41.1.1\)) Subject: Re: [PATCH 2/2] mm: Remember young bit for page migrations From: Nadav Amit In-Reply-To: <20220803012159.36551-3-peterx@redhat.com> Date: Wed, 3 Aug 2022 00:42:54 -0700 Cc: LKML , linux-mm@kvack.org, Andrea Arcangeli , Andi Kleen , Andrew Morton , David Hildenbrand , Hugh Dickins , Huang Ying , "Kirill A . Shutemov" , Vlastimil Babka Content-Transfer-Encoding: quoted-printable Message-Id: References: <20220803012159.36551-1-peterx@redhat.com> <20220803012159.36551-3-peterx@redhat.com> To: Peter Xu X-Mailer: Apple Mail (2.3696.120.41.1.1) X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Aug 2, 2022, at 6:21 PM, Peter Xu wrote: > When page migration happens, we always ignore the young bit settings = in the > old pgtable, and marking the page as old in the new page table using = either > pte_mkold() or pmd_mkold(). >=20 > That's fine from functional-wise, but that's not friendly to page = reclaim > because the moving page can be actively accessed within the procedure. = Not > to mention hardware setting the young bit can bring quite some = overhead on > some systems, e.g. x86_64 needs a few hundreds nanoseconds to set the = bit. >=20 > Actually we can easily remember the young bit configuration and = recover the > information after the page is migrated. To achieve it, define a new = bit in > the migration swap offset field to show whether the old pte has young = bit > set or not. Then when removing/recovering the migration entry, we can > recover the young bit even if the page changed. >=20 > One thing to mention is that here we used max_swapfile_size() to = detect how > many swp offset bits we have, and we'll only enable this feature if we = know > the swp offset can be big enough to store both the PFN value and the = young > bit. Otherwise the young bit is dropped like before. I gave it some more thought and I am less confident whether this is the = best solution. Not sure it is not either, so I am raising an alternative with pros and cons. An alternative would be to propagate the access bit into the page (i.e., using folio_set_young()) and then set it back into the PTE later (i.e., based on folio_test_young()). It might even seem that in general it is better to always set the page access bit if folio_test_young(). This can be simpler and more performant. Setting the access-bit would = not impact reclaim decisions (as the page is already considered young), = would not induce overheads on clearing the access-bit (no TLB flush is needed = at least on x86), and would save the time the CPU takes to set the access = bit if the page is ever accessed (on x86). It may also improve the preciseness of page-idle mechanisms and the interaction with it. IIUC, page-idle does not consider migration = entries, so the user would not get indication that pages under migration are not = idle. When page-idle is reset, migrated pages might be later reinstated as =E2=80=9Caccessed=E2=80=9D, giving wrong indication that the pages are = not-idle, when in fact they are. On the negative side, I am not sure whether other archs, that might = require a TLB flush for resetting the access-bit, and the overhead of doing = atomic operation to clear the access-bit, would not induce more overhead than = they would save. One more unrelated point - note that remove_migration_pte() would always = set a clean PTE even when the old one was dirty=E2=80=A6