From patchwork Wed Aug 19 04:27:22 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Duyck X-Patchwork-Id: 11722499 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id CD24F739 for ; Wed, 19 Aug 2020 04:27:27 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 90A5020772 for ; Wed, 19 Aug 2020 04:27:27 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Eoxng6/B" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 90A5020772 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id CDBB28D0008; Wed, 19 Aug 2020 00:27:26 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id C633A6B0036; Wed, 19 Aug 2020 00:27:26 -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 B523E8D0008; Wed, 19 Aug 2020 00:27:26 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0213.hostedemail.com [216.40.44.213]) by kanga.kvack.org (Postfix) with ESMTP id 9A0F76B0033 for ; Wed, 19 Aug 2020 00:27:26 -0400 (EDT) Received: from smtpin28.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 60F9F824805A for ; Wed, 19 Aug 2020 04:27:26 +0000 (UTC) X-FDA: 77166034092.28.store63_520f85d27025 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin28.hostedemail.com (Postfix) with ESMTP id 2E9F76C3B for ; Wed, 19 Aug 2020 04:27:26 +0000 (UTC) X-Spam-Summary: 1,0,0,5e884b3373084492,d41d8cd98f00b204,alexander.duyck@gmail.com,,RULES_HIT:41:152:355:379:960:973:988:989:1260:1277:1311:1313:1314:1345:1359:1431:1437:1515:1516:1518:1534:1541:1593:1594:1711:1730:1747:1777:1792:2198:2199:2393:2553:2559:2562:3138:3139:3140:3141:3142:3353:3865:3866:3867:3868:3870:3871:3872:3874:4250:4321:5007:6120:6261:6653:6742:7576:8660:8957:9413:10004:10128:10400:11026:11658:11914:12043:12296:12297:12438:12517:12519:12555:12679:12760:13069:13148:13161:13229:13230:13255:13311:13357:14096:14097:14181:14687:14721:21080:21444:21451:21627:21666:21939:30054:30090,0,RBL:209.85.222.193:@gmail.com:.lbl8.mailshell.net-62.18.0.100 66.100.201.100;04yfa4p8q1mcyhc5dom79n1yyzj3gyc51gk6hknm6wko4dffkpf7m4r48q3zcqg.8h9kuqauh7szb1s5gdkw659db3p7xj93ew6gc79gnccsp8ghas8i7gk9tmcw3b6.c-lbl8.mailshell.net-223.238.255.100,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fp,MSBL:0,DNSBL:neutral,Custom_rules:0:0:0,LFtime:24,LUA_SUMMARY:no ne X-HE-Tag: store63_520f85d27025 X-Filterd-Recvd-Size: 4999 Received: from mail-qk1-f193.google.com (mail-qk1-f193.google.com [209.85.222.193]) by imf01.hostedemail.com (Postfix) with ESMTP for ; Wed, 19 Aug 2020 04:27:25 +0000 (UTC) Received: by mail-qk1-f193.google.com with SMTP id b14so20519729qkn.4 for ; Tue, 18 Aug 2020 21:27:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:from:to:cc:date:message-id:in-reply-to:references :user-agent:mime-version:content-transfer-encoding; bh=T7hUYa5UogPv6sBfCV0FhXNPQBfOPqefw0rv85aPgto=; b=Eoxng6/BeOd5C+j6fxh7qVKG8VAHJChogDv9BN+ih1vUiDUYa428vI1Qr+RZbHjb+F z3PDkhrTAEWMFXQqqS47dXG8H6GuVtMQfIdV1JByxC7hytaIGD/THiPJiKiGDitv9Mu4 SF3IEcMaQ/mNQsTxJY6Sja8V162q2FroarImRxmS5HP5urBApgHmPQxX4t9Ai+lsXxSG OYKZmN1fuUCZoYCc/WUjYKRxEgh+BdWg8jQZdErGjvVfvxnfHHrBPVrpqC0lZKb0eTR+ n58O8F+j9uYedxQzKWsfe2axi/nAxCbseEV93iRLNiPzCtPxbpaHLF8Aslyd2pM2RZa+ 82Mw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:from:to:cc:date:message-id:in-reply-to :references:user-agent:mime-version:content-transfer-encoding; bh=T7hUYa5UogPv6sBfCV0FhXNPQBfOPqefw0rv85aPgto=; b=NOBZia7cifbGdS0HMrnC98pDiCKKhFRGA2RRa3uGLKWovpWIY26JZ/Pqnpz2/LECU/ FzOr4e6mzXu7dopx2mO/R+9RbXa5FetsxfWN2j68B6wKkK2nhhWATRag8LQjJd1ryKNR ziFykp00CQ0bclemnCX6KD2cRUqFcnCLAaoftfjXIZPaKVYc039V9olet5jpSuECwm7s bF6YzNjPPyqArOWkmnvoXqXkxtnencj+e+/kgBDnt/SbbcYdrKu2dQBK++TFC5P8jqND G6C8nyb67kuHS0dmnFJbugWHjnEt0rhCjQWDtYURh8UhLV+MstM2k/YIf/VHPcZQ2eFY SEsg== X-Gm-Message-State: AOAM530l3mtH940u5FvHfMYspeUYqKP69ePQQxUYhhHCfS4xBgrGN7jE 2oraxhh9NJTUwoygil2QPTY= X-Google-Smtp-Source: ABdhPJwjewQd6K+YoPWRo0i16OTkUs6Abew8umKdDVBaSIhn0FBlk9jhcWGGDVzESBeD13fateK8hQ== X-Received: by 2002:a37:bd46:: with SMTP id n67mr20703006qkf.190.1597811245192; Tue, 18 Aug 2020 21:27:25 -0700 (PDT) Received: from localhost.localdomain ([2001:470:b:9c3:9e5c:8eff:fe4f:f2d0]) by smtp.gmail.com with ESMTPSA id w58sm27335636qth.95.2020.08.18.21.27.23 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 18 Aug 2020 21:27:24 -0700 (PDT) Subject: [RFC PATCH v2 3/5] mm: Add explicit page decrement in exception path for isolate_lru_pages From: Alexander Duyck To: alex.shi@linux.alibaba.com Cc: yang.shi@linux.alibaba.com, lkp@intel.com, rong.a.chen@intel.com, khlebnikov@yandex-team.ru, kirill@shutemov.name, hughd@google.com, linux-kernel@vger.kernel.org, alexander.duyck@gmail.com, daniel.m.jordan@oracle.com, linux-mm@kvack.org, shakeelb@google.com, willy@infradead.org, hannes@cmpxchg.org, tj@kernel.org, cgroups@vger.kernel.org, akpm@linux-foundation.org, richard.weiyang@gmail.com, mgorman@techsingularity.net, iamjoonsoo.kim@lge.com Date: Tue, 18 Aug 2020 21:27:22 -0700 Message-ID: <20200819042722.23414.2654.stgit@localhost.localdomain> In-Reply-To: <20200819041852.23414.95939.stgit@localhost.localdomain> References: <20200819041852.23414.95939.stgit@localhost.localdomain> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-Rspamd-Queue-Id: 2E9F76C3B X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam05 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: From: Alexander Duyck In isolate_lru_pages we have an exception path where if we call get_page_unless_zero and that succeeds, but TestClearPageLRU fails we call put_page. Normally this would be problematic but due to the way that the calls are ordered and the fact that we are holding the LRU lock we know that the caller must be holding another reference for the page. Since we can assume that we can replace the put_page with a call to put_page_testzero contained within a WARN_ON. By doing this we should see if we ever leak a page as a result of the reference count somehow hitting zero when it shouldn't, and can avoid the overhead and confusion of using the full put_page call. Signed-off-by: Alexander Duyck Reviewed-by: Alex Shi --- mm/vmscan.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/mm/vmscan.c b/mm/vmscan.c index 5bc0c2322043..3ebe3f9b653b 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -1688,10 +1688,13 @@ static unsigned long isolate_lru_pages(unsigned long nr_to_scan, if (!TestClearPageLRU(page)) { /* - * This page may in other isolation path, - * but we still hold lru_lock. + * This page is being isolated in another + * thread, but we still hold lru_lock. The + * other thread must be holding a reference + * to the page so this should never hit a + * reference count of 0. */ - put_page(page); + WARN_ON(put_page_testzero(page)); goto busy; }