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 7D526C54EBC for ; Thu, 12 Jan 2023 12:01:51 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 008098E0002; Thu, 12 Jan 2023 07:01:51 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id EFAD28E0001; Thu, 12 Jan 2023 07:01:50 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DA5618E0002; Thu, 12 Jan 2023 07:01:50 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id C81E08E0001 for ; Thu, 12 Jan 2023 07:01:50 -0500 (EST) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 8C8BB160993 for ; Thu, 12 Jan 2023 12:01:50 +0000 (UTC) X-FDA: 80346007980.28.9502B51 Received: from mail-wr1-f50.google.com (mail-wr1-f50.google.com [209.85.221.50]) by imf27.hostedemail.com (Postfix) with ESMTP id B33FA40014 for ; Thu, 12 Jan 2023 12:01:48 +0000 (UTC) Authentication-Results: imf27.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=mnYTsyv1; spf=pass (imf27.hostedemail.com: domain of lstoakes@gmail.com designates 209.85.221.50 as permitted sender) smtp.mailfrom=lstoakes@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1673524908; 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:in-reply-to:references:references:dkim-signature; bh=1WT7VEidhNV2omGBYhLrUDOURbROFBE8pJSOw9tEWNg=; b=3cEagUnmHLEmYqfn8KhXjHeDfXfECdGEVO0yR4Dc/6xr9Q9DfswtLmV6wLk8PIu5FQLDd+ eHKufvHkqDaiJgwGtQfnGNpABY96kTAR2DmNhntJWOqaAQby/8cbcWix08iBpYvvWQ47+x 2WjATHdMCwWMK0vEnZ7qTaVbbi/4W/Y= ARC-Authentication-Results: i=1; imf27.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=mnYTsyv1; spf=pass (imf27.hostedemail.com: domain of lstoakes@gmail.com designates 209.85.221.50 as permitted sender) smtp.mailfrom=lstoakes@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1673524908; a=rsa-sha256; cv=none; b=yBUrAnib9UiIvgWiIK23RFzFA6WkEdMJf6QmXsMBIG0yDzDwYCJ9bZqhZBzwvb/PP/EqRw 43nlHYpJ3a8/XXnVE6oTquqlFOQY9Cc5LDHcb+04yfXxCBXXmVGb3szVmPkMPse548e74f GiyUNYMtQc1sUx5Ao+J1vU66mAloOvw= Received: by mail-wr1-f50.google.com with SMTP id v2so6848529wrw.10 for ; Thu, 12 Jan 2023 04:01:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=1WT7VEidhNV2omGBYhLrUDOURbROFBE8pJSOw9tEWNg=; b=mnYTsyv1rGsyTK2QOVe9k5ieQnSkp7eYAEN7ZnH2LkI3aFDlY2tpzMT1HZQIb8UP3K 6TwHK977eVdxBtMtu5rw93XY5t9zqLD6r7ZESxBKFfs2prjCoMkE2LgCCQrSlAuvTN0T iVOVvA1s5itKF/U0Dp4VP6sHooqEKWyP3majEjmPeLN2W/n0CDBRaCZxRjat+OVfmpuK irsPdsEmoDUyhqgvOOm8vxGaHPb/vBCPPO2IWEg0bqz4tv6vqsLnXvo1g1KZU9ZoJMz9 Sv87Lkg+rK8f1vV9hEOODp8aj0A5d3dC69qOiCjjHG8FAhjdA0hyeFO+cFqVtZ0E1FYz FJVA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=1WT7VEidhNV2omGBYhLrUDOURbROFBE8pJSOw9tEWNg=; b=IZM6dKfnVJGuNZb24rMSc1+h4QoPwLjkZAPfemTlrGGzkWoF0yDIF2dfa9a9x/0D2/ KVs3sWFw3BdiUuEIBaoB639ym57a0eanUP4yomUtZeFU2OBByVTaKsOhjJ/dv4IcbAjW Zu3EhYWpblkXHYBlF+4Rf6gRPa3lG+d0zV2mjMAA5h6K8szPPzxn1ZrwJar0DmkrcwU4 8MTGhRIBkc/pcl+t5x5mavRPZ0pixQ7h/zbU8hukvFerPAfxuoHFgd/G36rVoNJ/+Cd6 Tv/Gl99GMaPq6pWjVO7Hpv4hb0JLtWOVeKhVPRi01jB8lB9aTs2WefWlddg9l5oMEjys kThQ== X-Gm-Message-State: AFqh2kp1d5PGS8ToCAoQgFICp31oLX4eTMKIfNHoFuG65ajCPUptKaEs U8BRNbR/tj//ERt8hHVuORU= X-Google-Smtp-Source: AMrXdXt3goV8FsMG6U3iFuBWXTkhiCO0BCOS7Hw4Vtb/2tQiGYhprzWZdUm9TbwUt/CEU1C5LoLSpw== X-Received: by 2002:a5d:5747:0:b0:2bd:beac:ef7b with SMTP id q7-20020a5d5747000000b002bdbeacef7bmr5982944wrw.52.1673524907228; Thu, 12 Jan 2023 04:01:47 -0800 (PST) Received: from localhost (host86-164-169-89.range86-164.btcentralplus.com. [86.164.169.89]) by smtp.gmail.com with ESMTPSA id f3-20020adfdb43000000b00236883f2f5csm16508537wrj.94.2023.01.12.04.01.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Jan 2023 04:01:46 -0800 (PST) Date: Thu, 12 Jan 2023 12:01:45 +0000 From: Lorenzo Stoakes To: Vlastimil Babka Cc: linux-mm@kvack.org, Andrew Morton , linux-kernel@vger.kernel.org, Matthew Wilcox , Hugh Dickins , Liam Howlett , William Kucharski , Christian Brauner , Jonathan Corbet , Mike Rapoport , Joel Fernandes , Geert Uytterhoeven Subject: Re: [PATCH v3 4/5] mm: mlock: update the interface to use folios Message-ID: References: <50cc1bfc-6cee-dc98-7ed9-cc3f0c863c02@suse.cz> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <50cc1bfc-6cee-dc98-7ed9-cc3f0c863c02@suse.cz> X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: B33FA40014 X-Rspam-User: X-Stat-Signature: ps1fdawy5s48mzbduja455w4phppux7f X-HE-Tag: 1673524908-469676 X-HE-Meta: U2FsdGVkX1+fi93Izc0xUxzX48kHHFXEa7y8L5YaonrlP/EzBH9tythYtiKGLGX6hXYjDjovm0Crs8OXyV0JSf8g4tarmVa4Ww7bacoe2sgVqkhf/dtWbCrsDCXHbj94uQOLA1+QQrNSdUiIyHwcyqRJ9S6T7asTn2OwHHOgA7KVvvDZBkQV2FTUIX0ofieoyrWBmJlHi2yIetj3zbpWzw4q5PC7TXXqpEN/HmJ1F+08ruV+t2uegHZ7gP8p/yToCJ4MHDHTs8RPbnV/79Ed+pZyAFKYnUAIYbJbzG3j8MwIi+Ku6Lj9WuCiL1EVKvodzlzo0aYLmsX5WGFP0NaDLEl2/K7uph4n8++sr8c79Xp5NPCvQFFaDUcdgmJOJu8yvWrz/x6TyK24FDu/TF5b7+ngENRA3jcNz2uEQel6h8n7AGlcQbwK7V8Wec7hTJ5VxQ9PbMST2YFYssMawIwZcs5U35uJ9BulqFrvEMZvLK1Oir6vALcvn3x3xKxRAtvBdO13vPYWPY/xcNNojfVgUC0wD/9bJuGKlzYf+qdm0D1ZcwQuH5SyrgyUkczMzJxYd17h6pz1pQtJh9hazAmVoF2f+8GxzIWL336joCQ7Q42LrAyEJNhmkc5Me+bFhND2Sn/YO1hFhas7yNfiWJDAVwK9l70D9RNS5SuPcinlZSdPpELJqe9qG5wO8nid0fwlm/2pzmZDhnaGyTukk/5lgr+pHxRHWJILcszUI5hOjditT4BI8ArSKwW62G9id/pHxS0ydCq1rvVwLdH7B5YZQZCh5vK6H7P5eH6iOHD+70HWT2BNGADSWSj1Kje836hiwNc8uDf0JefIRw/q7WAWJmfkCIJfPYkvaq7JfFON3/mle+2kkap4UHbIcO1lBrTdaZszqmSv9YFjNLxNe5ktyQomwNYb+2s7/FoP18KElr1Nb4SnRCm3hIkzScPDCspGkDxNtyDQaNlVQTvuLaM 9xzM2VpQ dObe4Bf76Of7rO4EwMPqliROn8JCt2jKNNvZ68ORgscAwU3ZNyuQIv9Qp+jKWbqj4bHzOo4FGypI66ln59KQtOls+ug== 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 Thu, Jan 12, 2023 at 11:55:13AM +0100, Vlastimil Babka wrote: > On 12/26/22 09:44, Lorenzo Stoakes wrote: > > This patch updates the mlock interface to accept folios rather than pages, > > bringing the interface in line with the internal implementation. > > > > munlock_vma_page() still requires a page_folio() conversion, however this > > is consistent with the existent mlock_vma_page() implementation and a > > product of rmap still dealing in pages rather than folios. > > > > Signed-off-by: Lorenzo Stoakes > > Acked-by: Vlastimil Babka > > With some suggestion: > > > --- > > mm/internal.h | 26 ++++++++++++++++---------- > > mm/mlock.c | 32 +++++++++++++++----------------- > > mm/swap.c | 2 +- > > 3 files changed, 32 insertions(+), 28 deletions(-) > > > > diff --git a/mm/internal.h b/mm/internal.h > > index 1d6f4e168510..8a6e83315369 100644 > > --- a/mm/internal.h > > +++ b/mm/internal.h > > @@ -515,10 +515,9 @@ extern int mlock_future_check(struct mm_struct *mm, unsigned long flags, > > * should be called with vma's mmap_lock held for read or write, > > * under page table lock for the pte/pmd being added or removed. > > * > > - * mlock is usually called at the end of page_add_*_rmap(), > > - * munlock at the end of page_remove_rmap(); but new anon > > - * pages are managed by lru_cache_add_inactive_or_unevictable() > > - * calling mlock_new_page(). > > + * mlock is usually called at the end of page_add_*_rmap(), munlock at > > + * the end of page_remove_rmap(); but new anon folios are managed by > > + * folio_add_lru_vma() calling mlock_new_folio(). > > * > > * @compound is used to include pmd mappings of THPs, but filter out > > * pte mappings of THPs, which cannot be consistently counted: a pte > > @@ -547,15 +546,22 @@ static inline void mlock_vma_page(struct page *page, > > mlock_vma_folio(page_folio(page), vma, compound); > > } > > > > -void munlock_page(struct page *page); > > -static inline void munlock_vma_page(struct page *page, > > +void munlock_folio(struct folio *folio); > > + > > +static inline void munlock_vma_folio(struct folio *folio, > > struct vm_area_struct *vma, bool compound) > > { > > if (unlikely(vma->vm_flags & VM_LOCKED) && > > - (compound || !PageTransCompound(page))) > > - munlock_page(page); > > + (compound || !folio_test_large(folio))) > > + munlock_folio(folio); > > +} > > + > > +static inline void munlock_vma_page(struct page *page, > > + struct vm_area_struct *vma, bool compound) > > +{ > > + munlock_vma_folio(page_folio(page), vma, compound); > > } > > -void mlock_new_page(struct page *page); > > +void mlock_new_folio(struct folio *folio); > > bool need_mlock_page_drain(int cpu); > > void mlock_page_drain_local(void); > > void mlock_page_drain_remote(int cpu); > > I think these drain related functions could use a rename as well? > Maybe replace "page" with "fbatch" or "folio_batch"? Even the old name isn't > great, should have been "pagevec". Agreed, though I feel it's more readable if we just drop this bit altogether, which is also more consistent with the core batch drain functions like e.g. lru_add_drain(). In this case we'd go to need_mlock_drain(), mlock_drain_local() and mlock_drain_remote(). > But maybe it would fit patch 2/5 rather than 4/5 as it's logically internal > even if in a .h file. > > Even though it is an internal interface across the board I feel like it makes the patch series a little easier to read keeping this separate, so I think it makes sense to keep it here so we can have a separation between internal-to-mlock changes vs. internal-to-mm ones :)