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 24B03C00144 for ; Mon, 1 Aug 2022 08:21:39 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 90D136B0071; Mon, 1 Aug 2022 04:21:38 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 8BC556B0072; Mon, 1 Aug 2022 04:21:38 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 75DF18E0001; Mon, 1 Aug 2022 04:21:38 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 62CB76B0071 for ; Mon, 1 Aug 2022 04:21:38 -0400 (EDT) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 286BFA08E8 for ; Mon, 1 Aug 2022 08:21:38 +0000 (UTC) X-FDA: 79750329876.17.F648B37 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf18.hostedemail.com (Postfix) with ESMTP id C088D1C00F6 for ; Mon, 1 Aug 2022 08:21:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1659342096; h=from:from: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; bh=HBClpZM4c3tRI2ZtjvvEsL5Ch6l2+EpXFVIr6Odc95M=; b=Oz5Ote/pz+/Wr+QpXYGVROPfYRNeumAaEsn+AL9g9XB/40CHbBvpdzsE32KYNNUqzxDA6N OmbhbNjM/NofutUZ/eoeSENzrgAeMWePHH3QzHyZ/vb8uhpJJq4U5JYP3RMTQcjXkPgvCh qtCDZwx4BG7JvbBqXaEVvNE/EyCOxnM= Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-511-mciA42kpNxudH7s-Kx6skw-1; Mon, 01 Aug 2022 04:21:35 -0400 X-MC-Unique: mciA42kpNxudH7s-Kx6skw-1 Received: by mail-wm1-f72.google.com with SMTP id r82-20020a1c4455000000b003a300020352so4918961wma.5 for ; Mon, 01 Aug 2022 01:21:34 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent:subject :content-language:to:cc:references:from:organization:in-reply-to :content-transfer-encoding; bh=HBClpZM4c3tRI2ZtjvvEsL5Ch6l2+EpXFVIr6Odc95M=; b=6Kk+56V+EB1kpmZbC23AdoZ7uSgr/CqWSlHr1ZGC0bNm9Wwif5DukOLv3SpMgTz7iU LACE3letMHIkN+aEelIdU+TE8RXh/7giwqoMxCFcHWqH9FBKeeXQnwqtfM+BqLn+IlI/ YMj565p984mFqedi5oiimp0tzhh3qZx7f0K1TNuoGSp348XYOxFYd2aZnuXId6I+BkkQ kY2PA3QCckhNZHs4uqVa+QT6pshtBq7AiPvQ8ofr8J9f4icRLKgulhSxMEEE7wJbre11 LDx+1AUatOY2mCvWspfbt1K21UJTaeg+Gjp0n1VeYFnamhPk/HxhCZn9OdyAywjJX4Be nE4Q== X-Gm-Message-State: ACgBeo1T+SChMzCeVheIEqI28nF3bgkZh8BAuM2/7VAibZ+Gq0PeNYnK ic12ekoGbuXvNSACcx/M2OESFCrXblyN/mLiCQ9RfnrE5XEUkHu/DjF3trZWB376l6AlwbRW3j2 vgZBs1l3W1uU= X-Received: by 2002:a05:6000:156b:b0:21d:9daf:3cdb with SMTP id 11-20020a056000156b00b0021d9daf3cdbmr9500852wrz.492.1659342093800; Mon, 01 Aug 2022 01:21:33 -0700 (PDT) X-Google-Smtp-Source: AA6agR7n7InSWLOF1ARNqkJ63A2m8/M5LaKV9UbPgaCenBCLJ3N4gb+2KCRwNDlehTMSqpFDshnOYA== X-Received: by 2002:a05:6000:156b:b0:21d:9daf:3cdb with SMTP id 11-20020a056000156b00b0021d9daf3cdbmr9500834wrz.492.1659342093502; Mon, 01 Aug 2022 01:21:33 -0700 (PDT) Received: from ?IPV6:2003:cb:c704:6900:6d08:8df1:dd2c:bf00? (p200300cbc70469006d088df1dd2cbf00.dip0.t-ipconnect.de. [2003:cb:c704:6900:6d08:8df1:dd2c:bf00]) by smtp.gmail.com with ESMTPSA id u1-20020adfdd41000000b0021d80f53324sm11101578wrm.7.2022.08.01.01.21.32 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 01 Aug 2022 01:21:33 -0700 (PDT) Message-ID: Date: Mon, 1 Aug 2022 10:21:32 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.11.0 Subject: Re: [PATCH RFC 0/4] mm: Remember young bit for migration entries To: Peter Xu , linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: Huang Ying , Andrea Arcangeli , Andrew Morton , "Kirill A . Shutemov" , Nadav Amit , Hugh Dickins , Vlastimil Babka References: <20220729014041.21292-1-peterx@redhat.com> From: David Hildenbrand Organization: Red Hat In-Reply-To: <20220729014041.21292-1-peterx@redhat.com> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1659342097; 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=HBClpZM4c3tRI2ZtjvvEsL5Ch6l2+EpXFVIr6Odc95M=; b=XcbBe1F8xrjjmgJ4DkVf4CY4WgMYYrqmR5TWFsTeyZ3hoV+w6M0g84IICIc2Hrn0sdw2+0 33q7imFuVz5KoPavX/r/8Wuy5k8q9KLGx0cfFzuzfnTzkwUtvsGp0LAss2ujyEmXGQXque yisYC3CFs3O0QriX37iiYoe21S6aQn4= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b="Oz5Ote/p"; spf=pass (imf18.hostedemail.com: domain of david@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=david@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1659342097; a=rsa-sha256; cv=none; b=l4DZv5OkwMvZ2IUBk8Up/zefs4fx1D+Mr0VOCdK5kHwysulPKPQmzaj6IIWm2U9/6lyAIo uZWmGYYZXZe9K8xkyXBTQvpm9PGWogK+0RMt10XZA0DChhLfXOnzDx8ww/qWcvPt99JI2e opuI+xokLlYvyxOm/t0XwROpeHSkKzM= X-Rspam-User: Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b="Oz5Ote/p"; spf=pass (imf18.hostedemail.com: domain of david@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=david@redhat.com; dmarc=pass (policy=none) header.from=redhat.com X-Stat-Signature: xnotkxnjayxrx9zuwa7ickgnk1g48xx1 X-Rspamd-Queue-Id: C088D1C00F6 X-Rspamd-Server: rspam10 X-HE-Tag: 1659342096-167052 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 29.07.22 03:40, Peter Xu wrote: > [Marking as RFC; only x86 is supported for now, plan to add a few more > archs when there's a formal version] > > Problem > ======= > > When migrate a page, right now we always mark the migrated page as old. > The reason could be that we don't really know whether the page is hot or > cold, so we could have taken it a default negative assuming that's safer. > > However that could lead to at least two problems: > > (1) We lost the real hot/cold information while we could have persisted. > That information shouldn't change even if the backing page is changed > after the migration, > > (2) There can be always extra overhead on the immediate next access to > any migrated page, because hardware MMU needs cycles to set the young > bit again (as long as the MMU supports). > > Many of the recent upstream works showed that (2) is not something trivial > and actually very measurable. In my test case, reading 1G chunk of memory > - jumping in page size intervals - could take 99ms just because of the > extra setting on the young bit on a generic x86_64 system, comparing to 4ms > if young set. > > This issue is originally reported by Andrea Arcangeli. > > Solution > ======== > > To solve this problem, this patchset tries to remember the young bit in the > migration entries and carry it over when recovering the ptes. > > We have the chance to do so because in many systems the swap offset is not > really fully used. Migration entries use swp offset to store PFN only, > while the PFN is normally not as large as swp offset and normally smaller. > It means we do have some free bits in swp offset that we can use to store > things like young, and that's how this series tried to approach this > problem. > > One tricky thing here is even though we're embedding the information into > swap entry which seems to be a very generic data structure, the number of > bits that are free is still arch dependent. Not only because the size of > swp_entry_t differs, but also due to the different layouts of swap ptes on > different archs. > > Here, this series requires specific arch to define an extra macro called > __ARCH_SWP_OFFSET_BITS represents the size of swp offset. With this > information, the swap logic can know whether there's extra bits to use, > then it'll remember the young bits when possible. By default, it'll keep > the old behavior of keeping all migrated pages cold. > I played with a similar idea when working on pte_swp_exclusive() but gave up, because it ended up looking too hacky. Looking at patch #2, I get the same feeling again. Kind of hacky. If we mostly only care about x86_64, and it's a performance improvement after all, why not simply do it like pte_swp_mkexclusive/pte_swp_exclusive/ ... and reuse a spare PTE bit? -- Thanks, David / dhildenb