Received: by 2002:a05:7412:b995:b0:f9:9502:5bb8 with SMTP id it21csp660009rdb; Fri, 22 Dec 2023 00:41:43 -0800 (PST) X-Google-Smtp-Source: AGHT+IHNz5IfSzPTXgXVEIDZYOstasBtJwcqwAi0Ag91bkGUMdil/gKUm6YEcbI29TLbnR51St16 X-Received: by 2002:a05:6102:5e91:b0:466:b3a9:ec56 with SMTP id ij17-20020a0561025e9100b00466b3a9ec56mr791552vsb.47.1703234503594; Fri, 22 Dec 2023 00:41:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703234503; cv=none; d=google.com; s=arc-20160816; b=HU1SbLOGSJrr4qhFskNcBbMllMLqeE4MeDqE/dSXJTDtc8Ri6ZzPTc2A8Je9jn7Bn2 4ag9qyLQdnJsVK9/RcnlJwHfkZraHm+yuq1Lpwwq/4vD8vYC4x5+T8kFJoWQTwU0p8mT 6Yt1gI5ROMpZuNCkWhMIM7fPto7UDleOuAEnea14xWAcIWQbyY+1N4gc6igJDvkSj5/T WMyyf36VHF+yrF+kZxSO9cNPkvXwihpRvoXw/5CbL45dRy1d69fiRQKg/AHmDSmYq6fh WIa3CK627tuIeb+yDN/9fDGl7BJ0AS47CjIE2i14VLTVx61oyItZnFnuL2/h3rHwPatU LzVA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:dkim-signature; bh=P66lBpZdkUC3/1oyh59gObPlC1U1DYIHSlxdNgyPt2M=; fh=1SDhOsM2/LFdl7wH4zgkLBoyTmlA3hP9gTDsfgkYNY0=; b=o5+t5sSMefkg6Mk7uIgr+SR33puE/SOKNz+oFTHl531w3BaD/FtXc+BvtjU4N/Ir1d uPuNAokaCmAsJi295i5ltOGbCfiLGdnfBVD/YriqvMzID5TEybB+eBEunF9f7QDlb9Z2 xjSXqOEzJE7ERuuCkqARmNxTLv/qTp4uGZ+hW5bueP5nTtbn+wTCxPEBbh4Ln3a9ga/h etOdAtwefu/o+eNt5chVQlH9YI2s0JgCd70Kibth9TSk93oJ9uVyeqm1DC1fl4FIq8zv MeSvSxb442lETT/FSF2KuYe9bV6VOlpeCJw27Nacl9LP0QTLTMMjJsZoS0SDuNUfGxT+ JN/g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=MIrStesy; spf=pass (google.com: domain of linux-kernel+bounces-9512-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-9512-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id c5-20020ac85a85000000b004277b58474csi3803013qtc.145.2023.12.22.00.41.43 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Dec 2023 00:41:43 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-9512-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=MIrStesy; spf=pass (google.com: domain of linux-kernel+bounces-9512-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-9512-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 4ADB81C21E0E for ; Fri, 22 Dec 2023 08:41:43 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 8B2C9CA5D; Fri, 22 Dec 2023 08:41:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="MIrStesy" X-Original-To: linux-kernel@vger.kernel.org Received: from mail-lf1-f43.google.com (mail-lf1-f43.google.com [209.85.167.43]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 078E7C8CF for ; Fri, 22 Dec 2023 08:41:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-lf1-f43.google.com with SMTP id 2adb3069b0e04-50e6a5b5e36so299884e87.3 for ; Fri, 22 Dec 2023 00:41:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1703234493; x=1703839293; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=P66lBpZdkUC3/1oyh59gObPlC1U1DYIHSlxdNgyPt2M=; b=MIrStesydGEKJryNV0/aC330q4qp1FC7OunSJfIMfjaVhR3o4tBCEsxNFINgAnAlRa 00auRkLTHA9z5M4RVVQYZ3ufsoU+NF2znX6vxR+FCsR7M6WN3kytvaKirbBj/tOusmcq Rnxy1/i3pz0bemH5rHbtIK7tLVPDCvlZKQ9ZQRgcDd2HJppLUxItHGAwxc98suEaE0U1 lk28pkgaOdxwEcHde92Y86zXISat40d4i1TKxo3zuqxr1EWLPC6CMDamqe+L89OylPzR qAxniwlTGyJByiYLJipDRU7FnyqOgWkX775l3Wzg+Ey4wuccqB2y32QTTaHa7kGIKhGo IYAw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1703234493; x=1703839293; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=P66lBpZdkUC3/1oyh59gObPlC1U1DYIHSlxdNgyPt2M=; b=UsXLnh6R6TwSfOrrFGXdwgPG/+ub6GAnJdp9lthpSzaaMQ/m5Jwt8xTDGzfo4ijAnQ v+AbWMhf5BGWkx8cYHSY2/yQDZS/n45S9hUzlK5IL2Cs0Tb/Xq6zesfLtu9lUWEyDVsI RLTMhTKE5P0QjQ7mm/4wEvb7mhExeSsXWgno1Le9bKs5RMSNDMK5/GToFbKV8QdW2Fm3 K8ocix84l5qXD5ZEl1Te6lIybbqErsCxz0pAJB0cM6xyGYUzNTmEOGXod/wY1QKXf9b0 I6MbndVfwFMMDtAOweU9w79y8LnuyXqtG11oML1LvbqFzNr4qJHrTkHMr3ancRM7dkYD et4g== X-Gm-Message-State: AOJu0Yz3t/RPxqG0zpM/Uj/TYf+wpg08KFlYotOcHEADxvwExAW+56l0 qE0a4Yk4CYD6bEZviAYZvx8JGrhex2yqaqYuA+Y= X-Received: by 2002:a05:6512:208e:b0:50e:6878:a71d with SMTP id t14-20020a056512208e00b0050e6878a71dmr362356lfr.44.1703234492506; Fri, 22 Dec 2023 00:41:32 -0800 (PST) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20231220102948.1963798-1-zhaoyang.huang@unisoc.com> <1703226522421.22653@unisoc.com> In-Reply-To: From: Zhaoyang Huang Date: Fri, 22 Dec 2023 16:41:20 +0800 Message-ID: Subject: Re: reply: [RFC PATCH 1/1] mm: mark folio accessed in minor fault To: Yu Zhao Cc: =?UTF-8?B?6buE5pyd6ZizIChaaGFveWFuZyBIdWFuZyk=?= , Matthew Wilcox , Andrew Morton , "linux-mm@kvack.org" , "linux-kernel@vger.kernel.org" , =?UTF-8?B?5bq357qq5ruoIChTdGV2ZSBLYW5nKQ==?= Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Fri, Dec 22, 2023 at 2:45=E2=80=AFPM Yu Zhao wrote: > > On Thu, Dec 21, 2023 at 11:29=E2=80=AFPM =E9=BB=84=E6=9C=9D=E9=98=B3 (Zha= oyang Huang) > wrote: > > > > > > On Thu, Dec 21, 2023 at 10:53=E2=80=AFPM Zhaoyang Huang wrote: > > > > > > On Thu, Dec 21, 2023 at 2:33=E2=80=AFPM Yu Zhao w= rote: > > > > > > > > On Wed, Dec 20, 2023 at 11:28=E2=80=AFPM Zhaoyang Huang wrote: > > > > > > > > > > On Thu, Dec 21, 2023 at 12:53=E2=80=AFPM Yu Zhao wrote: > > > > > > > > > > > > On Wed, Dec 20, 2023 at 9:09=E2=80=AFPM Matthew Wilcox wrote: > > > > > > > > > > > > > > On Thu, Dec 21, 2023 at 09:58:25AM +0800, Zhaoyang Huang wrot= e: > > > > > > > > On Wed, Dec 20, 2023 at 10:14=E2=80=AFPM Matthew Wilcox wrote: > > > > > > > > > > > > > > > > > > On Wed, Dec 20, 2023 at 06:29:48PM +0800, zhaoyang.huang = wrote: > > > > > > > > > > From: Zhaoyang Huang > > > > > > > > > > > > > > > > > > > > Inactive mapped folio will be promoted to active only w= hen it is > > > > > > > > > > scanned in shrink_inactive_list, while the vfs folio wi= ll do this > > > > > > > > > > immidiatly when it is accessed. These will introduce tw= o affections: > > > > > > > > > > > > > > > > > > > > 1. NR_ACTIVE_FILE is not accurate as expected. > > > > > > > > > > 2. Low reclaiming efficiency caused by dummy nactive fo= lio which should > > > > > > > > > > be kept as earlier as shrink_active_list. > > > > > > > > > > > > > > > > > > > > I would like to suggest mark the folio be accessed in m= inor fault to > > > > > > > > > > solve this situation. > > > > > > > > > > > > > > > > > > This isn't going to be as effective as you imagine. Almo= st all file > > > > > > > > > faults are handled through filemap_map_pages(). So I mus= t ask, what > > > > > > > > > testing have you done with this patch? > > > > > > > > > > > > > > > > > > And while you're gathering data, what effect would this p= atch have on your > > > > > > > > > workloads? > > > > > > > > Thanks for heads-up, I am out of date for readahead mechani= sm. My goal > > > > > > > > > > > > > > It's not a terribly new mechanism ... filemap_map_pages() was= added nine > > > > > > > years ago in 2014 by commit f1820361f83d > > > > > > > > > > > > > > > is to have mapped file pages behave like other pages which = could be > > > > > > > > promoted immediately when they are accessed. I will update = the patch > > > > > > > > and provide benchmark data in new patch set. > > > > > > > > > > > > > > Understood. I don't know the history of this, so I'm not sur= e if the > > > > > > > decision to not mark folios as accessed here was intentional = or not. > > > > > > > I suspect it's entirely unintentional. > > > > > > > > > > > > It's intentional. For the active/inactive LRU, all folios start > > > > > > inactive. The first scan of a folio transfers the A-bit (if it'= s set > > > > > > during the initial fault) to PG_referenced; the second scan of = this > > > > > > folio, if the A-bit is set again, moves it to the active list. = This > > > > > > way single-use folios, i.e., folios mapped for file streaming, = can be > > > > > > reclaimed quickly, since they are "demoted" rather than "promot= ed" on > > > > > > the second scan. This RFC would regress memory streaming worklo= ads. > > > > > Thanks. Please correct me if I am wrong. IMO, there will be no > > > > > minor-fault for single-use folios > > > > > > > > Why not? What prevents a specific *access pattern* from triggering = minor faults? > > > Please find the following chart for mapped page state machine > > > transfication. > > > > > I'm not sure what you are asking me to look at -- is the following > > > trying to illustrate something related to my question above? > > > > sorry for my fault on table generation, resend it, I am trying to prese= nt how RFC performs in a page's stat transfer > > > > 1. RFC behaves the same as the mainline in (1)(2) > > 2. VM_EXEC mapped pages are activated earlier than mainline which help = improve scan efficiency in (3)(4) > > 3. none VM_EXEC mapped pages are dropped as vfs pages do during 3rd sca= n. > > > > (1) > > 1st access shrink_active_list= 1st scan(shink_folio_list) 2nd scan(shrink_folio_list') > > mainline INA/UNR NA = INA/REF DROP > > RFC INA/UNR NA = INA/REF DROP > > I don't think this is the case -- with this RFC, *readahead* folios, > which are added into pagecache as INA/UNR, become PG_referenced upon > the initial fault (first access), i.e., INA/REF. The first scan will > actually activate them, i.e., they become ACT/UNR, because they have > both PG_referenced and the A-bit. No,Sorry for the confusion. This RFC actually aims at minor fault of the faulted pages(with one pte setup). In terms of the readahead pages, can we solve it by add one criteria as bellow, which unifies all kinds of mapped pages in RFC. @@ -3273,6 +3273,12 @@ vm_fault_t filemap_fault(struct vm_fault *vmf) */ folio =3D filemap_get_folio(mapping, index); if (likely(!IS_ERR(folio))) { + /* + * try to promote inactive folio here when it is accessed + * as minor fault + */ + if(folio_mapcount(folio)) + folio_mark_accessed(folio); /* * We found the page, so try async readahead before waiting= for * the lock. > > So it doesn't behave the same way the mainline does for the first case > you listed. (I didn't look at the rest of the cases.)