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 7A6F4C433FE for ; Wed, 19 Oct 2022 05:44:03 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C98716B0072; Wed, 19 Oct 2022 01:44:02 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C48696B0073; Wed, 19 Oct 2022 01:44:02 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B36E46B0074; Wed, 19 Oct 2022 01:44:02 -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 A12236B0072 for ; Wed, 19 Oct 2022 01:44:02 -0400 (EDT) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 6BE2FC057F for ; Wed, 19 Oct 2022 05:44:02 +0000 (UTC) X-FDA: 80036607924.11.1865371 Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by imf16.hostedemail.com (Postfix) with ESMTP id 9432C18002C for ; Wed, 19 Oct 2022 05:44:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1666158240; x=1697694240; h=from:to:cc:subject:references:date:in-reply-to: message-id:mime-version; bh=rEU2UxyC7K1CU8TUsquirfHP1cok345aGVjiXwCezq4=; b=TOGDFsSildZligmd9m377+0GGch5UPmBpY937REbgJRzqJpQs1EKJEUO zZ5hl9RzLr4WdYtoVvxCcvlFJv/CwhMrWIT8OJLEYVo03sMgDXnvjPELH 1hBP/WABkbuvn9uitTITblFkDmgRpQ4Rdpe5NwJczfhIJq/pS0AAYTacc 2Khs9EmktpUED6z71K3jLNW3W+K7Ze8ndXcqlyW355i4Jp4Oh5RUEeyv4 OnuZM43Hm7LFH93pSNbF5Mg3T2ytTfKQwokms1+IKX3LN8grHiqWq1J93 KufRf03amKLl1n5k5fmhVvijBEVVHCq6ZrsGKst5+axuNNL9FEGyoGcA0 Q==; X-IronPort-AV: E=McAfee;i="6500,9779,10504"; a="303928472" X-IronPort-AV: E=Sophos;i="5.95,195,1661842800"; d="scan'208";a="303928472" Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Oct 2022 22:43:59 -0700 X-IronPort-AV: E=McAfee;i="6500,9779,10504"; a="958158545" X-IronPort-AV: E=Sophos;i="5.95,195,1661842800"; d="scan'208";a="958158545" Received: from yhuang6-desk2.sh.intel.com (HELO yhuang6-desk2.ccr.corp.intel.com) ([10.238.208.55]) by fmsmga005-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Oct 2022 22:43:57 -0700 From: "Huang, Ying" To: Cc: , , , , Subject: Re: [PATCH v3 2/3] mm: changes to split_huge_page() to free zero filled tail pages References: <8d286a7029079c1da0b062fbb045317508409187.1665614216.git.alexlzhu@fb.com> Date: Wed, 19 Oct 2022 13:43:17 +0800 In-Reply-To: <8d286a7029079c1da0b062fbb045317508409187.1665614216.git.alexlzhu@fb.com> (alexlzhu@fb.com's message of "Wed, 12 Oct 2022 15:51:46 -0700") Message-ID: <87h700pdvu.fsf@yhuang6-desk2.ccr.corp.intel.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=ascii ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=none ("invalid DKIM record") header.d=intel.com header.s=Intel header.b=TOGDFsSi; spf=pass (imf16.hostedemail.com: domain of ying.huang@intel.com designates 192.55.52.93 as permitted sender) smtp.mailfrom=ying.huang@intel.com; dmarc=pass (policy=none) header.from=intel.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1666158242; a=rsa-sha256; cv=none; b=Qmkpx+5du10x0qFIHl4WBu6hbK5zu98zEt+2EXoFBEnsJA3duiEBZxDg9+9oR3fN5mS8uA pFTbjq02ewmC0Pbu7ExO40647cgKwkeDxDxemaJvoTr/Vq/iCFxn6Xga3EE7nyGXd3gDwV Eu7ywkYUHHktrH3mmfdLTaWO/Ok3Ipo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1666158242; 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=7e+MYDyozLgqvfeEqbIcWt3bwEw2ESNCK3dzc6TFlv8=; b=4diwU/ztpQrcUfETTwCtGkACXBEWaqidVvdJRwVZss8Jr4SoGKztr0WUd6JZFPUWut/1gP 5VJYWc6Q/4yLBtdN/6W5wF3187079FMhTmJ3HCmhKnwKQbbB+j5imqoVpVskZ2KkZPvc9q 5iBY+hOhw1ol6qFfyHf15JqK+YJCmh4= X-Stat-Signature: ejra4cikmp3eegab66pctf4gh6cj84en X-Rspamd-Queue-Id: 9432C18002C Authentication-Results: imf16.hostedemail.com; dkim=none ("invalid DKIM record") header.d=intel.com header.s=Intel header.b=TOGDFsSi; spf=pass (imf16.hostedemail.com: domain of ying.huang@intel.com designates 192.55.52.93 as permitted sender) smtp.mailfrom=ying.huang@intel.com; dmarc=pass (policy=none) header.from=intel.com X-Rspam-User: X-Rspamd-Server: rspam01 X-HE-Tag: 1666158240-796426 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: writes: [snip] > diff --git a/mm/migrate.c b/mm/migrate.c > index c228afba0963..504ea5d7fd43 100644 > --- a/mm/migrate.c > +++ b/mm/migrate.c > @@ -168,13 +168,62 @@ void putback_movable_pages(struct list_head *l) > } > } > > +static bool try_to_unmap_clean(struct page_vma_mapped_walk *pvmw, struct page *page) > +{ > + void *addr; > + bool dirty; > + pte_t newpte; > + > + VM_BUG_ON_PAGE(PageCompound(page), page); > + VM_BUG_ON_PAGE(!PageAnon(page), page); > + VM_BUG_ON_PAGE(!PageLocked(page), page); > + VM_BUG_ON_PAGE(pte_present(*pvmw->pte), page); > + > + if (PageMlocked(page) || (pvmw->vma->vm_flags & VM_LOCKED)) > + return false; > + > + /* > + * The pmd entry mapping the old thp was flushed and the pte mapping > + * this subpage has been non present. Therefore, this subpage is > + * inaccessible. We don't need to remap it if it contains only zeros. > + */ > + addr = kmap_local_page(page); > + dirty = memchr_inv(addr, 0, PAGE_SIZE); > + kunmap_local(addr); > + > + if (dirty) > + return false; > + > + pte_clear_not_present_full(pvmw->vma->vm_mm, pvmw->address, pvmw->pte, false); > + > + if (userfaultfd_armed(pvmw->vma)) { > + newpte = pte_mkspecial(pfn_pte(page_to_pfn(ZERO_PAGE(pvmw->address)), > + pvmw->vma->vm_page_prot)); > + ptep_clear_flush(pvmw->vma, pvmw->address, pvmw->pte); Why do we need clear PTE and flush TLB again? If my understanding were correct, the TLB has been flushed when unmapping the page. Otherwise, we need to flush TLB before checking whether the page is all-zero. > + set_pte_at(pvmw->vma->vm_mm, pvmw->address, pvmw->pte, newpte); > + dec_mm_counter(pvmw->vma->vm_mm, MM_ANONPAGES); > + count_vm_event(THP_SPLIT_REMAP_READONLY_ZERO_PAGE); > + return true; > + } > + > + dec_mm_counter(pvmw->vma->vm_mm, mm_counter(page)); This can be moved before "if (userfaultfd_armed(pvmw->vma))". > + count_vm_event(THP_SPLIT_UNMAP); > + return true; > +} > + [snip] Best Regards, Huang, Ying