From patchwork Tue Oct 10 14:27:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naoya Horiguchi X-Patchwork-Id: 150824 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp243832vqb; Tue, 10 Oct 2023 07:29:35 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEzgzRTq3txL7JrAXI96mib+rT/8aXHgI+Ub6QMg0e2ddAi2Sg6rhsiMzZPIHxe9VlT5Fsb X-Received: by 2002:a05:6a20:8f1d:b0:16b:79b3:210b with SMTP id b29-20020a056a208f1d00b0016b79b3210bmr12194113pzk.31.1696948174923; Tue, 10 Oct 2023 07:29:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696948174; cv=none; d=google.com; s=arc-20160816; b=g6JlxPcYgqy3TjGYr1JGMrRVR8PJqFxi7IszToRnJPCxJ6jUKl3ZGYRkseGYKPEFPr XP/5QhQHJAXYg17io8PKjygjyYjJ9tDAPgAyzWA+tJxFVWfL4lonmXE2dxQ4CMEPCF07 26dJrzhpaW7J5csngvfegest3SKw8YSg+qEbEUfudF0gwwoboEhhRFpwuJCqSEDKaUGN SL4WJ/X4lPvjdMj2OMOb6Pyt1hL+hcAj3nV3tFKPhu10bBghNXdEjnLhr3dZxzdKoCd/ OQt3CSU3GlrXc23RRPYBIPdySvzGxSOUK32jaq484tKIdVifnz7v0l+P5SNWh0+n8LZK L3AA== 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=ct5h8XiEF6Z6bh0u0KQdOShLvibauoLK/pnF+aCIbHs=; fh=vd113QmVxKSP0xyTVgYADqM2Ffy1JHXPefyn38Zlb+8=; b=BJZ5RE8Y9Nw2Wnkw9Qc48/CXTk9HE11DNFBa7NY3kQcycq1CIbIVsJAKA4XrXQKDcW PJl2JtiOgD3M/P+gT9KpTe5Z8GKBenMoQsQCR+HX1P8J137hDKP8u5BynHWe0S1WjzQx 1DIyAXWU7O69bk82hLW/vcOhHGix2hUa6zaM2WqLv8aGLLL31fIToE3bJncIG7pFEAZx lhe6RdXUV+BKfFgKsIvWBEFdrTX6gW6SEBE29XuaOjqW0MGwJJlelQ3VXAf0B26qQzBE IYW4W2tXlNEq928sRl8yEHtycpF0Pd0Kre2jTYToR6YcmfNGV8UceTjvhvlCnaj1wZVn uMsg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b="bpjtc/LF"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: from lipwig.vger.email (lipwig.vger.email. [2620:137:e000::3:3]) by mx.google.com with ESMTPS id 36-20020a631664000000b0054ff717395dsi12213208pgw.691.2023.10.10.07.29.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Oct 2023 07:29:34 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) client-ip=2620:137:e000::3:3; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b="bpjtc/LF"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id 630BB8025B44; Tue, 10 Oct 2023 07:29:32 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233255AbjJJO3V (ORCPT + 20 others); Tue, 10 Oct 2023 10:29:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50344 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233386AbjJJO2y (ORCPT ); Tue, 10 Oct 2023 10:28:54 -0400 Received: from out-193.mta0.migadu.com (out-193.mta0.migadu.com [IPv6:2001:41d0:1004:224b::c1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EC34B91 for ; Tue, 10 Oct 2023 07:28:52 -0700 (PDT) X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1696948131; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ct5h8XiEF6Z6bh0u0KQdOShLvibauoLK/pnF+aCIbHs=; b=bpjtc/LFwjIYuknqBdChdrg6pH5LhH0gERemOAwGNiqO/B0yhaIPcKkXhCyk1Y+6QiAB6D pdmVPLFHqF8iWcxI7QpWy2AkvCdR7eOxKKaViIq1Qya/PPl2bRQHZMcyklBZ8+34tDxuvO QoG/rGqvVIFHC+5eFcdEu8fJDv1/1Hs= From: Naoya Horiguchi To: linux-mm@kvack.org Cc: Andrew Morton , Matthew Wilcox , David Hildenbrand , "Kirill A. Shutemov" , Mike Kravetz , Miaohe Lin , Vlastimil Babka , Muchun Song , Naoya Horiguchi , linux-kernel@vger.kernel.org Subject: [PATCH v1 2/5] mm: kpageflags: distinguish thp and folio Date: Tue, 10 Oct 2023 23:27:58 +0900 Message-Id: <20231010142801.3780917-3-naoya.horiguchi@linux.dev> In-Reply-To: <20231010142801.3780917-1-naoya.horiguchi@linux.dev> References: <20231010142801.3780917-1-naoya.horiguchi@linux.dev> MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Spam-Status: No, score=2.7 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, RCVD_IN_SBL_CSS,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (lipwig.vger.email [0.0.0.0]); Tue, 10 Oct 2023 07:29:32 -0700 (PDT) X-Spam-Level: ** X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1779379129455855107 X-GMAIL-MSGID: 1779379129455855107 From: Naoya Horiguchi Currently a large folio is considered as thp in the output of /proc/kpageflags because stable_page_flags() does not have resolution to distinguish thp and large folio. This is confusing and the readers of /proc/kpageflags need additional checks in userspace, which is inefficient. Check page order in stable_page_flags() to distinguish thp and large folio. Although thp (or other types of compound page) is a special form of folio, but the KPF_FOLIO means "folio" in narrower meaning (representing folios in page cache), so KPF_FOLIO is not set on thp or hugetlb pages. This is because thp and hugetlb (and other compound pages) have their own KPF_* flags, so those are already identifiable. Thp and folio use some struct page's field of the first tail pages for internal use. There's no point to parse and show flag info based on tail pages, so return immediately when finding thp/folio tail pages. The output below shows how this patch changes the output of page-types. Before patch: // anonymous thp voffset offset len flags ... 700000000 156c00 1 ___U_l_____Ma_bH______t_____________f_d_____1 700000001 156c01 1 L__U_______Ma___T_____t_____________f_______1 700000002 156c02 1fe ___________Ma___T_____t_____________f_______1 ^ this 't' means thp // file thp 700000000 15d600 1 __RUDl_____M__bH______t_____________f__I____1 700000001 15d601 1 L__U_______M____T_____t_____________f_______1 700000002 15d602 1fe ___________M____T_____t_____________f_______1 // large folio 700000000 154f84 1 __RU_l_____M___H______t________P____f_____F_1 700000001 154f85 1 ________W__M____T_____t_____________f_____F_1 700000002 154f86 2 ___________M____T_____t_____________f_____F_1 After patch: // anonymous thp 700000000 117000 1 ___U_l_____Ma_bH______t_____________f_d_____1 700000001 117001 1ff ________________T_____t_____________f_______1 // file thp 700000000 118400 1 __RUDl_____M__bH______t_____________f__I____1 700000001 118401 1ff ________________T_____t_____________f_______1 // large folio 700000000 148da4 1 __RU_l_____M___H___________f___P____f_____F_1 700000001 148da5 3 ________________T__________f________f_____F_1 ^ this 'f' means folio Signed-off-by: Naoya Horiguchi --- fs/proc/page.c | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/fs/proc/page.c b/fs/proc/page.c index 195b077c0fac..78f675f791c1 100644 --- a/fs/proc/page.c +++ b/fs/proc/page.c @@ -154,11 +154,24 @@ u64 stable_page_flags(struct page *page) else if (PageTransCompound(page)) { struct page *head = compound_head(page); - if (PageLRU(head) || PageAnon(head)) - u |= 1 << KPF_THP; - else if (is_huge_zero_page(head)) { + /* + * We need to check PageLRU/PageAnon to make sure a given page + * is a thp, not a huge zero page or a generic compound page + * (allocated by drivers with __GFP_COMP). + */ + if (PageLRU(head) || PageAnon(head)) { + if (compound_order(head) == HPAGE_PMD_ORDER) + u |= 1 << KPF_THP; + else + u |= 1 << KPF_FOLIO; + } else if (is_huge_zero_page(head)) u |= 1 << KPF_ZERO_PAGE; - u |= 1 << KPF_THP; + + if (PageHead(page)) + u |= 1 << KPF_COMPOUND_HEAD; + if (PageTail(page)) { + u |= 1 << KPF_COMPOUND_TAIL; + return u; } } else if (is_zero_pfn(page_to_pfn(page))) u |= 1 << KPF_ZERO_PAGE;