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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 21EB6EE4996 for ; Mon, 21 Aug 2023 01:32:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231969AbjHUBcU (ORCPT ); Sun, 20 Aug 2023 21:32:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41026 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232381AbjHUBcS (ORCPT ); Sun, 20 Aug 2023 21:32:18 -0400 Received: from invmail4.hynix.com (exvmail4.hynix.com [166.125.252.92]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 2B9BAA3 for ; Sun, 20 Aug 2023 18:31:44 -0700 (PDT) X-AuditID: a67dfc5b-d6dff70000001748-a6-64e2be5bc41e Date: Mon, 21 Aug 2023 10:28:05 +0900 From: Byungchul Park To: "Huang, Ying" Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, kernel_team@skhynix.com, akpm@linux-foundation.org, namit@vmware.com, xhao@linux.alibaba.com, mgorman@techsingularity.net, hughd@google.com, willy@infradead.org, david@redhat.com, peterz@infradead.org, luto@kernel.org, dave.hansen@linux.intel.com Subject: Re: [RFC 2/2] mm: Defer TLB flush by keeping both src and dst folios at migration Message-ID: <20230821012804.GA43847@system.software.com> References: <20230804061850.21498-1-byungchul@sk.com> <20230804061850.21498-3-byungchul@sk.com> <877cpx9jsx.fsf@yhuang6-desk2.ccr.corp.intel.com> <20230816001307.GA44941@system.software.com> <87r0o37qcn.fsf@yhuang6-desk2.ccr.corp.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <87r0o37qcn.fsf@yhuang6-desk2.ccr.corp.intel.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wsTs6azOLA57FgU6nH5hVaHov3vGTy2LSqk81j06dJ7B4nZvxm8dj50NJj3slAj/f7rrJ5 LH7xgclj6y87j8+b5DzezX/LFsAbxWWTkpqTWZZapG+XwJWx61w/W8Ev0YqnU56yNTC+Eehi 5OSQEDCReL7hHguIzSKgKvFj/xFWEJtNQF3ixo2fzCC2iICGxKeFy9lBbGaBbUwSC+45gNjC AjESJ7Z8ZgKxeQUsJK49bGfsYuTiEBL4wSixf9cVNoiEoMTJmU9YIJq1JG78ewnUwAFkS0ss /8cBEuYUsJP4fnIy2HxRAWWJA9uOM01g5J2FpHsWku5ZCN0LGJlXMYpk5pXlJmbmmOoVZ2dU 5mVW6CXn525iBEbIsto/E3cwfrnsfohRgINRiYc3QeZRihBrYllxZe4hRgkOZiURXunvD1OE eFMSK6tSi/Lji0pzUosPMUpzsCiJ83qFpyYICaQnlqRmp6YWpBbBZJk4OKUaGKddscz3Phgg l3HzqqRB0Ckt+zaxlOr/doFqEzseLXbh0Cu9/fuAWmSB3ZYJgYczWZS91bo3n3zzm/GM/DOe xZFq70OyDT5cvtzEqsEaYPgm7orpi6Kii7X7Ij6GH5iR2/Yhz1uqrXfapPhT9+a3lx6rT7fj 8avN/pF10P7f+S1K6yv2dImqK7EUZyQaajEXFScCAMmg4uWMAgAA X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Aug 16, 2023 at 09:01:12AM +0800, Huang, Ying wrote: > Byungchul Park writes: > > > On Tue, Aug 15, 2023 at 09:27:26AM +0800, Huang, Ying wrote: > >> Byungchul Park writes: > >> > >> > Implementation of CONFIG_MIGRC that stands for 'Migration Read Copy'. > >> > > >> > We always face the migration overhead at either promotion or demotion, > >> > while working with tiered memory e.g. CXL memory and found out TLB > >> > shootdown is a quite big one that is needed to get rid of if possible. > >> > > >> > Fortunately, TLB flush can be defered or even skipped if both source and > >> > destination of folios during migration are kept until all TLB flushes > >> > required will have been done, of course, only if the target PTE entries > >> > have read only permission, more precisely speaking, don't have write > >> > permission. Otherwise, no doubt the folio might get messed up. > >> > > >> > To achieve that: > >> > > >> > 1. For the folios that have only non-writable TLB entries, prevent > >> > TLB flush by keeping both source and destination of folios during > >> > migration, which will be handled later at a better time. > >> > > >> > 2. When any non-writable TLB entry changes to writable e.g. through > >> > fault handler, give up CONFIG_MIGRC mechanism so as to perform > >> > TLB flush required right away. > >> > > >> > 3. TLB flushes can be skipped if all TLB flushes required to free the > >> > duplicated folios have been done by any reason, which doesn't have > >> > to be done from migrations. > >> > > >> > 4. Adjust watermark check routine, __zone_watermark_ok(), with the > >> > number of duplicated folios because those folios can be freed > >> > and obtained right away through appropreate TLB flushes. > >> > > >> > 5. Perform TLB flushes and free the duplicated folios pending the > >> > flushes if page allocation routine is in trouble due to memory > >> > pressure, even more aggresively for high order allocation. > >> > >> Is the optimization restricted for page migration only? Can it be used > >> for other places? Like page reclaiming? > > > > Just to make sure, are you talking about the (5) description? For now, > > it's performed at the beginning of __alloc_pages_slowpath(), say, before > > page recaiming. Do you think it'd be meaningful to perform it during page > > reclaiming? Or do you mean something else? > > Not for (5). TLB needs to be flushed during page reclaiming too. Can > similar method be used to reduce TLB flushing there too? If you were talking about unmapping for swap while reclaiming, then I think yes. The case can also take benefit from CONFIG_MIGRC. Byungchul