Received: by 2002:a05:6a10:1a4d:0:0:0:0 with SMTP id nk13csp1846009pxb; Wed, 9 Feb 2022 05:51:31 -0800 (PST) X-Google-Smtp-Source: ABdhPJwTFsjIRtVWv+TxV4SblN/fjMVSG7TWpuUZ0uLdS5JcokBvhrrZAeKQR4UMf8ViZwlRHWTb X-Received: by 2002:a17:90a:8804:: with SMTP id s4mr2635341pjn.129.1644414691497; Wed, 09 Feb 2022 05:51:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1644414691; cv=none; d=google.com; s=arc-20160816; b=nj9cnQbp5qwU//gCjMN8w6nE7GR5OONaZeXlT1Iotuj1tkDfOy4hhJdsrYvg5ByuT1 +rHPmevwK65DXkZjgi0j42zBBzXSocWDl1iY54lLOAYqKUTaZDV0jCDk7KPajx7SWIEf Yjot304inf8BDgu71S1DfjEdDRXfLiRNs8ZYA+z01OZlePY7bA5sj+r11D9eKn4+Dohx SKNGfFmjOGSU7VdK/q7fhZvRwjQtbYXBe/KXEFHm8Dd2Tiv9JvwpiDuEDfyRjmtbSYY4 sobqaqVpIq5V8U+blCjmW9Bo8XwmH35zYP5SYWsorBuXpHbfSCkwDmIeOTvfU7Asl1hK wZkw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version; bh=egMSJIvSX/ns0qIJFcOE/5MMNPaCOyLP5cST6Zx2qZ4=; b=GxK90B7K8eXjZhRB/yB+Xl8R+uv7hJf5J/V+UWBTQjPpg08xEbmz4eOIh87k4tLyrV e6+SdIivQeRCPOweVKnhr0TCAkP5QEuGNoi4YIQrRjGDr6eVjNhxbVq4EkC1zJY6W8xM pQMotT422nQhibFBRBTt6cpM86ibe5MyEs5PHCAFLn0NyEayCwoMRMHYDyhCR8KnfkG3 423+W//jUFggxHX+PYE4vNeQIlQrWjDOhUkgESij3jPfY9e3N6rwlCc6pkE7GY8+mGhW PRQ6kk4a9R0aZ3MGIBHoEJMQE2Vjv8hN2i9syXTWzq6Dqz39zkGwGDer9PoqGx3Iwoos 5lEQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id t7si9638354plz.412.2022.02.09.05.51.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 09 Feb 2022 05:51:31 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 46892E053722; Wed, 9 Feb 2022 02:31:34 -0800 (PST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236534AbiBIIPz convert rfc822-to-8bit (ORCPT + 99 others); Wed, 9 Feb 2022 03:15:55 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57292 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240664AbiBIIPu (ORCPT ); Wed, 9 Feb 2022 03:15:50 -0500 Received: from mail-vs1-f45.google.com (mail-vs1-f45.google.com [209.85.217.45]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B58CBC0613CA for ; Wed, 9 Feb 2022 00:15:53 -0800 (PST) Received: by mail-vs1-f45.google.com with SMTP id a19so1718649vsi.2 for ; Wed, 09 Feb 2022 00:15:53 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=CCbpx5jLa8X1+FwaGeKkcnSoDsrgs8CZ2w84UAyChHY=; b=wbeb+XQbXBO6k+XQKwz3tHc5yras5NA3fo94VGDJSgrFIkwZmJhY2rMmdS38jhx95i +w3/MwBPlktClzK6eC0M6SCJIZYhlQ58Vek/LJEi6VSE6G//PQPPzwJUNNdlkwdPijkl qd6p0SNF7LpYkFpuCKbI9PeORNXblTDcoTVmQdD8gfdEXmYnWM2Keo/O0BpvczAJCgDs mdC5WmG5Igt/zhCzuaGa024l0nZ9HEO+PflogjqRSPOd/Kcd/e1cKWj6+IJxd3tXt46I fiUPD7ahO1nyNbPGMeA2MVIZiAcdcCcG4eurKe0dmO1QY6tGmzhOcMBp2f6FufqvnQh6 Copg== X-Gm-Message-State: AOAM532IMOzH+XJUGdChLNTR6rwmzjkWoJvhIvQEZG/3EnrmTmZxGQLf M3gH+hIKKlyCd7PYbl+reS3UvNXt2ZUjaw== X-Received: by 2002:a05:6102:2251:: with SMTP id e17mr310750vsb.13.1644394552090; Wed, 09 Feb 2022 00:15:52 -0800 (PST) Received: from mail-vk1-f176.google.com (mail-vk1-f176.google.com. [209.85.221.176]) by smtp.gmail.com with ESMTPSA id a21sm679398vsl.16.2022.02.09.00.15.50 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 09 Feb 2022 00:15:51 -0800 (PST) Received: by mail-vk1-f176.google.com with SMTP id m131so711322vkm.7 for ; Wed, 09 Feb 2022 00:15:50 -0800 (PST) X-Received: by 2002:a1f:2555:: with SMTP id l82mr414163vkl.7.1644394550779; Wed, 09 Feb 2022 00:15:50 -0800 (PST) MIME-Version: 1.0 References: <8e4356d-9622-a7f0-b2c-f116b5f2efea@google.com> In-Reply-To: From: Geert Uytterhoeven Date: Wed, 9 Feb 2022 09:15:39 +0100 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH 10/13] mm/munlock: mlock_page() munlock_page() batch by pagevec To: Hugh Dickins Cc: Andrew Morton , Michal Hocko , Vlastimil Babka , "Kirill A. Shutemov" , Matthew Wilcox , David Hildenbrand , Alistair Popple , Johannes Weiner , Rik van Riel , Suren Baghdasaryan , Yu Zhao , Greg Thelen , Shakeel Butt , Linux Kernel Mailing List , Linux MM Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8BIT X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RDNS_NONE, SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no 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 Hi Hugh, On Wed, Feb 9, 2022 at 3:46 AM Hugh Dickins wrote: > A weakness of the page->mlock_count approach is the need for lruvec lock > while holding page table lock. That is not an overhead we would allow on > normal pages, but I think acceptable just for pages in an mlocked area. > But let's try to amortize the extra cost by gathering on per-cpu pagevec > before acquiring the lruvec lock. > > I have an unverified conjecture that the mlock pagevec might work out > well for delaying the mlock processing of new file pages until they have > got off lru_cache_add()'s pagevec and on to LRU. > > The initialization of page->mlock_count is subject to races and awkward: > 0 or !!PageMlocked or 1? Was it wrong even in the implementation before > this commit, which just widens the window? I haven't gone back to think > it through. Maybe someone can point out a better way to initialize it. > > Bringing lru_cache_add_inactive_or_unevictable()'s mlock initialization > into mm/mlock.c has helped: mlock_new_page(), using the mlock pagevec, > rather than lru_cache_add()'s pagevec. > > Experimented with various orderings: the right thing seems to be for > mlock_page() and mlock_new_page() to TestSetPageMlocked before adding to > pagevec, but munlock_page() to leave TestClearPageMlocked to the later > pagevec processing. > > Dropped the VM_BUG_ON_PAGE(PageTail)s this time around: they have made > their point, and the thp_nr_page()s already contain a VM_BUG_ON_PGFLAGS() > for that. > > This still leaves acquiring lruvec locks under page table lock each time > the pagevec fills (or a THP is added): which I suppose is rather silly, > since they sit on pagevec waiting to be processed long after page table > lock has been dropped; but I'm disinclined to uglify the calling sequence > until some load shows an actual problem with it (nothing wrong with > taking lruvec lock under page table lock, just "nicer" to do it less). > > Signed-off-by: Hugh Dickins Thanks for your patch, which is now commit cbaf47432c909044 ("mm/munlock: mlock_page() munlock_page() batch by pagevec") in next-20220209. > --- a/mm/internal.h > +++ b/mm/internal.h > @@ -402,7 +402,8 @@ extern int mlock_future_check(struct mm_struct *mm, unsigned long flags, > * > * 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 in lru_cache_add_inactive_or_unevictable(). > + * pages are managed by lru_cache_add_inactive_or_unevictable() > + * calling mlock_new_page(). > * > * @compound is used to include pmd mappings of THPs, but filter out > * pte mappings of THPs, which cannot be consistently counted: a pte > @@ -425,6 +426,9 @@ static inline void munlock_vma_page(struct page *page, > (compound || !PageTransCompound(page))) > munlock_page(page); > } > +void mlock_new_page(struct page *page); > +bool need_mlock_page_drain(int cpu); > +void mlock_page_drain(int cpu); This is inside an #ifdef CONFIG_MMU section. > --- a/mm/swap.c > +++ b/mm/swap.c > @@ -640,6 +634,7 @@ void lru_add_drain_cpu(int cpu) > pagevec_lru_move_fn(pvec, lru_lazyfree_fn); > > activate_page_drain(cpu); > + mlock_page_drain(cpu); noreply@ellerman.id.au reported for m5272c3_defconfig: mm/swap.c:637:2: error: implicit declaration of function ‘mlock_page_drain’ [-Werror=implicit-function-declaration] http://kisskb.ellerman.id.au/kisskb/buildresult/14694567/ Gr{oetje,eeting}s, Geert -- Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that. -- Linus Torvalds