From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.8 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C5C5BC32756 for ; Wed, 7 Aug 2019 17:16:26 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 925C521E73 for ; Wed, 7 Aug 2019 17:16:26 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=joelfernandes.org header.i=@joelfernandes.org header.b="cpS86uEm" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387957AbfHGRQZ (ORCPT ); Wed, 7 Aug 2019 13:16:25 -0400 Received: from mail-pl1-f195.google.com ([209.85.214.195]:43287 "EHLO mail-pl1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389078AbfHGRQY (ORCPT ); Wed, 7 Aug 2019 13:16:24 -0400 Received: by mail-pl1-f195.google.com with SMTP id 4so34765145pld.10 for ; Wed, 07 Aug 2019 10:16:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=joelfernandes.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=xT1EUv7l9ELnBbW3Pj9GyH6zMTpmJcDHOSB5E5y40eQ=; b=cpS86uEmYIzhxFzCySaqqOeImVDTWodZUXCQVQcRGqqRAGGDs1sNZw0oH3tmy2iZOE XkIu9l2OhfxN0xt6NyH+lVLF+8mXgqz7NSPIIJ+egtHoGZEtUgQY7iySTu1NQl565je/ qL/IqLU05tBxt6AwDFcVVWZEJCirczwMCOG/I= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=xT1EUv7l9ELnBbW3Pj9GyH6zMTpmJcDHOSB5E5y40eQ=; b=Ba2f3wXSeeyd6opr3uUQr9lzrUA+dn4wfCmjSeRTP4W+4Afs6z28bqncumKnO95l8N Cv31DQ21jBiNnj2bC1k1VA+BHkEtJfbxWW8GIUjnwJ+mfaHeOEGZ7/J95qnvQ8fXuQ1W qs1mQNgxKaTGjlu5Bptx70EPqdTaK73G5MIoCTMYul8yatCkioPdwC5t25NM+4xd+Y3X 4JxpKjy6C/MLIPIqXPbwNnYyKr/5aijhwTMYc7l7qx2rjzdJvAe05abQOKLTYVkLoAKY dHaumttLRth4FD/nCg0PrqdmbVVQX+cMllnOZpxOBO2o8CkeT49kT0hPY+kBVp6/Lkix Mp0Q== X-Gm-Message-State: APjAAAXechU0WdbtqQc01WIsBIz/v1c5KZlvDVwgl735CWmzW/FDChqJ UJSBGJ/fghSkRa1llCU82N5NRw== X-Google-Smtp-Source: APXvYqwugi3AW6n6dfP+TB/Uc5APuLJqoUYRpEzJ6Mn8Htn03idxWxXllDnzug9Hw6aLl8p384B8Ag== X-Received: by 2002:a17:90a:1785:: with SMTP id q5mr950338pja.106.1565198183794; Wed, 07 Aug 2019 10:16:23 -0700 (PDT) Received: from joelaf.cam.corp.google.com ([2620:15c:6:12:9c46:e0da:efbf:69cc]) by smtp.gmail.com with ESMTPSA id a1sm62692130pgh.61.2019.08.07.10.16.20 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Wed, 07 Aug 2019 10:16:23 -0700 (PDT) From: "Joel Fernandes (Google)" To: linux-kernel@vger.kernel.org Cc: "Joel Fernandes (Google)" , Alexey Dobriyan , Andrew Morton , Borislav Petkov , Brendan Gregg , Catalin Marinas , Christian Hansen , dancol@google.com, fmayer@google.com, "H. Peter Anvin" , Ingo Molnar , joelaf@google.com, Jonathan Corbet , Kees Cook , kernel-team@android.com, linux-api@vger.kernel.org, linux-doc@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, Michal Hocko , Mike Rapoport , minchan@kernel.org, namhyung@google.com, paulmck@linux.ibm.com, Robin Murphy , Roman Gushchin , Stephen Rothwell , surenb@google.com, Thomas Gleixner , tkjos@google.com, Vladimir Davydov , Vlastimil Babka , Will Deacon Subject: [PATCH v5 5/6] page_idle: Drain all LRU pagevec before idle tracking Date: Wed, 7 Aug 2019 13:15:58 -0400 Message-Id: <20190807171559.182301-5-joel@joelfernandes.org> X-Mailer: git-send-email 2.22.0.770.g0f2c4a37fd-goog In-Reply-To: <20190807171559.182301-1-joel@joelfernandes.org> References: <20190807171559.182301-1-joel@joelfernandes.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org During idle page tracking, we see that sometimes faulted anon pages are in pagevec but are not drained to LRU. Idle page tracking only considers pages on LRU. I am able to find multiple issues involving this. One issue looks like idle tracking is completely broken. It shows up in my testing as if a page that is marked as idle is always "accessed" -- because it was never marked as idle (due to not draining of pagevec). The other issue shows up as a failure during swapping (support for which this series adds), with the following sequence: 1. Allocate some pages 2. Write to them 3. Mark them as idle <--- fails 4. Introduce some memory pressure to induce swapping. 5. Check the swap bit I introduced in this series. <--- fails to set idle bit in swap PTE. To fix this, this patch drains all CPU's pagevec before starting idle tracking. Signed-off-by: Joel Fernandes (Google) --- mm/page_idle.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/mm/page_idle.c b/mm/page_idle.c index 2766d4ab348c..26440a497609 100644 --- a/mm/page_idle.c +++ b/mm/page_idle.c @@ -180,6 +180,13 @@ static ssize_t page_idle_bitmap_read(struct file *file, struct kobject *kobj, unsigned long pfn, end_pfn; int bit, ret; + /* + * Idle page tracking currently works only on LRU pages, so drain + * them. This can cause slowness, but in the future we could + * remove this operation if we are tracking non-LRU pages too. + */ + lru_add_drain_all(); + ret = page_idle_get_frames(pos, count, NULL, &pfn, &end_pfn); if (ret == -ENXIO) return 0; /* Reads beyond max_pfn do nothing */ @@ -211,6 +218,13 @@ static ssize_t page_idle_bitmap_write(struct file *file, struct kobject *kobj, unsigned long pfn, end_pfn; int bit, ret; + /* + * Idle page tracking currently works only on LRU pages, so drain + * them. This can cause slowness, but in the future we could + * remove this operation if we are tracking non-LRU pages too. + */ + lru_add_drain_all(); + ret = page_idle_get_frames(pos, count, NULL, &pfn, &end_pfn); if (ret) return ret; @@ -428,6 +442,13 @@ ssize_t page_idle_proc_generic(struct file *file, char __user *ubuff, walk.private = &priv; walk.mm = mm; + /* + * Idle page tracking currently works only on LRU pages, so drain + * them. This can cause slowness, but in the future we could + * remove this operation if we are tracking non-LRU pages too. + */ + lru_add_drain_all(); + down_read(&mm->mmap_sem); /* -- 2.22.0.770.g0f2c4a37fd-goog