From patchwork Thu May 31 19:34:20 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ivan Kalvachev X-Patchwork-Id: 10441897 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 8756E602BD for ; Thu, 31 May 2018 19:34:51 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7A665290D8 for ; Thu, 31 May 2018 19:34:51 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6ED42290EA; Thu, 31 May 2018 19:34:51 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 099D4290D8 for ; Thu, 31 May 2018 19:34:50 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9B3086B0005; Thu, 31 May 2018 15:34:49 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 962306B0006; Thu, 31 May 2018 15:34:49 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 852DA6B0007; Thu, 31 May 2018 15:34:49 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-wr0-f198.google.com (mail-wr0-f198.google.com [209.85.128.198]) by kanga.kvack.org (Postfix) with ESMTP id 2590E6B0005 for ; Thu, 31 May 2018 15:34:49 -0400 (EDT) Received: by mail-wr0-f198.google.com with SMTP id 44-v6so17697085wrt.9 for ; Thu, 31 May 2018 12:34:49 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:dkim-signature:from:to:cc:subject:date :message-id; bh=ot1HoePPVZS62dxxQuYNZ0A+5UXliHYlhcit1rSvkaM=; b=jO89CqPHr3QtkE2N6qUkHsHUvRDop+x9cvQWxTJyDSevrJkbfGCxycvQK1hlqmyT0x 6zku58FF9lHQL0g9cx4G83S2Fg/0GssKqJcYqLhvSzAHlDQqzFjEnkBI+J+Di7aqU7Qa Xk5YnTZhsZwv2zhlaM2Ni6UhQkjfWMrrPu50xUGFQ29gGXRyBqvf207UYIchQgozU1HU lAG8dKVLYbul9693FkIMu2gzFX2Cm381vbHQixf9z1/8iBM+RWHP9sRHJj9QskHqKHA2 SrtjDfH1KO8vPjn/Ydw4t082LCbxiof0eS3JTmEYqSQHewE2O5WdeoKsBp3xPL7N+7OP 6AKg== X-Gm-Message-State: ALKqPweADQzkOQjPD4hZHPszmZfJW9ckr4oRQGDN01gsgyLpINNXTNou VprXF+50NuCPb8/7qB8t7kESesz0ZjDfWgAuH4bLVuhpbLBHPYFeYMYttoW0YEkGC7VY9R7MkPY dEgF8SMErJ6VY98xzvdy6zlHexatiigYlVgk3uX4cdwXVlN93UB5RKZgx6fzUgg4S+WAgei7vFK woY9J9I7uc9ftey8aHfazKJNV4kwX4iEEFrm5DVYzGEgGRG3zaGTRr+aK49ClyVYdaD6ukP4wLd cDWaVRdoDfgNZbLfvYfBhAr0i6wRT+STVHQLh4GvZS6P6hA6WJvuZmqMU3H6ZCHNwiGoFzx8n/T 7HZ6k47AC75gccZPBaOJ7YI4UVXlKIY6w0448orhsIPGqrY9LaFSFFnYbI7JepKwKU2zhqWRtPX I X-Received: by 2002:adf:9302:: with SMTP id 2-v6mr6283002wro.175.1527795288453; Thu, 31 May 2018 12:34:48 -0700 (PDT) X-Received: by 2002:adf:9302:: with SMTP id 2-v6mr6282971wro.175.1527795287646; Thu, 31 May 2018 12:34:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527795287; cv=none; d=google.com; s=arc-20160816; b=VgfKE2YEeKnqW6e09qtXSo76WkFy12H/ibnIBnewWkJn3fjfrW651UAst1gNbGbNaW uoEgjPNAibrc1PeDPl50gE1fPgmIFGlaUjDyxj6KoKvL23sHiFPvf8oo3TWwfLLgyMuw X/Oio2J7w6hdnMN0wsQ19W/E7WGbgl8dZ9cVBUDmjmEUw99mffWMCKlxprsDJ1KGtrNO OfJJNH942VJnQ/iHnaKbjzQLZtU+kCOET8cmXRzjE3bsUdCWCQdWicZUzM64Ief8xxft eubKs2PChsN6zUMshGA+oEbFrTn/mK4bOkPr8r5YJW59ppvrQY3XQuVZcovseUjbrFYh Xpzg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=message-id:date:subject:cc:to:from:dkim-signature :arc-authentication-results; bh=ot1HoePPVZS62dxxQuYNZ0A+5UXliHYlhcit1rSvkaM=; b=t/1o5woYrJ0LdlXjYsgwS9yDwnHjS3zmv6FkWXoEgsQGrqLlkACltEHlkUabu4/QGc eGx2Yl1Xt/3qE/2s/mgqTka7L6Q9xtJvPhMc7JFmdHc1a098md7IT/a2KrxZ999lz5+h 49Aff/OfKf8sWRGGkNi68lJZ3EIVvAC/NITr8RNgXTxIxZnKIjcPvzV/5haoQ6j6sf7C Sgy6YjdQBeqEFKAZq3T5H/G15Qcp5YlkFibCds8w1AjxNjAwSCUudXrsS/1Et/GnpOYt EF0q+H3KrPsPyKBL2ZZ8SzWCC/CWNAUbw2V9WRfV0K2zvYOO+kUtpk0sKtXTgNj4MLRU x60A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=eoMML4s9; spf=pass (google.com: domain of ikalvachev@gmail.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=ikalvachev@gmail.com; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id g9-v6sor1014426wrp.71.2018.05.31.12.34.47 for (Google Transport Security); Thu, 31 May 2018 12:34:47 -0700 (PDT) Received-SPF: pass (google.com: domain of ikalvachev@gmail.com designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=eoMML4s9; spf=pass (google.com: domain of ikalvachev@gmail.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=ikalvachev@gmail.com; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=ot1HoePPVZS62dxxQuYNZ0A+5UXliHYlhcit1rSvkaM=; b=eoMML4s9RcFr0biD1OySFqaX3lB6lLYiupf6TROwDAKYBv7u2TyqxVpkq+UDHOrxwr iEVapsyLegvED33uNqjWmxvlx5skniWiCAxEspxLBuPbLeVqLnLwWo73GYjOtp1/ArAt sV33uCl25ZUq7kyNaRJtd2n46+gr9UV4LKLlKy6wiiRbJG6VNRGoI9Kc/69Lu0nf9b4j O0qM6V2aEcnHyJdfP+jdlIB00GiMl/9+4KLjXho0eGWYoYbugJuI+l11ry8GrXwwE9mJ Zlq2jUojCNym4JzTBIwPNcJAocIyGqvcaX5uW4cR5KDARtSWSZ1XvBpjsoSJzLiSHv74 8xBQ== X-Google-Smtp-Source: ADUXVKLq4/N3hOcDXbPbf8kk2pl1LtUPfO16EXZ0VH6/Ufqotn4XJFKC7PsgdFO3mK4BLBkAqR9niA== X-Received: by 2002:adf:ed52:: with SMTP id u18-v6mr5766846wro.262.1527795286749; Thu, 31 May 2018 12:34:46 -0700 (PDT) Received: from clarkdale64.home.bg (87.119.101.204.client.entry.bg. [87.119.101.204]) by smtp.gmail.com with ESMTPSA id k28-v6sm51320661wrk.46.2018.05.31.12.34.45 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 31 May 2018 12:34:45 -0700 (PDT) From: Ivan Kalvachev To: linux-mm@kvack.org Cc: Ivan Kalvachev Subject: [PATCH] mm: fix kswap excessive pressure after wrong condition transfer Date: Thu, 31 May 2018 22:34:20 +0300 Message-Id: <20180531193420.26087-1-ikalvachev@gmail.com> X-Mailer: git-send-email 2.17.1 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: X-Virus-Scanned: ClamAV using ClamSMTP Fixes commit 69d763fc6d3aee787a3e8c8c35092b4f4960fa5d (mm: pin address_space before dereferencing it while isolating an LRU page) working code: mapping = page_mapping(page); if (mapping && !mapping->a_ops->migratepage) return ret; buggy code: if (!trylock_page(page)) return ret; mapping = page_mapping(page); migrate_dirty = mapping && mapping->a_ops->migratepage; unlock_page(page); if (!migrate_dirty) return ret; The problem is that !(a && b) = (!a || !b) while the old code was (a && !b). The commit message of the buggy commit explains the need for locking/unlocking around the check but does not give any reason for the change of the condition. It seems to be an unintended change. The result of that change is noticeable under swap pressure. Big memory consumers like browsers would have a lot of pages swapped out, even pages that are been used actively, causing the process to repeatedly block for second or longer. At the same time there would be gigabytes of unused free memory (sometimes half of the total RAM). The buffers/cache would also be at minimum size. Fixes: 69d763fc6d3a ("mm: pin address_space before dereferencing it while isolating an LRU page") Signed-off-by: Ivan Kalvachev --- mm/vmscan.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mm/vmscan.c b/mm/vmscan.c index 9b697323a88c..83df26078d13 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -1418,9 +1418,9 @@ int __isolate_lru_page(struct page *page, isolate_mode_t mode) return ret; mapping = page_mapping(page); - migrate_dirty = mapping && mapping->a_ops->migratepage; + migrate_dirty = mapping && !mapping->a_ops->migratepage; unlock_page(page); - if (!migrate_dirty) + if (migrate_dirty) return ret; } }