Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp523058pxa; Wed, 19 Aug 2020 07:53:45 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwhgl0xaUqhrf3A+ByJ+9MXHtAnj1kCzHGnLBR0qG7qlYn4XWeFufP0+VBfRWm6Q6X8n/0S X-Received: by 2002:a17:906:f1da:: with SMTP id gx26mr4705233ejb.129.1597848824688; Wed, 19 Aug 2020 07:53:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597848824; cv=none; d=google.com; s=arc-20160816; b=EtX7wRK0pbIHd1tyxkAkOUQrOJ9r3GfYd5WyfDqbcK2VHACa+/mlNG5F2IKVg8k3rz 3BrkMs/yvS8qshErarStCcz7Xnrq5MR+uMUsSE1c6pZ8OCZmJ+2iLElXU+9DzD88cYEY BaYAdHt1wrq+0ZcCBjLuRoSyTHHBOLUHfgUZe8ea/79vCC1Me7mcvV/VDp2uM4vs9RKF SEAqgjepLbXbO9sBL5N2xtBG1IiPE3prFUYU+mj+ZkrzWzeElk8Em4fQOQOoGLj1Olxs nPqEf+i3mlifc9Zv1BjLchHjtNSOuYEw/n832k1KhsX0QHRbDDMhZYmH1f4kQqS0X8EE fAoA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=tScvbNwkYnRqhhATPJ7UjpnLY9tTLi+iAPlBc9rB3iY=; b=lvNvjXusA9DTpPeM0a6TqFJhbfp+0G0P8/Pc1NTUgZZ+3CzpgiWY6dDDKKoux1/ek6 lEr9fyJp/A2Fub0ilpRo4GqnOBCg+Yf3u8B09Y3/d4ayLhvcJ446OaZtEShPGV+ac/2x rGDAsog2NJfDfE2dS+ZxenL40/AGn5b0n+QSVqDqvFq6d8AvItNRWuqoh1bjQ132+tOb p2X7WTmesgrije6FN/BYxLWygbg/crwuMllv9k+p7epE0Zc0t16qPSt/5f8tWDia02pT LrxABICtbYQD0XbQ+cHGM/qqSxrlPBWk/Ya8J+3WSiNRrZTJWskX0gDe5MonxtfcW0fC p34A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=VNV2FDB4; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id f25si15656451eje.338.2020.08.19.07.53.20; Wed, 19 Aug 2020 07:53:44 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=VNV2FDB4; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728574AbgHSOwY (ORCPT + 99 others); Wed, 19 Aug 2020 10:52:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53992 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728415AbgHSOwV (ORCPT ); Wed, 19 Aug 2020 10:52:21 -0400 Received: from mail-il1-x141.google.com (mail-il1-x141.google.com [IPv6:2607:f8b0:4864:20::141]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0F36AC061757; Wed, 19 Aug 2020 07:52:21 -0700 (PDT) Received: by mail-il1-x141.google.com with SMTP id c6so20837595ilo.13; Wed, 19 Aug 2020 07:52:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=tScvbNwkYnRqhhATPJ7UjpnLY9tTLi+iAPlBc9rB3iY=; b=VNV2FDB4prOhD7krvEKqNRccc1tIE3ic5uWeIuDwt90ZWFOeL9havI3q4VWlHeDNlD uX4QctT6sFkcZWlNwOUZBAhC/iupzupsuaErPhzT+hlDNLUmnr4kgfjEGWXt8gMext8c cwcsyhcty5Qifn13F1KfJQf+979yllT0BJpyWnMYHpQWw+goI30FSA2OJ9jnDoHnwrvx idKl3jZ7EBFt5GgiHIEFz8JalGse5Hvwjr4tsZsSU9/99CqD/yc0FyUux/NERNg/tT9L /GQFmg6aYSFpKCG/utfJlBNzWbz8PKJEZx5Th8eOvf+1KdoanUNVoXNh55++qa10pIl2 gQIA== 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:content-transfer-encoding; bh=tScvbNwkYnRqhhATPJ7UjpnLY9tTLi+iAPlBc9rB3iY=; b=du2HVlkan4dCRHjafxmN7BOGR3/rnqPfFbCr/hHZZ+deGBusVaxsxe+BD3vtpbNkv4 s8uUqWuQmgvj1k3rB4OUCHdLEOqhOopGp2e2ziflDxDtCCj/hZNJ4Bekhy6ZNj81sQ0B i3iH6vHVbgVASJDaCX1BEJz57JIcSKiqYWYOu1O9VfLlFcAqH0eF7KftXfhA3JNndyIw OHTSivjT2b111aE8ENxQ5zFQu5C9+ws6wAyIz6ny1txNy8qhwMpirxk5zT5YmR1to5K2 f6LyKTcPUN674xPNse+z/UykM6GXmf2csBJJnZ3ZBqZB3ENMEGzbrF8x50Ynqj755u74 128g== X-Gm-Message-State: AOAM53328STxgxRxBpWL2LCgaJ/lTNkViPgaEtFja4CNZ4vuSVZeIKWt TQTdx65hom+uQo9n6tbciEbHwQrU/I20X49AUJQ= X-Received: by 2002:a92:99d4:: with SMTP id t81mr10297363ilk.95.1597848740262; Wed, 19 Aug 2020 07:52:20 -0700 (PDT) MIME-Version: 1.0 References: <20200819041852.23414.95939.stgit@localhost.localdomain> <20200819042722.23414.2654.stgit@localhost.localdomain> In-Reply-To: From: Alexander Duyck Date: Wed, 19 Aug 2020 07:52:09 -0700 Message-ID: Subject: Re: [RFC PATCH v2 3/5] mm: Add explicit page decrement in exception path for isolate_lru_pages To: Alex Shi Cc: Yang Shi , kbuild test robot , Rong Chen , Konstantin Khlebnikov , "Kirill A. Shutemov" , Hugh Dickins , LKML , Daniel Jordan , linux-mm , Shakeel Butt , Matthew Wilcox , Johannes Weiner , Tejun Heo , cgroups@vger.kernel.org, Andrew Morton , Wei Yang , Mel Gorman , Joonsoo Kim Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Aug 19, 2020 at 12:52 AM Alex Shi wrot= e: > > > > =E5=9C=A8 2020/8/19 =E4=B8=8B=E5=8D=8812:27, Alexander Duyck =E5=86=99=E9= =81=93: > > 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 c= all > > put_page. Normally this would be problematic but due to the way that th= e > > 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 w= e > > 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 s= ee > > if we ever leak a page as a result of the reference count somehow hitti= ng > > zero when it shouldn't, and can avoid the overhead and confusion of usi= ng > > the full put_page call. > > > > Signed-off-by: Alexander Duyck > > --- > > 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. Th= e > > + * other thread must be holding a referen= ce > > + * to the page so this should never hit a > > + * reference count of 0. > > */ > > - put_page(page); > > + WARN_ON(put_page_testzero(page)); > > seems WARN_ON is always enabled. > > Reviewed-by: Alex Shi Yeah, it is always enabled however it should never be triggered. I had considered just putting a page_ref_dec here since in theory this path should never be triggered but I thought as a debug catch I add the WARN_ON and put_page_testzero. If we ever do encounter this being triggered then it will leak a page of memory which isn't the end of the world but I thought would warrant a WARN_ON.