Received: by 2002:a05:6a10:17d3:0:0:0:0 with SMTP id hz19csp592566pxb; Thu, 15 Apr 2021 01:45:07 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwNNp3SDLDsX5v/EkeTqNEh0ChnMlJZjw4NvibdZrumYh1O3YzB85obdfYYAlEv13w9poZ/ X-Received: by 2002:aa7:dd98:: with SMTP id g24mr2789505edv.75.1618476307673; Thu, 15 Apr 2021 01:45:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1618476307; cv=none; d=google.com; s=arc-20160816; b=yJJK5K2xO8ivq2uNgVGCYHwmWc971B7xvMikGoQbA4HRl0/t0tCKUXJVCu1/KlMdOS N8cFoUVkmEMhnVM6OIloDSkDaJNgOOPERi/aDatOccn50KebFi/DgMYNFwKC8sldLIfY 2Gbw5TjnXEr6CK/V2PJhnzYoN5F0CIwtSO24J8InxvDl04E1yXlx7iE4IlSGKiN7fDBt dEKzHKM5hwLTrGSCCcSZndxVNSYX8pl/nEzqazv07jaNWCtdy9867ePTc6meZ/Pd2b54 ZltPPzwfIbl9c00rkPYgL6tjtd4p7nqAYevw/Ge9TqYo6KPDPLsnq3Weou7Zyp0O9wZC 4JwA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=6TWaOIOsTerxj3mJL6eq87dt1yIFOG9nTLeeYfIsCVs=; b=aEiQ5xWOep7/Q9xoC3YPa8VJeQSMEV/TA/F7LKAKDGwGF2ZuRZy1an78VImClJKdTD HbHYr7+9+kpFSTs6EiwoNFOTxuVvm4XTY4jYJp75BH/l/HhSneF4ZpZOujP1X3MmShtM S3Fp4WQ27Ek/7VvCPfX5MLI6odIu6yeZaWhvCfw2KTaquBHioz4l/4+nk/JV8/R1XNCX QaCZDOmj26QbtmEMc+DV3+k+s93EhsaxP6eVRJEhOwCiYOrDDH3DPpaaJyaulHNv7+SN +6KH0dzGayjauEGIRixqnsO+NkZ5tizQNg3Lyfq4ld2VXhK3p7ySU/l/2ysj3cQyKDYw S5mw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bytedance-com.20150623.gappssmtp.com header.s=20150623 header.b="2B/7nhsw"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=bytedance.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id bi22si1782484edb.191.2021.04.15.01.44.44; Thu, 15 Apr 2021 01:45:07 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@bytedance-com.20150623.gappssmtp.com header.s=20150623 header.b="2B/7nhsw"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=bytedance.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231534AbhDOInU (ORCPT + 99 others); Thu, 15 Apr 2021 04:43:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46440 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231903AbhDOInP (ORCPT ); Thu, 15 Apr 2021 04:43:15 -0400 Received: from mail-pl1-x630.google.com (mail-pl1-x630.google.com [IPv6:2607:f8b0:4864:20::630]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5D8FBC061574 for ; Thu, 15 Apr 2021 01:42:53 -0700 (PDT) Received: by mail-pl1-x630.google.com with SMTP id j7so11669339plx.2 for ; Thu, 15 Apr 2021 01:42:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=6TWaOIOsTerxj3mJL6eq87dt1yIFOG9nTLeeYfIsCVs=; b=2B/7nhsw2xEIQKmLjJ7aBwin8TXHNpJiJkmdaLsd979e20DhPX4OMUfCVwZIFa2TN4 F/JXI4BhmvN30z+IJcoaGsSIdaxHjCXldThwCavxssw+Fi7NzGjeMvlk/GkUcY2iOVtR k8m0TzBYtqg7+F4PQHlAbcU8TNnsdAaTCP2nnPxwkubSdyNZ8SY48XonOImvd/s8q3zW fQHqdD2UM5LDQIYHbLQRHjdlIXNl5dEWthO2vW8KOaJjiQ98IDxD8CAd/NJJFVzNf9j2 tERae+6Y3FjRozk4SF6gNSXWcd7uKEAgAqKD9k0BS4ZREM3HwIA3E4m/FnsN8bhe9IKD AO9w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=6TWaOIOsTerxj3mJL6eq87dt1yIFOG9nTLeeYfIsCVs=; b=dpKqZeUHrl+sSNAuFezzwWEli7y4TokTjyvcC4foZY5RtgVkrhSvEOUMhsvEWW44F/ 1kIg55hdWs7LuBBw6KIQod9m0sh2V2jfcy+x/StE4nJoJrU+n5eW7UOgM0drSFFPDD6u TZ2ZWI7Xfw82eIdWPIMy25BHm6J3zubkUQeHk+hI9pemB4Ar3jW2Ud4+TY1tHHFHsDxN qEcslblphWmbiFxUidoTRe8UcPY2ROZXHrL6vKZgKTA1XZY6UKmKjm0nbveD7m+Vokdm XJhiMXfgJB9HkoMcEsN8Ux9K7wAh3R0LKYjrNskv8SP2U43J/5ZZIsrZKYYHdpDG+jan QRYw== X-Gm-Message-State: AOAM530m6u9cnJCYDLCCk/3krBUsSPUJyVGQCs1DB4js5h4Ua1n9Y/a/ awsxKmBji2bilbrrnRJFh+q7gQ== X-Received: by 2002:a17:902:8601:b029:e6:7b87:8add with SMTP id f1-20020a1709028601b02900e67b878addmr2736039plo.3.1618476172961; Thu, 15 Apr 2021 01:42:52 -0700 (PDT) Received: from localhost.localdomain ([139.177.225.234]) by smtp.gmail.com with ESMTPSA id e13sm1392365pgt.91.2021.04.15.01.42.41 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 15 Apr 2021 01:42:52 -0700 (PDT) From: Muchun Song To: 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, 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, willy@infradead.org, osalvador@suse.de, mhocko@suse.com, song.bao.hua@hisilicon.com, david@redhat.com, naoya.horiguchi@nec.com, joao.m.martins@oracle.com Cc: duanxiongchun@bytedance.com, fam.zheng@bytedance.com, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, Muchun Song , Miaohe Lin , Chen Huang , Bodeddula Balasubramaniam Subject: [PATCH v20 3/9] mm: hugetlb: gather discrete indexes of tail page Date: Thu, 15 Apr 2021 16:39:59 +0800 Message-Id: <20210415084005.25049-4-songmuchun@bytedance.com> X-Mailer: git-send-email 2.21.0 (Apple Git-122) In-Reply-To: <20210415084005.25049-1-songmuchun@bytedance.com> References: <20210415084005.25049-1-songmuchun@bytedance.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org For HugeTLB page, there are more metadata to save in the struct page. But the head struct page cannot meet our needs, so we have to abuse other tail struct page to store the metadata. In order to avoid conflicts caused by subsequent use of more tail struct pages, we can gather these discrete indexes of tail struct page. In this case, it will be easier to add a new tail page index later. Signed-off-by: Muchun Song Reviewed-by: Oscar Salvador Reviewed-by: Miaohe Lin Tested-by: Chen Huang Tested-by: Bodeddula Balasubramaniam Acked-by: Michal Hocko --- include/linux/hugetlb.h | 21 +++++++++++++++++++-- include/linux/hugetlb_cgroup.h | 19 +++++++++++-------- 2 files changed, 30 insertions(+), 10 deletions(-) diff --git a/include/linux/hugetlb.h b/include/linux/hugetlb.h index 09f1fd12a6fa..0abed7e766b8 100644 --- a/include/linux/hugetlb.h +++ b/include/linux/hugetlb.h @@ -29,6 +29,23 @@ typedef struct { unsigned long pd; } hugepd_t; #include #include +/* + * For HugeTLB page, there are more metadata to save in the struct page. But + * the head struct page cannot meet our needs, so we have to abuse other tail + * struct page to store the metadata. In order to avoid conflicts caused by + * subsequent use of more tail struct pages, we gather these discrete indexes + * of tail struct page here. + */ +enum { + SUBPAGE_INDEX_SUBPOOL = 1, /* reuse page->private */ +#ifdef CONFIG_CGROUP_HUGETLB + SUBPAGE_INDEX_CGROUP, /* reuse page->private */ + SUBPAGE_INDEX_CGROUP_RSVD, /* reuse page->private */ + __MAX_CGROUP_SUBPAGE_INDEX = SUBPAGE_INDEX_CGROUP_RSVD, +#endif + __NR_USED_SUBPAGE, +}; + struct hugepage_subpool { spinlock_t lock; long count; @@ -626,13 +643,13 @@ extern unsigned int default_hstate_idx; */ static inline struct hugepage_subpool *hugetlb_page_subpool(struct page *hpage) { - return (struct hugepage_subpool *)(hpage+1)->private; + return (void *)page_private(hpage + SUBPAGE_INDEX_SUBPOOL); } static inline void hugetlb_set_page_subpool(struct page *hpage, struct hugepage_subpool *subpool) { - set_page_private(hpage+1, (unsigned long)subpool); + set_page_private(hpage + SUBPAGE_INDEX_SUBPOOL, (unsigned long)subpool); } static inline struct hstate *hstate_file(struct file *f) diff --git a/include/linux/hugetlb_cgroup.h b/include/linux/hugetlb_cgroup.h index 0bff345c4bc6..0b8d1fdda3a1 100644 --- a/include/linux/hugetlb_cgroup.h +++ b/include/linux/hugetlb_cgroup.h @@ -21,15 +21,16 @@ struct hugetlb_cgroup; struct resv_map; struct file_region; +#ifdef CONFIG_CGROUP_HUGETLB /* * Minimum page order trackable by hugetlb cgroup. * At least 4 pages are necessary for all the tracking information. - * The second tail page (hpage[2]) is the fault usage cgroup. - * The third tail page (hpage[3]) is the reservation usage cgroup. + * The second tail page (hpage[SUBPAGE_INDEX_CGROUP]) is the fault + * usage cgroup. The third tail page (hpage[SUBPAGE_INDEX_CGROUP_RSVD]) + * is the reservation usage cgroup. */ -#define HUGETLB_CGROUP_MIN_ORDER 2 +#define HUGETLB_CGROUP_MIN_ORDER order_base_2(__MAX_CGROUP_SUBPAGE_INDEX + 1) -#ifdef CONFIG_CGROUP_HUGETLB enum hugetlb_memory_event { HUGETLB_MAX, HUGETLB_NR_MEMORY_EVENTS, @@ -66,9 +67,9 @@ __hugetlb_cgroup_from_page(struct page *page, bool rsvd) if (compound_order(page) < HUGETLB_CGROUP_MIN_ORDER) return NULL; if (rsvd) - return (struct hugetlb_cgroup *)page[3].private; + return (void *)page_private(page + SUBPAGE_INDEX_CGROUP_RSVD); else - return (struct hugetlb_cgroup *)page[2].private; + return (void *)page_private(page + SUBPAGE_INDEX_CGROUP); } static inline struct hugetlb_cgroup *hugetlb_cgroup_from_page(struct page *page) @@ -90,9 +91,11 @@ static inline int __set_hugetlb_cgroup(struct page *page, if (compound_order(page) < HUGETLB_CGROUP_MIN_ORDER) return -1; if (rsvd) - page[3].private = (unsigned long)h_cg; + set_page_private(page + SUBPAGE_INDEX_CGROUP_RSVD, + (unsigned long)h_cg); else - page[2].private = (unsigned long)h_cg; + set_page_private(page + SUBPAGE_INDEX_CGROUP, + (unsigned long)h_cg); return 0; } -- 2.11.0