Received: by 2002:a05:6a10:a841:0:0:0:0 with SMTP id d1csp2662894pxy; Sun, 25 Apr 2021 00:15:40 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwvVB/kdECi/bS3TotjYLhmsbaYt56ga16A2kr+wy4jyVByW45vikxqzdEvOdWpSnm2u56D X-Received: by 2002:a17:90a:fd83:: with SMTP id cx3mr13247448pjb.41.1619334940064; Sun, 25 Apr 2021 00:15:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1619334940; cv=none; d=google.com; s=arc-20160816; b=p1DEmVgSozfJkcVwnNT8UyEey0W3yAYEXrdqP3NXvHgobDCdJAtBXGKw1uHmojQDDN CJ4lm6RgFpV7pOHIkxeK0UUt5Sgw9VPK5fFrJrnZw1aIXle5dgCeSflZBFXs3UQLJlWz cHZum2IbBtxev3GYTjiS6KUeokWiVKov2DkrYa/FkmMgMjIQH8XjB07qHHd4wN9LJFDz vE2tpVA0hwkJqOK96+TZQhqqRekQPmm7L73AazPNadjF7N+hZgJwZ+vSAD8pc3DU2t8B 4Cm0D3cv7fyffx6G14KjBSRwCMel3vQn+5Nyx66MsJlGbfTNhTYErImT9qy8xra3E0Kt C5kA== 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=VCnSzaZHCKqH61wVuHk0o1TT9bY3u6rBTZhvsMh9WN0=; b=OkLxEg19H6ItoNECIxzahCWiZjUNtvVg1KtpLlTlAf7ZXDmS+VnXo/2O2z1lhaAmQR J36TDjx7jsxlYwKCwXTFx0Uc3zhzH1s+e6f4l0JXDijzPD4FIZ/6nxgbMp11l6b40s3E gbfmWIE/FPEpQdyBx78Oif4YjIzHK3b3sfe38WJg3aFQVZS+z1kHOJnsNEi4CkT03wIV ep1lxGmPLv9zdpcVgp8et60YA39cqX6xXQC4PIrGzt7Ht+mlfe05riKy2oE3XLRSiUlJ sbIgRxQ6D7GXRxGuQ8MKvbHFEtzkL5lYfvGJxP40ub1eo5yQ6WC4BlFJio3cxRBErdJv u81Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bytedance-com.20150623.gappssmtp.com header.s=20150623 header.b=iuQotF7k; 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 u16si12658689pfk.295.2021.04.25.00.15.27; Sun, 25 Apr 2021 00:15:40 -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=iuQotF7k; 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 S230024AbhDYHOC (ORCPT + 99 others); Sun, 25 Apr 2021 03:14:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60878 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230020AbhDYHOA (ORCPT ); Sun, 25 Apr 2021 03:14:00 -0400 Received: from mail-pg1-x530.google.com (mail-pg1-x530.google.com [IPv6:2607:f8b0:4864:20::530]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 807B6C06175F for ; Sun, 25 Apr 2021 00:13:21 -0700 (PDT) Received: by mail-pg1-x530.google.com with SMTP id 31so6124462pgn.13 for ; Sun, 25 Apr 2021 00:13:21 -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=VCnSzaZHCKqH61wVuHk0o1TT9bY3u6rBTZhvsMh9WN0=; b=iuQotF7krxl+PvfWxvrxojZC+Ta2JWPbGuN2zQiuPoAyq/hTMN+QHfdyvnmzFdNrtY PZoazCj4l9Qk3whw/6Lo9YfVMl8m5vCJq5PSfaeaWDFWN/JIu3LzyNtFtDZEDEM9l7zt BHb8F8zJ4VZnvv0x2w8QBXd74v7xGF8eCU+MnGs1BmRzSLbLWQkAQfJgOGYbR78a5nHT 6NWPZfdHnQPBDYLqa49bu1p3uIrYtt5tcBydJxCBdpYvpBL3ROPVFwDo9QEXmILBsslJ FrphOMXa3NlDc7zj+lKCgZJhf7l7ho81fJX8cYJwlnkYk2t9+UnctntoezhwWokv+Xhj yD9A== 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=VCnSzaZHCKqH61wVuHk0o1TT9bY3u6rBTZhvsMh9WN0=; b=YPC8Nk6EEe+E8HgFIpmQ/x4G2+cwqOJUieUvAuObpr+dlXZSZGAnakC+sUlt37BpHn ReW/bkscodEC48nuYCafb5o7Lc5RuS1Xviar8TIy+y70WIdcXlyRo85RKde4n/R5cyLn If71LHBGqsbh0uO05e9VytgWEJpxuttWYY72zQahDMrLWUXIMa1JlZc9jzTA9hZi0fK1 FtnAQqsNHI0K8HIqogSIzbMCAdJXeqysNEbks9PenKh5lvoJoEiAREFby06+7hFr/naW 6XFWSp19Vrv5Z9L95FqusirhSWKI+OCYaRgi0LuZdMgvkECPxPLhBJGXzBF8G+PsWd6J V6Mw== X-Gm-Message-State: AOAM532OazcnYY4kevPBS3AqrxCZ4uYmDKTK3Pb76ymhHOqcVPsuFNyb X44hHLO0S7SVR/0Wg5FEL4pPlg== X-Received: by 2002:aa7:8142:0:b029:256:d3d4:16a0 with SMTP id d2-20020aa781420000b0290256d3d416a0mr11569996pfn.56.1619334801067; Sun, 25 Apr 2021 00:13:21 -0700 (PDT) Received: from localhost.localdomain ([139.177.225.255]) by smtp.gmail.com with ESMTPSA id h8sm8767125pjt.17.2021.04.25.00.13.09 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sun, 25 Apr 2021 00:13:20 -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, zhengqi.arch@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 v21 3/9] mm: hugetlb: gather discrete indexes of tail page Date: Sun, 25 Apr 2021 15:07:46 +0800 Message-Id: <20210425070752.17783-4-songmuchun@bytedance.com> X-Mailer: git-send-email 2.21.0 (Apple Git-122) In-Reply-To: <20210425070752.17783-1-songmuchun@bytedance.com> References: <20210425070752.17783-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 Reviewed-by: Mike Kravetz --- 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 b92f25ccef58..d523a345dc86 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; @@ -627,13 +644,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