Received: by 2002:a05:6a10:a841:0:0:0:0 with SMTP id d1csp1976912pxy; Thu, 29 Apr 2021 20:22:32 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy8foxsmE7sg61ndaOTG1//B7wIsW85S7cfyn0ACZz/IY07c6704sBIlsq1oaO6t5/vhsgo X-Received: by 2002:aa7:80c9:0:b029:249:cac5:e368 with SMTP id a9-20020aa780c90000b0290249cac5e368mr2848452pfn.12.1619752952411; Thu, 29 Apr 2021 20:22:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1619752952; cv=none; d=google.com; s=arc-20160816; b=siwUDhub0v5761z0n/ADM9XNVI82Tq8NG2B+FXLIAE0GbImC8WLeJmU/Rj5FFmw7Ss r4v9QTjBpzSyzmEvhue2jHAbzJ8N8C5LZZ2jDs5mpVQQeZhQfRaq/TsUglrsjdu6h4vq DgsmBvSGb/7kt9/bb8CH1LD5FStUImwjkVNgZGChffAMyPZYt9jaVHcYh77U0D3qYwRb oBXJL4ejBRS9PhvfSPcsr4kdJBT/8+vumhuIXO6twVFLiyxybzARB09VWuDOcAydmTfN vP4oLYxKnDOwSHnz2yYviJcvKourBqccnBjk7FhpY/XA1bDr4s0Mh5GbaVppDHv29vMy 5pEA== 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=ws9o6y+MbVUT/jaOpvRG9TUejBHlQHdOtjzVac4f+grB4I6jKbKLTOi6nOlFOZMKym 7vdmjX/qsgCmH8e/KkL7ssG7g+oaQltVj3QNYTaHnqnvGFZ2I+LBPoqH9DgMzpwtjiph sx5H3oLNAHGErgaXsokVkOjoiqKRVzWn5FI5N/af9DaReWIXUJrlMdIJG4BsK/1UN+0I 1i/KDALk1RVb5fF+ZreOfsbVOPRb8zs/5Idumx+Wj2kwaLki1Tl7SvEfRg/0HlHYkKZW Pe2ylxMw/7sIXRcwziu1igi+bjq2TFeUHuKeowLjQtJXaQlUqHmpcSm7AFP0TI85/Rxe cGaw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bytedance-com.20150623.gappssmtp.com header.s=20150623 header.b=0a3c+Xqp; 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 t33si1858548pgk.133.2021.04.29.20.22.19; Thu, 29 Apr 2021 20:22:32 -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=0a3c+Xqp; 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 S230187AbhD3DVx (ORCPT + 99 others); Thu, 29 Apr 2021 23:21:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41280 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230083AbhD3DVm (ORCPT ); Thu, 29 Apr 2021 23:21:42 -0400 Received: from mail-pg1-x531.google.com (mail-pg1-x531.google.com [IPv6:2607:f8b0:4864:20::531]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 48654C061347 for ; Thu, 29 Apr 2021 20:20:48 -0700 (PDT) Received: by mail-pg1-x531.google.com with SMTP id i14so4029123pgk.5 for ; Thu, 29 Apr 2021 20:20:48 -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=0a3c+XqpDKUksTgDeefxtvlVMr9j5bJ5syA8Qbdru9tYDe510pt8c/OYH5NtaKpPNu oNl9xnMwPYwuTfMdxlokEXO5GVpUob9eeUuc6Nop4U43DSInOLQ2dCs+hJFqpBO79QUu 9yWvbJPd5m28CGJDDChh6pp3ZI6A5VHj2sCDiAv7kvusb7jODz6UvfjvGbe+7ZDLzxrQ l+cPpQ/QD1l8wFfOj3E66QB4nWJlvGc8mMpRa6fRrI31LEUO/nZV4d0zCdgepj7Ytu5o hlsjkqH3GufCIOx3907/rUW67Yzm3uaXDlrG+WTi+7iaQF+DTYwdpC199bEfjSC37HVq oB4g== 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=HT+5dI8S96hhRjgWPx7ZxM8k0UyKl2D7BW68FOFyiiaeSyUOruKJrZIl1rYTgG7Z1i H7bsVVTlbQNlfJ/N/IWXM1dIOVT6+C1aOVg9r3/N6zdrwPtBG6rIhX18eqFEIEDbfSac /hSUWIerQ8x7zGgu75WjhRN+7sIAvYi1wrW9uFWCxeIXLJr/q77Gxab0olePMNYUYkGo /Olb5EnN7T93AP3XqxCyQ+K5b/cZjFJOkNH3551Hx9sLTBrxe+I7jl7IbCzuh6QgdTS1 cS3lCx9FpPf1Aq9eJVfIseENFxg1IIY8hSUI3lp4XXWcc4IUCQ+GM79E+DsgVNe6B82F RE2g== X-Gm-Message-State: AOAM531WQVJ+LNB8mYvKV25sRWuLyIqsnMbAev84ZgLtLlTf8+wbFZ3O nEVpZJsok+MYrBe8LRpVyYJQKw== X-Received: by 2002:a65:4c89:: with SMTP id m9mr2670013pgt.330.1619752847833; Thu, 29 Apr 2021 20:20:47 -0700 (PDT) Received: from localhost.localdomain ([139.177.225.239]) by smtp.gmail.com with ESMTPSA id t6sm405317pjl.57.2021.04.29.20.20.36 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 29 Apr 2021 20:20:47 -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 v22 3/9] mm: hugetlb: gather discrete indexes of tail page Date: Fri, 30 Apr 2021 11:13:46 +0800 Message-Id: <20210430031352.45379-4-songmuchun@bytedance.com> X-Mailer: git-send-email 2.21.0 (Apple Git-122) In-Reply-To: <20210430031352.45379-1-songmuchun@bytedance.com> References: <20210430031352.45379-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