Received: by 2002:a05:7412:a9a2:b0:e2:908c:2ebd with SMTP id o34csp2888557rdh; Mon, 30 Oct 2023 10:26:08 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGvOwgHJdiq8BmNjjhbejaCiyy+IXFjyB+c7o0srNYynjVOuXTKZ4GLlcKpvvuxML8/YFp7 X-Received: by 2002:a17:90a:884:b0:27d:5568:e867 with SMTP id v4-20020a17090a088400b0027d5568e867mr334811pjc.9.1698686767634; Mon, 30 Oct 2023 10:26:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698686767; cv=none; d=google.com; s=arc-20160816; b=jQu5K2TTPZx0Ixsu7mWYISoOj1UqB6gKg1qAnQ1lyTQbqizDVYDbBzZyG7BrUY55cE PCzKO1oOjaw9/Do2mpBMm7acNME4du0/EHGaYBiBU8K8v6qkLpKnmu4qft+Qwu2trCxb /SiO54ysggaTfwKU8fzCgIz/RW0I3WIYaW8ShF81NL2/WYRB1tQrXzfwEjYbAnXsvUIl ca2jwlQv+Aq1vlrotYDNbtpay2uY62+m2kv8NtfNPxCOTl27tBVUHXTMiZFadYlBbJ12 DVJ+MdrTiyniuk3VCPmJR+sSee50LFiAHOSsWV64aVV3JcI3FcKlG6Q3v0iQFnK3wg0W ybkA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:autocrypt :from:references:cc:to:content-language:subject:user-agent :mime-version:date:message-id:dkim-signature; bh=aTBFgLt9uRovWwF2IMctF7UYTEbuVr1QbBbWiOdNkAA=; fh=9GjpMzJz+uuhn19uB36EwSK3xE6lNesC+Xo4sskdlZ8=; b=QzjBHEIepwClqsIk6C0h/bK2eSZjEQ7zyGIzzxoIXMCterXF8gmfsE+AmtqYwY6WrW 6/XGyRBsc3YYhur7X2ukc0WrVecQ9+exNTvDkDCoTtMINuv6UZUeCyByYegRZ15CczzY AEdeXdwZAw1IunoZ1OgnjlR7vHqvGBLRIyJ2Ykrc40hl3+0GWHBMGzpGWlqge3dBAzc3 HqAdBVfjYaG5DaK3TkHAs/3f/1ZAEyxgW0VVWlhB+HG+zYp8lx96KgVTTt71Em2eE+fz 7pinpzJgwvkQC7Fgcp5NLSwnHhPlkAfVj8GXBf2B9YS4uaefi50O/sNuRa+6EUDHnTLb GK7g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=YtEiCgiR; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from pete.vger.email (pete.vger.email. [2620:137:e000::3:6]) by mx.google.com with ESMTPS id mr7-20020a17090b238700b0026822221502si5212807pjb.163.2023.10.30.10.26.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Oct 2023 10:26:07 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) client-ip=2620:137:e000::3:6; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=YtEiCgiR; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by pete.vger.email (Postfix) with ESMTP id 1ABDC8050015; Mon, 30 Oct 2023 10:26:04 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233016AbjJ3RZx (ORCPT + 99 others); Mon, 30 Oct 2023 13:25:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58492 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232654AbjJ3RZw (ORCPT ); Mon, 30 Oct 2023 13:25:52 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BB97B9F for ; Mon, 30 Oct 2023 10:25:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1698686704; 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:autocrypt:autocrypt; bh=aTBFgLt9uRovWwF2IMctF7UYTEbuVr1QbBbWiOdNkAA=; b=YtEiCgiRBCgSqdKLh4oVxoQXZPZto5z/gsEXLAFKsXtopfmMy0bQPbL9Xn3AxLmcy1dHDt wlNp7PUXUezBBi+mMKlCEXfDlMV02bDPUm3hc3hE+0walDLIdqOBRgFiQ7F16odu4oEyJF Uw5qPgTLpo1NS3nUDCWmOr8Z7bHFUIE= Received: from mail-lj1-f198.google.com (mail-lj1-f198.google.com [209.85.208.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-84-Y4LGCtdUPV2is72tMNUPwg-1; Mon, 30 Oct 2023 13:24:52 -0400 X-MC-Unique: Y4LGCtdUPV2is72tMNUPwg-1 Received: by mail-lj1-f198.google.com with SMTP id 38308e7fff4ca-2c50255b905so50618401fa.0 for ; Mon, 30 Oct 2023 10:24:52 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698686691; x=1699291491; h=content-transfer-encoding:in-reply-to:autocrypt:from:references:cc :to:content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=aTBFgLt9uRovWwF2IMctF7UYTEbuVr1QbBbWiOdNkAA=; b=JUiCbccNpsvPCDGOfDR5A1sAvWgfyhn9KdAbcHGSLcARJ6Kk5PASyCUNbtqzdfAv+M Dkr9LuJD3WAT6reGESWoinbxtqpBYbnpReqeA4T8BEpW7dARCaP2nKIjJUxCZoVm7Xo+ mVoWMbA/L+18nrIuQluvm6h2oZgPcVVO8x9B/g/kVWOusY7glTymMCpDh734GEEvg+R3 4EONI5GLpReaft2QgeeDlYKqWHAHBBKCINhzOgXjXJHB0ZZGPZAI9adn4oOp7crR0uNK c6Un6lihTVx0xr6unRJ+ACsWnmsG/xD4RyviKnCT5I0gcbl0y5T2QnqTIzqgul/RM15L kBJQ== X-Gm-Message-State: AOJu0YwsWo86ApsZRfgQ0xn7NjGSr3Lldk4jAr1Mr1YwPvP7xeuBTxFi 0z+XadihUS2iYD7+3jjY0pyA62eLb6zYP4YYYePwUU6mG1UnKjIhQYj41ZYTA8RpzBYQnqlBOFl juyW/0mpBgIj67gDNbE8ZlRR7 X-Received: by 2002:a05:651c:c98:b0:2c5:13b1:b450 with SMTP id bz24-20020a05651c0c9800b002c513b1b450mr10090916ljb.26.1698686691293; Mon, 30 Oct 2023 10:24:51 -0700 (PDT) X-Received: by 2002:a05:651c:c98:b0:2c5:13b1:b450 with SMTP id bz24-20020a05651c0c9800b002c513b1b450mr10090869ljb.26.1698686690900; Mon, 30 Oct 2023 10:24:50 -0700 (PDT) Received: from [192.168.1.174] ([151.81.68.207]) by smtp.googlemail.com with ESMTPSA id n13-20020a05600c500d00b0040772934b12sm13131967wmr.7.2023.10.30.10.24.37 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 30 Oct 2023 10:24:49 -0700 (PDT) Message-ID: <601f24a0-cb55-458e-aa15-3970f2290172@redhat.com> Date: Mon, 30 Oct 2023 18:24:34 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v13 14/35] mm: Add AS_UNMOVABLE to mark mapping as completely unmovable Content-Language: en-US To: Sean Christopherson , Marc Zyngier , Oliver Upton , Huacai Chen , Michael Ellerman , Anup Patel , Paul Walmsley , Palmer Dabbelt , Albert Ou , Alexander Viro , Christian Brauner , "Matthew Wilcox (Oracle)" , Andrew Morton Cc: kvm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, linux-mips@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, kvm-riscv@lists.infradead.org, linux-riscv@lists.infradead.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Xiaoyao Li , Xu Yilun , Chao Peng , Fuad Tabba , Jarkko Sakkinen , Anish Moorthy , David Matlack , Yu Zhang , Isaku Yamahata , =?UTF-8?B?TWlja2HDq2wgU2FsYcO8?= =?UTF-8?Q?n?= , Vlastimil Babka , Vishal Annapurve , Ackerley Tng , Maciej Szmigiero , David Hildenbrand , Quentin Perret , Michael Roth , Wang , Liam Merwick , Isaku Yamahata , "Kirill A . Shutemov" References: <20231027182217.3615211-1-seanjc@google.com> <20231027182217.3615211-15-seanjc@google.com> From: Paolo Bonzini Autocrypt: addr=pbonzini@redhat.com; keydata= xsEhBFRCcBIBDqDGsz4K0zZun3jh+U6Z9wNGLKQ0kSFyjN38gMqU1SfP+TUNQepFHb/Gc0E2 CxXPkIBTvYY+ZPkoTh5xF9oS1jqI8iRLzouzF8yXs3QjQIZ2SfuCxSVwlV65jotcjD2FTN04 hVopm9llFijNZpVIOGUTqzM4U55sdsCcZUluWM6x4HSOdw5F5Utxfp1wOjD/v92Lrax0hjiX DResHSt48q+8FrZzY+AUbkUS+Jm34qjswdrgsC5uxeVcLkBgWLmov2kMaMROT0YmFY6A3m1S P/kXmHDXxhe23gKb3dgwxUTpENDBGcfEzrzilWueOeUWiOcWuFOed/C3SyijBx3Av/lbCsHU Vx6pMycNTdzU1BuAroB+Y3mNEuW56Yd44jlInzG2UOwt9XjjdKkJZ1g0P9dwptw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x9uImI5nX24PIlqT+zasVEEVGSRF m8dgkcJDB7Tps0IkNrUi4yof3B3shR+vMY3i3Ip0e41zKx0CvlAhMOo6otaHmcxr35sWq1Jk tLkbn3wG+fPQCVudJJECvVQ//UAthSSEklA50QtD2sBkmQ14ZryEyTHQ+E42K3j2IUmOLriF dNr9NvE1QGmGyIcbw2NIVEBOK/GWxkS5+dmxM2iD4Jdaf2nSn3jlHjEXoPwpMs0KZsgdU0pP JQzMUMwmB1wM8JxovFlPYrhNT9MAEQEAAcLBMwQYAQIACQUCVEJx7gIbDAAKCRB+FRAMzTZp sadRDqCctLmYICZu4GSnie4lKXl+HqlLanpVMOoFNnWs9oRP47MbE2wv8OaYh5pNR9VVgyhD OG0AU7oidG36OeUlrFDTfnPYYSF/mPCxHttosyt8O5kabxnIPv2URuAxDByz+iVbL+RjKaGM GDph56ZTswlx75nZVtIukqzLAQ5fa8OALSGum0cFi4ptZUOhDNz1onz61klD6z3MODi0sBZN Aj6guB2L/+2ZwElZEeRBERRd/uommlYuToAXfNRdUwrwl9gRMiA0WSyTb190zneRRDfpSK5d usXnM/O+kr3Dm+Ui+UioPf6wgbn3T0o6I5BhVhs4h4hWmIW7iNhPjX1iybXfmb1gAFfjtHfL xRUr64svXpyfJMScIQtBAm0ihWPltXkyITA92ngCmPdHa6M1hMh4RDX+Jf1fiWubzp1voAg0 JBrdmNZSQDz0iKmSrx8xkoXYfA3bgtFN8WJH2xgFL28XnqY4M6dLhJwV3z08tPSRqYFm4NMP dRsn0/7oymhneL8RthIvjDDQ5ktUjMe8LtHr70OZE/TT88qvEdhiIVUogHdo4qBrk41+gGQh b906Dudw5YhTJFU3nC6bbF2nrLlB4C/XSiH76ZvqzV0Z/cAMBo5NF/w= In-Reply-To: <20231027182217.3615211-15-seanjc@google.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-1.3 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on pete.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (pete.vger.email [0.0.0.0]); Mon, 30 Oct 2023 10:26:04 -0700 (PDT) On 10/27/23 20:21, Sean Christopherson wrote: > Add an "unmovable" flag for mappings that cannot be migrated under any > circumstance. KVM will use the flag for its upcoming GUEST_MEMFD support, > which will not support compaction/migration, at least not in the > foreseeable future. > > Test AS_UNMOVABLE under folio lock as already done for the async > compaction/dirty folio case, as the mapping can be removed by truncation > while compaction is running. To avoid having to lock every folio with a > mapping, assume/require that unmovable mappings are also unevictable, and > have mapping_set_unmovable() also set AS_UNEVICTABLE. > > Cc: Matthew Wilcox > Co-developed-by: Vlastimil Babka > Signed-off-by: Vlastimil Babka > Signed-off-by: Sean Christopherson I think this could even be "From: Vlastimil", but no biggie. Paolo > --- > include/linux/pagemap.h | 19 +++++++++++++++++- > mm/compaction.c | 43 +++++++++++++++++++++++++++++------------ > mm/migrate.c | 2 ++ > 3 files changed, 51 insertions(+), 13 deletions(-) > > diff --git a/include/linux/pagemap.h b/include/linux/pagemap.h > index 351c3b7f93a1..82c9bf506b79 100644 > --- a/include/linux/pagemap.h > +++ b/include/linux/pagemap.h > @@ -203,7 +203,8 @@ enum mapping_flags { > /* writeback related tags are not used */ > AS_NO_WRITEBACK_TAGS = 5, > AS_LARGE_FOLIO_SUPPORT = 6, > - AS_RELEASE_ALWAYS, /* Call ->release_folio(), even if no private data */ > + AS_RELEASE_ALWAYS = 7, /* Call ->release_folio(), even if no private data */ > + AS_UNMOVABLE = 8, /* The mapping cannot be moved, ever */ > }; > > /** > @@ -289,6 +290,22 @@ static inline void mapping_clear_release_always(struct address_space *mapping) > clear_bit(AS_RELEASE_ALWAYS, &mapping->flags); > } > > +static inline void mapping_set_unmovable(struct address_space *mapping) > +{ > + /* > + * It's expected unmovable mappings are also unevictable. Compaction > + * migrate scanner (isolate_migratepages_block()) relies on this to > + * reduce page locking. > + */ > + set_bit(AS_UNEVICTABLE, &mapping->flags); > + set_bit(AS_UNMOVABLE, &mapping->flags); > +} > + > +static inline bool mapping_unmovable(struct address_space *mapping) > +{ > + return test_bit(AS_UNMOVABLE, &mapping->flags); > +} > + > static inline gfp_t mapping_gfp_mask(struct address_space * mapping) > { > return mapping->gfp_mask; > diff --git a/mm/compaction.c b/mm/compaction.c > index 38c8d216c6a3..12b828aed7c8 100644 > --- a/mm/compaction.c > +++ b/mm/compaction.c > @@ -883,6 +883,7 @@ isolate_migratepages_block(struct compact_control *cc, unsigned long low_pfn, > > /* Time to isolate some pages for migration */ > for (; low_pfn < end_pfn; low_pfn++) { > + bool is_dirty, is_unevictable; > > if (skip_on_failure && low_pfn >= next_skip_pfn) { > /* > @@ -1080,8 +1081,10 @@ isolate_migratepages_block(struct compact_control *cc, unsigned long low_pfn, > if (!folio_test_lru(folio)) > goto isolate_fail_put; > > + is_unevictable = folio_test_unevictable(folio); > + > /* Compaction might skip unevictable pages but CMA takes them */ > - if (!(mode & ISOLATE_UNEVICTABLE) && folio_test_unevictable(folio)) > + if (!(mode & ISOLATE_UNEVICTABLE) && is_unevictable) > goto isolate_fail_put; > > /* > @@ -1093,26 +1096,42 @@ isolate_migratepages_block(struct compact_control *cc, unsigned long low_pfn, > if ((mode & ISOLATE_ASYNC_MIGRATE) && folio_test_writeback(folio)) > goto isolate_fail_put; > > - if ((mode & ISOLATE_ASYNC_MIGRATE) && folio_test_dirty(folio)) { > - bool migrate_dirty; > + is_dirty = folio_test_dirty(folio); > + > + if (((mode & ISOLATE_ASYNC_MIGRATE) && is_dirty) || > + (mapping && is_unevictable)) { > + bool migrate_dirty = true; > + bool is_unmovable; > > /* > * Only folios without mappings or that have > - * a ->migrate_folio callback are possible to > - * migrate without blocking. However, we may > - * be racing with truncation, which can free > - * the mapping. Truncation holds the folio lock > - * until after the folio is removed from the page > - * cache so holding it ourselves is sufficient. > + * a ->migrate_folio callback are possible to migrate > + * without blocking. > + * > + * Folios from unmovable mappings are not migratable. > + * > + * However, we can be racing with truncation, which can > + * free the mapping that we need to check. Truncation > + * holds the folio lock until after the folio is removed > + * from the page so holding it ourselves is sufficient. > + * > + * To avoid locking the folio just to check unmovable, > + * assume every unmovable folio is also unevictable, > + * which is a cheaper test. If our assumption goes > + * wrong, it's not a correctness bug, just potentially > + * wasted cycles. > */ > if (!folio_trylock(folio)) > goto isolate_fail_put; > > mapping = folio_mapping(folio); > - migrate_dirty = !mapping || > - mapping->a_ops->migrate_folio; > + if ((mode & ISOLATE_ASYNC_MIGRATE) && is_dirty) { > + migrate_dirty = !mapping || > + mapping->a_ops->migrate_folio; > + } > + is_unmovable = mapping && mapping_unmovable(mapping); > folio_unlock(folio); > - if (!migrate_dirty) > + if (!migrate_dirty || is_unmovable) > goto isolate_fail_put; > } > > diff --git a/mm/migrate.c b/mm/migrate.c > index 2053b54556ca..ed874e43ecd7 100644 > --- a/mm/migrate.c > +++ b/mm/migrate.c > @@ -956,6 +956,8 @@ static int move_to_new_folio(struct folio *dst, struct folio *src, > > if (!mapping) > rc = migrate_folio(mapping, dst, src, mode); > + else if (mapping_unmovable(mapping)) > + rc = -EOPNOTSUPP; > else if (mapping->a_ops->migrate_folio) > /* > * Most folios have a mapping and most filesystems