Received: by 2002:a05:7412:b995:b0:f9:9502:5bb8 with SMTP id it21csp8157849rdb; Thu, 4 Jan 2024 23:43:35 -0800 (PST) X-Google-Smtp-Source: AGHT+IGzgNdf03Kh2eNiKgLttWf99S5DVqc9toQZzGmuejJtCBqSnJc7KJ2C9KjiTM8d0NblxIU3 X-Received: by 2002:a05:6512:b21:b0:50e:936b:a466 with SMTP id w33-20020a0565120b2100b0050e936ba466mr999438lfu.90.1704440615744; Thu, 04 Jan 2024 23:43:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704440615; cv=none; d=google.com; s=arc-20160816; b=rSPb7yMNExqZ4PiZxPISYJQmSfStcydTa+qIt/bQgr42C7DMJ5jMswkBaw/RYYBzmr 9H/JOYFSvLMbqLJsnt9dhvwcKHjmYlzTDM/CTNYMQb8md9XKKt0qN9sh03xM5I1EibTY evpr4jB7s7Bh71pzyahpEVs9M1NoT+ywb/oHEPUC6306Jpc/wMdR9P4W7gsz2jH6lRfc 6EfdePLig+ItFF60ISx+6VSaRGTFh8LQqv/1hYufKiSlT0FQ3CvEGu1wWD7J/vXDU6zd UlkeuDdjXbA0SZiFD6ZvR0Wt9WbzL6BNUJeWaDyI8aX16UiMrIFCvKO4beS6n6xn45HL PIvw== 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=dE868xNBfi0PhqqrB/NKR+HFo2ZSd9jez98UiAP14BY=; fh=3Te4VzrR19Xj6LU2ZBrLkQucW4yaq3NF6TKWnMSnzLY=; b=0VyelM+3/vkT4UeAri60FjKPk2BDrr9t/9N5yQ9pl/8D1orSeqi+0w6BnfC1V92cLH R1JXctZMLRW2OZ7xP4MExOFtljOO5v5gve9A//dT5dN5aRkCcp+u9rjLrgolfxshXt59 L+fBIGGuh8iuvDFaI8GljdzgWBKtuP3SPcfWSKvAr7ANtBsVEO6frCpm+ZF9/xO6ajEC Ve4YzTnoyMiWkW5tHNPlFYv+KVtnOsT6IdYwZ+zj1A0TX7sL+8ZzrISuqo7Swzf6WU3h 13/LqnFs7Qp51SeezlQNKa4xxWuiHwA/zxNzpdpFZQwiPcQr8NwF54XLqNNSE3Z/swAw ZgSw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b="i/Ys391T"; spf=pass (google.com: domain of linux-kernel+bounces-17554-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-17554-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id lj24-20020a170906f9d800b00a286018179fsi367901ejb.222.2024.01.04.23.43.35 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Jan 2024 23:43:35 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-17554-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b="i/Ys391T"; spf=pass (google.com: domain of linux-kernel+bounces-17554-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-17554-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 am.mirrors.kernel.org (Postfix) with ESMTPS id 428F71F23510 for ; Fri, 5 Jan 2024 07:43:35 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 046ED20327; Fri, 5 Jan 2024 07:43:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="i/Ys391T" X-Original-To: linux-kernel@vger.kernel.org Received: from mail-lj1-f182.google.com (mail-lj1-f182.google.com [209.85.208.182]) (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 94FC620306 for ; Fri, 5 Jan 2024 07:43:25 +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-lj1-f182.google.com with SMTP id 38308e7fff4ca-2ccec119587so15684911fa.0 for ; Thu, 04 Jan 2024 23:43:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1704440603; x=1705045403; 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=dE868xNBfi0PhqqrB/NKR+HFo2ZSd9jez98UiAP14BY=; b=i/Ys391TpT3YGSUGFQXmf/qoTCaW6bwLI4pgvB/R0OKCNECHLHmfi9QJh/kBLQANU7 bKi8jb5IkJG/edKqk2Gsj4myTAP+uCYJFNNKGpoCoqt7j5FjVpMor90uLK5o/3IYNHf2 gdICn58MzriaB0Ex4LY5Ixkmn8XPi+11qXmFvjocZ8DCl6zRy/Z9fWRgR2dihWya0aBW mMTPpd5bis6k1c7YR4+tsaikPxRh9z8/NyESNoTxs5GkCZUM8e5EkoB9mfUGa0OPp5bq vI4ypjYgoUfYhqj1AaMzqyuF1rXESUcP8prkBq2EUFnqJEx8pM9MnnHYgRtF8UuNBesY +Ykw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704440603; x=1705045403; 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=dE868xNBfi0PhqqrB/NKR+HFo2ZSd9jez98UiAP14BY=; b=rxtx8TinaV+UfvJYKxBjOY8FTo7KTiSGoe3VfzSE+CvHZq/KRBYHYEtmYE3HQ6GE80 tzMDGQ+PDm0QBHgx2OyLglqa9F/tR6lXfIcV5AhhJkRr9Ayea566K5KTHje8IztjqhBm L1KpDcOu/GzZwUVk7MpgnBdwyi+2gDYn5oo0njPsbtQRPE4Vh01i+TZudNnH2S6foyUw yTTUZXE7lZXpzqeAMaKZqjZHWjtW0S4etKKNvrdwzr2HWg7ZZtuPJKvALQwsa6sB4paK EkDXKQ8/7PCTFRSD7rK7AyxD+2aeIeJJuJ/DT/BlxIfRJgRgDHX79KyTiBdYdnFlq9kT ouvA== X-Gm-Message-State: AOJu0Yw72dKYD1XmFlU0liCdWzxcDb1lD/KL+rKNUvybwBa+hARJ/qZf tvWoXXb7xcE4vyyLhYPwDomCCcsNzqp7dAUQCOo= X-Received: by 2002:a2e:3502:0:b0:2cc:de79:2b3b with SMTP id z2-20020a2e3502000000b002ccde792b3bmr931936ljz.44.1704440603311; Thu, 04 Jan 2024 23:43:23 -0800 (PST) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240102175338.62012-1-ryncsn@gmail.com> <20240102175338.62012-3-ryncsn@gmail.com> <87plyhblqe.fsf@yhuang6-desk2.ccr.corp.intel.com> In-Reply-To: <87plyhblqe.fsf@yhuang6-desk2.ccr.corp.intel.com> From: Kairui Song Date: Fri, 5 Jan 2024 15:43:04 +0800 Message-ID: Subject: Re: [PATCH v2 2/9] mm/swap: move no readahead swapin code to a stand-alone helper To: "Huang, Ying" Cc: linux-mm@kvack.org, Andrew Morton , Chris Li , Hugh Dickins , Johannes Weiner , Matthew Wilcox , Michal Hocko , Yosry Ahmed , David Hildenbrand , linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Huang, Ying =E4=BA=8E2024=E5=B9=B41=E6=9C=884=E6=97= =A5=E5=91=A8=E5=9B=9B 15:31=E5=86=99=E9=81=93=EF=BC=9A > > Kairui Song writes: > > > From: Kairui Song > > > > No feature change, simply move the routine to a standalone function to > > be re-used later. The error path handling is copied from the "out_page" > > label, to make the code change minimized for easier reviewing. > > > > Signed-off-by: Kairui Song > > --- > > mm/memory.c | 32 ++++---------------------------- > > mm/swap.h | 8 ++++++++ > > mm/swap_state.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++ > > 3 files changed, 59 insertions(+), 28 deletions(-) > > > > diff --git a/mm/memory.c b/mm/memory.c > > index a0a50d3754f0..0165c8cad489 100644 > > --- a/mm/memory.c > > +++ b/mm/memory.c > > @@ -3803,7 +3803,6 @@ vm_fault_t do_swap_page(struct vm_fault *vmf) > > swp_entry_t entry; > > pte_t pte; > > vm_fault_t ret =3D 0; > > - void *shadow =3D NULL; > > > > if (!pte_unmap_same(vmf)) > > goto out; > > @@ -3867,33 +3866,10 @@ vm_fault_t do_swap_page(struct vm_fault *vmf) > > if (!folio) { > > if (data_race(si->flags & SWP_SYNCHRONOUS_IO) && > > __swap_count(entry) =3D=3D 1) { > > - /* skip swapcache */ > > - folio =3D vma_alloc_folio(GFP_HIGHUSER_MOVABLE, 0= , > > - vma, vmf->address, false)= ; > > - page =3D &folio->page; > > - if (folio) { > > - __folio_set_locked(folio); > > - __folio_set_swapbacked(folio); > > - > > - if (mem_cgroup_swapin_charge_folio(folio, > > - vma->vm_mm, GFP_K= ERNEL, > > - entry)) { > > - ret =3D VM_FAULT_OOM; > > - goto out_page; > > - } > > - mem_cgroup_swapin_uncharge_swap(entry); > > - > > - shadow =3D get_shadow_from_swap_cache(ent= ry); > > - if (shadow) > > - workingset_refault(folio, shadow)= ; > > - > > - folio_add_lru(folio); > > - > > - /* To provide entry to swap_read_folio() = */ > > - folio->swap =3D entry; > > - swap_read_folio(folio, true, NULL); > > - folio->private =3D NULL; > > - } > > + /* skip swapcache and readahead */ > > + folio =3D swapin_direct(entry, GFP_HIGHUSER_MOVAB= LE, vmf); > > + if (folio) > > + page =3D &folio->page; > > } else { > > page =3D swapin_readahead(entry, GFP_HIGHUSER_MOV= ABLE, > > vmf); > > diff --git a/mm/swap.h b/mm/swap.h > > index 758c46ca671e..83eab7b67e77 100644 > > --- a/mm/swap.h > > +++ b/mm/swap.h > > @@ -56,6 +56,8 @@ struct folio *swap_cluster_readahead(swp_entry_t entr= y, gfp_t flag, > > struct mempolicy *mpol, pgoff_t ilx); > > struct page *swapin_readahead(swp_entry_t entry, gfp_t flag, > > struct vm_fault *vmf); > > +struct folio *swapin_direct(swp_entry_t entry, gfp_t flag, > > + struct vm_fault *vmf); > > > > static inline unsigned int folio_swap_flags(struct folio *folio) > > { > > @@ -86,6 +88,12 @@ static inline struct folio *swap_cluster_readahead(s= wp_entry_t entry, > > return NULL; > > } > > > > +struct folio *swapin_direct(swp_entry_t entry, gfp_t flag, > > + struct vm_fault *vmf) > > +{ > > + return NULL; > > +} > > + > > static inline struct page *swapin_readahead(swp_entry_t swp, gfp_t gfp= _mask, > > struct vm_fault *vmf) > > { > > diff --git a/mm/swap_state.c b/mm/swap_state.c > > index e671266ad772..24cb93ed5081 100644 > > --- a/mm/swap_state.c > > +++ b/mm/swap_state.c > > @@ -861,6 +861,53 @@ static struct folio *swap_vma_readahead(swp_entry_= t targ_entry, gfp_t gfp_mask, > > return folio; > > } > > > > +/** > > + * swapin_direct - swap in folios skipping swap cache and readahead > > swap in a folio ... > > > + * @entry: swap entry of this memory > > + * @gfp_mask: memory allocation flags > > + * @vmf: fault information > > + * > > + * Returns the struct folio for entry and addr after the swap entry is= read > > + * in. > > + */ > > +struct folio *swapin_direct(swp_entry_t entry, gfp_t gfp_mask, > > + struct vm_fault *vmf) > > +{ > > + struct vm_area_struct *vma =3D vmf->vma; > > + struct folio *folio; > > + void *shadow =3D NULL; > > + > > + /* skip swapcache */ > > + folio =3D vma_alloc_folio(GFP_HIGHUSER_MOVABLE, 0, > > You passed gfp_mask in, but don't use it. > Thanks, will fix these. > -- > Best Regards, > Huang, Ying