Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp3795276ybb; Mon, 23 Mar 2020 07:52:18 -0700 (PDT) X-Google-Smtp-Source: ADFU+vv4QeBcoj8p5eov2duaT8ffQZcV5pbdzaf0FXcPJ8uwAHPSlns0yHUFRTVhfpNVqIsizKpX X-Received: by 2002:a9d:7c90:: with SMTP id q16mr17613004otn.257.1584975138382; Mon, 23 Mar 2020 07:52:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1584975138; cv=none; d=google.com; s=arc-20160816; b=o4dA929IoonUodBRWQp3nIxmtCC+wYugqAtJgI3U7PE2vTrujufxQ5hcMuUpG5LyIV xHNavfU5eOi3/yXyqLek8rQ/J7JX1+XnOXY5Wf2KmbECT9xIW1EVSaUHr/0hM9T5dy5T pWgufIPHGxE/9tA9zMRpXYP+HebU5ESwlITbAzkcrFGul5gZyHKZX3aAR7QuRkzNRagx /sZ9aC6z3THuF4AGOCOTerKaCR56wkh3LlU30QkfaV5y9RNGcY9ytHPB9g96D6CkmBfi 4lz+ubiePu7QndGM65U7WzO7AzVnlXtCgqr1/XleeJR7xDKV+PXNhCHTT8/sDxIiuDBS h0Tw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date; bh=6p44xGwV8r9hc9Uqd5WPQ5phNN16MgM5x4v+o5mOS6U=; b=pMmFto/KdClmFgc8YIe9ASpxrVsmImTNoUAitxzO6jA3O6xkqTgLyz/B4uq/WXqn0M 7hrNutDdhtU9QG0w6JhiWOVCbEtXmNkHFSunnFNCMKsSvdk2naMu4TYNyW4vx5W7Sw9i F452CbyB2sDNwMi4NeR3fbgys6GQqM15SItK28o8D7O7mPBe5ZMLyGXNt8wIbfYIIzsY WAA84f7EqGefayGFrlwLKCU8xqBpKC4d69O5oRVgGYjzhe9OIrOxb0daZ+RV0G1ien+7 yxdQQggOoSK/nc6aPFwug5JHPyRnm+O0tFOROKPybGK20eyQhtjguSzTP48lpMVjAITs si3Q== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l25si8067249otk.119.2020.03.23.07.52.01; Mon, 23 Mar 2020 07:52:18 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726955AbgCWOvQ (ORCPT + 99 others); Mon, 23 Mar 2020 10:51:16 -0400 Received: from mail-wm1-f65.google.com ([209.85.128.65]:37349 "EHLO mail-wm1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725710AbgCWOvP (ORCPT ); Mon, 23 Mar 2020 10:51:15 -0400 Received: by mail-wm1-f65.google.com with SMTP id d1so15131700wmb.2; Mon, 23 Mar 2020 07:51:13 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=6p44xGwV8r9hc9Uqd5WPQ5phNN16MgM5x4v+o5mOS6U=; b=XyQwvJ6anCbzIRyAA7M+eMaVsdn9MGlBGQP8IRpD8QCqgYK+GM4oEGShYwuSTVy9q4 17Bt8aghls7M3FXJ74jfwX3tog7rmRFnJp52ZMGTfEfF14EC0OlZS3GHxZK1M/fvVHgR +nQzSQFL5UAwMaGlOCUWkZNtwTjI9CtiRk5KvAH/pfXafc/ejgPhbnIyZxkTYSPtXS1e gY0Rs4wZbHbC+Zjl/mc3yQ279tZqz1rI5afxREfvayCC85fDpsKbVIiZorVCZ9FxQhTg RachXiyQzrGBwDOatErUv+jKgwpn9Mmu9GqBpaG6AXtz1hrNEaelKHQu660pv0humh+h Ztzw== X-Gm-Message-State: ANhLgQ1omInGi0JObneZ/8EAWWwpMDrJ98g9Nm6EbyHehywTj25OU8RW 2aAT9MLgRSBMtqZNpK1Osns= X-Received: by 2002:a05:600c:2283:: with SMTP id 3mr25533395wmf.157.1584975071478; Mon, 23 Mar 2020 07:51:11 -0700 (PDT) Received: from localhost (ip-37-188-135-150.eurotel.cz. [37.188.135.150]) by smtp.gmail.com with ESMTPSA id x24sm21883617wmc.36.2020.03.23.07.51.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Mar 2020 07:51:10 -0700 (PDT) Date: Mon, 23 Mar 2020 15:51:06 +0100 From: Michal Hocko To: Rafael Aquini Cc: Shakeel Butt , Andrew Morton , LKML , linux-kselftest@vger.kernel.org, shuah@kernel.org Subject: Re: [PATCH] tools/testing/selftests/vm/mlock2-tests: fix mlock2 false-negative errors Message-ID: <20200323145106.GM7524@dhcp22.suse.cz> References: <20200322013525.1095493-1-aquini@redhat.com> <20200321184352.826d3dba38aecc4ff7b32e72@linux-foundation.org> <20200322020326.GB1068248@t490s> <20200321213142.597e23af955de653fc4db7a1@linux-foundation.org> <20200323075208.GC7524@dhcp22.suse.cz> <20200323144240.GB23364@optiplex-lnx> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200323144240.GB23364@optiplex-lnx> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon 23-03-20 10:42:40, Rafael Aquini wrote: > On Mon, Mar 23, 2020 at 08:52:08AM +0100, Michal Hocko wrote: > > On Sun 22-03-20 09:36:49, Shakeel Butt wrote: > > > On Sat, Mar 21, 2020 at 9:31 PM 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. > > > > > > > > > > We already have other examples like memcg stats where the > > > optimizations like batching per-cpu stats collection exposes > > > differences to the userspace. I would not be that worried here. > > > > Agreed! Tests should be more tolerant for counters imprecision. > > Unevictable LRU is an optimization and transition to that list is a > > matter of an internal implementation detail. > > > > > > 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? > > > > > > > > > > I would rather prefer to have something similar to > > > /proc/sys/vm/stat_refresh which drains the pagevecs. > > > > No, please don't. Pagevecs draining is by far not the only batching > > scheme we use and an interface like this would promise users to > > effectivelly force flushing all of them. > > > > Can we simply update the test to be more tolerant to imprecisions > > instead? > > > > I don't think, thouhg, that this particular test case can be entirely > reduced as "counter imprecison". > > The reason I think this is a different beast, is that having the page > being flagged as PG_unevictable is expected part of the aftermath of > a mlock* call. This selftest is, IMO, correctly verifying that fact, > as it checks the functionality correctness. > > The problem boils down to the fact that the page would immediately > be flagged as PG_unevictable after the mlock (under MCL_FUTURE|MCL_ONFAULT > semantics) call, and the test was expecting it, and commit 9c4e6b1a7027f > changed that by "delaying" that flag setting. As I've tried to explain in other email in this email thread. The test was exploiting a certain user visible side effect. The unevictable flag or the placement on the unevictable LRU list is are not really needed for the user contract correctness. That means that the test is not really correct. Working around that by trying to enforce kernel to comply with the test expectations is just plain wrong at least for two reasons 1) you cannot expect or event do not want userspace to do the same because the behavior might change in the future 2) the test is not really testing for correctness in the first place. -- Michal Hocko SUSE Labs