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=-3.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS 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 4C577C433E0 for ; Thu, 11 Mar 2021 16:24:22 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id A485E64F9C for ; Thu, 11 Mar 2021 16:24:21 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org A485E64F9C Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 195C38D02CA; Thu, 11 Mar 2021 11:24:19 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 147658D02B2; Thu, 11 Mar 2021 11:24:19 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id F03CF8D02CA; Thu, 11 Mar 2021 11:24:18 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0212.hostedemail.com [216.40.44.212]) by kanga.kvack.org (Postfix) with ESMTP id D4C578D02B2 for ; Thu, 11 Mar 2021 11:24:18 -0500 (EST) Received: from smtpin25.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 84C921E06 for ; Thu, 11 Mar 2021 16:24:18 +0000 (UTC) X-FDA: 77908115796.25.B4B90AF Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf16.hostedemail.com (Postfix) with ESMTP id C58ED8019149 for ; Thu, 11 Mar 2021 16:24:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=exR+xERV3ojcQqtp1j0CKhkbLxukivv9ZQ+vpw6IcR0=; b=sor4KBFsMgwGYPobUwV20byRF6 nBo+e/5ydiYY7zAVnWIC7bmIw/77x1crliFWRtXap/kK1cXup1NcCnY4Y7aEUM/Y9V424KOMOsU6B UH8KjHCWcb6E7RUaEwvpfJzQFRwP4JYXoQ7RHAGOdzcnOU2wL9nxu/mopE+YSdk4dFcRRmB2X0ki0 E2ZCW/N9/LPg2PBknxSeOWa0yTFRC8KcHTB6OAtff6aan5rINwoWkVU5u3UpOlnN0jZNfDByV8mQF c2topVR7aDG+eIu78x5P89Nf+uOqbkbmscM3kJ2ZvpPTLnDU7Ya4cD9E0WF1J0lnAw3hOmQXnfXPT 4YeMVTDA==; Received: from willy by casper.infradead.org with local (Exim 4.94 #2 (Red Hat Linux)) id 1lKO6D-007jCd-AU; Thu, 11 Mar 2021 16:23:48 +0000 Date: Thu, 11 Mar 2021 16:23:45 +0000 From: Matthew Wilcox To: Johannes Weiner Cc: Michal Hocko , Zhou Guanghui , linux-kernel@vger.kernel.org, linux-mm@kvack.org, akpm@linux-foundation.org, hughd@google.com, kirill.shutemov@linux.intel.com, npiggin@gmail.com, ziy@nvidia.com, wangkefeng.wang@huawei.com, guohanjun@huawei.com, dingtianhong@huawei.com, chenweilong@huawei.com, rui.xiang@huawei.com Subject: Re: [PATCH v2 2/2] mm/memcg: set memcg when split page Message-ID: <20210311162345.GW3479805@casper.infradead.org> References: <20210304074053.65527-1-zhouguanghui1@huawei.com> <20210304074053.65527-3-zhouguanghui1@huawei.com> <20210308210225.GF3479805@casper.infradead.org> <20210309123255.GI3479805@casper.infradead.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Stat-Signature: kxogce64ae76wkxuf8og8fppp1iyb1g6 X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: C58ED8019149 Received-SPF: none (infradead.org>: No applicable sender policy available) receiver=imf16; identity=mailfrom; envelope-from=""; helo=casper.infradead.org; client-ip=90.155.50.34 X-HE-DKIM-Result: pass/pass X-HE-Tag: 1615479853-343030 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 Thu, Mar 11, 2021 at 10:21:39AM -0500, Johannes Weiner wrote: > On Thu, Mar 11, 2021 at 09:37:02AM +0100, Michal Hocko wrote: > > Johannes, Hugh, > > > > what do you think about this approach? If we want to stick with > > split_page approach then we need to update the missing place Matthew has > > pointed out. > > I find the __free_pages() code quite tricky as well. But for that > reason I would actually prefer to initiate the splitting in there, > since that's the place where we actually split the page, rather than > spread the handling of this situation further out. Mmm. The thing is, we don't actually split the page because it was never compound. I don't know whether anybody actually does this, but it's legitimate to write: struct page *p = alloc_pages(GFP_KERNEL, 2); free_unref_page(p + 1); free_unref_page(p + 3); free_unref_page(p + 2); __free_page(p); The good news is that I recently made free_unref_page() local to mm/internal.h, so we don't need to worry about device drivers doing this. As far as I can tell, we don't have any exposure to this kind of thing today through functions exported from mm, but I might have missed something. I'd really like to get rid of non-compound high-order pages. Slab, filesystems and anonymous memory all use compound pages. I think it's just crusty old device drivers that don't. And alloc_pages_exact(), of course, but that's kind of internal. > The race condition shouldn't be hot, so I don't think we need to be as > efficient about setting page->memcg_data only on the higher-order > buddies as in Willy's scratch patch. We can call split_page_memcg(), > which IMO should actually help document what's happening to the page. I'm cool with that. I agree, this is not a performance case! > I think that function could also benefit a bit more from step-by-step > documentation about what's going on. The kerneldoc is helpful, but I > don't think it does justice to how tricky this race condition is. Always good to have other people read over your explanation ... the kernel-doc could probably be simplified as a result.