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 32078C25B76 for ; Wed, 5 Jun 2024 03:59:03 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 58CD86B007B; Tue, 4 Jun 2024 23:59:03 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 53BDE6B0083; Tue, 4 Jun 2024 23:59:03 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3DBA86B0089; Tue, 4 Jun 2024 23:59:03 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 20C316B007B for ; Tue, 4 Jun 2024 23:59:03 -0400 (EDT) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id C36B9A0B40 for ; Wed, 5 Jun 2024 03:59:02 +0000 (UTC) X-FDA: 82195479324.18.E9AEF4D Received: from mail-pl1-f172.google.com (mail-pl1-f172.google.com [209.85.214.172]) by imf18.hostedemail.com (Postfix) with ESMTP id E1A011C0010 for ; Wed, 5 Jun 2024 03:59:00 +0000 (UTC) Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=FTAx3PPG; spf=pass (imf18.hostedemail.com: domain of seakeel@gmail.com designates 209.85.214.172 as permitted sender) smtp.mailfrom=seakeel@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1717559940; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=54k4JVJ2VfsnpnXkzAM0LcBwi0z2trB1l7d+zq3pvf4=; b=N0u56TITb7hI7wYR2S1Pp9BM4XIVYUdnjROWwD8TKejybIV/27k1RMOwpunJKpvNKMBLjq cZDEi/S8oVm1LjF3fwMloDbsHOviwtm2BPxO5fDP/Zyy7RZNTJuATlywcJmcur0KRtT6Bq bKMAb++OiMLOsWzag/KEC1fh72jJ0qc= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=FTAx3PPG; spf=pass (imf18.hostedemail.com: domain of seakeel@gmail.com designates 209.85.214.172 as permitted sender) smtp.mailfrom=seakeel@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1717559940; a=rsa-sha256; cv=none; b=huT8c5fQZbAGdVBYcu/deStiPFtzmEqoRRrlM5qw3Jjen/XCRRkCkGJ9pLCe8K61VVx2hX B4btLq0W4RKmon/uw4/yxyr8DW58ewNbBrrBlq+CASrc/LkDoHtcTFUqEtIi+/DScGOGH0 3T6BqlI9BzF/IG9r/xF7Rxg3/mJNlTA= Received: by mail-pl1-f172.google.com with SMTP id d9443c01a7336-1f47f07acd3so15755865ad.0 for ; Tue, 04 Jun 2024 20:59:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1717559940; x=1718164740; darn=kvack.org; h=content-transfer-encoding:in-reply-to:from:content-language :references:to:subject:user-agent:mime-version:date:message-id:from :to:cc:subject:date:message-id:reply-to; bh=54k4JVJ2VfsnpnXkzAM0LcBwi0z2trB1l7d+zq3pvf4=; b=FTAx3PPGxYOiCcknLVL3yPxCjxbHwYryJsRu9aHnYIAzwZi+Gtqm2VzMo40hDOn3OD jny2TcZlod8r/QsDy0zmYoOyoevcJWkJgIyBxVaq0TK3DVT1AXttJLxV3Ob3DdEbgUUL 9vwRxk759185JogWCDNF4ncdhNbl2PSlSwamdf/CuiC3siohoQ1Iyv6NyG+SJShXGhco SPW3WdKsvNMbrF0qCIsqTlFx8L8BL6rRwt7P2cGe0jxGVjEkT2IBGJHPKOFN00NUMrzG 30vByXfokf+G3Uzr9sZhmUqUfZgWF7Jp+CY5dzQRSxjgSQvgr2EAmnRpZQprdBD+/Qn1 pAOQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717559940; x=1718164740; h=content-transfer-encoding:in-reply-to:from:content-language :references:to:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=54k4JVJ2VfsnpnXkzAM0LcBwi0z2trB1l7d+zq3pvf4=; b=j3YJZi+2CT03zEc5FS1Mt1D8fIpEem0wsMIQVNUqTbGgO2G9uj09jz4ggzlbhKDH9N p0glu/AQW83uXDdLRfIkwGYV9JaysQhrn0WCURlVh+MIo4yuVTvylTQmgZ54qXytdmLK aEyWm40V6scshZItTnL647mY5CWFJDfGM2bB8SQe4SWRv20E9mMDWrlMEPzndrjTRdPB iAn0FwZAvECid8fbdEY2wgebuPG8YNE5ifMUNh6krfkb/Pshs2FAOSurKaVyZwM0eZVV 4CFHyTBO+WfsXS7498s7TKwcxexrqmZeg4rh327J68T9th1YSPWKSoCff52CPLrxK5Zg C4jg== X-Forwarded-Encrypted: i=1; AJvYcCXZnnGY2tFEF0G/QnTi9Udg90O27mLrIXvr4U8t/r2S1pZjLNlaXP5wh8NE8zDZL5WMV3D7rcAPpXdVLSVMbqKMXB4= X-Gm-Message-State: AOJu0YwiOdUAsR984BpLqWIrAgvKD9zmAdI8iMa6uECBFiXlg3peiCEt GFTdG+4iNyQ53zmYiLXnC4b2LvkMoXhpv6dFLfm3NLUgHO+xlNAg X-Google-Smtp-Source: AGHT+IE3tPaE85dvArgrwiDJsTFKRfY975PcDsEMBCKjm98mHDhrWWgCegkkSL7nEGU4MgFPgy/16Q== X-Received: by 2002:a17:903:2446:b0:1f6:6591:67ad with SMTP id d9443c01a7336-1f6a5a26e4bmr17151125ad.34.1717559939630; Tue, 04 Jun 2024 20:58:59 -0700 (PDT) Received: from [192.168.255.10] ([43.132.141.20]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1f632379db9sm91096445ad.110.2024.06.04.20.58.56 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 04 Jun 2024 20:58:59 -0700 (PDT) Message-ID: Date: Wed, 5 Jun 2024 11:58:55 +0800 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH 02/10] mm/ksm: skip subpages of compound pages To: David Hildenbrand , alexs@kernel.org, Andrew Morton , linux-mm@kvack.org, linux-kernel@vger.kernel.org, izik.eidus@ravellosystems.com, willy@infradead.org, aarcange@redhat.com, chrisw@sous-sol.org, hughd@google.com References: <20240604042454.2012091-1-alexs@kernel.org> <20240604042454.2012091-3-alexs@kernel.org> <8d3a60d5-06c5-4df4-aeda-2fbec45a8ae0@redhat.com> <00dcd224-6333-4f1e-9087-bdb5024ac236@redhat.com> <9f4f6f0e-81e8-4bd0-9f20-412a543a452d@gmail.com> <3d2ad8a3-30c6-41d6-841b-e8c376d01da3@redhat.com> Content-Language: en-US From: Alex Shi In-Reply-To: <3d2ad8a3-30c6-41d6-841b-e8c376d01da3@redhat.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Rspam-User: X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: E1A011C0010 X-Stat-Signature: t6oo74gasf6oph5i8twyz3yairhfx8dy X-HE-Tag: 1717559940-222021 X-HE-Meta: U2FsdGVkX192+vKcoe4tXRtw1jCl8Uf+7F7QAk5GFh61ibWpa2ScyKrYnULpdPpZ9hvqVrqyzmAS63Uz6yelAwM7wt5WsQ8dNSLJuBPRo+ucG1xG/mC8B+x8g4DQJKSk4UPcNRPRa+4rHQHIfEQkBjy7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CeZos+0vaEKZInLZzSXPNqdFPUKKimDmtnqu0rBmAo9lEwRSxZsjNiruyTHNdCj0SN6Y4GvnYeXocHSRqO+SivzqmOtO5Vdm0oY9taWcn4xy7/Us6LacvecetT5el9rCcoIvQMvTQ9hGB6y2dfwr83qy0EgFCXuLvzjPJ4R9WolxBK0+7NMt0rwjrrL4KFi4pMB79YlfQmRr2T3SI8NeKf4vK+m+our0iZLKszhOHKXh2KIaakMXqAOQQMpiH8ef7fIwWrx6slz8yw4TUX+gFxvSQuQ07OGBnCYvH+CVA== 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 6/4/24 9:14 PM, David Hildenbrand wrote: > On 04.06.24 15:10, Alex Shi wrote: >> >> >> On 6/4/24 6:43 PM, David Hildenbrand wrote: >>>>>> >>>>>> @@ -2680,7 +2685,7 @@ static struct ksm_rmap_item *scan_get_next_rmap_item(struct page **page) >>>>>>                 } >>>>>>     next_page: >>>>>>                 put_page(*page); >>>>>> -            ksm_scan.address += PAGE_SIZE; >>>>>> +            ksm_scan.address += nr * PAGE_SIZE; >>>>>>                 cond_resched(); >>>>>>             } >>>>>>         } >>>>> >>>>> You might be jumping over pages that don't belong to that folio. What you would actually want to do is somehow use folio_pte_batch() to really know the PTEs point at the same folio, so you can skip them. But that's not that easy when using follow_page() ... >>>>> >>>>> So I suggest dropping this change for now. >>>>> >>>> >>>> Hi David, >>>> >>>> Forgive my stupidity, where I jump over normal page that not to belong to the folio? >>> >>> IIUC, you assume that the folio is fully mapped by all PTEs that could span it, and that follow_page() would give you the head page, correct? >>> >>> As a simple example, assume only a single page of a large folio is still mapped, which could be any tail page. You couldn't jump over any PTEs. >>> >>> Or am I missing something? >> >> Uh, thanks for explanations. for what's we concerned, the following code could take care of the FULL or ERR pages. And it still keep the step of single page. >>                          page = follow_page(vma, ksm_scan.address, FOLL_GET); >>                          if (IS_ERR_OR_NULL(page)) { >>                                  ksm_scan.address += PAGE_SIZE; >>                                  cond_resched(); >>                                  continue; >>                          } >> And after the above code, step folio_nr_pages on address should be safe, isn't it? > > Not sure if I follow. Let me try explaining once again: > > Assume a PTE maps some tail page of the large anonymous folio. The other PTEs around it map some other anonymous folios, not pages of that large anonymous folio. Sorry, David, Do you meaning there are 2 folio pages, in a same vma, in their address, 'ksm_scan.address', would be overlapped in a folio size space? If so, that do out of my expect. I do have no idea of this thing. Could you give me more hints of this problem or how things work on it in current kernel? Thanks a lot! Alex > > Without looking at the other PTEs you don't know how much you can skip. >