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=-12.9 required=3.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1, USER_IN_DEF_DKIM_WL autolearn=unavailable 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 54570C33CB3 for ; Fri, 17 Jan 2020 19:11:09 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id E231A20728 for ; Fri, 17 Jan 2020 19:11:08 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="DLepnDTO" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org E231A20728 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 4B1986B04DD; Fri, 17 Jan 2020 14:11:08 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 461846B04DE; Fri, 17 Jan 2020 14:11:08 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3770F6B04DF; Fri, 17 Jan 2020 14:11:08 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0098.hostedemail.com [216.40.44.98]) by kanga.kvack.org (Postfix) with ESMTP id 1FE576B04DD for ; Fri, 17 Jan 2020 14:11:08 -0500 (EST) Received: from smtpin08.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with SMTP id AD86E824805A for ; Fri, 17 Jan 2020 19:11:07 +0000 (UTC) X-FDA: 76388068974.08.test39_26e011238650a X-HE-Tag: test39_26e011238650a X-Filterd-Recvd-Size: 7649 Received: from mail-pl1-f195.google.com (mail-pl1-f195.google.com [209.85.214.195]) by imf18.hostedemail.com (Postfix) with ESMTP for ; Fri, 17 Jan 2020 19:11:07 +0000 (UTC) Received: by mail-pl1-f195.google.com with SMTP id g6so10232997plp.6 for ; Fri, 17 Jan 2020 11:11:06 -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=ddh+J1aNApjVpqxRphFgI91ytuMiQu7DUUqdaf2bvPs=; b=DLepnDTOCwEvanSytGMrHpz+NjlAgL2dcwQ39A7BTwc8s8FXc0BaZ7AlHWmcIkt9U9 sCwIONzWg9+3KzSljhS98LitF3p0pltTBLulgZDkl3msMeZJ2jrgrmWLG6EGUlAVQ1Vv QgyeAJSi6uecYBlxuzQG40GSKW165jtPxrSSO5s889P/gq8XFoBW2geGkyzrQ/V8ntJJ XMXCVexiShBajVAtI3kqmV4oy15aVW5Im3YeaBaAGctjn3p8SGciD50nMOfQfZgXpLuG 1lUayirspJWsOtQPQ+LLAq52zCfrBKZJoM0p6m8qNpuBwdy2x8ksgsTLnSwiyFmkqbnX dcpw== 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=ddh+J1aNApjVpqxRphFgI91ytuMiQu7DUUqdaf2bvPs=; b=Y6+ZebfUPxPaF6N67rTRn/L0buJt7mVXgFNrv3WMOvAJ3/4irxvGc/pkrnfV3Godqd eoNEH+UWA05APdF4LjV4Hx2a2v/GVBSsdgYetb5NpF2agfzkTXynk5qaU9LeuFevgIlh sgus9ihkA1FTocKQLdZkuEL//t7c1j4c5R52kMYmYXdZ8bi91PUll0Y5PLNKtf1h2mEX 0VZuxMBsUFCl7hhQq8WbZh2GpiYDpa+HnhkN5yxszrvSWwted9i2gluOkuFZ9uWckZCn qkUuPSRA+H2uVN/hUGGtOuwhQyBzXED6nsjpGzB7YOqO79BfIdYphJnOJXenmPVZfAxt mUeg== X-Gm-Message-State: APjAAAV/vOnpu9AjrVU0wPZoT8Kz28z8+g0ahqluGOUSX37LwNwp+EL2 cDrPXctwyNinov9fvw9m3FVz1g== X-Google-Smtp-Source: APXvYqzdNSS5A2A8ttf6eq9zuCpovcga8x+VM76dxFBLeN+NunYP6bxDWbzwk2CpJUlya2rtbGf8fQ== X-Received: by 2002:a17:902:10e:: with SMTP id 14mr660521plb.122.1579288265782; Fri, 17 Jan 2020 11:11:05 -0800 (PST) Received: from [2620:15c:17:3:3a5:23a7:5e32:4598] ([2620:15c:17:3:3a5:23a7:5e32:4598]) by smtp.gmail.com with ESMTPSA id i23sm29833186pfo.11.2020.01.17.11.11.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 Jan 2020 11:11:05 -0800 (PST) Date: Fri, 17 Jan 2020 11:11:04 -0800 (PST) From: David Rientjes X-X-Sender: rientjes@chino.kir.corp.google.com To: "Kirill A. Shutemov" cc: Michal Hocko , Kirill Tkhai , Wei Yang , hannes@cmpxchg.org, vdavydov.dev@gmail.com, akpm@linux-foundation.org, kirill.shutemov@linux.intel.com, yang.shi@linux.alibaba.com, cgroups@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, alexander.duyck@gmail.com, stable@vger.kernel.org Subject: Re: [Patch v3] mm: thp: grab the lock before manipulation defer list In-Reply-To: <20200117153839.pcnfomzuaha3dafh@box> Message-ID: References: <20200116013100.7679-1-richardw.yang@linux.intel.com> <0bb34c4a-97c7-0b3c-cf43-8af6cf9c4396@virtuozzo.com> <20200117091002.GM19428@dhcp22.suse.cz> <20200117153839.pcnfomzuaha3dafh@box> User-Agent: Alpine 2.21 (DEB 202 2017-01-01) 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, 17 Jan 2020, Kirill A. Shutemov wrote: > > Right, and I don't think that it necessarily is and the second > > conditional in Wei's patch will always succeed unless we have raced. That > > patch is for a lock concern but I think Kirill's question has uncovered > > something more interesting. > > > > Kirill S would definitely be best to answer Kirill T's question, but from > > my understanding when mem_cgroup_move_account() is called with > > compound == true that we always have an intact pmd (we never migrate > > partial page charges for pages on the deferred split queue with the > > current charge migration implementation) and thus the underlying page is > > not eligible to be split and shouldn't be on the deferred split queue. > > > > In other words, a page being on the deferred split queue for a memcg > > should only happen when it is charged to that memcg. (This wasn't the > > case when we only had per-node split queues.) I think that's currently > > broken in mem_cgroup_move_account() before Wei's patch. > > Right. It's broken indeed. > > We are dealing with anon page here. And it cannot be on deferred list as > long as it's mapped with PMD. We cannot get compound == true && > !list_empty() on the (first) enter to the function. Any PMD-mapped page > will be put onto deferred by the function. This is wrong. > > The fix is not obvious. > > This comment got in mem_cgroup_move_charge_pte_range() my attention: > > /* > * We can have a part of the split pmd here. Moving it > * can be done but it would be too convoluted so simply > * ignore such a partial THP and keep it in original > * memcg. There should be somebody mapping the head. > */ > > That's exactly the case we care about: PTE-mapped THP that has to be split > under load. We don't move charge of them between memcgs and therefore we > should not move the page to different memcg. > > I guess this will do the trick :P > > diff --git a/mm/memcontrol.c b/mm/memcontrol.c > index c5b5f74cfd4d..e87ee4c10f6e 100644 > --- a/mm/memcontrol.c > +++ b/mm/memcontrol.c > @@ -5359,14 +5359,6 @@ static int mem_cgroup_move_account(struct page *page, > __mod_lruvec_state(to_vec, NR_WRITEBACK, nr_pages); > } > > -#ifdef CONFIG_TRANSPARENT_HUGEPAGE > - if (compound && !list_empty(page_deferred_list(page))) { > - spin_lock(&from->deferred_split_queue.split_queue_lock); > - list_del_init(page_deferred_list(page)); > - from->deferred_split_queue.split_queue_len--; > - spin_unlock(&from->deferred_split_queue.split_queue_lock); > - } > -#endif > /* > * It is safe to change page->mem_cgroup here because the page > * is referenced, charged, and isolated - we can't race with > @@ -5376,16 +5368,6 @@ static int mem_cgroup_move_account(struct page *page, > /* caller should have done css_get */ > page->mem_cgroup = to; > > -#ifdef CONFIG_TRANSPARENT_HUGEPAGE > - if (compound && list_empty(page_deferred_list(page))) { > - spin_lock(&to->deferred_split_queue.split_queue_lock); > - list_add_tail(page_deferred_list(page), > - &to->deferred_split_queue.split_queue); > - to->deferred_split_queue.split_queue_len++; > - spin_unlock(&to->deferred_split_queue.split_queue_lock); > - } > -#endif > - > spin_unlock_irqrestore(&from->move_lock, flags); > > ret = 0; Yeah, this is what I was thinking as well. When PageTransHuge(page) == true and there's a mapping pmd, the charge gets moved but the page shouldn't appear on any deferred split queue; when there isn't a mapped pmd, it should already be on a queue but the charge doesn't get moved so no change in which queue is needed. There was no deferred split handling in mem_cgroup_move_account() needed for per-node deferred split queues either so this is purely an issue for commit 87eaceb3faa5 ("mm: thp: make deferred split shrinker memcg aware") so I think we need your patch and it should be annotated for stable 5.4+.