From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.9 required=3.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1,USER_IN_DEF_DKIM_WL autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5D68AC432C3 for ; Sat, 23 Nov 2019 00:58:51 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 12E5320714 for ; Sat, 23 Nov 2019 00:58:51 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="SWT9RPbb" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 12E5320714 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 9F8F56B053A; Fri, 22 Nov 2019 19:58:50 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 9A98F6B053B; Fri, 22 Nov 2019 19:58:50 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 871716B053C; Fri, 22 Nov 2019 19:58:50 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0208.hostedemail.com [216.40.44.208]) by kanga.kvack.org (Postfix) with ESMTP id 6E99E6B053A for ; Fri, 22 Nov 2019 19:58:50 -0500 (EST) Received: from smtpin05.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with SMTP id 1B165181AEF1D for ; Sat, 23 Nov 2019 00:58:50 +0000 (UTC) X-FDA: 76185732420.05.skin79_6a28fcaed9f07 X-HE-Tag: skin79_6a28fcaed9f07 X-Filterd-Recvd-Size: 7370 Received: from mail-pf1-f195.google.com (mail-pf1-f195.google.com [209.85.210.195]) by imf29.hostedemail.com (Postfix) with ESMTP for ; Sat, 23 Nov 2019 00:58:49 +0000 (UTC) Received: by mail-pf1-f195.google.com with SMTP id c184so4381156pfb.0 for ; Fri, 22 Nov 2019 16:58:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:from:to:cc:subject:in-reply-to:message-id:references :user-agent:mime-version; bh=IuWeFnrYeJCjuhCM2V1dA58lGjRpOtXacus/IBoPj+E=; b=SWT9RPbbH0wqbnY590Ng1zNYJSEYMwqyk2hjYVStgfe3cn8J9xhspUE/IhAhMyiyYF ITsmkvVswijzNTydtgsNqLfWO5AlPmHZfgbeP/ck3vqmG8WD1AthVOBjQq/7wIxhNj6N IhmPbMJDedgw7loa0CC2hR6GkM41ieeXfMen6GAXTZZY2Y0aEjcK/Bj1BejspvEmOXyA zo/hn1dh/4KxioncezIii0LXRSfDqEwYu6VZbBVGOhhR7OLAyWwJhZLPdB9oGfMaULZa gsxPSmoSKUVsQOHxRh4sawj5xROFzr/xaOzGB7fddbIKF3FVjM+LXYaqj5zXQ27i30Lz iu+g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:in-reply-to:message-id :references:user-agent:mime-version; bh=IuWeFnrYeJCjuhCM2V1dA58lGjRpOtXacus/IBoPj+E=; b=t9oW/mBufw7bu9bIs6P+LO12m3NtyWmGVAhpbM0NlQ5UbUc+DtrievFRNWIyuJbtZu 95HN/gDNvE15enx/h648MjnRV40rATO2loVO/vaDMh10gaWYnctwi2n0lGOnjvFcAYqG VYOfVRUSGfrAzV+kMNW43NPIQ5g4m8OcmxgbAfu89OKQTBqPCke0aGVoi/W1oYH+ucK8 hDc1VUiVgtTW1SlBY4eaKWdiUe9errhVB893+3nWeqq2/i396TYZB4RtPgAold5rXeeY z3Togxm4Hov7kQuDwmQYrhJxQsgF5YSwe3o8lmU1Lx3bDS9Xnb5ntd+GVdahYVOMwmP0 pryg== X-Gm-Message-State: APjAAAWaTgHrZvjcGlMlApk0zEocKHYSI0pfVK8gKb6YV/EITK52JI61 Wb3TnLKKo/ZEPUoerVWbwu3OMw== X-Google-Smtp-Source: APXvYqz0ZXll8DZmCwf0ofv4uPNO7sFTvsQEUZIIytWRI6hPkiIhvNBJyAjp5BS/LzwHLnPhFD8fWw== X-Received: by 2002:a63:fb04:: with SMTP id o4mr1513860pgh.122.1574470727152; Fri, 22 Nov 2019 16:58:47 -0800 (PST) Received: from [100.112.92.218] ([104.133.9.106]) by smtp.gmail.com with ESMTPSA id w69sm9117470pfc.164.2019.11.22.16.58.45 (version=TLS1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 22 Nov 2019 16:58:46 -0800 (PST) Date: Fri, 22 Nov 2019 16:58:34 -0800 (PST) From: Hugh Dickins X-X-Sender: hugh@eggly.anvils To: Johannes Weiner cc: 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, khlebnikov@yandex-team.ru, daniel.m.jordan@oracle.com, yang.shi@linux.alibaba.com, willy@infradead.org, shakeelb@google.com, Michal Hocko , Vladimir Davydov , Roman Gushchin , Chris Down , Thomas Gleixner , Vlastimil Babka , Qian Cai , Andrey Ryabinin , "Kirill A. Shutemov" , Jerome Glisse , Andrea Arcangeli , David Rientjes , "Aneesh Kumar K.V" , swkhack , "Potyra, Stefan" , Mike Rapoport , Stephen Rothwell , Colin Ian King , Jason Gunthorpe , Mauro Carvalho Chehab , Peng Fan , Nikolay Borisov , Ira Weiny , Kirill Tkhai , Yafang Shao Subject: Re: [PATCH v4 3/9] mm/lru: replace pgdat lru_lock with lruvec lock In-Reply-To: <20191122161652.GA489821@cmpxchg.org> Message-ID: References: <1574166203-151975-1-git-send-email-alex.shi@linux.alibaba.com> <1574166203-151975-4-git-send-email-alex.shi@linux.alibaba.com> <20191119160456.GD382712@cmpxchg.org> <20191121220613.GB487872@cmpxchg.org> <20191122161652.GA489821@cmpxchg.org> User-Agent: Alpine 2.11 (LSU 23 2013-08-11) MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII 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: On Fri, 22 Nov 2019, Johannes Weiner wrote: > > But that leaves me with one more worry: compaction. We locked out > charge moving now, so between that and knowing that the page is alive, > we have page->mem_cgroup stable. But compaction doesn't know whether > the page is alive - it comes from a pfn and finds out using PageLRU. > > In the current code, pgdat->lru_lock remains the same before and after > the page is charged to a cgroup, so once compaction has that locked > and it observes PageLRU, it can go ahead and isolate the page. > > But lruvec->lru_lock changes during charging, and then compaction may > hold the wrong lock during isolation: > > compaction: generic_file_buffered_read: > > page_cache_alloc() > > !PageBuddy() > > lock_page_lruvec(page) > lruvec = mem_cgroup_page_lruvec() > spin_lock(&lruvec->lru_lock) > if lruvec != mem_cgroup_page_lruvec() > goto again > > add_to_page_cache_lru() > mem_cgroup_commit_charge() > page->mem_cgroup = foo > lru_cache_add() > __pagevec_lru_add() > SetPageLRU() > > if PageLRU(page): > __isolate_lru_page() > > I don't see what prevents the lruvec from changing under compaction, > neither in your patches nor in Hugh's. Maybe I'm missing something? Speaking for my patches only: I'm humbled, I think you have caught me, I cannot find any argument against the race you suggest here. The race with mem_cgroup_move_account(), which Konstantin pointed out in 2012's https://lore.kernel.org/lkml/4F433418.3010401@openvz.org/ but I later misunderstood, and came to think I needed no patch against, until this week coming to perceive the same race in isolate_lru_page(): that one is easily and satisfactorily fixed by holding lruvec lock in mem_cgroup_move_account() - embarrassing, but not too serious. Your race here (again, lruvec lock taken then PageLRU observed, but page->mem_cgroup changed in between) really questions my whole scheme: I am not going to propose a solution now, I'll have to go back and recheck my assumptions all over. Certainly isolate_migratepage_block() has a harder job than any other, but I need to re-review it all. Maybe we got it right back in the days of PageCgroupUsed, and then I paid too little attention when rebasing to your welcome simplifications. I don't think any of us want to bring back PageCgroupUsed! And maybe we could get it right by always holding lruvec lock in commit_charge(), lrucare or not; but that's a much hotter path, and not a change I'd expect anyone to embrace. I'll go away and re-examine it all; probably start by verifying that your race actually happens in practice, though we never observed it. Heavy-hearted thanks, Hannes! Hugh