From patchwork Mon Mar 28 21:44:11 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hugh Dickins X-Patchwork-Id: 12794266 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 A398FC433FE for ; Mon, 28 Mar 2022 21:44:15 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 319068D0002; Mon, 28 Mar 2022 17:44:15 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 2A9D38D0001; Mon, 28 Mar 2022 17:44:15 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 167008D0002; Mon, 28 Mar 2022 17:44:15 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (relay.hostedemail.com [64.99.140.28]) by kanga.kvack.org (Postfix) with ESMTP id 04CCA8D0001 for ; Mon, 28 Mar 2022 17:44:15 -0400 (EDT) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id B4E80230BD for ; Mon, 28 Mar 2022 21:44:14 +0000 (UTC) X-FDA: 79295123628.04.E60A7BF Received: from mail-oa1-f43.google.com (mail-oa1-f43.google.com [209.85.160.43]) by imf27.hostedemail.com (Postfix) with ESMTP id 4C1DA4003E for ; Mon, 28 Mar 2022 21:44:14 +0000 (UTC) Received: by mail-oa1-f43.google.com with SMTP id 586e51a60fabf-de3ca1efbaso16689132fac.9 for ; Mon, 28 Mar 2022 14:44:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:from:to:cc:subject:message-id:mime-version; bh=hYgV/cj7s/KJHrRdB4rcVThWkKuipKsBWWVTwy7GkeY=; b=ThkJbWLv9rIxaiiAXpFpGA+YNbqtfsNkqlw3AzbmFPP3LcN4iJXeUF9gPpwXpDO01P FVR0aoODFvCx6scl2+ryNEa8dSFVhyJttsE953LXv+e0Qj9KAmHc1nSGGOEGy6mOGO18 lQ2xXlaJ8YZDQfaNnAUL7djpj3Yg6aBk8y0mQDaoWcJiPsXqtjnEPx3EIpC0VT+Qod1y C61Xf8MN6RuLa9xpy410KXx0z1ik+WoyOGzFyTt2A06XAjp8S+I+/0KyRcj/urg3nsc+ PgWU31Bw4LtPiBL6RU44AiRmtVwF82RQHhT7ygzH+3PWe3c2YDFEc4/qjCsmH/v1uB3E RyKQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:mime-version; bh=hYgV/cj7s/KJHrRdB4rcVThWkKuipKsBWWVTwy7GkeY=; b=hZcEd6mogbg39gHYnVqSgPk4o0tHSSzxkR/eYia4iDO9CIRjrKW11xMmI2Wl3HdTU0 J2ZqR/vgCpLdalNckHCUXnIUW7adt+Ziv7HgU4Y9C1X+sPSQmq7hODGs69HtqNWhVckE AkcvC38uRGY4ASVmB7GKh8/QvjXx64JcBU6Ot7Db01OPXtk2vFBwPQXd0jVEe+4ae84/ 6RWmAPbGMeME4f7pi8ig6KNCFWzrjNoBifNL7HjAlmO/S86aEPk7+qSYHSicLt7aC5ow th+MMZufgiOndsp5NQXf1sjezxscJT/umW5Kj7QlpoVKhdhamLjEeRTzSVPBToNkqNlg m2Bg== X-Gm-Message-State: AOAM533qg5pc3kvhaOP7CSBgFDvTNa9Dwc+zNLS+6NvRQ4r4M3cVdB4P 71Tx2jsnXxDIJJPScNLOGI9OJw== X-Google-Smtp-Source: ABdhPJzIBjwmQbEY1T2jGgJO1yNijei4zyMA//zsn44ah4IfxKMgs56Z1dXVOvquog8xahe2gztSsw== X-Received: by 2002:a05:6870:1714:b0:dd:a30e:d23e with SMTP id h20-20020a056870171400b000dda30ed23emr577361oae.85.1648503853461; Mon, 28 Mar 2022 14:44:13 -0700 (PDT) Received: from ripple.attlocal.net (172-10-233-147.lightspeed.sntcca.sbcglobal.net. [172.10.233.147]) by smtp.gmail.com with ESMTPSA id r7-20020a056830418700b005cda6037350sm7614141otu.79.2022.03.28.14.44.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Mar 2022 14:44:13 -0700 (PDT) Date: Mon, 28 Mar 2022 14:44:11 -0700 (PDT) From: Hugh Dickins X-X-Sender: hugh@ripple.anvils To: Andrew Morton cc: Mike Galbraith , Vlastimil Babka , Hugh Dickins , linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH] mm/munlock: add lru_add_drain() to fix memcg_stat_test Message-ID: <47f6d39c-a075-50cb-1cfb-26dd957a48af@google.com> MIME-Version: 1.0 X-Stat-Signature: ri1c8nkhbnsiedyhxe5xhn8ksjyy5rxt Authentication-Results: imf27.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=ThkJbWLv; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf27.hostedemail.com: domain of hughd@google.com designates 209.85.160.43 as permitted sender) smtp.mailfrom=hughd@google.com X-Rspam-User: X-Rspamd-Server: rspam11 X-Rspamd-Queue-Id: 4C1DA4003E X-HE-Tag: 1648503854-688964 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: Mike reports that LTP memcg_stat_test usually leads to... memcg_stat_test 3 TINFO: Test unevictable with MAP_LOCKED memcg_stat_test 3 TINFO: Running memcg_process --mmap-lock1 -s 135168 memcg_stat_test 3 TINFO: Warming up pid: 3460 memcg_stat_test 3 TINFO: Process is still here after warm up: 3460 memcg_stat_test 3 TFAIL: unevictable is 122880, 135168 expected ...but may lead to... memcg_stat_test 4 TINFO: Test unevictable with mlock memcg_stat_test 4 TINFO: Running memcg_process --mmap-lock2 -s 135168 memcg_stat_test 4 TINFO: Warming up pid: 4271 memcg_stat_test 4 TINFO: Process is still here after warm up: 4271 memcg_stat_test 4 TFAIL: unevictable is 122880, 135168 expected ...or both. A wee bit flaky. follow_page_pte() used to have an lru_add_drain() per each page mlocked, and the test came to rely on accurate stats. The pagevec to be drained is different now, but still covered by lru_add_drain(); and, never mind the test, I believe it's in everyone's interest that a bulk faulting interface like populate_vma_page_range() or faultin_vma_page_range() should drain its local pagevecs at the end, to save others sometimes needing the much more expensive lru_add_drain_all(). This does not absolutely guarantee exact stats - the mlocking task can be migrated between CPUs as it proceeds - but it's good enough and the tests pass. Reported-by: Mike Galbraith Fixes: b67bf49ce7aa ("mm/munlock: delete FOLL_MLOCK and FOLL_POPULATE") Signed-off-by: Hugh Dickins --- One can argue about the Fixes tag - I'd have chosen the pagevec commit, but this is the one Mike identified, and the one which touches mm/gup.c, so I'm happy to go with this - and doesn't matter so long as 5.18 gets it. mm/gup.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) --- 5.18-pre/mm/gup.c +++ linux/mm/gup.c @@ -1404,6 +1404,7 @@ long populate_vma_page_range(struct vm_a struct mm_struct *mm = vma->vm_mm; unsigned long nr_pages = (end - start) / PAGE_SIZE; int gup_flags; + long ret; VM_BUG_ON(!PAGE_ALIGNED(start)); VM_BUG_ON(!PAGE_ALIGNED(end)); @@ -1438,8 +1439,10 @@ long populate_vma_page_range(struct vm_a * We made sure addr is within a VMA, so the following will * not result in a stack expansion that recurses back here. */ - return __get_user_pages(mm, start, nr_pages, gup_flags, + ret = __get_user_pages(mm, start, nr_pages, gup_flags, NULL, NULL, locked); + lru_add_drain(); + return ret; } /* @@ -1471,6 +1474,7 @@ long faultin_vma_page_range(struct vm_ar struct mm_struct *mm = vma->vm_mm; unsigned long nr_pages = (end - start) / PAGE_SIZE; int gup_flags; + long ret; VM_BUG_ON(!PAGE_ALIGNED(start)); VM_BUG_ON(!PAGE_ALIGNED(end)); @@ -1498,8 +1502,10 @@ long faultin_vma_page_range(struct vm_ar if (check_vma_flags(vma, gup_flags)) return -EINVAL; - return __get_user_pages(mm, start, nr_pages, gup_flags, + ret = __get_user_pages(mm, start, nr_pages, gup_flags, NULL, NULL, locked); + lru_add_drain(); + return ret; } /*