Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp3752677ybl; Mon, 13 Jan 2020 01:57:25 -0800 (PST) X-Google-Smtp-Source: APXvYqwF32gkTT9nwH7y0sd/ttwITyQvzNa1kuU4deaeZxBoPBJYgwKkIGMECKNQeb1B5JfQ0WSj X-Received: by 2002:aca:b187:: with SMTP id a129mr12224872oif.175.1578909445302; Mon, 13 Jan 2020 01:57:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1578909445; cv=none; d=google.com; s=arc-20160816; b=H78qwW09gQoarR5ps0Fsw70KvFeOXHOlYQUlgXg32jvyAtQdiurewp6ZyiHS1NM2Bz qtaPv04DTb+NE8Du9jnT6ortJGzqZK/NqpojPQRrZJFvSXqCodvmFvhe1NkO5510ONjR sXjLbQrbiywtdiLaIZPbV9yFEuIQ0RO5UZ/bpjQMPIyIQK7L9BOXBThAPjCJ5c/A85km 4ECHLtCSpwMDRFY2MUTKdcH2gUFGeKRQP8GA8yiDqCdJvSpWoYgoB8oJBEjLlZJMh3IG ZeQ+6eck1KCutHvPUTMTJBq4JtAVYlKmoQGvuIRhXgy1MtNZtLd8qNPl2xsUeI5XgsMg TOWg== 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 :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:dkim-signature; bh=tfWEf85Tg93V8jfj/kRU8NVn5c39kp85P+atbWGt+tM=; b=cY78MkbShTX3BrhpIZYDha3RB23TFiIQ/M711YAs01kO1iimU5o7OEgABajAW5BL9W /AWRYHPYx4o8HWPEBEbxAtZqcpX43vvBm0Q1q/AjhEeQKClerGc/QLzIpbO1beBsG+/P Y3K90DzibOzhU9CFRnAjTq8dHMWo/UdhJ+gLWosU6op8zbkKWFwx3S64wcoJUypbzBt8 kdwufFDBq81EnuzIbqcxj050M8zu/0EDShUv7ftV/3MFYPC095S5EAmdYGzBCo/QB5Nv VrsZtTqVcXs3+I0IAYL8+EWxvCHKkMqeMXSSqUD+IPuY6La22okxnEjarpruvJDyHf6S LGCA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@yandex-team.ru header.s=default header.b=XmwXyts9; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=yandex-team.ru Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id n2si6312109otk.177.2020.01.13.01.57.13; Mon, 13 Jan 2020 01:57:25 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@yandex-team.ru header.s=default header.b=XmwXyts9; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=yandex-team.ru Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728669AbgAMJ4F (ORCPT + 99 others); Mon, 13 Jan 2020 04:56:05 -0500 Received: from forwardcorp1j.mail.yandex.net ([5.45.199.163]:38272 "EHLO forwardcorp1j.mail.yandex.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725992AbgAMJ4E (ORCPT ); Mon, 13 Jan 2020 04:56:04 -0500 Received: from mxbackcorp2j.mail.yandex.net (mxbackcorp2j.mail.yandex.net [IPv6:2a02:6b8:0:1619::119]) by forwardcorp1j.mail.yandex.net (Yandex) with ESMTP id 76AB82E0B1E; Mon, 13 Jan 2020 12:56:01 +0300 (MSK) Received: from vla5-58875c36c028.qloud-c.yandex.net (vla5-58875c36c028.qloud-c.yandex.net [2a02:6b8:c18:340b:0:640:5887:5c36]) by mxbackcorp2j.mail.yandex.net (mxbackcorp/Yandex) with ESMTP id 2kBEcgvne1-u0Luud4o; Mon, 13 Jan 2020 12:56:01 +0300 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1578909361; bh=tfWEf85Tg93V8jfj/kRU8NVn5c39kp85P+atbWGt+tM=; h=In-Reply-To:Message-ID:From:Date:References:To:Subject:Cc; b=XmwXyts9sUV12nUE4N1YSxf4tvNZDuR2Ax8TvGvRhsh26jDwzbTHtJ99/Mlp6VqtB /AYBkrEzUXcCxSzePb6NELBf292iLyFGmNdmZlMZGMCS1/0JVKkw2VGFtnDeFj+HEA Vxi2Izzl7c6DKKT3UT00eui5YKjhKoMkMkTm2wwY= Authentication-Results: mxbackcorp2j.mail.yandex.net; dkim=pass header.i=@yandex-team.ru Received: from dynamic-red.dhcp.yndx.net (dynamic-red.dhcp.yndx.net [2a02:6b8:0:40c:8448:fbcc:1dac:c863]) by vla5-58875c36c028.qloud-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id 6iOpZA3Dpj-txX0Y9uN; Mon, 13 Jan 2020 12:56:00 +0300 (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (Client certificate not present) Subject: Re: [PATCH v7 02/10] mm/memcg: fold lru_lock in lock_page_lru To: Alex Shi , cgroups@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, akpm@linux-foundation.org, mgorman@techsingularity.net, tj@kernel.org, hughd@google.com, daniel.m.jordan@oracle.com, yang.shi@linux.alibaba.com, willy@infradead.org, shakeelb@google.com, hannes@cmpxchg.org Cc: Michal Hocko , Vladimir Davydov References: <1577264666-246071-1-git-send-email-alex.shi@linux.alibaba.com> <1577264666-246071-3-git-send-email-alex.shi@linux.alibaba.com> <36d7e390-a3d1-908c-d181-4a9e9c8d3d98@yandex-team.ru> <952d02c2-8aa5-40bb-88bb-c43dee65c8bc@linux.alibaba.com> From: Konstantin Khlebnikov Message-ID: <2ba8a04e-d8e0-1d50-addc-dbe1b4d8e0f1@yandex-team.ru> Date: Mon, 13 Jan 2020 12:55:59 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.2.2 MIME-Version: 1.0 In-Reply-To: <952d02c2-8aa5-40bb-88bb-c43dee65c8bc@linux.alibaba.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-CA Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 13/01/2020 12.45, Alex Shi wrote: > > > 在 2020/1/10 下午4:49, Konstantin Khlebnikov 写道: >> On 25/12/2019 12.04, Alex Shi wrote: >>>  From the commit_charge's explanations and mem_cgroup_commit_charge >>> comments, as well as call path when lrucare is ture, The lru_lock is >>> just to guard the task migration(which would be lead to move_account) >>> So it isn't needed when !PageLRU, and better be fold into PageLRU to >>> reduce lock contentions. >>> >>> Signed-off-by: Alex Shi >>> Cc: Johannes Weiner >>> Cc: Michal Hocko >>> Cc: Matthew Wilcox >>> Cc: Vladimir Davydov >>> Cc: Andrew Morton >>> Cc: cgroups@vger.kernel.org >>> Cc: linux-mm@kvack.org >>> Cc: linux-kernel@vger.kernel.org >>> --- >>>   mm/memcontrol.c | 9 ++++----- >>>   1 file changed, 4 insertions(+), 5 deletions(-) >>> >>> diff --git a/mm/memcontrol.c b/mm/memcontrol.c >>> index c5b5f74cfd4d..0ad10caabc3d 100644 >>> --- a/mm/memcontrol.c >>> +++ b/mm/memcontrol.c >>> @@ -2572,12 +2572,11 @@ static void cancel_charge(struct mem_cgroup *memcg, unsigned int nr_pages) >>>     static void lock_page_lru(struct page *page, int *isolated) >>>   { >>> -    pg_data_t *pgdat = page_pgdat(page); >>> - >>> -    spin_lock_irq(&pgdat->lru_lock); >>>       if (PageLRU(page)) { >>> +        pg_data_t *pgdat = page_pgdat(page); >>>           struct lruvec *lruvec; >>>   +        spin_lock_irq(&pgdat->lru_lock); >> >> That's wrong. Here PageLRU must be checked again under lru_lock. > Hi, Konstantin, > > For logical remain, we can get the lock and then release for !PageLRU. > but I still can figure out the problem scenario. Would like to give more hints? That's trivial race: page could be isolated from lru between if (PageLRU(page)) and spin_lock_irq(&pgdat->lru_lock); > > >> >> >> Also I don't like these functions: >> - called lock/unlock but actually also isolates >> - used just once >> - pgdat evaluated twice > > That's right. I will fold these functions into commit_charge. > > Thanks > Alex >