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.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,URIBL_BLOCKED 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 9E1AFC56202 for ; Wed, 18 Nov 2020 02:44:13 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 383E52220B for ; Wed, 18 Nov 2020 02:44:13 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=bytedance-com.20150623.gappssmtp.com header.i=@bytedance-com.20150623.gappssmtp.com header.b="bbch85dd" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726768AbgKRCnw (ORCPT ); Tue, 17 Nov 2020 21:43:52 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43174 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726417AbgKRCnw (ORCPT ); Tue, 17 Nov 2020 21:43:52 -0500 Received: from mail-pg1-x542.google.com (mail-pg1-x542.google.com [IPv6:2607:f8b0:4864:20::542]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B8C98C061A4D for ; Tue, 17 Nov 2020 18:43:50 -0800 (PST) Received: by mail-pg1-x542.google.com with SMTP id f18so167120pgi.8 for ; Tue, 17 Nov 2020 18:43:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=cIZ+YWWP5aqalUoRio2QtJMh5XCbXXDA9kJRwC7+zv8=; b=bbch85ddNZ7XzpLUOYzExmTsbmLKMUrE9yX+1sYtLTuQIw8ozlyrK0AUfruD2uMB8P 6FNZterRPoL/JxxCQOE66gZrVVt84KUGv3FnJx3SDvodbBi6iowaXhCLd2TA5DOMSGe0 SRjy4IuV5OTslaeKmbzNIBAIPNtEt56wYcPKmVdWyiYt8CJHgfVPWHmSHxAkIWO4apO4 qTmvP8l8gWp7CKIOdxDrhM2uWcMO4rKs9rRpPQFiEbYc0Ei/qlaJeWdKQTN6s1ppRauD /PioS9bT+LFuJ5NT2IoOvE18sAWFzx3ej5zoGL2Ax7RG5rNSntedlGRaoxDAHdUinMyW M+wA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=cIZ+YWWP5aqalUoRio2QtJMh5XCbXXDA9kJRwC7+zv8=; b=FAv+KrmBCwwxDJ/l9IJwV5dqMe2goYhYduUAFW0MxYWVA/GrlcTc0RlqeKSzMH0uSw 6kqYp8hL0ZoeEgDiTBi/dxfC2YaPEasZZkdJQHgzrST9Gnf26TsczXCQCTJGfi+Koots MYi85nuU1SZ6QOtnx3A22+tFJbIy4meX8AHBuFYr9udFgECi1wa8Da37UdTvYXIBLBf2 kVJ4dsFxyQ+9N+KBQusOCKMSA56I8nexySZxTmKsxG/zKwAna5f2Hwh7BSLJPpNEzkGr rpvlCF9IsFVxXxYWWJf69hH90IqYt8guzNMSMPS8g060nvbkAmNce/ZYGy/tHCySgO/m qfnw== X-Gm-Message-State: AOAM533ph/qpBRsfmgmQIzgsSFiBoqBLos8WoZxZ+aWgC31LKcpDfmk5 QokHvrpPTC+Nxt6EAk38Kp+EPM5Xzwqwbr2HOUVLcQ== X-Google-Smtp-Source: ABdhPJxGDISMqn2bIRZh7wORdl/cIXS0Q2etgc5JYSCpx/B0Jr1Wza3ya52gTSkwn/Ea57CTkeoqexeqyVXu0Ud+DQE= X-Received: by 2002:a62:16c1:0:b029:18c:8a64:fc04 with SMTP id 184-20020a6216c10000b029018c8a64fc04mr2397649pfw.59.1605667430141; Tue, 17 Nov 2020 18:43:50 -0800 (PST) MIME-Version: 1.0 References: <20201113105952.11638-1-songmuchun@bytedance.com> <349168819c1249d4bceea26597760b0a@hisilicon.com> <714ae7d701d446259ab269f14a030fe9@hisilicon.com> <20201117192223.GW29991@casper.infradead.org> In-Reply-To: <20201117192223.GW29991@casper.infradead.org> From: Muchun Song Date: Wed, 18 Nov 2020 10:43:06 +0800 Message-ID: Subject: Re: [External] RE: [PATCH v4 00/21] Free some vmemmap pages of hugetlb page To: Matthew Wilcox Cc: "Song Bao Hua (Barry Song)" , "corbet@lwn.net" , "mike.kravetz@oracle.com" , "tglx@linutronix.de" , "mingo@redhat.com" , "bp@alien8.de" , "x86@kernel.org" , "hpa@zytor.com" , "dave.hansen@linux.intel.com" , "luto@kernel.org" , "peterz@infradead.org" , "viro@zeniv.linux.org.uk" , "akpm@linux-foundation.org" , "paulmck@kernel.org" , "mchehab+huawei@kernel.org" , "pawan.kumar.gupta@linux.intel.com" , "rdunlap@infradead.org" , "oneukum@suse.com" , "anshuman.khandual@arm.com" , "jroedel@suse.de" , "almasrymina@google.com" , "rientjes@google.com" , "osalvador@suse.de" , "mhocko@suse.com" , "duanxiongchun@bytedance.com" , "linux-doc@vger.kernel.org" , "linux-kernel@vger.kernel.org" , "linux-mm@kvack.org" , "linux-fsdevel@vger.kernel.org" Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Nov 18, 2020 at 3:22 AM Matthew Wilcox wrote: > > On Wed, Nov 18, 2020 at 12:29:07AM +0800, Muchun Song wrote: > > > ideally, we should be able to free PageTail if we change struct page in some way. > > > Then we will save much more for 2MB hugetlb. but it seems it is not easy. > > > > Now for the 2MB HugrTLB page, we only free 6 vmemmap pages. > > But your words woke me up. Maybe we really can free 7 vmemmap > > pages. In this case, we can see 8 of the 512 struct page structures > > has beed set PG_head flag. If we can adjust compound_head() > > slightly and make compound_head() return the real head struct > > page when the parameter is the tail struct page but with PG_head > > flag set. I will start an investigation and a test. > > What are you thinking? > > static inline struct page *compound_head(struct page *page) > { > unsigned long head = READ_ONCE(page->compound_head); > > if (unlikely(head & 1)) > return (struct page *) (head - 1); > + if (unlikely(page->flags & PG_head)) > + return (struct page *)(page[1]->compound_head - 1) Yeah, I think so too. Maybe adding an align check is better. + if ((test_bit(PG_head, &page->flags) && + IS_ALIGNED((unsigned long)page, PAGE_SIZE)) > return page; > } > > ... because if it's that, there are code paths which also just test > PageHead, and so we'd actually need to change PageHead to be something > like: Yeah, I also think that rework compound_head() and PageHead() is enough. Thanks. > > static inline bool PageHead(struct page *page) > { > return (page->flags & PG_head) && > (page[1]->compound_head == (unsigned long)page + 1); > } > > I'm not sure if that's worth doing -- there may be other things I > haven't thought of. -- Yours, Muchun 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.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,URIBL_BLOCKED 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 94EACC2D0E4 for ; Wed, 18 Nov 2020 02:43:56 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id B623C2468E for ; Wed, 18 Nov 2020 02:43:53 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=bytedance-com.20150623.gappssmtp.com header.i=@bytedance-com.20150623.gappssmtp.com header.b="bbch85dd" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org B623C2468E Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=bytedance.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id D572A6B006C; Tue, 17 Nov 2020 21:43:52 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id D2F796B0070; Tue, 17 Nov 2020 21:43:52 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C44AC6B0071; Tue, 17 Nov 2020 21:43:52 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0192.hostedemail.com [216.40.44.192]) by kanga.kvack.org (Postfix) with ESMTP id 9945E6B006C for ; Tue, 17 Nov 2020 21:43:52 -0500 (EST) Received: from smtpin06.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 3E1A81EE6 for ; Wed, 18 Nov 2020 02:43:52 +0000 (UTC) X-FDA: 77495993904.06.cloud75_450980e27336 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin06.hostedemail.com (Postfix) with ESMTP id 201A91003EE29 for ; Wed, 18 Nov 2020 02:43:52 +0000 (UTC) X-HE-Tag: cloud75_450980e27336 X-Filterd-Recvd-Size: 6250 Received: from mail-pg1-f195.google.com (mail-pg1-f195.google.com [209.85.215.195]) by imf27.hostedemail.com (Postfix) with ESMTP for ; Wed, 18 Nov 2020 02:43:51 +0000 (UTC) Received: by mail-pg1-f195.google.com with SMTP id m9so176708pgb.4 for ; Tue, 17 Nov 2020 18:43:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=cIZ+YWWP5aqalUoRio2QtJMh5XCbXXDA9kJRwC7+zv8=; b=bbch85ddNZ7XzpLUOYzExmTsbmLKMUrE9yX+1sYtLTuQIw8ozlyrK0AUfruD2uMB8P 6FNZterRPoL/JxxCQOE66gZrVVt84KUGv3FnJx3SDvodbBi6iowaXhCLd2TA5DOMSGe0 SRjy4IuV5OTslaeKmbzNIBAIPNtEt56wYcPKmVdWyiYt8CJHgfVPWHmSHxAkIWO4apO4 qTmvP8l8gWp7CKIOdxDrhM2uWcMO4rKs9rRpPQFiEbYc0Ei/qlaJeWdKQTN6s1ppRauD /PioS9bT+LFuJ5NT2IoOvE18sAWFzx3ej5zoGL2Ax7RG5rNSntedlGRaoxDAHdUinMyW M+wA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=cIZ+YWWP5aqalUoRio2QtJMh5XCbXXDA9kJRwC7+zv8=; b=CMEn7Z2NXc5SjKrbOB6DeIjNJEkm6/brHjUQ7tFBSGpO7MEsarpD2SnIltrJm99OAM wL4DRHA77ND4wTf86FbhNe2B2tyys5ssVWJHR/oYARyPBQiScneXZ4h8iZKvSJMgq3/n hQclkzC6QLkIKOqHJ5hcP4cJcFoNgmQN8saxSHWYrr/G4EamJrgnAPrFwO2geeIHpkzO W//DLGI+pusOaMyFyOSFemhHxKvUuPLRzoT940iTNRHzd+HZ76UR3sX3R+dy+9M1WD6D oU7rr6yiv1Wo7QQNdGx9UqftYCWBm8f3TY9VxW2aBmVglwq/4qIP0e4BbJUzLRFm5Ui1 IIwg== X-Gm-Message-State: AOAM530IqX02fvvKKoob2f9hNmRIGUKxradh8vI+PfLUa2CvPZVSwuRI tsIUog6ulYGZBKu/8uMJuXEVQz4knBkZh/4iA2iN+g== X-Google-Smtp-Source: ABdhPJxGDISMqn2bIRZh7wORdl/cIXS0Q2etgc5JYSCpx/B0Jr1Wza3ya52gTSkwn/Ea57CTkeoqexeqyVXu0Ud+DQE= X-Received: by 2002:a62:16c1:0:b029:18c:8a64:fc04 with SMTP id 184-20020a6216c10000b029018c8a64fc04mr2397649pfw.59.1605667430141; Tue, 17 Nov 2020 18:43:50 -0800 (PST) MIME-Version: 1.0 References: <20201113105952.11638-1-songmuchun@bytedance.com> <349168819c1249d4bceea26597760b0a@hisilicon.com> <714ae7d701d446259ab269f14a030fe9@hisilicon.com> <20201117192223.GW29991@casper.infradead.org> In-Reply-To: <20201117192223.GW29991@casper.infradead.org> From: Muchun Song Date: Wed, 18 Nov 2020 10:43:06 +0800 Message-ID: Subject: Re: [External] RE: [PATCH v4 00/21] Free some vmemmap pages of hugetlb page To: Matthew Wilcox Cc: "Song Bao Hua (Barry Song)" , "corbet@lwn.net" , "mike.kravetz@oracle.com" , "tglx@linutronix.de" , "mingo@redhat.com" , "bp@alien8.de" , "x86@kernel.org" , "hpa@zytor.com" , "dave.hansen@linux.intel.com" , "luto@kernel.org" , "peterz@infradead.org" , "viro@zeniv.linux.org.uk" , "akpm@linux-foundation.org" , "paulmck@kernel.org" , "mchehab+huawei@kernel.org" , "pawan.kumar.gupta@linux.intel.com" , "rdunlap@infradead.org" , "oneukum@suse.com" , "anshuman.khandual@arm.com" , "jroedel@suse.de" , "almasrymina@google.com" , "rientjes@google.com" , "osalvador@suse.de" , "mhocko@suse.com" , "duanxiongchun@bytedance.com" , "linux-doc@vger.kernel.org" , "linux-kernel@vger.kernel.org" , "linux-mm@kvack.org" , "linux-fsdevel@vger.kernel.org" Content-Type: text/plain; charset="UTF-8" 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 Wed, Nov 18, 2020 at 3:22 AM Matthew Wilcox wrote: > > On Wed, Nov 18, 2020 at 12:29:07AM +0800, Muchun Song wrote: > > > ideally, we should be able to free PageTail if we change struct page in some way. > > > Then we will save much more for 2MB hugetlb. but it seems it is not easy. > > > > Now for the 2MB HugrTLB page, we only free 6 vmemmap pages. > > But your words woke me up. Maybe we really can free 7 vmemmap > > pages. In this case, we can see 8 of the 512 struct page structures > > has beed set PG_head flag. If we can adjust compound_head() > > slightly and make compound_head() return the real head struct > > page when the parameter is the tail struct page but with PG_head > > flag set. I will start an investigation and a test. > > What are you thinking? > > static inline struct page *compound_head(struct page *page) > { > unsigned long head = READ_ONCE(page->compound_head); > > if (unlikely(head & 1)) > return (struct page *) (head - 1); > + if (unlikely(page->flags & PG_head)) > + return (struct page *)(page[1]->compound_head - 1) Yeah, I think so too. Maybe adding an align check is better. + if ((test_bit(PG_head, &page->flags) && + IS_ALIGNED((unsigned long)page, PAGE_SIZE)) > return page; > } > > ... because if it's that, there are code paths which also just test > PageHead, and so we'd actually need to change PageHead to be something > like: Yeah, I also think that rework compound_head() and PageHead() is enough. Thanks. > > static inline bool PageHead(struct page *page) > { > return (page->flags & PG_head) && > (page[1]->compound_head == (unsigned long)page + 1); > } > > I'm not sure if that's worth doing -- there may be other things I > haven't thought of. -- Yours, Muchun