Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp2678664pxa; Mon, 17 Aug 2020 16:23:38 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxwZDyrvq/4wdEaM/Mxpd8sj7p2rz+bafQCWUF3vRr0ooD3uEmkQeDk33hICvfLEXTskw+s X-Received: by 2002:a50:fc02:: with SMTP id i2mr17355733edr.121.1597706618445; Mon, 17 Aug 2020 16:23:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597706618; cv=none; d=google.com; s=arc-20160816; b=TDNM5dmoGI0Md3xbNXENOAlZ7G6FQgB2Ve42JjFBbVw9vTi0eY58/mhsEvoMwWoa2C kWcI3GY61hWqek0hIIzl4YC8+PFy/+lhGHqu0hA2dtIdVzC3GXBG/KR38LXZIpt4+Y0E ahn3BtBG627sJk6FBpeH0/PalrsXVhDT1WYTOhvlpC4cIUFSJltL+hHYufY+pTiTbIyh Vfk9xYs2ltq7mxTRLpSAqRGZ4pKIuVFDFY4MkOkJExCfF8kIox17Djm+oRW+nhPpNvNc vXwJve6opAZinBWALHCLbeAWKYEeeOCQQ3eSnOaYcWFMC9rakMxUS9SQId2knqqyv9eL mqrw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=CUinOKHyVodz4jvTS1Tm95hUcIyZXDORsxNhMipeHNI=; b=nHloNtMD0P+b5Vicy3Q2HlUlKeF4+UrJMXDZAUPyeE7s1qiZdd3Vu1FlsP5JjWB0rh i6BDX95gIOED4KLGC+b9pHGDqwfq/hUdBd2D7mCvzhTfKuFwrydnCF9maFGD3PBQENAM So/hkBMFtScxMu7wFYMLz/P5H6NfJh8L39w3Rjch168s+Cc+WnOuNuTeqgxRaatomSYI BPDQU27Fyv112DWLvkoO0f0ABz++Pmu8ZjNe50x11zuaPo/AF2c5DbWaE7VwlsnZV1yI xIEdxSzzCaQPUoOSyAGAVQstBcD5rqlvWepyfN7mVu6qjogPBwFZnH6soQUWcacGD+8G iAEA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=byIpvA6P; 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 a7si12147050ejd.422.2020.08.17.16.23.14; Mon, 17 Aug 2020 16:23:38 -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=byIpvA6P; 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 S1728027AbgHQW6b (ORCPT + 99 others); Mon, 17 Aug 2020 18:58:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47504 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727966AbgHQW62 (ORCPT ); Mon, 17 Aug 2020 18:58:28 -0400 Received: from mail-io1-xd41.google.com (mail-io1-xd41.google.com [IPv6:2607:f8b0:4864:20::d41]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6C41AC061389; Mon, 17 Aug 2020 15:58:27 -0700 (PDT) Received: by mail-io1-xd41.google.com with SMTP id u126so19218794iod.12; Mon, 17 Aug 2020 15:58:27 -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; bh=CUinOKHyVodz4jvTS1Tm95hUcIyZXDORsxNhMipeHNI=; b=byIpvA6PXapCvY4kbX9hsHPmMFKCY69IW6PMIvbws4/x8AN3hC6qzvqvx9OoH0NDvs K0+ur+V+gik/czeG85229oQgaJMslt/bpivK5ELrz0IRun/ymrxVU3pKlTz/rce9mJT5 oQ+qmEmqZJ48NuA2NMUtEhzYNqRqAcKYfhLcV6LSxNzWtoCVDiosbiVVcrX7w+BkVx1w 884NUizKW61AP8E0defZhjbkHF3jdtVA3osKGJbKcWwqHVB4nLH36OeiyJh5y2sxkp1Z XPcZiDkxup87SeHU138rtD0cipsLApPga25ffrPjsj7opfL3vKkN2yGeFCUprlbS0XDQ pbpA== 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; bh=CUinOKHyVodz4jvTS1Tm95hUcIyZXDORsxNhMipeHNI=; b=dNn8LM8+aKlIFOy4t5rlHqvyo1OLYMO/f+Yjsz1lrIS7j6teRdwPAHBET08B6Jkq/k wf5SwB/DwfW0UnWdSWZ+Sy8VQY2ruA060k5fnTfgDnELiMuwbtPQo5+0pnelgeVajJF0 4pk6PRyTXmaDxHv9OS48TFdVdhfL3muaIVdAUuz3Z8nMWXY1AWVxdh5RxAXBYDph6bnQ 8iawP5DDbpOF40LpYpfQSKO+GC/Qivb6xIyFpJCIyO05X/mmO+ww+DVsQAzueTUeNSdo MxsBENKJsJUs2IWLQKKKyk4VLKNwLIklcF5Plfmp6+/TGA+iBk1HOq3PASoCIVqHJt3R Wo9g== X-Gm-Message-State: AOAM532XLtrIqUEdX7/eSoa/8OWzhus9t2XRKiBQ3rqmIixmIXTK6Cxn FjTZ8/Ty8G2OMO1hgayCW1X94hAMn8CLdWDRBSA= X-Received: by 2002:a05:6638:1508:: with SMTP id b8mr16744973jat.96.1597705106519; Mon, 17 Aug 2020 15:58:26 -0700 (PDT) MIME-Version: 1.0 References: <1595681998-19193-1-git-send-email-alex.shi@linux.alibaba.com> <1595681998-19193-15-git-send-email-alex.shi@linux.alibaba.com> In-Reply-To: <1595681998-19193-15-git-send-email-alex.shi@linux.alibaba.com> From: Alexander Duyck Date: Mon, 17 Aug 2020 15:58:15 -0700 Message-ID: Subject: Re: [PATCH v17 14/21] mm/compaction: do page isolation first in compaction To: Alex Shi Cc: Andrew Morton , Mel Gorman , Tejun Heo , Hugh Dickins , Konstantin Khlebnikov , Daniel Jordan , Yang Shi , Matthew Wilcox , Johannes Weiner , kbuild test robot , linux-mm , LKML , cgroups@vger.kernel.org, Shakeel Butt , Joonsoo Kim , Wei Yang , "Kirill A. Shutemov" , Rong Chen Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org > @@ -1691,17 +1680,34 @@ static unsigned long isolate_lru_pages(unsigned long nr_to_scan, > * only when the page is being freed somewhere else. > */ > scan += nr_pages; > - switch (__isolate_lru_page(page, mode)) { > + switch (__isolate_lru_page_prepare(page, mode)) { > case 0: > + /* > + * Be careful not to clear PageLRU until after we're > + * sure the page is not being freed elsewhere -- the > + * page release code relies on it. > + */ > + if (unlikely(!get_page_unless_zero(page))) > + goto busy; > + > + if (!TestClearPageLRU(page)) { > + /* > + * This page may in other isolation path, > + * but we still hold lru_lock. > + */ > + put_page(page); > + goto busy; > + } > + So I was reviewing the code and came across this piece. It has me a bit concerned since we are calling put_page while holding the LRU lock which was taken before calling the function. We should be fine in terms of not encountering a deadlock since the LRU bit is cleared the page shouldn't grab the LRU lock again, however we could end up grabbing the zone lock while holding the LRU lock which would be an issue. One other thought I had is that this might be safe because the assumption would be that another thread is holding a reference on the page, has already called TestClearPageLRU on the page and retrieved the LRU bit, and is waiting on us to release the LRU lock before it can pull the page off of the list. In that case put_page will never decrement the reference count to 0. I believe that is the current case but I cannot be certain. I'm just wondering if we should just replace the put_page(page) with a WARN_ON(put_page_testzero(page)) and a bit more documentation. If I am not mistaken it should never be possible for the reference count to actually hit zero here. Thanks. - Alex