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 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id A8789C54E58 for ; Thu, 21 Mar 2024 19:59:56 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3C5956B0089; Thu, 21 Mar 2024 15:59:56 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 375B96B008A; Thu, 21 Mar 2024 15:59:56 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 23E206B008C; Thu, 21 Mar 2024 15:59:56 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 133C16B0089 for ; Thu, 21 Mar 2024 15:59:56 -0400 (EDT) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id A7401A04A4 for ; Thu, 21 Mar 2024 19:59:55 +0000 (UTC) X-FDA: 81922111950.24.DAB8B22 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf20.hostedemail.com (Postfix) with ESMTP id 733B41C001F for ; Thu, 21 Mar 2024 19:59:53 +0000 (UTC) Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b="Ff7/4oH4"; dmarc=none; spf=none (imf20.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1711051194; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=BYPwtyCYd5a4JYAUK9MQluNVapG0iz3U/+Y3po5f7DY=; b=jVZALE5vEXAVIVyk/rJB5Vhhfp91OPWd2YwNrM6kwLlugZszTJYX4amkZMZ0ECJa6vghTr 3gQuTz3jEt6YjS7aUmdAoahNfu0xfDAgGNYY9jqhhucRrpVIphkefI3OIYKzaQcd9d6UcO vgP1Wjjrn7hzotBqGGbQ3hacHYp5Rw4= ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b="Ff7/4oH4"; dmarc=none; spf=none (imf20.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1711051194; a=rsa-sha256; cv=none; b=7Rj3rQLMvcCoyiUAbhXsrFWzgL2SqSFVoGfI9psvKRqtO3/4GA3pMMQu2S7+T2D5sUFTwg 9ucTY4mc/C21Th3XjKTModIjeQNV/GOnWW5IFkotiXgexWDu40UyhTDJjmKJbbAY6xPUsA TaTSwyoAJEygjmpvZRJVbMdslB5tQ8g= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=BYPwtyCYd5a4JYAUK9MQluNVapG0iz3U/+Y3po5f7DY=; b=Ff7/4oH45A2jTNadCdQVtTteKx GvDjUzmbI7lEkAktx9oWHQ81RLamkG6ExAICJUUhg155LXm0ylzDEHKTR9u0rI3DAEpkBIVGyZr4P NJe28imfM7bV3S2h8MfNysnm3habPiFSxr5enFrID713fhv8sUVVroA2OKSIsUQ7tsezkJK0d+gtp F3tPZwVPVxo7QQahLjompHhMnHd8jHkNjYGbg/X5c1QvJZT7EdNGzBkKXHBQ8XWs7ISCJKpY5vIiW ALjGJNPK+9zDOdGzkqj0fAtug+lqv9JTolICvWh99R/7Q4GE3vWl1bCP4GCXJSjcKFPT7ZSgHRadF NcIql1Ng==; Received: from willy by casper.infradead.org with local (Exim 4.97.1 #2 (Red Hat Linux)) id 1rnOZn-00000007Tdd-1WHx; Thu, 21 Mar 2024 19:59:47 +0000 Date: Thu, 21 Mar 2024 19:59:47 +0000 From: Matthew Wilcox To: Svetly Todorov Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, gregory.price@memverge.com, wangkefeng.wang@huawei.com, akpm@linux-foundation.org, david@redhat.com, vbabka@suse.cz, naoya.horiguchi@linux.dev Subject: Re: [PATCH v3] kpageflags: respect folio head-page flag placement Message-ID: References: <20240320-kpageflags-svetly-v3-1-b6725843bfa7@memverge.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Rspamd-Queue-Id: 733B41C001F X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: dhgwp3epwdmip5ngk7mmfusr8smxe6r4 X-HE-Tag: 1711051193-177120 X-HE-Meta: U2FsdGVkX1/bK6B78mqUR5vpuupZs/NBiGlkyqRhDsRpmjA+8rE9yFAX0d+NYy45eaGSHphZlEUnd0F+JCciOhBjxwJ5/SRkqZU+nzZ2OqoK6JRAPcsYLsGcFrQq2rjrE8tCfTbHJK5oRCd/SaU+NIAFJ+WmD95T7uwClDAowmsh8hbEZ8m3OIfAtRrZ+wTNr6MA4GxordI/LJV/ki0vFq1RA3c81Lwg9YDVLg0VjQV/FZcfVvsqwBq8WdQ3ar8OeR/ET7Aqg6xtLMAAFqFxlWf+2nnkgk59R3h0PKKGMgvWKrkCSFJIIvhuihXDjBN8lBaYq4tOn/UXq/YSDpgCmS37SADaN9HLR7/iz8TskqRsD7QE19gvfbrjhYU7SvvzCUEeaBlcA31m2yd9Mjh5uVnFholeP0Zt4WvyWLk0czyaPSHYDtgPdIaMwAeTkCdgjWhONbfZrfd1s5xMj57A6F3straEPQtsHrLhmHRV/gPY6IYjDBJvoKs7P1L82pE3R3n9PGqErUC0jHIvhk3IQwVdFYeaDbevpqUmxdf1WmkwAwfMZQhK7xnzc9MyjjTzKpEbkeo7UycAzm97B8wcQmBCtA3RDNHGTi6MfZbDh30tf0b9Nuf9bpNgfGQqrQNBAjH6WphRV1yjrQ5uBpVXz8rVM/os+D1luNzJX7Zs0GfPRMUrD7OoZs5kUVgGw6a9/ym98PJved5YK0EmtjP/SzlW28HHb/+T8CLOfve/k+1A8cG1sUhS/1BTj5STk5pFymDsNqiSTWB280u62PTw3WdVloLa2EbueM7P9ZSzDgq/2tbBZCOEzRXUC0C2Lpoc8kIYQHNXWAGQ6Es9jqljA7iVigOZDQbT2wcdo84DdGip3VntA0yb1BLnSxOBtNhPjQN/PrDbkTZ1KyzPEX0vgKCigBbSAnvmMTt4a1ADz6yQF9vuDG/C3n1DF30/c5zsdvN69H3CJh56PX/T+fb cPfe8fji LON1ZnmLVEboiorUeYR7LMIZbDLAc+yM4BHImBIGdoZEylkiCGvLDy6bP57r7iFetO1KDsgrAsKiOh19zln1RSATn5Xe6di1GhCftq2XguaRt6bJp/kToBxQtJHLcPQlozDqK7D7ebs1QiLM= 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: List-Subscribe: List-Unsubscribe: On Thu, Mar 21, 2024 at 12:08:01PM -0700, Svetly Todorov wrote: > > > > - if (PageKsm(page)) > > > > + if (mapping & PAGE_MAPPING_KSM) > > > > u |= 1 << KPF_KSM; > > > This might need an #ifdef? > > > Say mapping is movable and anon -- then (mapping & PAGE_MAPPING_KSM) is > > > true. Before, we called PageKsm, which falls through to a PG_ksm check. > > > If !CONFIG_KSM then that flag is always false. But now, we're liable to > > > report KPF_KSM even if !CONFIG_KSM. > > > > I'm not sure where you see a PG_ksm check: > > > > static __always_inline bool folio_test_ksm(const struct folio *folio) > > { > > return ((unsigned long)folio->mapping & PAGE_MAPPING_FLAGS) == > > PAGE_MAPPING_KSM; > > } > > > > static __always_inline bool PageKsm(const struct page *page) > > { > > return folio_test_ksm(page_folio(page)); > > } > My bad. What I meant was, if CONFIG_KSM is undefined, then > > > #ifdef CONFIG_KSM > > ... > > static __always_inline bool PageKsm(struct page *page) > > { > > return folio_test_ksm(page_folio(page)); > > } > > will fall through to > > > # else > > TESTPAGEFLAG_FALSE(Ksm, ksm) > > #endif > > And you're right -- there is no PG_ksm comparison -- > but the autogenerated PageKsm will always return false: Yes, that's true. Usually we care about this because we can optimise out large chunks of code if a config option (eg CONFIG_KSM) is disabled. In this case, we're talking about a couple of instructions, and it's generally not worth optimising those out in order to add an ifdef in the code. We've got quite a long way with Linux without it becoming overrun with ifdefs (compare, eg, the Mach source code), and long may that continue ;-) > > 00 file (or NULL) > > 01 anon > > 10 movable > > 11 KSM > > > > Perhaps it might be clearer to say that anon pages are inherently > > movable; the movable type really means that the reset of the mapping > > pointer refers to a movable_operations instead of a mapping or anon_vma. > I see. I misunderstood how the flags are applied. > I thought that 11 == (01 | 10) -- i.e. that KSM was an intersection of > MOVABLE and ANON. But they're more like mutually-exclusive states. And > I doubt that a page will end up in the KSM "state" if CONFIG_KSM is > disabled. So we don't need to rely on PageKsm() for the CONFIG_KSM > check. > > That said, won't > > if (mapping & PAGE_MAPPING_KSM) > > return true even if a mapping is ANON (01) or MOVABLE (10) > but not KSM (11)? Shouldn't this at least be > > if (mapping & PAGE_MAPPING_KSM == PAGE_MAPPING_KSM) Uh, yeah, that was a mistake. This should do the trick: if (is_anon) { u |= 1 << KPF_ANON; if (mapping & PAGE_MAPPING_KSM) u |= 1 << KPF_KSM; } (all KSM pages are reported as anon pages as well, both before and after this patch; see how folio_test_anon() only checks the bottom bit) > > I see your confusion. We have three cases; head, tail and neither > > (obviously a page is never both head & tail). If a page is neither, > > it's order-0 and it is the only page in the folio. So we handle head > > or neither in the first leg of the 'if' where we set KPF_COMPOUND_HEAD > > if PG_head is set, and tail in the 'else' leg. > > Dumb mistake on my part. For some reason, I thought that every > folio->page had its PG_head set. At this point, it's bad naming, but it's not worth the churn of fixing it; we have a better destination in mind, and we'll get there soon enough. > Cool! Thanks for bearing with me. Beyond the KSM stuff, my only > hangup is that this patch doesn't account for the handful of > remaining per-page flags (KPF_HWPOISON, KPF_ARCH_*). Should I > take this diff, tack those on in a second commit, and then put > up a v4? Forgive me, I'm very green to the kernel dev process... Oh, yes, that's a bug on my part. HWPOISON is definitely per-page, not per-folio (although the handling of it differs for hugetlb) and I haven't looked at the PG_arch gunk yet. We are trying to sliminate the per-page flags, because there's no space for them in the future (we'll have special handling for hwpoison because that really is very special)