Received: by 2002:ab2:23c8:0:b0:1f2:fdbc:cb93 with SMTP id a8csp114910lqe; Tue, 26 Mar 2024 23:49:49 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUNvJg0zQjbY6jdC1iIToSgkGQJso7YFVkvI9aXdDIUtpZeOtDj316KPuoQOUH86fHEcQxfyrwNZeEee6e6Zpj92aaGcpIhNAHT4Wa6yw== X-Google-Smtp-Source: AGHT+IHnUZQhofWF2baZ9DxVxXu9T8BYvgpv9CeP6PcLjycGzOG7FasQruLZMDY/gZ90igXQwmbb X-Received: by 2002:a05:6214:27c6:b0:696:7f66:279b with SMTP id ge6-20020a05621427c600b006967f66279bmr4245759qvb.13.1711522189727; Tue, 26 Mar 2024 23:49:49 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711522189; cv=pass; d=google.com; s=arc-20160816; b=nfCw3iIvKOPX1o5G7WKrdIp6gEfrt9GgxGNtfI+hofh4Lid+vDFUdDyHzByKNT/FCc n1oi3sqyzS/jCCvMd6eT022wA9Nvn9nBIGyzZvkFChnRb1hAdGj9Sk9gUCooJUP7KvIh hiJtUYr1DUv8vhrIZ4oGps9QO2BWF98ll+dT3BHgJxF6Jmyp1vFPqOSiTj0a77wOmcMk fSLJZ/P8DWpn7DulJoQDQAFa473par/xGH0AJ2sSmaZFmue+pD/fTpIUzpVvpX5s6/wp awZmrwod9yRhGfjeytMYMEEKVvkYHSyBmVBjEzicRWxd3ZN7z2aSrlj/Jqs+0JuZ3+eJ adsg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:user-agent:message-id:date :references:in-reply-to:subject:cc:to:from:dkim-signature; bh=X2RCSLf7ypV2Z1in03ulc0Gi7o9Tn/EfpLBlwrrDqSk=; fh=htf+G5UP1tW33xiaRGgcDGHDwxhlr2HI3+wiE5DfPPA=; b=yAMt56E1U0k8o5PGFhmV/EAkb3ZxQpI886Qw+EMlawRCVMP3xVWD51Sy9LMyDceHB7 vPd3UUx9gJzOx6qaFGuBws9ueTgmRPhBtHrAPdy61KY4WTCBzdBr2GxtSURjYuMfKztz gCm5U0GzXv26C5A4uHhTheGSfN57jldrvdRJV57nu3UuCotOcNvO9gwzqrv+ORm9jP4L ApE76VedeKbG/HQ427L5knrib1xdx5ShdT8Bz/hfL9gDHfz/H/8nvclR6KSdAYeJldQi jg0ZRfqoWzG1l5p9CwI8tr7tbFG1kQsPgZ9lLqn0whn+41BpuKU8umI5j869LByJPIt+ EoTw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=OM7GjAr1; arc=pass (i=1 spf=pass spfdomain=intel.com dkim=pass dkdomain=intel.com dmarc=pass fromdomain=intel.com); spf=pass (google.com: domain of linux-kernel+bounces-120398-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-120398-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id ey7-20020a0562140b6700b00696125ba4a9si662624qvb.432.2024.03.26.23.49.49 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Mar 2024 23:49:49 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-120398-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=OM7GjAr1; arc=pass (i=1 spf=pass spfdomain=intel.com dkim=pass dkdomain=intel.com dmarc=pass fromdomain=intel.com); spf=pass (google.com: domain of linux-kernel+bounces-120398-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-120398-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.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 728281C24504 for ; Wed, 27 Mar 2024 06:49:49 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1B626224CE; Wed, 27 Mar 2024 06:49:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="OM7GjAr1" Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7A1861C11 for ; Wed, 27 Mar 2024 06:49:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.19 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711522183; cv=none; b=dGbsjlQP8wukBwiz3d613bXeWWBfy+xi7pi9mTnE/6CE4ccPCooytQeCbPinGlVHxucHduv5IwcdQYX+a1sJCACeJ/wi8t4TbQ9vqzFfGPueI4uBjr0aD1g7yB7pU/gDBv6t1ndCLEhP16aDQ3FfhVEgm4L9EjCAegIMg6aUW4k= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711522183; c=relaxed/simple; bh=NpBdR2o53eZcSNfBWFivW7bvko295qnK4Dgh0nt/fNc=; h=From:To:Cc:Subject:In-Reply-To:References:Date:Message-ID: MIME-Version:Content-Type; b=byCn5aOTa2QLDgsSNeFX02R4Ghd93+JMluIfyvLkkRDuLSt4hSXAl4bE/EguyW9bawmCqFnWlhYctQ45GBE7xTK5nylSyRTdreSJtDyxFnZFLir0ivp+7Jg7lFa+jwaDgGFUI9zRR1NVKf5vIcWvl5sD5sNOOQXfvjTrWDrpwWs= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=OM7GjAr1; arc=none smtp.client-ip=198.175.65.19 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1711522182; x=1743058182; h=from:to:cc:subject:in-reply-to:references:date: message-id:mime-version:content-transfer-encoding; bh=NpBdR2o53eZcSNfBWFivW7bvko295qnK4Dgh0nt/fNc=; b=OM7GjAr1ocZSg2KQ0tR41dYV+C1SyI07QkFxdp6J1y7ayStrByoajC6B sdoP7eDVKECq9dYlJJGPecDu+Fng3gbNViLmtZRzd7T2DfmgguCsh4jOo ATsRrg2y98YMYmhj51ixA9iqhHtJoG0WipjZuiyYt4PmtEydqFpgxTN9u O+VlVSSqPPr7/MhKWyP/ukdhtJ5BoMFmuLEA0HSS8+Ufltxu4c9FVtJh3 qMfYBbYhvZmqvhJNgiPf+QhI0meHJmeyIZYVKaNixCXsPVylRy2UxlLLn H3cYznEAeNWsig3EzGi6mY0YggzGIHEJ+qtRVejr28V4NiMl6bddU8+ix w==; X-CSE-ConnectionGUID: xIxvcPRxR4aI5QIdJL2YKQ== X-CSE-MsgGUID: Aunz6d88RQKq4oQalBslKw== X-IronPort-AV: E=McAfee;i="6600,9927,11025"; a="6462094" X-IronPort-AV: E=Sophos;i="6.07,158,1708416000"; d="scan'208";a="6462094" Received: from fmviesa007.fm.intel.com ([10.60.135.147]) by orvoesa111.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Mar 2024 23:49:41 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.07,158,1708416000"; d="scan'208";a="16185085" Received: from yhuang6-desk2.sh.intel.com (HELO yhuang6-desk2.ccr.corp.intel.com) ([10.238.208.55]) by fmviesa007-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Mar 2024 23:49:37 -0700 From: "Huang, Ying" To: Kairui Song Cc: linux-mm@kvack.org, Chris Li , Minchan Kim , Barry Song , Ryan Roberts , Yu Zhao , SeongJae Park , David Hildenbrand , Yosry Ahmed , Johannes Weiner , Matthew Wilcox , Nhat Pham , Chengming Zhou , Andrew Morton , linux-kernel@vger.kernel.org Subject: Re: [RFC PATCH 10/10] mm/swap: optimize synchronous swapin In-Reply-To: (Kairui Song's message of "Wed, 27 Mar 2024 14:37:27 +0800") References: <20240326185032.72159-1-ryncsn@gmail.com> <20240326185032.72159-11-ryncsn@gmail.com> <87zfukmbwz.fsf@yhuang6-desk2.ccr.corp.intel.com> Date: Wed, 27 Mar 2024 14:47:43 +0800 Message-ID: <87r0fwmar4.fsf@yhuang6-desk2.ccr.corp.intel.com> User-Agent: Gnus/5.13 (Gnus v5.13) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Kairui Song writes: > On Wed, Mar 27, 2024 at 2:24=E2=80=AFPM Huang, Ying wrote: >> >> Kairui Song writes: >> >> > From: Kairui Song >> > >> > Interestingly the major performance overhead of synchronous is actually >> > from the workingset nodes update, that's because synchronous swap in >> >> If it's the major overhead, why not make it the first optimization? > > This performance issue became much more obvious after doing other > optimizations, and other optimizations are for general swapin not only > for synchronous swapin, that's also how I optimized things step by > step, so I kept my patch order... > > And it is easier to do this after Patch 8/10 which introduces the new > interface for swap cache. > >> >> > keeps adding single folios into a xa_node, making the node no longer >> > a shadow node and have to be removed from shadow_nodes, then remove >> > the folio very shortly and making the node a shadow node again, >> > so it has to add back to the shadow_nodes. >> >> The folio is removed only if should_try_to_free_swap() returns true? >> >> > Mark synchronous swapin folio with a special bit in swap entry embedded >> > in folio->swap, as we still have some usable bits there. Skip workings= et >> > node update on insertion of such folio because it will be removed very >> > quickly, and will trigger the update ensuring the workingset info is >> > eventual consensus. >> >> Is this safe? Is it possible for the shadow node to be reclaimed after >> the folio are added into node and before being removed? > > If a xa node contains any non-shadow entry, it can't be reclaimed, > shadow_lru_isolate will check and skip such nodes in case of race. In shadow_lru_isolate(), /* * The nodes should only contain one or more shadow entries, * no pages, so we expect to be able to remove them all and * delete and free the empty node afterwards. */ if (WARN_ON_ONCE(!node->nr_values)) goto out_invalid; if (WARN_ON_ONCE(node->count !=3D node->nr_values)) goto out_invalid; So, this isn't considered normal and will cause warning now. >> >> If so, we may consider some other methods. Make shadow_nodes per-cpu? > > That's also an alternative solution if there are other risks. This appears a general optimization and more clean. -- Best Regards, Huang, Ying