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 7F979C52D77 for ; Fri, 20 Jan 2023 19:47:52 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id F1DEF6B0071; Fri, 20 Jan 2023 14:47:51 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id EA6316B0073; Fri, 20 Jan 2023 14:47:51 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D46D56B0074; Fri, 20 Jan 2023 14:47:51 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id C022E6B0071 for ; Fri, 20 Jan 2023 14:47:51 -0500 (EST) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 8E00880B30 for ; Fri, 20 Jan 2023 19:47:51 +0000 (UTC) X-FDA: 80376212742.29.5FE8CFD Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf10.hostedemail.com (Postfix) with ESMTP id E2B2BC000D for ; Fri, 20 Jan 2023 19:47:48 +0000 (UTC) Authentication-Results: imf10.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=BdJbrjdi; spf=none (imf10.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1674244069; a=rsa-sha256; cv=none; b=EgAbmT5jYbn7Cv0zl2EEpXRHqdWQEYdg6waWdCKR47PMVp3G7vHSiCaxZPn/a3P7VJDf+m m/v9kGTFm1xRgVlNccHT8N8VQbBLl5zKaJ5eS5iN2j3gHl3Ac1bIZS0XVI7GfKxoHQ5sfS B2l6YNWKvFqc/knNBVlfDryM4hS9hmw= ARC-Authentication-Results: i=1; imf10.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=BdJbrjdi; spf=none (imf10.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1674244069; 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=d03v7w3Y8XlCff6/igHH0oG20Hre0Avz6+XHwVubR4M=; b=D851yUaN17eo9apSwkZ/QfVkFr8pHiCyB1fr/zAHbTblQvVxXoyaugVQgmSXzWg+tvdh08 KmcxCe6ljOZJ3gmx1iORLIocLBpy2f9wDuNKGTyikPjokkeJVtaDrGVS8M8XO+7Q5+CNjz u5OKyyhOrM2LSbuTBaNjJsdBkIG4a88= 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=d03v7w3Y8XlCff6/igHH0oG20Hre0Avz6+XHwVubR4M=; b=BdJbrjdi06pDLVM5tbWxRZ44cA ExOvpVsVE3JY9GP6qCHzk1++rM1Kfhr2+GQehjehl2bbBDCMutwJUv+sQg1gGKgj9Bi1Y5Ej8YSdU MVgVi27aTKjBFhFBRk7H6ozd3AS+8pYnqjrXKsas3ZOV2ticNZDDL6vk+1V7us0TtAz+7aCRMHC8A 9R4EoeI+82A2VN3n+1V5Eh/udQcWeOQSeNezfY2hjwkIguOb8ZabvNNWDZlAvqrP6Bzq3ItJaV9+8 /5wTealt3nuwoEMJNarZFzByWlLy0hjfcairU6GiTBzLfYcPF84L7RJcvEE3qRxbDN1zMt6e/fkXN rianS3PQ==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1pIxMV-002MtE-4I; Fri, 20 Jan 2023 19:47:43 +0000 Date: Fri, 20 Jan 2023 19:47:43 +0000 From: Matthew Wilcox To: "Yin, Fengwei" Cc: "Vishal Moola (Oracle)" , linux-mm@kvack.org, akpm@linux-foundation.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH mm-unstable 5/5] mm/mempolicy: Convert migrate_page_add() to migrate_folio_add() Message-ID: References: <20230118232219.27038-1-vishal.moola@gmail.com> <20230118232219.27038-6-vishal.moola@gmail.com> <4dd1a4f4-4da6-8079-a8de-bea7d8c18681@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <4dd1a4f4-4da6-8079-a8de-bea7d8c18681@intel.com> X-Rspam-User: X-Rspamd-Queue-Id: E2B2BC000D X-Rspamd-Server: rspam01 X-Stat-Signature: cku5rmaygujy89d3x171f6ib357gsj9z X-HE-Tag: 1674244068-19845 X-HE-Meta: U2FsdGVkX1/CJFAug9D4r+ThSXHyWOWpSj1HxyWOxp3shEbGo3vEKeGPMwG/SYDTSYKfesvz0afev0nBAKV88Sk3L0jaidMj1Xk+rOzXAqwqwTAMQvmhsMTi+d8g7fY30w3L+tE8FznUcIPAv4vempHtWMzbQmUxKH06oZVVs3rFPV46PibjDBRucI9GXEd9VYXdcD9UH5ajzcI8jsbJOme6YJb4IcDj75/8A9lVQwu0tFlqOi3uiXjpniBCpswhbwNol4nmfx7SWPc5HJxtpkQ6tIiG7pBKo4UH6sGmC+66npjjPiWz8nDWfATiipPjSfaEA19Q7vOC+d2c9Fhum3ZlLHl7+isHF7WedwEZzS1EAeYfFi+uzTtptTFsNc4mrN1nWOuwJjo0tLKhB+CFFMgOhy5Ka6WS0dYLmOeaz2xdBbcAntTAh0Ajc//ys8GOxk8vpKe+5uv+kqy7Ch+JjrAarPPzufG4il1NyE9B7CXveU4RmI6f0/9/pebQ10wsdsMLarzcd67nZNoVV52UAdJ4DmnXORcSUz7eVvOgQ8uOK9Hf8XbORy3+zoLoZZgy6lQS8OEhsyh158pOaaE7dw3txrJ9lWfUo9EJh1zzV+VB6LRLSrPo2jFBBGUpO2zNT3GFRYcYG+npvuMefjzEDWIZ1oor1SmP5b9REmUnoBHuHaXVWzVrhHLLaFu9qH6I2gPcAZjqtLX5lx2wy8jvhrVYtebOy9BTzO6qPo22UvLL5zlDxofHiWVEnIE8qwkTB+bT309jpRHQXth4DkMpD7sYvtyRBbSTQp4JwoqnDK3Asp/HQHemeocvosxSJ91jCY9bCPWnj4HpdRUI71uJU2bNO2V1O5bBxJGdVtlfzshhgq6/SJOgxRwqtBb5FTcxwYBgVqhiEhnJ97b64QmyO3u8Je/rClLRF8kM8bdxQ44nwemA69iRDpFhktN/uALValdMXGtiSpqGTK2fJgw cTluYuZ3 bnWOyrMEg37Sk/KreNI3xd+kijQJlHpi7sqMEBtKBdQ1bMz5H56uRdA/F9nq8DB2Iozd1iIySZEoarx5q6WyON3oFNcbjhzqS5UDWLutZ1TJYBGpW05tfIfILMCWhcBTOJTJ3xNlFC/G+5KsKVOUy70tIh16hSGQRWLmeHuCFAmpyuerUVAePnua7Pz+xDDnGjHQcaTUKF4NY6lCL3YIK2f+RDtZfWiQvMTr7qyriq4dSi5U/BcTobkEWc2JqqYuiVfKTQQ5krjYcmGuF6dEN+MlpS2FVoG2mKjv7 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: On Thu, Jan 19, 2023 at 09:24:16AM +0800, Yin, Fengwei wrote: > On 1/19/2023 7:22 AM, Vishal Moola (Oracle) wrote: > > @@ -1022,27 +1022,23 @@ static long do_get_mempolicy(int *policy, nodemask_t *nmask, > > } > > > > #ifdef CONFIG_MIGRATION > > -/* > > - * page migration, thp tail pages can be passed. > > - */ > > -static int migrate_page_add(struct page *page, struct list_head *pagelist, > > +static int migrate_folio_add(struct folio *folio, struct list_head *foliolist, > > unsigned long flags) > > { > > - struct page *head = compound_head(page); > > /* > > - * Avoid migrating a page that is shared with others. > > + * Avoid migrating a folio that is shared with others. > > */ > > - if ((flags & MPOL_MF_MOVE_ALL) || page_mapcount(head) == 1) { > > - if (!isolate_lru_page(head)) { > > - list_add_tail(&head->lru, pagelist); > > - mod_node_page_state(page_pgdat(head), > > - NR_ISOLATED_ANON + page_is_file_lru(head), > > - thp_nr_pages(head)); > > + if ((flags & MPOL_MF_MOVE_ALL) || folio_mapcount(folio) == 1) { > One question to the page_mapcount -> folio_mapcount here. > > For a large folio with 0 entire mapcount, if the first sub-page and any > other sub-page are mapped, page_mapcount(head) == 1 is true while > folio_mapcount(folio) == 1 is not. We had a good discussion about this in today's THP Cabal meeting [1]. I didn't quite check everything that I said was true, so let me summarise & correct it now ... - This is a heuristic. We're trying to see whether this folio is mapped by multiple processes (because if it is, it's probably not worth migrating). If the heuristic is wrong, it probably doesn't matter _too_ much? - A proper heuristic for this would be folio_total_mapcount(folio) == folio_nr_pages(folio) but this would be expensive to calculate as it requires examining 512 cachelines for a 2MB page. - For a large folio which is smaller than PMD size, we're guaranteed that folio_mapcount() is 0 today. - In the meeting I said that page_mapcount() of the head of a THP page was zero; that's not true; I had forgotten that we added in entire_mapcount to the individual page mapcount. so I now think this should be: page_mapcount(folio_page(folio, 0)) with an explanation that checking every page is too heavy-weight. Maybe it should be its own function: static inline int folio_estimated_mapcount(folio) { return page_mapcount(folio_page(folio, 0)); } with a nice comment explaining what's going on. [1] https://www.youtube.com/watch?v=A3PoGQQQD3Q is the recording of today's meeting.