Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp2872668ybb; Sun, 22 Mar 2020 09:42:32 -0700 (PDT) X-Google-Smtp-Source: ADFU+vtNtAYBJ+CqjkyYaqGkZbEBzu1iuxlP4e6/H03zkA78GVx8nMtCnlIy8WJDfBx/ekuPFEk0 X-Received: by 2002:aca:4fcc:: with SMTP id d195mr14975024oib.99.1584895352023; Sun, 22 Mar 2020 09:42:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1584895352; cv=none; d=google.com; s=arc-20160816; b=xIK1mpk++ScCXQmpuLrstJgNTEW95PILuT9BO30FTrCxDoVeWdItLbAihhbkOQYZ6X SNJOI0yiN0WybGrhtqdeF4a5LuHv8NJEhyt7vylZJxPSSy4lyRSf3Jh7f6itY2DzX/gp CLcSh826Hqb5fOtEH++RundDxK3jiTR+WsZrWRH9uQfBtXvaau1Glcq0AI1Bc5Lv42dP g1CXP5kIpkGuh5pMwv8z6GMyYaOtyISQM9OFGYKtuh0rkbxm3UVahZ5JmLpUCk6rsa3O A9e5YlIhlavJN5b8n1/xQrXcBo+rTGU+U1QHKkMCFxRWJ12D+svKbeDKqs0uXyWCiEcx 8EVg== 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=/NRcff3IU+6Tgzkshu1srIwPGx1YyS4nMPqqG29Ytvw=; b=QVAm1Lw0v+fezjd0Up3A8cbEzPMW5awTE6FWuOYB6/+va8U19Rnz/3I/f/OovJ8blW K7kINT+yLB7vBdYDXy5IXLOfWoD/e/iCTPbo+WHMzeg8HiI+2n0SOfrlGMZ7IwHCO9IB LkKtiDQwKJiIOwC8HeZlFflckf0wPmUbuV8q0v1hLEhBUCKhDxTdcz3L9TheynGkJU3d TESZ9WsmQy+AWj9nHAV4iLVpbu96IuJaQXvj329B8QIBNMTkwZhT57eX33NZNbNe+JQZ VUZIwIskCMqmEOrXAvsHkrkoyJVf/SG+TKT6oku+tE/Q6ixQq2xpu7fg6cZxV/HssOnP 7u4Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=qOUehZhX; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l65si6344062oig.156.2020.03.22.09.42.20; Sun, 22 Mar 2020 09:42:32 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=qOUehZhX; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726901AbgCVQkn (ORCPT + 99 others); Sun, 22 Mar 2020 12:40:43 -0400 Received: from mail-ot1-f66.google.com ([209.85.210.66]:45886 "EHLO mail-ot1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725881AbgCVQkn (ORCPT ); Sun, 22 Mar 2020 12:40:43 -0400 Received: by mail-ot1-f66.google.com with SMTP id c9so823195otl.12 for ; Sun, 22 Mar 2020 09:40:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=/NRcff3IU+6Tgzkshu1srIwPGx1YyS4nMPqqG29Ytvw=; b=qOUehZhX/pacNMUrZn/+2SHmA4iod5L4EySZ0kuBn/JxSDPHHsZ4fUjgfRPm5xH/ur QhZW2pgT6REGxos8IW5vtbuWqrcPmZOKZYbh0zucvshGq41tH0oYUvqFq9R52YJ2MSCK ui/JImCB7Ii7rGWqmE83tjH2r0Ktg/7whFLg8eTxxywfklN6+NgCwh9TwZHvrYvDXdXa f8hTK2U4JPZ6vqrGlbaqIyTYMooPNXIMk4L1t2LND7/PBl2spbVXqYl4p9bZ/LCVrcqu LS+UD0HrPB7TiFLSrhB+PyIsdC1e3Tcw4GVy+2xakizAMaqU7c2RcnqGxmVVrmur5Mtk F+ug== 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=/NRcff3IU+6Tgzkshu1srIwPGx1YyS4nMPqqG29Ytvw=; b=JEEGNP2jiJWujUNoTgmospO/qfLu33rRR9ROPj8RYIlTG+0GLsQQK0Vx/LJKkBWBJe FttkMONdYJIGJq1yij7JtGXOp3HMEX+fWvayAsv5JDt1eq2zZ3ioLfPptEximHsDbxdF P2WuBdYLCIvBh+Vn7crBQQkEaQhQlNvJ1sLAv9MtadpLtlIegVzDwFTdKMqAX3yW4tuo rbvSXWs0jqxVE6jZuTnvqmOLjlHn1skzqfvZEggNmqDwYsHv1gzaIkrSb2j8dUAW/sRN 3F2XD60QEUnr86L4imF/xwHZG4thhX+BpN9fqr66EhJv65FVJGl61CTYwt/6W2yeGIF0 NmfQ== X-Gm-Message-State: ANhLgQ2tyXO/lq4wxCBKAnwGhryWX/wOgspHvK+2SPDvhv+hKnIqpiVR ttn3mMTuRACKkcDX7vOmmFtYxX98a1yaY0dUJR9ygA== X-Received: by 2002:a05:6830:1054:: with SMTP id b20mr4151189otp.360.1584895240706; Sun, 22 Mar 2020 09:40:40 -0700 (PDT) MIME-Version: 1.0 References: <20200322013525.1095493-1-aquini@redhat.com> <20200321184352.826d3dba38aecc4ff7b32e72@linux-foundation.org> <20200322020326.GB1068248@t490s> <20200321213142.597e23af955de653fc4db7a1@linux-foundation.org> <20200322054131.GC1068248@t490s> In-Reply-To: <20200322054131.GC1068248@t490s> From: Shakeel Butt Date: Sun, 22 Mar 2020 09:40:29 -0700 Message-ID: Subject: Re: [PATCH] tools/testing/selftests/vm/mlock2-tests: fix mlock2 false-negative errors To: Rafael Aquini Cc: Andrew Morton , LKML , linux-kselftest@vger.kernel.org, shuah@kernel.org 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 Sat, Mar 21, 2020 at 10:41 PM Rafael Aquini wrote: > > On Sat, Mar 21, 2020 at 09:31:42PM -0700, Andrew Morton wrote: > > On Sat, 21 Mar 2020 22:03:26 -0400 Rafael Aquini wrote: > > > > > > > + * In order to sort out that race, and get the after fault checks consistent, > > > > > + * the "quick and dirty" trick below is required in order to force a call to > > > > > + * lru_add_drain_all() to get the recently MLOCK_ONFAULT pages moved to > > > > > + * the unevictable LRU, as expected by the checks in this selftest. > > > > > + */ > > > > > +static void force_lru_add_drain_all(void) > > > > > +{ > > > > > + sched_yield(); > > > > > + system("echo 1 > /proc/sys/vm/compact_memory"); > > > > > +} > > > > > > > > What is the sched_yield() for? > > > > > > > > > > Mostly it's there to provide a sleeping gap after the fault, whithout > > > actually adding an arbitrary value with usleep(). > > > > > > It's not a hard requirement, but, in some of the tests I performed > > > (whithout that sleeping gap) I would still see around 1% chance > > > of hitting the false-negative. After adding it I could not hit > > > the issue anymore. > > > > It's concerning that such deep machinery as pagevec draining is visible > > to userspace. > > > > I suppose that for consistency and correctness we should perform a > > drain prior to each read from /proc/*/pagemap. Presumably this would > > be far too expensive. > > > > Is there any other way? One such might be to make the MLOCK_ONFAULT > > pages bypass the lru_add_pvecs? > > > > Well, > > I admit I wasn't taking the approach of changing the kernel because I was > thinking it would require a partial, or even full, revert of commit > 9c4e6b1a7027f, and that would be increasing complexity, but on a > second thought, it seems that we might just be missing: > > diff --git a/mm/swap.c b/mm/swap.c > index cf39d24ada2a..b1601228ded4 100644 > --- a/mm/swap.c > +++ b/mm/swap.c > @@ -473,6 +473,7 @@ void lru_cache_add_active_or_unevictable(struct page *page, > __mod_zone_page_state(page_zone(page), NR_MLOCK, > hpage_nr_pages(page)); > count_vm_event(UNEVICTABLE_PGMLOCKED); > + SetPageUnevictable(page); No, this is not correct. Check __pagevec_lru_add_fn() for TestClearPageUnevictable(). As I mentioned in the other email, I think the better solution would be to introduce a sysctl to drain the pageves. That way there will not be any dependency on compaction as was in your original patch. Shakeel