Received: by 2002:a25:e74b:0:0:0:0:0 with SMTP id e72csp1722496ybh; Thu, 16 Jul 2020 22:12:17 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzqersv2VQz4bU0kPZwRCFqZzNZa/syiwuQR3A4V4SwIZ6TQ2t7FH++CPgxb4L7Yu/R8eff X-Received: by 2002:a05:6402:49:: with SMTP id f9mr214846edu.112.1594962736830; Thu, 16 Jul 2020 22:12:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1594962736; cv=none; d=google.com; s=arc-20160816; b=XV/wEneF4vnoLoiLthYTXMiqoo96UHlGi4Wn3FUixQ4ip6yyZqOKtVEhnJTMpR89cg e7UWmpQn+j8482fsLtN6rN8kjF/bI/GIF1fSpbZebgmY9B61S7w3DgVMMvCSoGZKSqN+ E3S2trSUXXbAMHFft47XVpxqJbajuNuurICtEQpqWygYWCZ9/XeCFn7KKAge2qGdsGWm NBq/QKBbPSNyKB7O5IuPE37671Ph/n+NwCHRKd/4q1usZQGCfrRlt/CQcoYbSQW2vJ5U fjUrKqlodqc7I6QBpi8lCK8d7U/SM+pkzocFnUH+mtj6P3av/K95KgBEg9oytObPtYVN bwwg== 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:in-reply-to :mime-version:user-agent:date:message-id:from:references:cc:to :subject; bh=zuc82NGWOLZbfbtFDwLLrfQn0dMAklPGcMsjgJhgNvw=; b=0O3kHoPMfaNRz+2d+gNKkBoq6ArDk6F/xOmwlVgd0liM0mn/YT1AyzmoEMrEv5T2cn WHpnAoLUfFeRA4sCFjmehLRXrtUPJCFRNU8HNxMrt7UKJXinRUNkmVWkngGNjtV1H7b8 omyRyuSv2r6mpEJyvpmMPqHT4tIhWZbIgA+gWd2wf/olGi9mSpMmxYdDBKfTidp0Lvfr dmvEREhG7vKSYhHZAO8N5xuRXTGqPNEFfuLYhVvTHk//p2YVoGny0O+unvrkSibWwPNM lQo2E3iemqZggR4c/gz6mpcUrMPau+pEwaU/+4APLuPBkeD3OoNhUNuhwoVrCnPyflMf ju8w== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id j4si4707138edt.73.2020.07.16.22.11.53; Thu, 16 Jul 2020 22:12:16 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725999AbgGQFLC (ORCPT + 99 others); Fri, 17 Jul 2020 01:11:02 -0400 Received: from out30-42.freemail.mail.aliyun.com ([115.124.30.42]:46617 "EHLO out30-42.freemail.mail.aliyun.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725300AbgGQFLC (ORCPT ); Fri, 17 Jul 2020 01:11:02 -0400 X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R141e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=e01f04397;MF=alex.shi@linux.alibaba.com;NM=1;PH=DS;RN=18;SR=0;TI=SMTPD_---0U2ytDbF_1594962637; Received: from IT-FVFX43SYHV2H.local(mailfrom:alex.shi@linux.alibaba.com fp:SMTPD_---0U2ytDbF_1594962637) by smtp.aliyun-inc.com(127.0.0.1); Fri, 17 Jul 2020 13:10:38 +0800 Subject: Re: [PATCH v16 15/22] mm/compaction: do page isolation first in compaction To: Alexander Duyck 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" References: <1594429136-20002-1-git-send-email-alex.shi@linux.alibaba.com> <1594429136-20002-16-git-send-email-alex.shi@linux.alibaba.com> From: Alex Shi Message-ID: Date: Fri, 17 Jul 2020 13:09:43 +0800 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:68.0) Gecko/20100101 Thunderbird/68.7.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org >> @@ -950,6 +951,21 @@ static bool too_many_isolated(pg_data_t *pgdat) >> if (!(cc->gfp_mask & __GFP_FS) && page_mapping(page)) >> goto isolate_fail; >> >> + /* >> + * 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 isolate_fail; >> + >> + if (__isolate_lru_page_prepare(page, isolate_mode) != 0) >> + goto isolate_fail_put; >> + >> + /* Try isolate the page */ >> + if (!TestClearPageLRU(page)) >> + goto isolate_fail_put; >> + >> /* If we already hold the lock, we can skip some rechecking */ >> if (!locked) { >> locked = compact_lock_irqsave(&pgdat->lru_lock, > > Why not do the __isolate_lru_page_prepare before getting the page? > That way you can avoid performing an extra atomic operation on non-LRU > pages. > This change come from Hugh Dickins as mentioned from commit log: >> trylock_page() is not safe to use at this time: its setting PG_locked >> can race with the page being freed or allocated ("Bad page"), and can >> also erase flags being set by one of those "sole owners" of a freshly >> allocated page who use non-atomic __SetPageFlag(). Hi Hugh, would you like to show more details of the bug? ... >> + * 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; >> + } >> + > > I wonder if it wouldn't make sense to combine these two atomic ops > with tests and the put_page into a single inline function? Then it > could be possible to just do one check and if succeeds you do the > block of code below, otherwise you just fall-through into the -EBUSY > case. > Uh, since get_page changes page->_refcount, TestClearPageLRU changes page->flags, So I don't know how to combine them, could you make it more clear with code? Thanks Alex