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 2ACCAC00140 for ; Fri, 5 Aug 2022 12:18:01 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 468B58E0002; Fri, 5 Aug 2022 08:18:00 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 418658E0001; Fri, 5 Aug 2022 08:18:00 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2B8BE8E0002; Fri, 5 Aug 2022 08:18:00 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 1BFDC8E0001 for ; Fri, 5 Aug 2022 08:18:00 -0400 (EDT) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id E12EF818C9 for ; Fri, 5 Aug 2022 12:17:59 +0000 (UTC) X-FDA: 79765440678.02.6950CE7 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf15.hostedemail.com (Postfix) with ESMTP id 89436A012F for ; Fri, 5 Aug 2022 12:17:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1659701879; 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=kOHdOlusLImHqeSrvcvuEjySBTnIFF6YxV9UFOMchZA=; b=hqGRPk2sc7nhXiUxtvUhdo85Vg7edmC/eaaF9N+ZqsmxLmK8lzO71mNIvQcPfB+TsdhIvP j7l4qt5cnN5zUVqmDCKOmiTZIJ2dfJzd4D+8ZZhkYLSxmk7Q7lU4GnZsSj23Hw3WidapBT HSmIOD/WG1Tk9llIaFdC2Gq302991SU= Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-16-cd830fQRO_C3Y0SAz1qwpA-1; Fri, 05 Aug 2022 08:17:58 -0400 X-MC-Unique: cd830fQRO_C3Y0SAz1qwpA-1 Received: by mail-wm1-f70.google.com with SMTP id d10-20020a05600c34ca00b003a4f0932ec3so4151607wmq.0 for ; Fri, 05 Aug 2022 05:17:57 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:in-reply-to:organization:from:references :cc:to:content-language:subject:user-agent:mime-version:date :message-id:x-gm-message-state:from:to:cc; bh=kOHdOlusLImHqeSrvcvuEjySBTnIFF6YxV9UFOMchZA=; b=T8TXKDAulCC63/la1CEPkEw9+iiL8bv2923qaAidY6BjiYY6znfKgmX4uWhQn1I/Zy xdiPDhuvwgMsNVVMzyFr3HmjIx0WxdnuA1K6dUVYJgE9HeAt7O2w7DP8ySiqoacDqnDJ UNeWWzpdM/njGuktK6zfGXvEjkQdrcuaHMGWKjcvntsLk5+DeN6NzONxPQvZquAEvh3o DlnJ+5JxptpIPHHXEOVTj0BaHcTfPYgiNbOjH0KCHkJYgKafM1U1GddwpiuVFJOuEwf1 VPknDHlUV6zABY3yQzAUSvI7CGx+sz6SnPcxI9+MqS/Hx5M1rEZMAq6BAzUE+9k0wBKt T3ow== X-Gm-Message-State: ACgBeo2XGTKqqoJoyaATpSJvMzeUp7Ik60rhKguhAUl7kqE6zk3ZYrzl rjd6diJVsQK0bNL9QVe17lYsGaTVQj8MqhaFe2q/aV7Gz2d3cyxMVRjgjlK69F3TO53HdNBzlDh 6KuTqLjdnjCI= X-Received: by 2002:a5d:6c64:0:b0:21e:f5bb:e00d with SMTP id r4-20020a5d6c64000000b0021ef5bbe00dmr3954676wrz.521.1659701876874; Fri, 05 Aug 2022 05:17:56 -0700 (PDT) X-Google-Smtp-Source: AA6agR659tX52h3jfMegC9JVmztcb3U2Z0AFJbAbn5HDCgNOYs4FSFOHSrD0DFs1CDg4sqPcqMp8kA== X-Received: by 2002:a5d:6c64:0:b0:21e:f5bb:e00d with SMTP id r4-20020a5d6c64000000b0021ef5bbe00dmr3954657wrz.521.1659701876558; Fri, 05 Aug 2022 05:17:56 -0700 (PDT) Received: from ?IPV6:2003:cb:c706:fb00:f5c3:24b2:3d03:9d52? (p200300cbc706fb00f5c324b23d039d52.dip0.t-ipconnect.de. [2003:cb:c706:fb00:f5c3:24b2:3d03:9d52]) by smtp.gmail.com with ESMTPSA id bd6-20020a05600c1f0600b003a2cf1535aasm4644811wmb.17.2022.08.05.05.17.55 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 05 Aug 2022 05:17:56 -0700 (PDT) Message-ID: <62d52657-12d2-8563-4ead-027480065d9f@redhat.com> Date: Fri, 5 Aug 2022 14:17:55 +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 v2 2/2] mm: Remember young/dirty bit for page migrations To: Peter Xu , linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: Huang Ying , Andrea Arcangeli , Minchan Kim , Andrew Morton , Vlastimil Babka , Nadav Amit , Hugh Dickins , Andi Kleen , "Kirill A . Shutemov" References: <20220804203952.53665-1-peterx@redhat.com> <20220804203952.53665-3-peterx@redhat.com> From: David Hildenbrand Organization: Red Hat In-Reply-To: <20220804203952.53665-3-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=1659701879; 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=kOHdOlusLImHqeSrvcvuEjySBTnIFF6YxV9UFOMchZA=; b=A82usKDLt+xDue3lbf9SQiMHQILsCSUx6NpdMEaVW/Ir2t0nWn4x+Odiz+JcHzUbPOSVYW yN+l1ovXar7t57GktjyrdUOQKzyaETp+6ls5lm5/kAeU0XlDjOP3tCk78DY9l1/0CmmdiS bkvaGJs5U1nxUO5zMneUCs7ARpc8k3Y= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=hqGRPk2s; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf15.hostedemail.com: domain of david@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=david@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1659701879; a=rsa-sha256; cv=none; b=ueVs9Y7JDx/QP0C/YGOWYqOPQ/RM7HDlx4H2oS6q8WU+6eFozdIzGhTrfspI74xRxirQnx SpAKg8q5MPslE8s3Vs6GMLYZTJ0ewfbYV67DOn1TensvlvH66djNl/L10asyjvQ3Tlz/f/ 2Br8l8ttbzXxcYU5UUbiBTGsSt9meDg= X-Stat-Signature: nasqtqy4c1xnb9s673mg8t9w38a5y4bj X-Rspamd-Queue-Id: 89436A012F X-Rspamd-Server: rspam01 Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=hqGRPk2s; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf15.hostedemail.com: domain of david@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=david@redhat.com X-Rspam-User: X-HE-Tag: 1659701879-66303 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 04.08.22 22:39, Peter Xu wrote: > When page migration happens, we always ignore the young/dirty bit settings > in the old pgtable, and marking the page as old in the new page table using > either pte_mkold() or pmd_mkold(), and keeping the pte clean. > > 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. > The same slowdown problem to dirty bits when the memory is first written > after page migration happened. > > Actually we can easily remember the A/D bit configuration and recover the > information after the page is migrated. To achieve it, define a new set of > bits in the migration swap offset field to cache the A/D bits for old pte. > Then when removing/recovering the migration entry, we can recover the A/D > bits even if the page changed. > > 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 A/D bits are dropped like before. > > Signed-off-by: Peter Xu > --- > include/linux/swapops.h | 91 +++++++++++++++++++++++++++++++++++++++++ > mm/huge_memory.c | 26 +++++++++++- > mm/migrate.c | 6 ++- > mm/migrate_device.c | 4 ++ > mm/rmap.c | 5 ++- > 5 files changed, 128 insertions(+), 4 deletions(-) > > diff --git a/include/linux/swapops.h b/include/linux/swapops.h > index 1d17e4bb3d2f..34aa448ac6ee 100644 > --- a/include/linux/swapops.h > +++ b/include/linux/swapops.h > @@ -8,6 +8,8 @@ > > #ifdef CONFIG_MMU > > +#include > + > /* > * swapcache pages are stored in the swapper_space radix tree. We want to > * get good packing density in that tree, so the index should be dense in > @@ -35,6 +37,24 @@ > #endif > #define SWP_PFN_MASK ((1UL << SWP_PFN_BITS) - 1) > > +/** > + * Migration swap entry specific bitfield definitions. > + * > + * @SWP_MIG_YOUNG_BIT: Whether the page used to have young bit set > + * @SWP_MIG_DIRTY_BIT: Whether the page used to have dirty bit set > + * > + * Note: these bits will be stored in migration entries iff there're enough > + * free bits in arch specific swp offset. By default we'll ignore A/D bits > + * when migrating a page. Please refer to migration_entry_supports_ad() > + * for more information. > + */ > +#define SWP_MIG_YOUNG_BIT (SWP_PFN_BITS) > +#define SWP_MIG_DIRTY_BIT (SWP_PFN_BITS + 1) > +#define SWP_MIG_TOTAL_BITS (SWP_PFN_BITS + 2) > + > +#define SWP_MIG_YOUNG (1UL << SWP_MIG_YOUNG_BIT) > +#define SWP_MIG_DIRTY (1UL << SWP_MIG_DIRTY_BIT) > + > static inline bool is_pfn_swap_entry(swp_entry_t entry); > > /* Clear all flags but only keep swp_entry_t related information */ > @@ -265,6 +285,57 @@ static inline swp_entry_t make_writable_migration_entry(pgoff_t offset) > return swp_entry(SWP_MIGRATION_WRITE, offset); > } > > +/* > + * Returns whether the host has large enough swap offset field to support > + * carrying over pgtable A/D bits for page migrations. The result is > + * pretty much arch specific. > + */ > +static inline bool migration_entry_supports_ad(void) > +{ > + /* > + * max_swapfile_size() returns the max supported swp-offset plus 1. > + * We can support the migration A/D bits iff the pfn swap entry has > + * the offset large enough to cover all of them (PFN, A & D bits). > + */ > +#ifdef CONFIG_SWAP > + return max_swapfile_size() >= (1UL << SWP_MIG_TOTAL_BITS); > +#else > + return false; > +#endif > +} This looks much cleaner to me. It might be helpful to draw an ascii picture where exatcly these bits reside isnide the offset. > + > +static inline swp_entry_t make_migration_entry_young(swp_entry_t entry) > +{ > + if (migration_entry_supports_ad()) Do we maybe want to turn that into a static key and enable it once and for all? As Nadav says, the repeated max_swapfile_size() calls/checks might be worth optimizing out. [...] -- Thanks, David / dhildenb