Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp1844595pxk; Tue, 1 Sep 2020 09:06:28 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy6czhYL5EIO7bZLm12xhS2ve75JVhZERbyReEamLEFeHnB+HLjPFxpc0BaP4CoDpIC6iBx X-Received: by 2002:a17:906:5f96:: with SMTP id a22mr2219406eju.335.1598976388572; Tue, 01 Sep 2020 09:06:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1598976388; cv=none; d=google.com; s=arc-20160816; b=wPE8FFe1GxU7vRv0LHd4KCjgqjxONiQaOUaiZcPBM6JbNYtdIGLhSjMwrpb16MQt5x ezRGG4d424yBgxIX2K+v7jdwl35v+20klLuzuwOr/G5FTi9umQM4VwwlGaMO0I35xmVF 73lxaMWFb4Ak5z5w4adc39NS8eJMlM0SutcgCjTc7dmBQVl1NRwt34G6psE5aqG+96Nm ArSfJSKxY4mBDFb+Dmd3zAD/rU9S2vO6KKVzAQ6cVT2VXDSsl4lKZHzVLZtEPCzv4Qwa qQfJ4r5c3Qa6C64KtXmI5NgkFZHwIi6YpC7jjEf6tC5T9Ewm/loj+Lk0Xx/hGPsiofEK DH1A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=mRRv/JWr8lefJK8mOV5+SVMKnyOKM6jC1YlJAAQDR3k=; b=WhZcTtheJhtg78AhD0P7SSCXlp0dZIBqxHh+iLQik3R5zehH2NYl4xOgbavHRfkwvg 9Bou0R8y/7gFU7yDE1hT9yQh0YEn4xpNfDUno8VwqEW7smdT8ScAgiaa2ws5Gtv4/f9H /yQQWM2iSFFLNOmux2T6j6a53I2L9qWKNNUK9e3C9bPr2CACC+z7QF3XUOMdnoIwjt8n habAngQenk/vTihYjg/tZK/DRDGmG015XQnE/CYVANYJPVMsZMpSkeCoVw6BaZbVyJGV m43z7QT2Jmjr0d2FHiDHNmglYWDA4/ZlPDZbGmHqgkhsLj7NsjotMDaBNx8UWodpma1m YSbA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=DKvWNEH3; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id u23si788626edb.1.2020.09.01.09.06.04; Tue, 01 Sep 2020 09:06:28 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=DKvWNEH3; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728832AbgIAQFS (ORCPT + 99 others); Tue, 1 Sep 2020 12:05:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55920 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730560AbgIAPlZ (ORCPT ); Tue, 1 Sep 2020 11:41:25 -0400 Received: from mail-ej1-x644.google.com (mail-ej1-x644.google.com [IPv6:2a00:1450:4864:20::644]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 338E3C061244 for ; Tue, 1 Sep 2020 08:41:24 -0700 (PDT) Received: by mail-ej1-x644.google.com with SMTP id i26so2284245ejb.12 for ; Tue, 01 Sep 2020 08:41:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=mRRv/JWr8lefJK8mOV5+SVMKnyOKM6jC1YlJAAQDR3k=; b=DKvWNEH3Gj78jemdv3xdYpWry18IwiJrX2WSmxBD9QiFUMXZk7WJJK1Ckv3j2MsKvd JkZDL3Cspa3ZWauj6niFf3qa3/wvuCOvJQCPlQCDK/7DrAmMohx4s35NZd60qn7rEaRf eD0Zh6lsBKI35S5bYfaD2ggRIZUIMTVnWUaWahiuKMTXQ2XYMYyedsSkPvMaM+qP04AN qLGyply6M6Uz0B5UiUDHj9ORJSfdI1J5B0ah9ay62g6TRX0DPYuDY3NbHcVlR2zj5cxC aHz1xeWR/XNN9xLbd7VSng/wpbh5+TAU8986gqSMno0rABJJjgxBSzNRsg2RzbDPmgOO eT4w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=mRRv/JWr8lefJK8mOV5+SVMKnyOKM6jC1YlJAAQDR3k=; b=uUhWSknU1rZogW4MtABMWOnipRb9psLoKUA5zfSaNDGJTKRqSyoxrfYHZk6ZOdx6Fv UAhfrRupKSPTjyB0vAFJJmPEKtGq7ELr8B1jF+0sEWVGNZpFAkGvV0Lc9bnbZD1jFY0b 306WNLwKEkohpYziFN9lU8Hu9fbo3k6bINkxEbwkAz4OTtZ0Qu8fcqxYIHelfsXWgbdA O8ob/BIPMxgpyvKjmTV83I/oKFvF0bZ3yYBsZZ5Y73Sy6YkpySmS1ZrAU3uZLsOEyYF9 nXklef6ccAKJsq/hM4Qn4mfjcGuyPQ2KihjM9txfZ4FJZAVdV1Tt5EnW5pWGMSvkyFA7 bEgg== X-Gm-Message-State: AOAM5339vE5DnHbNTLU1/riRLb+nuK6rTaIIXg0wXtEa+jKxKN7g8iH6 sCoIZEVBiG2nayZrviv1+mKWKcd/dry4jsG6sxY= X-Received: by 2002:a17:906:edd6:: with SMTP id sb22mr1852146ejb.499.1598974882857; Tue, 01 Sep 2020 08:41:22 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Yang Shi Date: Tue, 1 Sep 2020 08:41:11 -0700 Message-ID: Subject: Re: [PATCH 5/5] mlock: fix unevictable_pgs event counts on THP To: Hugh Dickins Cc: Andrew Morton , Alex Shi , Johannes Weiner , Michal Hocko , Mike Kravetz , Shakeel Butt , Matthew Wilcox , Qian Cai , Linux Kernel Mailing List , Linux MM Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sun, Aug 30, 2020 at 2:09 PM Hugh Dickins wrote: > > 5.8 commit 5d91f31faf8e ("mm: swap: fix vmstats for huge page") has > established that vm_events should count every subpage of a THP, > including unevictable_pgs_culled and unevictable_pgs_rescued; but > lru_cache_add_inactive_or_unevictable() was not doing so for > unevictable_pgs_mlocked, and mm/mlock.c was not doing so for > unevictable_pgs mlocked, munlocked, cleared and stranded. > > Fix them; but THPs don't go the pagevec way in mlock.c, > so no fixes needed on that path. > > Fixes: 5d91f31faf8e ("mm: swap: fix vmstats for huge page") > Signed-off-by: Hugh Dickins Acked-by: Yang Shi > --- > I've only checked UNEVICTABLEs: there may be more inconsistencies left. > The check_move_unevictable_pages() patch brought me to this one, but > this is more important because mlock works on all THPs, without needing > special testing "force". But, it's still just monotonically increasing > event counts, so not all that important. > > mm/mlock.c | 24 +++++++++++++++--------- > mm/swap.c | 6 +++--- > 2 files changed, 18 insertions(+), 12 deletions(-) > > --- 5.9-rc2/mm/mlock.c 2020-08-16 17:32:50.665507048 -0700 > +++ linux/mm/mlock.c 2020-08-28 17:42:07.975278411 -0700 > @@ -58,11 +58,14 @@ EXPORT_SYMBOL(can_do_mlock); > */ > void clear_page_mlock(struct page *page) > { > + int nr_pages; > + > if (!TestClearPageMlocked(page)) > return; > > - mod_zone_page_state(page_zone(page), NR_MLOCK, -thp_nr_pages(page)); > - count_vm_event(UNEVICTABLE_PGCLEARED); > + nr_pages = thp_nr_pages(page); > + mod_zone_page_state(page_zone(page), NR_MLOCK, -nr_pages); > + count_vm_events(UNEVICTABLE_PGCLEARED, nr_pages); > /* > * The previous TestClearPageMlocked() corresponds to the smp_mb() > * in __pagevec_lru_add_fn(). > @@ -76,7 +79,7 @@ void clear_page_mlock(struct page *page) > * We lost the race. the page already moved to evictable list. > */ > if (PageUnevictable(page)) > - count_vm_event(UNEVICTABLE_PGSTRANDED); > + count_vm_events(UNEVICTABLE_PGSTRANDED, nr_pages); > } > } > > @@ -93,9 +96,10 @@ void mlock_vma_page(struct page *page) > VM_BUG_ON_PAGE(PageCompound(page) && PageDoubleMap(page), page); > > if (!TestSetPageMlocked(page)) { > - mod_zone_page_state(page_zone(page), NR_MLOCK, > - thp_nr_pages(page)); > - count_vm_event(UNEVICTABLE_PGMLOCKED); > + int nr_pages = thp_nr_pages(page); > + > + mod_zone_page_state(page_zone(page), NR_MLOCK, nr_pages); > + count_vm_events(UNEVICTABLE_PGMLOCKED, nr_pages); > if (!isolate_lru_page(page)) > putback_lru_page(page); > } > @@ -138,7 +142,7 @@ static void __munlock_isolated_page(stru > > /* Did try_to_unlock() succeed or punt? */ > if (!PageMlocked(page)) > - count_vm_event(UNEVICTABLE_PGMUNLOCKED); > + count_vm_events(UNEVICTABLE_PGMUNLOCKED, thp_nr_pages(page)); > > putback_lru_page(page); > } > @@ -154,10 +158,12 @@ static void __munlock_isolated_page(stru > */ > static void __munlock_isolation_failed(struct page *page) > { > + int nr_pages = thp_nr_pages(page); > + > if (PageUnevictable(page)) > - __count_vm_event(UNEVICTABLE_PGSTRANDED); > + __count_vm_events(UNEVICTABLE_PGSTRANDED, nr_pages); > else > - __count_vm_event(UNEVICTABLE_PGMUNLOCKED); > + __count_vm_events(UNEVICTABLE_PGMUNLOCKED, nr_pages); > } > > /** > --- 5.9-rc2/mm/swap.c 2020-08-16 17:32:50.709507284 -0700 > +++ linux/mm/swap.c 2020-08-28 17:42:07.975278411 -0700 > @@ -494,14 +494,14 @@ void lru_cache_add_inactive_or_unevictab > > unevictable = (vma->vm_flags & (VM_LOCKED | VM_SPECIAL)) == VM_LOCKED; > if (unlikely(unevictable) && !TestSetPageMlocked(page)) { > + int nr_pages = thp_nr_pages(page); > /* > * We use the irq-unsafe __mod_zone_page_stat because this > * counter is not modified from interrupt context, and the pte > * lock is held(spinlock), which implies preemption disabled. > */ > - __mod_zone_page_state(page_zone(page), NR_MLOCK, > - thp_nr_pages(page)); > - count_vm_event(UNEVICTABLE_PGMLOCKED); > + __mod_zone_page_state(page_zone(page), NR_MLOCK, nr_pages); > + count_vm_events(UNEVICTABLE_PGMLOCKED, nr_pages); > } > lru_cache_add(page); > } >